1#define BOOST_TEST_MODULE ArmarX::RobotTrajectoryDesigner::KinematicSolver
2#define ARMARX_BOOST_TEST
7#include <VirtualRobot/XML/RobotIO.h>
14#include <RobotComponents/Test.h>
33 QuaternionBasePtr
ori;
38createPosePkg(
float x,
float y,
float z,
float qw,
float qx,
float qy,
float qz)
42 posePkg.
ori = QuaternionBasePtr(
new Quaternion(qw, qx, qy, qz));
43 PoseBasePtr tmp = PoseBasePtr(
new Pose(posePkg.
pos, posePkg.
ori));
51 if (current->orientation->qw - other->orientation->qw > delta &&
52 other->orientation->qw - current->orientation->qw > delta)
56 if (current->orientation->qx - other->orientation->qx > delta &&
57 other->orientation->qx - current->orientation->qx > delta)
61 if (current->orientation->qy - other->orientation->qy > delta &&
62 other->orientation->qy - current->orientation->qy > delta)
66 if (current->orientation->qz - other->orientation->qz > delta &&
67 other->orientation->qz - current->orientation->qz > delta)
71 if (current->position->x - other->position->x > delta &&
72 other->position->x - current->position->x > delta)
76 if (current->position->y - other->position->y > delta &&
77 other->position->y - current->position->y > delta)
81 if (current->position->z - other->position->z > delta &&
82 other->position->z - current->position->z > delta)
95 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
100 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
103 vector<double> v = {2, 3, 4, 5, 0, 1, 2, 3, 3, 4};
104 ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"), v);
113 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
118 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
120 std::cout << robot->getRobotNodeSet(
"TorsoRightArm")->getAllRobotNodes().size();
122 ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"),
123 {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
125 ks2->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"),
126 {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
128 ks2->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"),
129 {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
132 ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoRightArm"),
133 {2, 3, 4, 5, 0, 1, 2, 3, 3, 4});
143 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
148 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
151 PoseBasePtr pose = PoseBasePtr(
154 ks1->doForwardKinematic(robot->getRobotNodeSet(
"TorsoLeftArm"),
155 ks1->solveIK(robot->getRobotNodeSet(
"TorsoLeftArm"),
157 IKSolver::CartesianSelection::Position,
159 BOOST_CHECK_CLOSE(pose->position->x, result->position->x, 1);
160 BOOST_CHECK_CLOSE(pose->position->y, result->position->y, 1);
161 BOOST_CHECK_CLOSE(pose->position->z, result->position->z, 1);
188 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
193 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
196 Vector3BasePtr pos1 =
new Vector3(-100, 700, 1000);
198 PoseBasePtr pose1 =
new Pose(pos1, ori1);
200 Vector3BasePtr pos2 =
new Vector3(0, 600, 1400);
202 PoseBasePtr pose2 =
new Pose(pos2, ori2);
205 Vector3BasePtr pos3 =
new Vector3(-250, 700, 1350);
207 PoseBasePtr pose3 =
new Pose(pos3, ori3);
209 std::vector<PoseBasePtr> cp = {pose1, pose2, pose3};
213 std::vector<PoseBasePtr> myPoints = std::vector<PoseBasePtr>();
214 std::vector<IKSolver::CartesianSelection> mySelection =
215 std::vector<IKSolver::CartesianSelection>();
216 for (
double d = 0; d < 1; d = d + 0.01f)
218 myPoints.push_back(ip->getPoseAt(d));
219 mySelection.push_back(IKSolver::CartesianSelection::All);
221 std::vector<std::vector<double>> result =
222 ks->solveRecursiveIK(robot->getRobotNodeSet(
"TorsoLeftArm"),
223 ks->solveIK(robot->getRobotNodeSet(
"TorsoLeftArm"),
225 IKSolver::CartesianSelection::Position,
319 std::vector<double> ja = {
320 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
343 std::vector<AbstractInterpolationPtr> ip =
346 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
347 std::vector<IKSolver::CartesianSelection> mySelection =
348 std::vector<IKSolver::CartesianSelection>();
351 for (
int i = 0; i < 100; i++)
353 poses.push_back(current->getPoseAt(i / 100.0));
354 std::cout << std::to_string(current->getPoseAt(i / 100.0)->position->x) +
"\n";
355 mySelection.push_back(IKSolver::CartesianSelection::Position);
360 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
365 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
369 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
370 std::vector<std::vector<double>> result =
371 ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
372 for (vector<double> tempResult : result)
374 for (
double angle : tempResult)
376 std::cout << std::to_string(
angle) +
",";
457 std::vector<double> ja = {
458 -0.818259, 0.428277, 0.136299, -0.608422, 1.064518, -0.227969, -0.289433};
462 -0.03198593109846115,
472 -0.5647976398468018);
481 std::vector<AbstractInterpolationPtr> ip =
484 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
485 std::vector<IKSolver::CartesianSelection> mySelection =
486 std::vector<IKSolver::CartesianSelection>();
489 for (
int i = 0; i < 50; i++)
491 poses.push_back(current->getPoseAt(i / 50.0));
492 mySelection.push_back(IKSolver::CartesianSelection::Position);
497 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
502 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
506 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
508 std::vector<std::vector<double>> result =
509 ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
510 for (vector<double> tempResult : result)
512 for (
double angle : tempResult)
514 std::cout << std::to_string(
angle) +
",";
516 std::cout <<
"----------------------------------\n";
576 std::vector<double> ja = {
577 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
593 std::vector<AbstractInterpolationPtr> ip =
595 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
596 std::vector<IKSolver::CartesianSelection> mySelection =
597 std::vector<IKSolver::CartesianSelection>();
600 for (
int i = 0; i < 50; i++)
602 poses.push_back(current->getPoseAt(i / 50.0));
604 mySelection.push_back(IKSolver::CartesianSelection::Position);
609 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
614 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
618 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
619 std::vector<std::vector<double>> result =
620 ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
621 for (vector<double> tempResult : result)
623 for (
double angle : tempResult)
625 std::cout << std::to_string(
angle) +
",";
627 std::cout <<
"----------------------------------\n";
687 std::vector<double> ja = {
688 -0.763830, -0.244323, 0.619645, -0.281197, 0.040509, 0.444159, 0.536926};
704 std::vector<AbstractInterpolationPtr> ip =
706 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
707 std::vector<IKSolver::CartesianSelection> mySelection =
708 std::vector<IKSolver::CartesianSelection>();
711 for (
int i = 0; i < 50; i++)
713 poses.push_back(current->getPoseAt(i / 50.0));
714 std::cout << std::to_string(current->getPoseAt(i / 50.0)->position->x) +
"\n";
715 mySelection.push_back(IKSolver::CartesianSelection::Position);
720 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
725 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
729 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
817 std::vector<double> ja = {
818 -0.763830, -0.244323, 0.619645, -0.281197, 0.040509, 0.444159, 0.536926};
842 std::vector<AbstractInterpolationPtr> ip =
845 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
846 std::vector<IKSolver::CartesianSelection> mySelection =
847 std::vector<IKSolver::CartesianSelection>();
850 for (
int i = 0; i < 50; i++)
852 poses.push_back(current->getPoseAt(i / 50.0));
854 mySelection.push_back(IKSolver::CartesianSelection::Position);
858 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
863 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
867 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
913 std::vector<double> ja = {
914 0.315176, -0.0275324, 1.00421, 0.0182586, 0.127499, -0.0255035, -0.299747};
931 std::vector<AbstractInterpolationPtr> ip =
933 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
934 std::vector<IKSolver::CartesianSelection> mySelection =
935 std::vector<IKSolver::CartesianSelection>();
938 for (
int i = 0; i < 50; i++)
940 poses.push_back(current->getPoseAt(i / 50.0));
942 mySelection.push_back(IKSolver::CartesianSelection::Position);
947 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
952 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
956 PoseBasePtr result2 = ks->doForwardKinematic(robot->getRobotNodeSet(
"LeftArm"), ja);
957 std::cout <<
"XXXXXXXXX" + std::to_string(result2->position->x) +
"," +
958 std::to_string(result2->position->y) +
"," +
959 std::to_string(result2->position->z) +
"\n";
960 std::vector<std::vector<double>> result =
961 ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
1012 std::vector<double> ja = {
1013 -0.0475329, -0.0275045, 0.790436, -0.205607, 0.561071, -0.322912, -0.256206};
1018 -0.4538218379020691,
1020 0.5485371351242065);
1026 -0.4268467724323273,
1028 0.5577904582023621);
1030 std::vector<AbstractInterpolationPtr> ip =
1032 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
1033 std::vector<IKSolver::CartesianSelection> mySelection =
1034 std::vector<IKSolver::CartesianSelection>();
1037 for (
int i = 0; i < 50; i++)
1039 poses.push_back(current->getPoseAt(i / 50.0));
1041 mySelection.push_back(IKSolver::CartesianSelection::Position);
1046 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
1051 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
1055 PoseBasePtr result2 = ks->doForwardKinematicRelative(robot->getRobotNodeSet(
"LeftArm"), ja);
1056 std::vector<std::vector<double>> result =
1057 ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
1079 std::cout <<
"NO MOVEMENT START";
1080 std::vector<double> ja = {
1081 -0.0475329, -0.0275045, 0.790436, -0.205607, 0.561071, -0.322912, -0.256206};
1086 -0.4538218379020691,
1088 0.5485371351242065);
1093 -0.4538218379020691,
1095 0.5485371351242065);
1097 std::vector<PoseBasePtr> cp = {p1.
pose, p2.
pose};
1099 std::vector<PoseBasePtr> poses = std::vector<PoseBasePtr>();
1100 std::vector<IKSolver::CartesianSelection> mySelection =
1101 std::vector<IKSolver::CartesianSelection>();
1102 for (
int i = 0; i < 50; i++)
1104 poses.push_back(ip->getPoseAt(i / 50.0));
1105 std::cout << std::to_string(ip->getPoseAt(i / 50.0)->position->x) +
"\n";
1106 mySelection.push_back(IKSolver::CartesianSelection::Position);
1111 std::string robotFile =
"/RobotAPI/robots/Armar3/ArmarIII.xml";
1116 robot = VirtualRobot::RobotIO::loadRobot(finder.
getDataDir() + robotFile);
1120 std::vector<std::vector<double>> result =
1121 ks->solveRecursiveIK(robot->getRobotNodeSet(
"LeftArm"), ja, poses, mySelection);
1122 for (vector<double> tempResult : result)
1124 for (
double angle : tempResult)
1126 std::cout << std::to_string(
angle) +
",";
1128 std::cout <<
"----------------------------------\n";
1130 std::cout <<
"NO MOVEMENT END";
BOOST_AUTO_TEST_CASE(pleaseWorkTest)
Tests basic functionality of Kineamtic Solver.
bool isEqualRounded(PoseBasePtr current, PoseBasePtr other, double delta)
PosePkg createPosePkg(float x, float y, float z, float qw, float qx, float qy, float qz)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getDataDir() const
bool packageFound() const
Returns whether or not this package was found with cmake.
static std::vector< AbstractInterpolationPtr > produceLinearInterpolationSegments(std::vector< PoseBasePtr > controlPoints)
produceInterpolationSegments constructs a vector of LinearInterpolations
static std::shared_ptr< KinematicSolver > getInstance(VirtualRobot::ScenePtr scenario, VirtualRobot::RobotPtr robot)
SINGLETON-FEATURES///////////////////////////////////////////////////////////////////////////////////...
static void reset()
reset Destroys the current instance of KinematicSolver that a new one can be created via call of getI...
The LinearInterpolation class represents a linear Interpolation between a series of control points Li...
static QuaternionBasePtr toQuaternion(const double roll, const double pitch, const double yaw)
std::shared_ptr< class Robot > RobotPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< KinematicSolver > KinematicSolverPtr
std::shared_ptr< LinearInterpolation > LinearInterpolationPtr
std::shared_ptr< AbstractInterpolation > AbstractInterpolationPtr
double angle(const Point &a, const Point &b, const Point &c)
The PosePkg struct - Testing utility.