27 #include <gtest/gtest.h> 31 #include <cartesian_control_msgs/CartesianTrajectory.h> 32 #include "Eigen/src/Core/Matrix.h" 33 #include "cartesian_control_msgs/CartesianTrajectoryPoint.h" 40 TEST(TestCartesianTrajectory, SamplingFromEmptyTrajectoryGivesEmptyState)
46 empty_traj.
sample(-0.5, a);
48 std::stringstream a_str;
49 std::stringstream b_str;
53 EXPECT_EQ(b_str.str(), a_str.str());
56 TEST(TestCartesianTrajectory, DefaultQuaternionsGiveValidInterpolation)
58 auto p1 = cartesian_control_msgs::CartesianTrajectoryPoint();
59 p1.pose.position.x = 0.0;
60 p1.pose.position.y = 0.0;
61 p1.pose.position.z = 0.0;
64 auto p2 = cartesian_control_msgs::CartesianTrajectoryPoint();
65 p2.pose.position.x = 1.0;
66 p2.pose.position.y = 1.0;
67 p2.pose.position.z = 1.0;
70 cartesian_control_msgs::CartesianTrajectory traj;
71 traj.points.push_back(p1);
72 traj.points.push_back(p2);
76 c_traj.sample(2.5, c);
78 std::stringstream result;
82 EXPECT_EQ(std::string::npos, result.str().find(
"nan"));
85 TEST(TestCartesianTrajectory, NonIncreasingWaypointsInTimeFail)
87 auto p1 = cartesian_control_msgs::CartesianTrajectoryPoint();
88 auto p2 = cartesian_control_msgs::CartesianTrajectoryPoint();
92 cartesian_control_msgs::CartesianTrajectory
init;
93 init.points.push_back(p1);
94 init.points.push_back(p2);
97 EXPECT_FALSE(c_traj.
init(init));
100 TEST(TestCartesianTrajectory, InterpolationGivesPlausibleResults)
102 auto p1 = cartesian_control_msgs::CartesianTrajectoryPoint();
103 p1.pose.position.x = 0.0;
104 p1.pose.position.y = 0.0;
105 p1.pose.position.z = 0.0;
106 p1.pose.orientation.x = 0;
107 p1.pose.orientation.y = 0;
108 p1.pose.orientation.z = 0;
109 p1.pose.orientation.w = 1;
112 auto p2 = cartesian_control_msgs::CartesianTrajectoryPoint();
113 p2.pose.position.x = 1.1;
114 p2.pose.position.y = 2.2;
115 p2.pose.position.z = 3.3;
116 p2.pose.orientation.x = 1;
117 p2.pose.orientation.y = 0;
118 p2.pose.orientation.z = 0;
119 p2.pose.orientation.w = 0;
122 cartesian_control_msgs::CartesianTrajectory traj;
123 traj.points.push_back(p1);
124 traj.points.push_back(p2);
130 constexpr
double pi = 3.14159265358979323846;
133 EXPECT_DOUBLE_EQ(p2.pose.position.x / 2.0, c.
p.x());
134 EXPECT_DOUBLE_EQ(p2.pose.position.y / 2.0, c.
p.y());
135 EXPECT_DOUBLE_EQ(p2.pose.position.z / 2.0, c.
p.z());
136 EXPECT_DOUBLE_EQ(pi / 2.0, c.
rot().norm());
139 TEST(TestCartesianTrajectory, OppositeSignsGivesSameResults)
142 auto p1 = cartesian_control_msgs::CartesianTrajectoryPoint();
143 p1.pose.position.x = 0.0;
144 p1.pose.position.y = 0.0;
145 p1.pose.position.z = 0.0;
146 p1.pose.orientation.x = 0.0353693;
147 p1.pose.orientation.y = 0.984552;
148 p1.pose.orientation.z = 0.1707371;
149 p1.pose.orientation.w = 0.0159721;
152 auto p2 = cartesian_control_msgs::CartesianTrajectoryPoint();
153 p2.pose.position.x = 0.0;
154 p2.pose.position.y = 0.0;
155 p2.pose.position.z = 0.0;
157 p2.pose.orientation.x = -p1.pose.orientation.x;
158 p2.pose.orientation.y = -p1.pose.orientation.y;
159 p2.pose.orientation.z = -p1.pose.orientation.z;
160 p2.pose.orientation.w = -p1.pose.orientation.w;
163 cartesian_control_msgs::CartesianTrajectory traj;
164 traj.points.push_back(p1);
165 traj.points.push_back(p2);
169 c_traj.sample(1.0, c1);
170 c_traj.sample(4.0, c2);
172 EXPECT_DOUBLE_EQ(c1.
q.x(), c2.
q.x());
173 EXPECT_DOUBLE_EQ(c1.
q.y(), c2.
q.y());
174 EXPECT_DOUBLE_EQ(c1.
q.z(), c2.
q.z());
175 EXPECT_DOUBLE_EQ(c1.
q.w(), c2.
q.w());
178 TEST(TestCartesianTrajectory, ShortestPathIsFollowed)
180 auto p1 = cartesian_control_msgs::CartesianTrajectoryPoint();
181 p1.pose.position.x = 0.0;
182 p1.pose.position.y = 0.0;
183 p1.pose.position.z = 0.0;
184 p1.pose.orientation.x = 0.1046779;
185 p1.pose.orientation.y = -0.7045626;
186 p1.pose.orientation.z = 0.1234662;
187 p1.pose.orientation.w = 0.6909343;
190 auto p2 = cartesian_control_msgs::CartesianTrajectoryPoint();
191 p2.pose.position.x = 0.0;
192 p2.pose.position.y = 0.0;
193 p2.pose.position.z = 0.0;
195 p2.pose.orientation.x = 0.0485966;
196 p2.pose.orientation.y = 0.7107247;
197 p2.pose.orientation.z = 0.031284;
198 p2.pose.orientation.w = -0.7010921;
201 cartesian_control_msgs::CartesianTrajectory traj;
202 traj.points.push_back(p1);
203 traj.points.push_back(p2);
207 c_traj.sample(5.0, c);
210 EXPECT_NEAR(p2.pose.orientation.x * -1, c.
q.x(), 0.001);
211 EXPECT_NEAR(p2.pose.orientation.y * -1, c.
q.y(), 0.001);
212 EXPECT_NEAR(p2.pose.orientation.z * -1, c.
q.z(), 0.001);
213 EXPECT_NEAR(p2.pose.orientation.w * -1, c.
q.w(), 0.001);
216 int main(
int argc,
char** argv)
218 testing::InitGoogleTest(&argc, argv);
219 return RUN_ALL_TESTS();
Eigen::Vector3d p
position
int main(int argc, char **argv)
void sample(const CartesianTrajectorySegment::Time &time, CartesianState &state)
Sample a trajectory at a specified time.
void init(const M_string &remappings)
TEST(TestCartesianTrajectory, SamplingFromEmptyTrajectoryGivesEmptyState)
A class for Cartesian trajectory representation and interpolation.
bool init(const cartesian_control_msgs::CartesianTrajectory &ros_trajectory)
Initialize from ROS message.
Cartesian state with pose, velocity and acceleration.
Eigen::Quaterniond q
rotation
Eigen::Vector3d rot() const
Get Euler-Rodrigues vector from orientation.