3 #include <SimoxUtility/algorithm/string.h>
4 #include <SimoxUtility/math/pose/invert.h>
5 #include <SimoxUtility/meta/EnumNames.hpp>
6 #include <VirtualRobot/IK/CompositeDiffIK/CompositeDiffIK.h>
7 #include <VirtualRobot/IK/CompositeDiffIK/ManipulabilityNullspaceGradient.h>
8 #include <VirtualRobot/IK/CompositeDiffIK/SoechtingNullspaceGradient.h>
9 #include <VirtualRobot/Robot.h>
10 #include <VirtualRobot/RobotNodeSet.h>
11 #include <VirtualRobot/XML/RobotIO.h>
69 std::vector<std::string> options;
96 case viz::InteractionFeedbackType::ContextMenuChosen:
139 std::map<std::string, float> jointValues;
141 for (
const auto& rn :
nodeSet->getAllRobotNodes())
143 jointValues[rn->getName()] = result.
jointValues(i);
147 robot.
robot->setJointValues(jointValues);
160 const float jointLimitAvoidance = 0;
161 const float kGainManipulabilityAsNullspace = 0.01;
162 const float kSoechtingAsNullspace = 0.0;
163 const int steps = 100;
165 VirtualRobot::CompositeDiffIK ik(
nodeSet);
168 const bool ori =
true;
169 VirtualRobot::CompositeDiffIK::TargetPtr target1 = ik.addTarget(
175 if (jointLimitAvoidance > 0)
177 VirtualRobot::CompositeDiffIK::NullspaceJointLimitAvoidancePtr nsjla(
178 new VirtualRobot::CompositeDiffIK::NullspaceJointLimitAvoidance(
180 nsjla->kP = jointLimitAvoidance;
181 for (
auto node :
nodeSet->getAllRobotNodes())
183 if (node->isLimitless())
185 nsjla->setWeight(node->getName(), 0);
188 ik.addNullspaceGradient(nsjla);
191 VirtualRobot::NullspaceManipulabilityPtr nsman =
nullptr;
192 if (kGainManipulabilityAsNullspace > 0)
195 std::cout <<
"Adding manipulability as nullspace target" << std::endl;
196 auto manipTracking = getManipulabilityTracking(
nodeSet,
nullptr);
199 std::cout <<
"Manip tracking zero!" << std::endl;
202 Eigen::MatrixXd followManip = readFollowManipulability();
203 if (followManip.rows() != manipTracking->getTaskVars())
205 std::cout <<
"Wrong manipulability matrix!" << std::endl;
208 nsman = VirtualRobot::NullspaceManipulabilityPtr(
new VirtualRobot::NullspaceManipulability(manipTracking, followManip, Eigen::MatrixXd(),
true));
209 nsman->kP = kGainManipulabilityAsNullspace;
210 ik.addNullspaceGradient(nsman);
214 if (kSoechtingAsNullspace > 0)
216 if (robot.
robot->getName() ==
"Armar6" and
nodeSet->getName() ==
"RightArm")
218 std::cout <<
"Adding soechting nullspace" << std::endl;
219 VirtualRobot::SoechtingNullspaceGradient::ArmJoints armjoints;
220 armjoints.clavicula = robot.
robot->getRobotNode(
"ArmR1_Cla1");
221 armjoints.shoulder1 = robot.
robot->getRobotNode(
"ArmR2_Sho1");
222 armjoints.shoulder2 = robot.
robot->getRobotNode(
"ArmR3_Sho2");
223 armjoints.shoulder3 = robot.
robot->getRobotNode(
"ArmR4_Sho3");
224 armjoints.elbow = robot.
robot->getRobotNode(
"ArmR5_Elb1");
227 std::make_shared<VirtualRobot::SoechtingNullspaceGradient>(
230 VirtualRobot::Soechting::ArmType::Right,
233 gradient->kP = kSoechtingAsNullspace;
234 ik.addNullspaceGradient(gradient);
236 else if (robot.
robot->getName() ==
"Armar6" and
237 nodeSet->getName() ==
"LeftArm")
239 std::cout <<
"Adding soechting nullspace" << std::endl;
240 VirtualRobot::SoechtingNullspaceGradient::ArmJoints armjoints;
241 armjoints.clavicula = robot.
robot->getRobotNode(
"ArmL1_Cla1");
242 armjoints.shoulder1 = robot.
robot->getRobotNode(
"ArmL2_Sho1");
243 armjoints.shoulder2 = robot.
robot->getRobotNode(
"ArmL3_Sho2");
244 armjoints.shoulder3 = robot.
robot->getRobotNode(
"ArmL4_Sho3");
245 armjoints.elbow = robot.
robot->getRobotNode(
"ArmL5_Elb1");
248 std::make_shared<VirtualRobot::SoechtingNullspaceGradient>(
253 gradient->kP = kSoechtingAsNullspace;
254 ik.addNullspaceGradient(gradient);
258 ARMARX_INFO <<
"Soechting currently supports only Armar6 and "
259 "RightArm/LeftArm robot node set "
260 "for first robot node set for demonstration purposes.";
266 cp.resetRnsValues =
false;
267 cp.returnIKSteps =
true;
269 VirtualRobot::CompositeDiffIK::SolveState state;
274 (steps < 0 and not ik.getLastResult().reached and i < 1000))
276 ik.step(cp, state, i);
280 if (ik.getLastResult().reached)
283 robot.
robot->setJointValues(ik.getRobotNodeSet()->getJointValueMap());
296 VirtualRobot::RobotNodePtr
tcp;
321 VirtualRobot::RobotNodePtr
root;
333 robotFile(
"armar6_rt/robotmodel/Armar6-SH/Armar6-SH.xml"),
334 robotNodeSetNamesStr(
simox::alg::join({
"LeftArm",
"RightArm"},
"; "))
338 std::vector<std::string>
350 "The ArmarX data path to the robot XML file."
351 "\n For ARMAR-III: 'RobotAPI/robots/Armar3/ArmarIII.xml'"
352 "\n For ARMAR-6: 'armar6_rt/robotmodel/Armar6-SH/Armar6-SH.xml'");
354 "p.robotNodeSetNames",
355 "Names of robot node sets for TCPs.");
366 VirtualRobot::RobotIO::eStructure);
378 std::unique_ptr<PlatformManipulator> manip = std::make_unique<PlatformManipulator>();
380 manip->gizmo.initial = root->getGlobalPose();
389 <<
VAROUT(rnsName) <<
" must exist.";
391 const auto& rns =
robot.
robot->getRobotNodeSet(rnsName);
392 const auto tcp = rns->getTCP();
395 std::unique_ptr<TcpManipulator> manip = std::make_unique<TcpManipulator>();
397 manip->gizmo.initial = tcp->getGlobalPose();
399 manip->nodeSet = rns;
431 bool updated =
false;
436 updated |= manip->handle(inter, &
stage);