DesignerTrajectoryHolderTest.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE ArmarX::RobotTrajectoryDesigner::DesignerTrajectoryHolder
2 #define ARMARX_BOOST_TEST
3 
4 #include <RobotComponents/Test.h>
5 
6 
7 #include <VirtualRobot/XML/RobotIO.h>
9 
10 #include "../DesignerTrajectoryHolder.h"
11 
12 using namespace armarx;
13 using namespace VirtualRobot;
14 
15 struct PosePkg
16 {
17 public:
18  Vector3BasePtr pos;
19  QuaternionBasePtr ori;
20  PoseBasePtr pose;
21 };
22 
23 PosePkg createPosePkg(float x, float y, float z,
24  float qw, float qx, float qy, float qz)
25 {
26  PosePkg posePkg;
27  posePkg.pos = Vector3BasePtr(new Vector3(x, y, z));
28  posePkg.ori = QuaternionBasePtr(new Quaternion(qw, qx, qy, qz));
29  PoseBasePtr tmp = PoseBasePtr(new Pose(posePkg.pos, posePkg.ori));
30  posePkg.pose = tmp;
31  return posePkg;
32 }
33 
34 PoseBasePtr poseToLocal(PoseBasePtr pose, RobotPtr robot, std::string& rnsName)
35 {
36  return PoseBasePtr(
37  new Pose(
38  robot->getRobotNodeSet(rnsName)->getKinematicRoot()->toLocalCoordinateSystem(
39  (new Pose(pose->position, pose->orientation))->toEigen())));
40 }
41 
43 {
44  // Get Robot
45  std::string robotFile = "/RobotAPI/robots/Armar3/ArmarIII.xml";
46  CMakePackageFinder finder("RobotAPI");
47  RobotPtr robot;
48  if (finder.packageFound())
49  {
50  robot = VirtualRobot::RobotIO::loadRobot(finder.getDataDir() + robotFile);
51  }
52  else
53  {
54  robot = RobotIO::loadRobot(
55  "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
56  }
57 
58  EnvironmentPtr environment = std::make_shared<Environment>();
59  environment->setRobot(robot);
60 
61  // Get RobotNodeSet: LeftArm
62  VirtualRobot::RobotNodeSetPtr rnsLeftArm = robot->getRobotNodeSets()[10];
63 
64  // Get RobotNodeSet: RightArm
65  VirtualRobot::RobotNodeSetPtr rnsRightArm = robot->getRobotNodeSet("RightArm");
66 
67  // create designer trajectory holder
68  DesignerTrajectoryHolderPtr dth = std::make_shared<DesignerTrajectoryHolder>(environment);
69 
70  // create designer trajectory manager of LeftArm in holder
71  dth->createDesignerTrajectoryManager(rnsLeftArm->getName());
72 
73  BOOST_CHECK(dth->rnsExists(rnsLeftArm->getName()));
74  BOOST_CHECK(!dth->rnsExists(rnsRightArm->getName()));
75  BOOST_CHECK(!dth->rnsIsPartOfExistingRns(rnsRightArm->getName()));
76 }
77 
78 BOOST_AUTO_TEST_CASE(collisionDetectionNoCollisionTest)
79 {
80  // Get Robot
81  std::string robotFile = "/RobotAPI/robots/Armar3/ArmarIII.xml";
82  CMakePackageFinder finder("RobotAPI");
83  RobotPtr robot;
84  if (finder.packageFound())
85  {
86  robot = VirtualRobot::RobotIO::loadRobot(finder.getDataDir() + robotFile);
87  }
88  else
89  {
90  robot = RobotIO::loadRobot(
91  "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
92  }
93 
95 
96  EnvironmentPtr environment = std::make_shared<Environment>();
97  environment->setRobot(robot);
98 
99  // get LeftArm
100  std::string leftArmName = robot->getRobotNodeSet("LeftArm")->getName();
101 
102  // get LeftArmColModel
103  std::string leftArmColModelName = robot->getRobotNodeSet("LeftArmColModel")->getName();
104 
105  // get body collision models
106  std::vector<std::string> bodyColModelsNames;
107  bodyColModelsNames.push_back(robot->getRobotNodeSet("TorsoHeadColModel")->getName());
108 
109  // create designer trajectory holder
110  DesignerTrajectoryHolderPtr dth = std::make_shared<DesignerTrajectoryHolder>(environment);
111 
112  // create manager
113  dth->createDesignerTrajectoryManager(leftArmName);
114  DesignerTrajectoryManagerPtr dtm = dth->getTrajectoryManager(leftArmName);
115 
116 
117 
118 
119  // Create Poses
120  std::vector<double> p1ja = { 0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
121 
122  PosePkg pp4 = createPosePkg(-316.302246093750, 777.949218750, 1194.246459960938, 0.5907033681869507, -0.5503066778182983, 0.4992305040359497, 0.3146440684795380);
123  PosePkg pp2 = createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);//reachable
124  PosePkg pp3 = createPosePkg(-226.792480468750, 580.723144531250, 1186.157348632812, 0.4336481690406799, -0.4273631870746613, 0.5638203620910645, 0.5580471754074097);//reachable
125  PosePkg pp5 = createPosePkg(-348.304718, 580.476440, 712.264465, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);//reachable
126 
127  PoseBasePtr p1 = kc->doForwardKinematic(robot->getRobotNodeSet(leftArmName), p1ja);
128  PoseBasePtr p2 = poseToLocal(pp2.pose, robot, leftArmName);
129  //PoseBasePtr p2 = pp2.pose;
130  PoseBasePtr p3 = poseToLocal(pp3.pose, robot, leftArmName);
131  PoseBasePtr p4 = poseToLocal(pp4.pose, robot, leftArmName);
132 
133  // Add some poses to designer trajectory
134  dtm->initializeDesignerTrajectory(p1ja);
135  dtm->addWaypoint(p2);
136  dtm->insertWaypoint(1, p3);
137  dtm->insertWaypoint(0, p4);
138 
139  // get trajectory from designer trajectory
140  armarx::TrajectoryPtr t = dtm->getDesignerTrajectory()->getFinalTrajectory();
141 
142  // call collision detection
143  //TODO @Luca Quaer change
144  BOOST_CHECK(!dth->isInCollision(leftArmColModelName, bodyColModelsNames, 10));
145 }
146 
147 BOOST_AUTO_TEST_CASE(collisionDetectionCollisionTest)
148 {
149  // Get Robot
150  std::string robotFile = "/RobotAPI/robots/Armar3/ArmarIII.xml";
151  CMakePackageFinder finder("RobotAPI");
152  RobotPtr robot;
153  if (finder.packageFound())
154  {
155  robot = VirtualRobot::RobotIO::loadRobot(finder.getDataDir() + robotFile);
156  }
157  else
158  {
159  robot = RobotIO::loadRobot(
160  "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
161  }
163 
164  EnvironmentPtr environment = std::make_shared<Environment>();
165  environment->setRobot(robot);
166 
167  // get LeftArm
168  std::string leftArmName = robot->getRobotNodeSet("LeftArm")->getName();
169 
170  // get LeftArmColModel
171  std::string leftArmColModelName = robot->getRobotNodeSet("LeftArmColModel")->getName();
172 
173  // get body collision models
174  std::vector<std::string> bodyColModelsNames;
175  bodyColModelsNames.push_back(robot->getRobotNodeSet("TorsoHeadColModel")->getName());
176 
177  // create designer trajectory holder
178  DesignerTrajectoryHolderPtr dth = std::make_shared<DesignerTrajectoryHolder>(environment);
179 
180  // create manager
181  dth->createDesignerTrajectoryManager(leftArmName);
182  DesignerTrajectoryManagerPtr dtm = dth->getTrajectoryManager(leftArmName);
183 
184  // Create Poses
185  std::vector<double> p1ja = { 0.315176, -0.0275324, 1.00421, 0.0182586, 0.127499, -0.0255035, -0.299747};
186  PosePkg pp1 = createPosePkg(56.5798, 233.545, 992.508, 0.4453609585762024, -0.4538218379020691, 0.5429607033729553, 0.5485371351242065);//Colliding Pose
187  PosePkg pp2 = createPosePkg(-95.4907, 761.478, 1208.03, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);//Not Colliding Pose
188 
189  PosePkg pp9 = createPosePkg(-182.23925781250, 580.074218750, 1034.98925781250, 0.4338901340961456, -0.4268467724323273, 0.5642792582511902, 0.5577904582023621);//reachable
190 
191 
192  PoseBasePtr p1 = poseToLocal(pp1.pose, robot, leftArmName);
193  PoseBasePtr p2 = poseToLocal(pp2.pose, robot, leftArmName);
194  PoseBasePtr p9 = poseToLocal(pp9.pose, robot, leftArmName);
195 
196  // Add some poses to designer trajectory
197  dtm->initializeDesignerTrajectory(p1ja);
198  dtm->addWaypoint(p9);
199 
200  dtm->setTransitionUserDuration(0, 5.0);
201 
202  // get trajectory from designer trajectory
203  armarx::TrajectoryPtr t = dtm->getDesignerTrajectory()->getFinalTrajectory();
204 
205  // call collision detection
206  //TODO @Luca Quaer change
207  BOOST_CHECK(dth->isInCollision(leftArmColModelName, bodyColModelsNames, 10));
208 }
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(basicTest)
Definition: DesignerTrajectoryHolderTest.cpp:42
armarx::DesignerTrajectoryHolderPtr
std::shared_ptr< armarx::DesignerTrajectoryHolder > DesignerTrajectoryHolderPtr
Typedefinitions.
Definition: DesignerTrajectoryHolder.h:158
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:485
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
createPosePkg
PosePkg createPosePkg(float x, float y, float z, float qw, float qx, float qy, float qz)
Definition: DesignerTrajectoryHolderTest.cpp:23
VirtualRobot
Definition: FramedPose.h:43
poseToLocal
PoseBasePtr poseToLocal(PoseBasePtr pose, RobotPtr robot, std::string &rnsName)
Definition: DesignerTrajectoryHolderTest.cpp:34
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
PosePkg::pose
PoseBasePtr pose
Definition: DesignerTrajectoryHolderTest.cpp:20
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
IceInternal::Handle< Trajectory >
armarx::EnvironmentPtr
std::shared_ptr< Environment > EnvironmentPtr
Definition: Environment.h:29
PosePkg
The PosePkg struct - Testing utility.
Definition: DesignerTrajectoryHolderTest.cpp:15
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
armarx::DesignerTrajectoryManagerPtr
std::shared_ptr< armarx::DesignerTrajectoryManager > DesignerTrajectoryManagerPtr
Typedefinitions.
Definition: DesignerTrajectoryManager.h:399
armarx::KinematicSolver::getInstance
static std::shared_ptr< KinematicSolver > getInstance(VirtualRobot::ScenePtr scenario, VirtualRobot::RobotPtr robot)
SINGLETON-FEATURES///////////////////////////////////////////////////////////////////////////////////...
Definition: KinematicSolver.cpp:92
CMakePackageFinder.h
armarx::Pose
The Pose class.
Definition: Pose.h:242
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
armarx::KinematicSolverPtr
std::shared_ptr< KinematicSolver > KinematicSolverPtr
Definition: KinematicSolver.h:235
PosePkg::pos
Vector3BasePtr pos
Definition: DesignerTrajectoryHolderTest.cpp:18
PosePkg::ori
QuaternionBasePtr ori
Definition: DesignerTrajectoryHolderTest.cpp:19
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18