DesignerTrajectoryTests.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE ArmarX::RobotTrajectoryDesigner::DesignerTrajectory
2#define ARMARX_BOOST_TEST
3
4#include <VirtualRobot/XML/RobotIO.h>
5
6#include "../../../../../build/testing/RobotTrajectoryDesigner/Test.h"
8#include "../Util/OrientationConversion.h"
9
10using namespace armarx;
11
12namespace
13{
14 bool
15 equalPose(PoseBasePtr p1, PoseBasePtr p2)
16 {
17 QuaternionPtr q1 = QuaternionPtr::dynamicCast(p1->orientation);
18 QuaternionPtr q2 = QuaternionPtr::dynamicCast(p2->orientation);
19 Vector3Ptr pos1 = Vector3Ptr::dynamicCast(p1->position);
20 Vector3Ptr pos2 = Vector3Ptr::dynamicCast(p2->position);
21
22 if (q1->toEigen() == q2->toEigen() && pos1->toEigen() == pos2->toEigen())
23 {
24 return true;
25 }
26 else
27 {
28 return false;
29 }
30 }
31
32 bool
33 equalUserWaypoints(UserWaypointPtr w1, UserWaypointPtr w2)
34 {
35 return (w1->getIKSelection() == w2->getIKSelection() &&
36 w1->getIsTimeOptimalBreakpoint() == w2->getIsTimeOptimalBreakpoint() &&
37 w1->getJointAngles() == w2->getJointAngles() &&
38 equalPose(w1->getPose(), w2->getPose()) &&
39 w1->getTimeOptimalTimestamp() == w1->getTimeOptimalTimestamp() &&
40 w1->getUserTimestamp() == w2->getUserTimestamp())
41 ? true
42 : false;
43 }
44
45
46} // namespace
47
49{
50 //Init
51 Vector3BasePtr pos1 = Vector3BasePtr(new Vector3(1, 2, 3));
52 QuaternionBasePtr ori1 = OrientationConversion::toQuaternion(1, 2, 3);
53 PoseBasePtr pose1 = PoseBasePtr(new Pose(pos1, ori1));
54
55 Vector3BasePtr pos2 = Vector3BasePtr(new Vector3(4, 5, 6));
56 QuaternionBasePtr ori2 = OrientationConversion::toQuaternion(4, 5, 6);
57 PoseBasePtr pose2 = PoseBasePtr(new Pose(pos2, ori2));
58
59 Vector3BasePtr pos3 = Vector3BasePtr(new Vector3(7, 8, 9));
60 QuaternionBasePtr ori3 = OrientationConversion::toQuaternion(7, 8, 9);
61 PoseBasePtr pose3 = PoseBasePtr(new Pose(pos3, ori3));
62
63 Vector3BasePtr pos4 = Vector3BasePtr(new Vector3(10, 11, 12));
64 QuaternionBasePtr ori4 = OrientationConversion::toQuaternion(10, 11, 12);
65 PoseBasePtr pose4 = PoseBasePtr(new Pose(pos4, ori4));
66
68 w1->setJointAngles({1, 2, 3, 4, 5, 6, 7});
72
73 VirtualRobot::RobotPtr robot = VirtualRobot::RobotIO::loadRobot(
74 "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
75
76 VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSet(robot->getRobotNodeSetNames()[0]);
77
78 w1->setUserTimestamp(10);
79 w2->setUserTimestamp(20);
80 w3->setUserTimestamp(30);
81
83
84 BOOST_CHECK_EQUAL(dt1.getNrOfUserWaypoints(), 1);
85
86 //Wrong usage
87 BOOST_CHECK_THROW(dt1.getUserWaypoint(2), IndexOutOfBoundsException);
88 BOOST_CHECK_THROW(dt1.getTransition(2), IndexOutOfBoundsException);
89 BOOST_CHECK_THROW(dt1.getTrajectorySegment(2), IndexOutOfBoundsException);
90
91 //add UserWaypoints and test Transition
93 dt1.insertUserWaypoint(w3, 1);
94 dt1.addLastUserWaypoint(w4); // Userwaypoints should be w2,w3,w1,w4
95
96 BOOST_CHECK_EQUAL(dt1.getTransition(0)->getStart(), w2);
97 BOOST_CHECK_EQUAL(dt1.getTransition(0)->getEnd(), w3);
98 BOOST_CHECK_EQUAL(dt1.getTransition(1)->getStart(), w3);
99 BOOST_CHECK_EQUAL(dt1.getTransition(1)->getEnd(), w1);
100 BOOST_CHECK_EQUAL(dt1.getTransition(2)->getStart(), w1);
101 BOOST_CHECK_EQUAL(dt1.getTransition(2)->getEnd(), w4);
102
103 //delete UserWaypoint
104 dt1.deleteUserWaypoint(1);
105 BOOST_CHECK_THROW(dt1.getTransition(2),
106 IndexOutOfBoundsException); //there should be not three transitions
107 BOOST_CHECK_EQUAL(dt1.getTransition(0)->getStart(), w2);
108 BOOST_CHECK_EQUAL(dt1.getTransition(0)->getEnd(), w1);
109 BOOST_CHECK_EQUAL(dt1.getNrOfUserWaypoints(), 3);
110}
111
112BOOST_AUTO_TEST_CASE(getTimeOptimalTraj)
113{
114 //Init Designer Trajectory
115 Vector3BasePtr pos1 = Vector3BasePtr(new Vector3(1, 2, 3));
116 QuaternionBasePtr ori1 = OrientationConversion::toQuaternion(1, 2, 3);
117 PoseBasePtr pose1 = PoseBasePtr(new Pose(pos1, ori1));
119 VirtualRobot::RobotPtr robot = VirtualRobot::RobotIO::loadRobot(
120 "../../../../../data/RobotTrajectoryDesigner/Resources/ArmarIII.xml");
121 VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSet(robot->getRobotNodeSetNames()[0]);
123
124 //Init three Trajectories
125 std::vector<std::vector<double>> data1 = {{1, 2, 3, 4, 5},
126 {1, 2, 3, 4, 5},
127 {1, 2, 3, 4, 5},
128 {1, 2, 3, 4, 5},
129 {1, 2, 3, 4, 5},
130 {1, 2, 3, 4, 5},
131 {1, 2, 3, 4, 5}};
132 std::vector<std::vector<double>> data2 = {{5, 6, 7, 8, 9},
133 {5, 6, 7, 8, 9},
134 {5, 6, 7, 8, 9},
135 {5, 6, 7, 8, 9},
136 {5, 6, 7, 8, 9},
137 {5, 6, 7, 8, 9},
138 {5, 6, 7, 8, 9}};
139 std::vector<std::vector<double>> data3 = {{9, 10, 11, 12, 13},
140 {9, 10, 11, 12, 13},
141 {9, 10, 11, 12, 13},
142 {9, 10, 11, 12, 13},
143 {9, 10, 11, 12, 13},
144 {9, 10, 11, 12, 13},
145 {9, 10, 11, 12, 13}};
146
147 Ice::DoubleSeq timestamps1 = {0, 1, 2, 3, 4};
148 Ice::DoubleSeq timestamps2 = {0, 1, 2, 3, 4};
149 Ice::DoubleSeq timestamps3 = {0, 1, 2, 3, 4};
150 Ice::StringSeq dimensionNames = {"a", "b", "c", "d", "e", "f", "g"};
151
152 TrajectoryPtr traj1(new Trajectory(data1, timestamps1, dimensionNames));
153 TrajectoryPtr traj2(new Trajectory(data2, timestamps2, dimensionNames));
154 TrajectoryPtr traj3(new Trajectory(data3, timestamps3, dimensionNames));
155 /////////////////////////////////////////////////////////////////////////////////////
156
157 dt1.setInterBreakpointTrajectories({traj1, traj2, traj3});
158 BOOST_CHECK_EQUAL(dt1.getInterBreakpointTrajectories().size(), 3);
159
160
161 std::vector<std::vector<double>> data4 = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
162 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
163 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
164 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
165 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
166 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
167 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}};
168
169 Ice::DoubleSeq timestamps4 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
170 TrajectoryPtr traj4(new Trajectory(data4, timestamps4, dimensionNames));
171
173 // Traj5 should be same as traj4
174 //check every dimension
175 BOOST_CHECK_EQUAL(traj5->getDimensionData(0), traj4->getDimensionData(0));
176 BOOST_CHECK_EQUAL(traj5->getDimensionData(1), traj4->getDimensionData(1));
177 BOOST_CHECK_EQUAL(traj5->getDimensionData(2), traj4->getDimensionData(2));
178 BOOST_CHECK_EQUAL(traj5->getDimensionData(3), traj4->getDimensionData(3));
179 BOOST_CHECK_EQUAL(traj5->getDimensionData(4), traj4->getDimensionData(4));
180 BOOST_CHECK_EQUAL(traj5->getDimensionData(5), traj4->getDimensionData(5));
181 BOOST_CHECK_EQUAL(traj5->getDimensionData(6), traj4->getDimensionData(6));
182 //check timestamps
183 BOOST_CHECK_EQUAL(traj5->getTimestamps(), traj4->getTimestamps());
184
185 //checkDerivations
186 BOOST_CHECK_EQUAL(traj5->getDerivations(1, 0, 2), traj4->getDerivations(1, 0, 2));
187 BOOST_CHECK_EQUAL(traj5->getDerivations(3, 0, 2), traj4->getDerivations(3, 0, 2));
188 BOOST_CHECK_EQUAL(traj5->getDerivations(5, 0, 2), traj4->getDerivations(5, 0, 2));
189 BOOST_CHECK_EQUAL(traj5->getDerivations(7, 0, 2), traj4->getDerivations(7, 0, 2));
190 BOOST_CHECK_EQUAL(traj5->getDerivations(9, 0, 2), traj4->getDerivations(9, 0, 2));
191 BOOST_CHECK_EQUAL(traj5->getDerivations(11, 0, 2), traj4->getDerivations(11, 0, 2));
192}
193
195{
196}
BOOST_AUTO_TEST_CASE(basicTest)
void insertUserWaypoint(UserWaypointPtr &point, unsigned int index)
insert userwaypoint before index
void addFirstUserWaypoint(UserWaypointPtr &point)
add a new first userWaypoint
void setInterBreakpointTrajectories(const std::vector< TrajectoryPtr > &value)
set the interBreakpointTrajectories
UserWaypointPtr getUserWaypoint(unsigned int index)
get the userWaypoint
TransitionPtr getTransition(unsigned int index)
get the transition
TrajectoryPtr getTimeOptimalTrajectory()
get the time optimal trajectory.
TrajectoryPtr getTrajectorySegment(unsigned int index)
get one interBreakPoint trajectory
unsigned int getNrOfUserWaypoints() const
get the number of the userwaypoints
std::vector< TrajectoryPtr > getInterBreakpointTrajectories()
Returns the interBreakpointTrajectories.
void deleteUserWaypoint(unsigned int index)
delete the userwaypoint and remove all transitions including the userwaypoint.
void addLastUserWaypoint(UserWaypointPtr &point)
add new last userWaypoint
static QuaternionBasePtr toQuaternion(const double roll, const double pitch, const double yaw)
The Pose class.
Definition Pose.h:243
The Trajectory class represents n-dimensional sampled trajectories.
Definition Trajectory.h:77
The UserWaypoint class represents a waypoint of the trajectory.
The Vector3 class.
Definition Pose.h:113
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52
IceInternal::Handle< Quaternion > QuaternionPtr
Definition Pose.h:234
std::shared_ptr< UserWaypoint > UserWaypointPtr