1 #define BOOST_TEST_MODULE ArmarX::RobotTrajectoryDesigner::DesignerTrajectoryManager
2 #define ARMARX_BOOST_TEST
5 #include <RobotComponents/Test.h>
6 #include "../Manager/DesignerTrajectoryManager.h"
7 #include <VirtualRobot/XML/RobotIO.h>
8 #include "../Util/OrientationConversion.h"
9 #include "../Interpolation/LinearInterpolation.h"
22 QuaternionBasePtr ori;
27 float qw,
float qx,
float qy,
float qz)
30 posePkg.
pos = Vector3BasePtr(
new Vector3(x, y, z));
31 posePkg.
ori = QuaternionBasePtr(
new Quaternion(qw, qx, qy, qz));
32 PoseBasePtr tmp = PoseBasePtr(
new Pose(posePkg.
pos, posePkg.
ori));
39 return floor(d * pow10(accuracy)) / pow10(accuracy);
47 if (
roundTo(p1->position->x, accuracy) !=
roundTo(p2->position->x, accuracy))
51 if (
roundTo(p1->position->y, accuracy) !=
roundTo(p2->position->y, accuracy))
55 if (
roundTo(p1->position->z, accuracy) !=
roundTo(p2->position->z, accuracy))
61 if (
roundTo(p1->orientation->qw, accuracy) !=
roundTo(p2->orientation->qw, accuracy))
66 if (
roundTo(p1->orientation->qx, accuracy) !=
roundTo(p2->orientation->qx, accuracy))
71 if (
roundTo(p1->orientation->qy, accuracy) !=
roundTo(p2->orientation->qy, accuracy))
75 if (
roundTo(p1->orientation->qz, accuracy) !=
roundTo(p2->orientation->qz, accuracy))
86 if (t1->dim() != t2->dim())
92 for (
unsigned int dim = 0; dim < t1->dim(); dim++)
94 if (t1->getDimensionData(dim) != t2->getDimensionData(dim))
101 if (t1->getTimestamps() != t2->getTimestamps())
118 if (u1->getJointAngles() != u2->getJointAngles())
124 if (u1->getIKSelection() != u2->getIKSelection())
130 if (u1->getIsTimeOptimalBreakpoint() != u2->getIsTimeOptimalBreakpoint())
136 if (u1->getTimeOptimalTimestamp() != u2->getTimeOptimalTimestamp())
142 if (u1->getUserTimestamp() != u2->getUserTimestamp())
165 if (t1->getTimeOptimalDuration() != t2->getTimeOptimalDuration())
171 if (t1->getUserDuration() != t2->getUserDuration())
177 if (t1->getInterpolationType() != t2->getInterpolationType())
194 std::vector<armarx::TrajectoryPtr> dt1_interBPT = dt1->getInterBreakpointTrajectories();
195 std::vector<armarx::TrajectoryPtr> dt2_interBPT = dt2->getInterBreakpointTrajectories();
196 if (dt1_interBPT.size() != dt2_interBPT.size())
201 for (
unsigned int i = 0; i < dt1_interBPT.size(); i++)
210 std::vector<UserWaypointPtr> dt1_uwp = dt1->getAllUserWaypoints();
211 std::vector<UserWaypointPtr> dt2_uwp = dt2->getAllUserWaypoints();
212 if (dt1_uwp.size() != dt2_uwp.size())
217 for (
unsigned int i = 0; i < dt1_uwp.size(); i++)
228 for (
unsigned int i = 0; i < dt1_uwp.size() - 1; i++)
237 if (dt1->getRns()->getName() != dt2->getRns()->getName())
249 robot->getRobotNodeSet(rnsName)->getKinematicRoot()->toLocalCoordinateSystem(
250 (
new Pose(pose->position, pose->orientation))->toEigen())));
255 PosePkg pp4 =
createPosePkg(-316.302246093750, 777.949218750, 1194.246459960938, 0.5907033681869507, -0.5503066778182983, 0.4992305040359497, 0.3146440684795380);
256 PosePkg pp2 =
createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
264 PosePkg pp4_1 =
createPosePkg(-316.302246093, 777.9492187, 1194.246459960746, 0.5907046681869507, -0.55030667789183983, 0.4992304564358497, 0.3146440488984465480);
271 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
276 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
280 robot = RobotIO::loadRobot(
281 "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
286 VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSets()[10];
292 0.6987, 0.1106, 0.7, -0.0969);
294 vector<double> pp1_r_ja = {0.0540, 0.0398, 0.3851, 0.1253, -0.2440, 0.1100, -0.0342};
299 environment->setRobot(robot);
305 BOOST_CHECK_THROW(m->addWaypoint(pp1_r.
pose), NotInitializedException);
306 BOOST_CHECK_THROW(m->insertWaypoint(0, pp1_r.
pose), NotInitializedException);
307 BOOST_CHECK_THROW(m->editWaypointPoseBase(0, pp1_r.
pose), NotInitializedException);
308 BOOST_CHECK_THROW(m->editWaypointIKSelection(0, ikSelection), NotInitializedException);
309 BOOST_CHECK_THROW(m->deleteWaypoint(0), NotInitializedException);
310 BOOST_CHECK_THROW(m->setTransitionInterpolation(0, interpolationType), NotInitializedException);
311 BOOST_CHECK_THROW(m->setWaypointAsBreakpoint(0,
true), NotInitializedException);
312 BOOST_CHECK_THROW(m->setTransitionUserDuration(0, 10.0), NotInitializedException);
318 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
323 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
327 robot = RobotIO::loadRobot(
328 "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
334 VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSets()[10];
338 environment->setRobot(robot);
342 std::vector<double> p1ja = { 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
344 PosePkg pp4 =
createPosePkg(-316.302246093750, 777.949218750, 1194.246459960938, 0.5907033681869507, -0.5503066778182983, 0.4992305040359497, 0.3146440684795380);
345 PosePkg pp2 =
createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
346 PosePkg pp3 =
createPosePkg(-226.792480468750, 580.723144531250, 1186.157348632812, 0.4336481690406799, -0.4273631870746613, 0.5638203620910645, 0.5580471754074097);
347 PosePkg pp5 =
createPosePkg(-348.304718, 580.476440, 712.264465, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
349 std::string rnsName = rns->getName();
350 PoseBasePtr p1 =
poseToLocal(kc->doForwardKinematic(rns, p1ja), robot, rnsName);
359 dtm->initializeDesignerTrajectory(p1ja);
363 BOOST_CHECK_EQUAL(p1ja,
dt->getUserWaypoint(0)->getJointAngles());
368 dtm->addWaypoint(p2);
369 dtm->insertWaypoint(1, p3);
370 dtm->insertWaypoint(0, p4);
373 dt = dtm->getDesignerTrajectory();
379 BOOST_CHECK(
dt->getUserWaypoint(0)->getTimeOptimalTimestamp() == 0);
382 BOOST_CHECK(
dt->getUserWaypoint(1)->getTimeOptimalTimestamp() != 0);
383 BOOST_CHECK(
dt->getUserWaypoint(2)->getTimeOptimalTimestamp() != 0);
384 BOOST_CHECK(
dt->getUserWaypoint(3)->getTimeOptimalTimestamp() != 0);
387 BOOST_CHECK(
dt->getUserWaypoint(0)->getJointAngles().size() != 0);
388 BOOST_CHECK(
dt->getUserWaypoint(1)->getJointAngles().size() != 0);
389 BOOST_CHECK(
dt->getUserWaypoint(2)->getJointAngles().size() != 0);
390 BOOST_CHECK(
dt->getUserWaypoint(3)->getJointAngles().size() != 0);
394 BOOST_CHECK_EQUAL(
dt->getTransition(0)->getTimeOptimalDuration(),
395 dt->getTransition(0)->getEnd()->getTimeOptimalTimestamp()
396 -
dt->getTransition(0)->getStart()->getTimeOptimalTimestamp());
398 BOOST_CHECK_EQUAL(
dt->getTransition(1)->getTimeOptimalDuration(),
399 dt->getTransition(1)->getEnd()->getTimeOptimalTimestamp()
400 -
dt->getTransition(1)->getStart()->getTimeOptimalTimestamp());
402 BOOST_CHECK_EQUAL(
dt->getTransition(2)->getTimeOptimalDuration(),
403 dt->getTransition(2)->getEnd()->getTimeOptimalTimestamp()
404 -
dt->getTransition(2)->getStart()->getTimeOptimalTimestamp());
406 BOOST_CHECK(
dt->getTimeOptimalTrajectory()->size() > 1);
409 dtm->setTransitionUserDuration(0, 5.0);
410 dt = dtm->getDesignerTrajectory();
411 BOOST_CHECK(
dt->getUserWaypoint(0)->getUserTimestamp() == 0);
412 BOOST_CHECK(
dt->getUserWaypoint(1)->getUserTimestamp() == 5);
413 BOOST_CHECK(
dt->getUserWaypoint(2)->getUserTimestamp() > 5);
414 BOOST_CHECK(
dt->getUserWaypoint(3)->getUserTimestamp() > 5);
416 dtm->setTransitionUserDuration(1, 10.0);
417 dt = dtm->getDesignerTrajectory();
419 BOOST_CHECK(
dt->getUserWaypoint(0)->getUserTimestamp() == 0.0);
420 BOOST_CHECK(
dt->getUserWaypoint(1)->getUserTimestamp() == 5.0);
421 BOOST_CHECK(
dt->getUserWaypoint(2)->getUserTimestamp() == 15.0);
422 BOOST_CHECK(
dt->getUserWaypoint(3)->getUserTimestamp() > 15.0);
424 dtm->setTransitionUserDuration(2, 15.0);
425 dt = dtm->getDesignerTrajectory();
427 BOOST_CHECK(
dt->getUserWaypoint(0)->getUserTimestamp() == 0.0);
428 BOOST_CHECK(
dt->getUserWaypoint(1)->getUserTimestamp() == 5.0);
429 BOOST_CHECK(
dt->getUserWaypoint(2)->getUserTimestamp() == 15.0);
430 BOOST_CHECK(
dt->getUserWaypoint(3)->getUserTimestamp() == 30.0);
435 dtm->deleteWaypoint(0);
436 dtm->deleteWaypoint(0);
437 dtm->deleteWaypoint(0);
438 dtm->deleteWaypoint(0);
440 BOOST_CHECK(dtm->getIsInitialized() ==
false);
446 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
451 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
455 robot = RobotIO::loadRobot(
456 "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
462 VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSets()[10];
466 environment->setRobot(robot);
470 std::vector<double> p1ja = { 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
472 PosePkg pp4 =
createPosePkg(-316.302246093750, 777.949218750, 1194.246459960938, 0.5907033681869507, -0.5503066778182983, 0.4992305040359497, 0.3146440684795380);
473 PosePkg pp2 =
createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
474 PosePkg pp3 =
createPosePkg(-226.792480468750, 580.723144531250, 1186.157348632812, 0.4336481690406799, -0.4273631870746613, 0.5638203620910645, 0.5580471754074097);
475 PosePkg pp5 =
createPosePkg(-348.304718, 580.476440, 712.264465, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
477 std::string rnsName = rns->getName();
478 PoseBasePtr p1 =
poseToLocal(kc->doForwardKinematic(rns, p1ja), robot, rnsName);
486 dtm->initializeDesignerTrajectory(p1ja);
491 dtm->addWaypoint(p2);
492 dtm->addWaypoint(p3);
496 dtm->addWaypoint(p4);
515 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
520 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
524 robot = RobotIO::loadRobot(
525 "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
531 VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSets()[10];
535 environment->setRobot(robot);
539 std::vector<double> p1ja = { 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
541 PosePkg pp4 =
createPosePkg(-316.302246093750, 777.949218750, 1194.246459960938, 0.5907033681869507, -0.5503066778182983, 0.4992305040359497, 0.3146440684795380);
542 PosePkg pp2 =
createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
543 PosePkg pp3 =
createPosePkg(-226.792480468750, 580.723144531250, 1186.157348632812, 0.4336481690406799, -0.4273631870746613, 0.5638203620910645, 0.5580471754074097);
544 PosePkg pp5 =
createPosePkg(-348.304718, 580.476440, 712.264465, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
546 PoseBasePtr p1 = kc->doForwardKinematic(rns, p1ja);
547 std::string rnsName = rns->getName();
556 dtm->initializeDesignerTrajectory(p1ja);
561 dtm->addWaypoint(p2);
564 dtm->addWaypoint(p3);
579 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
584 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
588 robot = RobotIO::loadRobot(
589 "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
595 VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSets()[10];
599 environment->setRobot(robot);
603 std::vector<double> p1ja = { 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
605 PosePkg pp4 =
createPosePkg(-316.302246093750, 777.949218750, 1194.246459960938, 0.5907033681869507, -0.5503066778182983, 0.4992305040359497, 0.3146440684795380);
606 PosePkg pp2 =
createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
607 PosePkg pp3 =
createPosePkg(-226.792480468750, 580.723144531250, 1186.157348632812, 0.4336481690406799, -0.4273631870746613, 0.5638203620910645, 0.5580471754074097);
608 PosePkg pp5 =
createPosePkg(-348.304718, 580.476440, 712.264465, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
610 std::string rnsName = rns->getName();
611 PoseBasePtr p1 =
poseToLocal(kc->doForwardKinematic(rns, p1ja), robot, rnsName);
620 dtm->initializeDesignerTrajectory(p1ja);
621 dtm->addWaypoint(p2);
622 dtm->addWaypoint(p3);
627 dtm->setWaypointAsBreakpoint(2,
true);
629 BOOST_CHECK_NO_THROW(dtm->addWaypoint(p4));