1 #define BOOST_TEST_MODULE ArmarX::RobotTrajectoryDesigner::KinematicSolver
2 #define ARMARX_BOOST_TEST
5 #include <RobotComponents/Test.h>
10 #include "../KinematicSolver.h"
12 #include <VirtualRobot/XML/RobotIO.h>
14 #include "../Util/OrientationConversion.h"
16 #include "../Interpolation/LinearInterpolation.h"
18 #include "../Interpolation/InterpolationSegmentFactory.h"
35 QuaternionBasePtr ori;
40 float qw,
float qx,
float qy,
float qz)
43 posePkg.
pos = Vector3BasePtr(
new Vector3(x, y, z));
44 posePkg.
ori = QuaternionBasePtr(
new Quaternion(qw, qx, qy, qz));
45 PoseBasePtr tmp = PoseBasePtr(
new Pose(posePkg.
pos, posePkg.
ori));
52 if (current->orientation->qw - other->orientation->qw > delta && other->orientation->qw - current->orientation->qw > delta)
56 if (current->orientation->qx - other->orientation->qx > delta && other->orientation->qx - current->orientation->qx > delta)
60 if (current->orientation->qy - other->orientation->qy > delta && other->orientation->qy - current->orientation->qy > delta)
64 if (current->orientation->qz - other->orientation->qz > delta && other->orientation->qz - current->orientation->qz > delta)
68 if (current->position->x - other->position->x > delta && other->position->x - current->position->x > delta)
72 if (current->position->y - other->position->y > delta && other->position->y - current->position->y > delta)
76 if (current->position->z - other->position->z > delta && other->position->z - current->position->z > delta)
88 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
93 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
96 vector<double>
v = {2, 3, 4, 5, 0, 1, 2, 3, 3, 4};
97 ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"),
v);
106 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
111 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
113 std::cout << robot->getRobotNodeSet(
"TorsoRightArm")->getAllRobotNodes().size();
115 ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"), {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
117 ks2->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"), {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
119 ks2->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"), {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
122 ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"), {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
132 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
137 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
141 PoseBasePtr result = ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoLeftArm"), ks1->solveIK(robot->getRobotNodeSet(
"TorsoLeftArm"), pose,
IKSolver::CartesianSelection::Position, 50));
142 BOOST_CHECK_CLOSE(pose->position->x, result->position->x, 1);
143 BOOST_CHECK_CLOSE(pose->position->y, result->position->y, 1);
144 BOOST_CHECK_CLOSE(pose->position->z, result->position->z, 1);
171 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
176 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
179 Vector3BasePtr pos1 =
new Vector3(-100, 700, 1000);
181 PoseBasePtr pose1 =
new Pose(pos1, ori1);
183 Vector3BasePtr pos2 =
new Vector3(0, 600, 1400);
185 PoseBasePtr pose2 =
new Pose(pos2, ori2);
188 Vector3BasePtr pos3 =
new Vector3(-250, 700, 1350);
190 PoseBasePtr pose3 =
new Pose(pos3, ori3);
192 std::vector<PoseBasePtr> cp = {pose1, pose2, pose3};
196 std::vector<PoseBasePtr> myPoints = std::vector<PoseBasePtr>();
197 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
198 for (
double d = 0; d < 1; d = d + 0.01f)
200 myPoints.push_back(ip->getPoseAt(d));
201 mySelection.push_back(IKSolver::CartesianSelection::All);
203 std::vector<std::vector<double>> result = ks->solveRecursiveIK(robot->getRobotNodeSet(
"TorsoLeftArm"), ks->solveIK(robot->getRobotNodeSet(
"TorsoLeftArm"), pose1,
IKSolver::CartesianSelection::Position, 50), myPoints, mySelection);
296 std::vector<double> ja = { 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
297 PosePkg p1 =
createPosePkg(-348.304718, 580.476440, 712.264465, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
298 PosePkg p2 =
createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
299 PosePkg p3 =
createPosePkg(-226.792480468750, 580.723144531250, 1186.157348632812, 0.4336481690406799, -0.4273631870746613, 0.5638203620910645, 0.5580471754074097);
302 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
303 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
306 for (
int i = 0; i < 100; i++)
308 poses.push_back(current->getPoseAt(i / 100.0));
309 std::cout <<
std::to_string(current->getPoseAt(i / 100.0)->position->x) +
"\n";
315 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
320 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
324 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
325 std::vector<std::vector<double>> result = ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
326 for (vector<double> tempResult : result)
328 for (
double angle : tempResult)
412 std::vector<double> ja = { -0.818259, 0.428277, 0.136299, -0.608422, 1.064518, -0.227969, -0.289433};
413 PosePkg p1 =
createPosePkg(-337.719116, 927.767395, 907.007935, -0.03198593109846115, 0.01920612715184689, 0.7076730132102966, 0.7055543065071106);
414 PosePkg p2 =
createPosePkg(-290.5917968750, 636.383300781250, 1363.315063476562, 0.6405168175697327, -0.3970025181770325, -0.3363495767116547, -0.5647976398468018);
415 PosePkg p3 =
createPosePkg(-316.302246093750, 777.949218750, 1194.246459960938, 0.5907033681869507, -0.5503066778182983, 0.4992305040359497, 0.3146440684795380);
418 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
419 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
422 for (
int i = 0; i < 50; i++)
424 poses.push_back(current->getPoseAt(i / 50.0));
430 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
435 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
439 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
441 std::vector<std::vector<double>> result = ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
442 for (vector<double> tempResult : result)
444 for (
double angle : tempResult)
448 std::cout <<
"----------------------------------\n";
508 std::vector<double> ja = { 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
509 PosePkg p1 =
createPosePkg(-348.304718, 580.476440, 712.264465, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
510 PosePkg p2 =
createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
513 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
514 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
517 for (
int i = 0; i < 50; i++)
519 poses.push_back(current->getPoseAt(i / 50.0));
526 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
531 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
535 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
536 std::vector<std::vector<double>> result = ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
537 for (vector<double> tempResult : result)
539 for (
double angle : tempResult)
543 std::cout <<
"----------------------------------\n";
604 std::vector<double> ja = { -0.763830, -0.244323, 0.619645, -0.281197, 0.040509, 0.444159, 0.536926};
605 PosePkg p1 =
createPosePkg(4.825809, 788.516541, 1083.528442, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
606 PosePkg p2 =
createPosePkg(-93.015136718750, 784.5754394531250, 500.448608398438, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
609 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
610 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
613 for (
int i = 0; i < 50; i++)
615 poses.push_back(current->getPoseAt(i / 50.0));
616 std::cout <<
std::to_string(current->getPoseAt(i / 50.0)->position->x) +
"\n";
622 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
627 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
631 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
719 std::vector<double> ja = { -0.763830, -0.244323, 0.619645, -0.281197, 0.040509, 0.444159, 0.536926};
720 PosePkg p1 =
createPosePkg(4.825809, 788.516541, 1083.528442, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
721 PosePkg p2 =
createPosePkg(-93.015136718750, 784.5754394531250, 500.448608398438, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
722 PosePkg p3 =
createPosePkg(4.825809, 788.516541, 1083.528442, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
726 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
727 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
730 for (
int i = 0; i < 50; i++)
732 poses.push_back(current->getPoseAt(i / 50.0));
738 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
743 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
747 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
793 std::vector<double> ja = { 0.315176, -0.0275324, 1.00421, 0.0182586, 0.127499, -0.0255035, -0.299747};
794 PosePkg p1 =
createPosePkg(56.5798, 233.545, 992.508, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
795 PosePkg p2 =
createPosePkg(-95.4907, 761.478, 1208.03, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
799 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
800 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
803 for (
int i = 0; i < 50; i++)
805 poses.push_back(current->getPoseAt(i / 50.0));
812 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
817 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
821 PoseBasePtr result2 = ks->doForwardKinematic(robot->getRobotNodeSet(
"LeftArm"), ja);
823 std::vector<std::vector<double>> result = ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
874 std::vector<double> ja = { -0.0475329, -0.0275045, 0.790436, -0.205607, 0.561071, -0.322912, -0.256206};
875 PosePkg p1 =
createPosePkg(3.02088, 389.723, 938.033, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
877 PosePkg p2 =
createPosePkg(-167.276, -187.905, 999.493, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);
880 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
881 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
884 for (
int i = 0; i < 50; i++)
886 poses.push_back(current->getPoseAt(i / 50.0));
893 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
898 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
902 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
903 std::vector<std::vector<double>> result = ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
925 std::cout <<
"NO MOVEMENT START";
926 std::vector<double> ja = { -0.0475329, -0.0275045, 0.790436, -0.205607, 0.561071, -0.322912, -0.256206};
927 PosePkg p1 =
createPosePkg(3.02088, 389.723, 938.033, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
928 PosePkg p2 =
createPosePkg(3.02088, 389.723, 938.033, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);
930 std::vector<PoseBasePtr> cp = {p1.
pose, p2.
pose};
932 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
933 std::vector<IKSolver::CartesianSelection> mySelection = std::vector<IKSolver::CartesianSelection>();
934 for (
int i = 0; i < 50; i++)
936 poses.push_back(ip->getPoseAt(i / 50.0));
937 std::cout <<
std::to_string(ip->getPoseAt(i / 50.0)->position->x) +
"\n";
943 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
948 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
952 std::vector<std::vector<double>> result = ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
953 for (vector<double> tempResult : result)
955 for (
double angle : tempResult)
959 std::cout <<
"----------------------------------\n";
961 std::cout <<
"NO MOVEMENT END";