3 #include <SimoxUtility/algorithm/string.h>
4 #include <SimoxUtility/meta/EnumNames.hpp>
5 #include <SimoxUtility/math/pose/invert.h>
7 #include <VirtualRobot/Robot.h>
8 #include <VirtualRobot/XML/RobotIO.h>
9 #include <VirtualRobot/IK/CompositeDiffIK/CompositeDiffIK.h>
10 #include <VirtualRobot/IK/CompositeDiffIK/ManipulabilityNullspaceGradient.h>
11 #include <VirtualRobot/IK/CompositeDiffIK/SoechtingNullspaceGradient.h>
70 std::vector<std::string> options;
78 .contextMenu(options));
95 case viz::InteractionFeedbackType::ContextMenuChosen:
134 std::map<std::string, float> jointValues;
136 for (
const auto& rn :
nodeSet->getAllRobotNodes())
138 jointValues[rn->getName()] = result.
jointValues(i);
142 robot.
robot->setJointValues(jointValues);
154 const float jointLimitAvoidance = 0;
155 const float kGainManipulabilityAsNullspace = 0.01;
156 const float kSoechtingAsNullspace = 0.0;
157 const int steps = 100;
159 VirtualRobot::CompositeDiffIK ik(
nodeSet);
162 const bool ori =
true;
163 VirtualRobot::CompositeDiffIK::TargetPtr target1 = ik.addTarget(
167 if (jointLimitAvoidance > 0)
169 VirtualRobot::CompositeDiffIK::NullspaceJointLimitAvoidancePtr nsjla(
170 new VirtualRobot::CompositeDiffIK::NullspaceJointLimitAvoidance(
nodeSet));
171 nsjla->kP = jointLimitAvoidance;
172 for (
auto node :
nodeSet->getAllRobotNodes())
174 if (node->isLimitless())
176 nsjla->setWeight(node->getName(), 0);
179 ik.addNullspaceGradient(nsjla);
182 VirtualRobot::NullspaceManipulabilityPtr nsman =
nullptr;
183 if (kGainManipulabilityAsNullspace > 0)
186 std::cout <<
"Adding manipulability as nullspace target" << std::endl;
187 auto manipTracking = getManipulabilityTracking(
nodeSet,
nullptr);
190 std::cout <<
"Manip tracking zero!" << std::endl;
193 Eigen::MatrixXd followManip = readFollowManipulability();
194 if (followManip.rows() != manipTracking->getTaskVars())
196 std::cout <<
"Wrong manipulability matrix!" << std::endl;
199 nsman = VirtualRobot::NullspaceManipulabilityPtr(
new VirtualRobot::NullspaceManipulability(manipTracking, followManip, Eigen::MatrixXd(),
true));
200 nsman->kP = kGainManipulabilityAsNullspace;
201 ik.addNullspaceGradient(nsman);
205 if (kSoechtingAsNullspace > 0)
207 if (robot.
robot->getName() ==
"Armar6" and
nodeSet->getName() ==
"RightArm")
209 std::cout <<
"Adding soechting nullspace" << std::endl;
210 VirtualRobot::SoechtingNullspaceGradient::ArmJoints armjoints;
211 armjoints.clavicula = robot.
robot->getRobotNode(
"ArmR1_Cla1");
212 armjoints.shoulder1 = robot.
robot->getRobotNode(
"ArmR2_Sho1");
213 armjoints.shoulder2 = robot.
robot->getRobotNode(
"ArmR3_Sho2");
214 armjoints.shoulder3 = robot.
robot->getRobotNode(
"ArmR4_Sho3");
215 armjoints.elbow = robot.
robot->getRobotNode(
"ArmR5_Elb1");
217 auto gradient = std::make_shared<VirtualRobot::SoechtingNullspaceGradient>(
218 target1,
"ArmR2_Sho1", VirtualRobot::Soechting::ArmType::Right, armjoints);
220 gradient->kP = kSoechtingAsNullspace;
221 ik.addNullspaceGradient(gradient);
223 else if (robot.
robot->getName() ==
"Armar6" and
nodeSet->getName() ==
"LeftArm")
225 std::cout <<
"Adding soechting nullspace" << std::endl;
226 VirtualRobot::SoechtingNullspaceGradient::ArmJoints armjoints;
227 armjoints.clavicula = robot.
robot->getRobotNode(
"ArmL1_Cla1");
228 armjoints.shoulder1 = robot.
robot->getRobotNode(
"ArmL2_Sho1");
229 armjoints.shoulder2 = robot.
robot->getRobotNode(
"ArmL3_Sho2");
230 armjoints.shoulder3 = robot.
robot->getRobotNode(
"ArmL4_Sho3");
231 armjoints.elbow = robot.
robot->getRobotNode(
"ArmL5_Elb1");
233 auto gradient = std::make_shared<VirtualRobot::SoechtingNullspaceGradient>(
235 gradient->kP = kSoechtingAsNullspace;
236 ik.addNullspaceGradient(gradient);
240 ARMARX_INFO <<
"Soechting currently supports only Armar6 and RightArm/LeftArm robot node set "
241 "for first robot node set for demonstration purposes.";
246 VirtualRobot::CompositeDiffIK::Parameters cp;
247 cp.resetRnsValues =
false;
248 cp.returnIKSteps =
true;
250 VirtualRobot::CompositeDiffIK::SolveState state;
254 while (i < steps or (steps < 0 and not ik.getLastResult().reached and i < 1000))
256 ik.step(cp, state, i);
260 if (ik.getLastResult().reached)
263 robot.
robot->setJointValues(ik.getRobotNodeSet()->getJointValueMap());
276 VirtualRobot::RobotNodePtr
tcp;
299 VirtualRobot::RobotNodePtr
root;
314 robotFile(
"armar6_rt/robotmodel/Armar6-SH/Armar6-SH.xml"),
315 robotNodeSetNamesStr(
simox::alg::join({
"LeftArm",
"RightArm"},
"; "))
330 "The ArmarX data path to the robot XML file."
331 "\n For ARMAR-III: 'RobotAPI/robots/Armar3/ArmarIII.xml'"
332 "\n For ARMAR-6: 'armar6_rt/robotmodel/Armar6-SH/Armar6-SH.xml'"
335 "Names of robot node sets for TCPs.");
357 std::unique_ptr<PlatformManipulator> manip = std::make_unique<PlatformManipulator>();
359 manip->gizmo.initial = root->getGlobalPose();
369 const auto& rns =
robot.
robot->getRobotNodeSet(rnsName);
370 const auto tcp = rns->getTCP();
373 std::unique_ptr<TcpManipulator> manip = std::make_unique<TcpManipulator>();
375 manip->gizmo.initial = tcp->getGlobalPose();
377 manip->nodeSet = rns;
409 bool updated =
false;
414 updated |= manip->handle(inter, &
stage);