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 "../DesignerTrajectoryHolder.h"
5 
6 #include <VirtualRobot/XML/RobotIO.h>
7 
9 
10 #include <RobotComponents/Test.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
24 createPosePkg(float x, float y, float z, 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
35 poseToLocal(PoseBasePtr pose, RobotPtr robot, std::string& rnsName)
36 {
37  return PoseBasePtr(
38  new Pose(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  // Create Poses
118  std::vector<double> p1ja = {
119  0.464789, 0.357171, -0.303694, -0.067161, -0.445988, -0.204292, -0.070153};
120 
121  PosePkg pp4 = createPosePkg(-316.302246093750,
122  777.949218750,
123  1194.246459960938,
124  0.5907033681869507,
125  -0.5503066778182983,
126  0.4992305040359497,
127  0.3146440684795380);
128  PosePkg pp2 = createPosePkg(-182.23925781250,
129  580.074218750,
130  1034.98925781250,
131  0.4338901340961456,
132  -0.4268467724323273,
133  0.5642792582511902,
134  0.5577904582023621); //reachable
135  PosePkg pp3 = createPosePkg(-226.792480468750,
136  580.723144531250,
137  1186.157348632812,
138  0.4336481690406799,
139  -0.4273631870746613,
140  0.5638203620910645,
141  0.5580471754074097); //reachable
142  PosePkg pp5 = createPosePkg(-348.304718,
143  580.476440,
144  712.264465,
145  0.4453609585762024,
146  -0.4538218379020691,
147  0.5429607033729553,
148  0.5485371351242065); //reachable
149 
150  PoseBasePtr p1 = kc->doForwardKinematic(robot->getRobotNodeSet(leftArmName), p1ja);
151  PoseBasePtr p2 = poseToLocal(pp2.pose, robot, leftArmName);
152  //PoseBasePtr p2 = pp2.pose;
153  PoseBasePtr p3 = poseToLocal(pp3.pose, robot, leftArmName);
154  PoseBasePtr p4 = poseToLocal(pp4.pose, robot, leftArmName);
155 
156  // Add some poses to designer trajectory
157  dtm->initializeDesignerTrajectory(p1ja);
158  dtm->addWaypoint(p2);
159  dtm->insertWaypoint(1, p3);
160  dtm->insertWaypoint(0, p4);
161 
162  // get trajectory from designer trajectory
163  armarx::TrajectoryPtr t = dtm->getDesignerTrajectory()->getFinalTrajectory();
164 
165  // call collision detection
166  //TODO @Luca Quaer change
167  BOOST_CHECK(!dth->isInCollision(leftArmColModelName, bodyColModelsNames, 10));
168 }
169 
170 BOOST_AUTO_TEST_CASE(collisionDetectionCollisionTest)
171 {
172  // Get Robot
173  std::string robotFile = "/RobotAPI/robots/Armar3/ArmarIII.xml";
174  CMakePackageFinder finder("RobotAPI");
175  RobotPtr robot;
176  if (finder.packageFound())
177  {
178  robot = VirtualRobot::RobotIO::loadRobot(finder.getDataDir() + robotFile);
179  }
180  else
181  {
182  robot = RobotIO::loadRobot(
183  "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
184  }
186 
187  EnvironmentPtr environment = std::make_shared<Environment>();
188  environment->setRobot(robot);
189 
190  // get LeftArm
191  std::string leftArmName = robot->getRobotNodeSet("LeftArm")->getName();
192 
193  // get LeftArmColModel
194  std::string leftArmColModelName = robot->getRobotNodeSet("LeftArmColModel")->getName();
195 
196  // get body collision models
197  std::vector<std::string> bodyColModelsNames;
198  bodyColModelsNames.push_back(robot->getRobotNodeSet("TorsoHeadColModel")->getName());
199 
200  // create designer trajectory holder
201  DesignerTrajectoryHolderPtr dth = std::make_shared<DesignerTrajectoryHolder>(environment);
202 
203  // create manager
204  dth->createDesignerTrajectoryManager(leftArmName);
205  DesignerTrajectoryManagerPtr dtm = dth->getTrajectoryManager(leftArmName);
206 
207  // Create Poses
208  std::vector<double> p1ja = {
209  0.315176, -0.0275324, 1.00421, 0.0182586, 0.127499, -0.0255035, -0.299747};
210  PosePkg pp1 = createPosePkg(56.5798,
211  233.545,
212  992.508,
213  0.4453609585762024,
214  -0.4538218379020691,
215  0.5429607033729553,
216  0.5485371351242065); //Colliding Pose
217  PosePkg pp2 = createPosePkg(-95.4907,
218  761.478,
219  1208.03,
220  0.4338901340961456,
221  -0.4268467724323273,
222  0.5642792582511902,
223  0.5577904582023621); //Not Colliding Pose
224 
225  PosePkg pp9 = createPosePkg(-182.23925781250,
226  580.074218750,
227  1034.98925781250,
228  0.4338901340961456,
229  -0.4268467724323273,
230  0.5642792582511902,
231  0.5577904582023621); //reachable
232 
233 
234  PoseBasePtr p1 = poseToLocal(pp1.pose, robot, leftArmName);
235  PoseBasePtr p2 = poseToLocal(pp2.pose, robot, leftArmName);
236  PoseBasePtr p9 = poseToLocal(pp9.pose, robot, leftArmName);
237 
238  // Add some poses to designer trajectory
239  dtm->initializeDesignerTrajectory(p1ja);
240  dtm->addWaypoint(p9);
241 
242  dtm->setTransitionUserDuration(0, 5.0);
243 
244  // get trajectory from designer trajectory
245  armarx::TrajectoryPtr t = dtm->getDesignerTrajectory()->getFinalTrajectory();
246 
247  // call collision detection
248  //TODO @Luca Quaer change
249  BOOST_CHECK(dth->isInCollision(leftArmColModelName, bodyColModelsNames, 10));
250 }
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:156
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:511
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:24
VirtualRobot
Definition: FramedPose.h:42
poseToLocal
PoseBasePtr poseToLocal(PoseBasePtr pose, RobotPtr robot, std::string &rnsName)
Definition: DesignerTrajectoryHolderTest.cpp:35
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:52
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:194
armarx::DesignerTrajectoryManagerPtr
std::shared_ptr< armarx::DesignerTrajectoryManager > DesignerTrajectoryManagerPtr
Typedefinitions.
Definition: DesignerTrajectoryManager.h:402
armarx::KinematicSolver::getInstance
static std::shared_ptr< KinematicSolver > getInstance(VirtualRobot::ScenePtr scenario, VirtualRobot::RobotPtr robot)
SINGLETON-FEATURES///////////////////////////////////////////////////////////////////////////////////...
Definition: KinematicSolver.cpp:105
CMakePackageFinder.h
armarx::Pose
The Pose class.
Definition: Pose.h:242
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::KinematicSolverPtr
std::shared_ptr< KinematicSolver > KinematicSolverPtr
Definition: KinematicSolver.h:287
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:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19