36 #include <gtest/gtest.h> 41 geometry_msgs::TransformStamped
t;
42 static const double EPS = 1e-3;
47 geometry_msgs::PoseStamped v1;
48 v1.pose.position.x = 1;
49 v1.pose.position.y = 2;
50 v1.pose.position.z = 3;
51 v1.pose.orientation.x = 1;
53 v1.header.frame_id =
"A";
57 EXPECT_NEAR(v_simple.pose.position.x, -9,
EPS);
58 EXPECT_NEAR(v_simple.pose.position.y, 18,
EPS);
59 EXPECT_NEAR(v_simple.pose.position.z, 27,
EPS);
60 EXPECT_NEAR(v_simple.pose.orientation.x, 0.0,
EPS);
61 EXPECT_NEAR(v_simple.pose.orientation.y, 0.0,
EPS);
62 EXPECT_NEAR(v_simple.pose.orientation.z, 0.0,
EPS);
63 EXPECT_NEAR(v_simple.pose.orientation.w, 1.0,
EPS);
68 EXPECT_NEAR(v_advanced.pose.position.x, -9,
EPS);
69 EXPECT_NEAR(v_advanced.pose.position.y, 18,
EPS);
70 EXPECT_NEAR(v_advanced.pose.position.z, 27,
EPS);
71 EXPECT_NEAR(v_advanced.pose.orientation.x, 0.0,
EPS);
72 EXPECT_NEAR(v_advanced.pose.orientation.y, 0.0,
EPS);
73 EXPECT_NEAR(v_advanced.pose.orientation.z, 0.0,
EPS);
74 EXPECT_NEAR(v_advanced.pose.orientation.w, 1.0,
EPS);
77 TEST(TfGeometry, PoseWithCovarianceStamped)
79 geometry_msgs::PoseWithCovarianceStamped v1;
80 v1.pose.pose.position.x = 1;
81 v1.pose.pose.position.y = 2;
82 v1.pose.pose.position.z = 3;
83 v1.pose.pose.orientation.x = 1;
85 v1.header.frame_id =
"A";
86 v1.pose.covariance[0] = 1;
87 v1.pose.covariance[7] = 1;
88 v1.pose.covariance[14] = 1;
89 v1.pose.covariance[21] = 1;
90 v1.pose.covariance[28] = 1;
91 v1.pose.covariance[35] = 1;
94 const geometry_msgs::PoseWithCovarianceStamped v_simple = tf_buffer->
transform(v1,
"B",
ros::Duration(2.0));
95 EXPECT_NEAR(v_simple.pose.pose.position.x, -9,
EPS);
96 EXPECT_NEAR(v_simple.pose.pose.position.y, 18,
EPS);
97 EXPECT_NEAR(v_simple.pose.pose.position.z, 27,
EPS);
98 EXPECT_NEAR(v_simple.pose.pose.orientation.x, 0.0,
EPS);
99 EXPECT_NEAR(v_simple.pose.pose.orientation.y, 0.0,
EPS);
100 EXPECT_NEAR(v_simple.pose.pose.orientation.z, 0.0,
EPS);
101 EXPECT_NEAR(v_simple.pose.pose.orientation.w, 1.0,
EPS);
104 EXPECT_NEAR(v_simple.pose.covariance[0], 1.0,
EPS);
105 EXPECT_NEAR(v_simple.pose.covariance[7], 1.0,
EPS);
106 EXPECT_NEAR(v_simple.pose.covariance[14], 1.0,
EPS);
107 EXPECT_NEAR(v_simple.pose.covariance[21], 1.0,
EPS);
108 EXPECT_NEAR(v_simple.pose.covariance[28], 1.0,
EPS);
109 EXPECT_NEAR(v_simple.pose.covariance[35], 1.0,
EPS);
112 const geometry_msgs::PoseWithCovarianceStamped v_advanced = tf_buffer->
transform(v1,
"B",
ros::Time(2.0),
114 EXPECT_NEAR(v_advanced.pose.pose.position.x, -9,
EPS);
115 EXPECT_NEAR(v_advanced.pose.pose.position.y, 18,
EPS);
116 EXPECT_NEAR(v_advanced.pose.pose.position.z, 27,
EPS);
117 EXPECT_NEAR(v_advanced.pose.pose.orientation.x, 0.0,
EPS);
118 EXPECT_NEAR(v_advanced.pose.pose.orientation.y, 0.0,
EPS);
119 EXPECT_NEAR(v_advanced.pose.pose.orientation.z, 0.0,
EPS);
120 EXPECT_NEAR(v_advanced.pose.pose.orientation.w, 1.0,
EPS);
123 EXPECT_NEAR(v_advanced.pose.covariance[0], 1.0,
EPS);
124 EXPECT_NEAR(v_advanced.pose.covariance[7], 1.0,
EPS);
125 EXPECT_NEAR(v_advanced.pose.covariance[14], 1.0,
EPS);
126 EXPECT_NEAR(v_advanced.pose.covariance[21], 1.0,
EPS);
127 EXPECT_NEAR(v_advanced.pose.covariance[28], 1.0,
EPS);
128 EXPECT_NEAR(v_advanced.pose.covariance[35], 1.0,
EPS);
133 geometry_msgs::TransformStamped t_rot;
136 t_rot.header.frame_id =
"A";
137 t_rot.child_frame_id =
"rotated";
141 v1.pose.covariance[1] = 1;
142 v1.pose.covariance[6] = 1;
143 v1.pose.covariance[12] = 1;
146 const geometry_msgs::PoseWithCovarianceStamped v_rotated = tf_buffer->
transform(v1,
"rotated",
ros::Duration(2.0));
149 EXPECT_NEAR(v_rotated.pose.covariance[0], 1.0,
EPS);
150 EXPECT_NEAR(v_rotated.pose.covariance[1], 0.0,
EPS);
151 EXPECT_NEAR(v_rotated.pose.covariance[2],-1.0,
EPS);
152 EXPECT_NEAR(v_rotated.pose.covariance[6], 1.0,
EPS);
153 EXPECT_NEAR(v_rotated.pose.covariance[7], 1.0,
EPS);
154 EXPECT_NEAR(v_rotated.pose.covariance[8], 0.0,
EPS);
155 EXPECT_NEAR(v_rotated.pose.covariance[12],-1.0,
EPS);
156 EXPECT_NEAR(v_rotated.pose.covariance[13], 0.0,
EPS);
157 EXPECT_NEAR(v_rotated.pose.covariance[14], 1.0,
EPS);
165 geometry_msgs::TransformStamped v1;
166 v1.transform.translation.x = 1;
167 v1.transform.translation.y = 2;
168 v1.transform.translation.z = 3;
169 v1.transform.rotation.x = 1;
171 v1.header.frame_id =
"A";
175 EXPECT_NEAR(v_simple.transform.translation.x, -9,
EPS);
176 EXPECT_NEAR(v_simple.transform.translation.y, 18,
EPS);
177 EXPECT_NEAR(v_simple.transform.translation.z, 27,
EPS);
178 EXPECT_NEAR(v_simple.transform.rotation.x, 0.0,
EPS);
179 EXPECT_NEAR(v_simple.transform.rotation.y, 0.0,
EPS);
180 EXPECT_NEAR(v_simple.transform.rotation.z, 0.0,
EPS);
181 EXPECT_NEAR(v_simple.transform.rotation.w, 1.0,
EPS);
185 geometry_msgs::TransformStamped v_advanced = tf_buffer->
transform(v1,
"B",
ros::Time(2.0),
187 EXPECT_NEAR(v_advanced.transform.translation.x, -9,
EPS);
188 EXPECT_NEAR(v_advanced.transform.translation.y, 18,
EPS);
189 EXPECT_NEAR(v_advanced.transform.translation.z, 27,
EPS);
190 EXPECT_NEAR(v_advanced.transform.rotation.x, 0.0,
EPS);
191 EXPECT_NEAR(v_advanced.transform.rotation.y, 0.0,
EPS);
192 EXPECT_NEAR(v_advanced.transform.rotation.z, 0.0,
EPS);
193 EXPECT_NEAR(v_advanced.transform.rotation.w, 1.0,
EPS);
198 geometry_msgs::Vector3Stamped v1, res;
203 v1.header.frame_id =
"A";
207 EXPECT_NEAR(v_simple.vector.x, 1,
EPS);
208 EXPECT_NEAR(v_simple.vector.y, -2,
EPS);
209 EXPECT_NEAR(v_simple.vector.z, -3,
EPS);
212 geometry_msgs::Vector3Stamped v_advanced = tf_buffer->
transform(v1,
"B",
ros::Time(2.0),
214 EXPECT_NEAR(v_advanced.vector.x, 1,
EPS);
215 EXPECT_NEAR(v_advanced.vector.y, -2,
EPS);
216 EXPECT_NEAR(v_advanced.vector.z, -3,
EPS);
222 geometry_msgs::PointStamped v1, res;
227 v1.header.frame_id =
"A";
231 EXPECT_NEAR(v_simple.point.x, -9,
EPS);
232 EXPECT_NEAR(v_simple.point.y, 18,
EPS);
233 EXPECT_NEAR(v_simple.point.z, 27,
EPS);
236 geometry_msgs::PointStamped v_advanced = tf_buffer->
transform(v1,
"B",
ros::Time(2.0),
238 EXPECT_NEAR(v_advanced.point.x, -9,
EPS);
239 EXPECT_NEAR(v_advanced.point.y, 18,
EPS);
240 EXPECT_NEAR(v_advanced.point.z, 27,
EPS);
243 TEST(TfGeometry, doTransformPoint)
245 geometry_msgs::Point v1, res;
250 geometry_msgs::TransformStamped trafo;
251 trafo.transform.translation.x = -1;
252 trafo.transform.translation.y = 2;
253 trafo.transform.translation.z = -3;
258 EXPECT_NEAR(res.x, 0,
EPS);
259 EXPECT_NEAR(res.y, 0,
EPS);
260 EXPECT_NEAR(res.z, 0,
EPS);
263 TEST(TfGeometry, doTransformQuaterion)
265 geometry_msgs::Quaternion v1, res;
268 geometry_msgs::TransformStamped trafo;
269 trafo.transform.translation.x = -1;
270 trafo.transform.translation.y = 2;
271 trafo.transform.translation.z = -3;
276 EXPECT_NEAR(res.x, trafo.transform.rotation.x,
EPS);
277 EXPECT_NEAR(res.y, trafo.transform.rotation.y,
EPS);
278 EXPECT_NEAR(res.z, trafo.transform.rotation.z,
EPS);
279 EXPECT_NEAR(res.w, trafo.transform.rotation.w,
EPS);
282 TEST(TfGeometry, doTransformPose)
284 geometry_msgs::Pose v1, res;
288 v1.orientation.w = 1;
290 geometry_msgs::TransformStamped trafo;
291 trafo.transform.translation.x = -1;
292 trafo.transform.translation.y = 2;
293 trafo.transform.translation.z = -3;
298 EXPECT_NEAR(res.position.x, 0,
EPS);
299 EXPECT_NEAR(res.position.y, 0,
EPS);
300 EXPECT_NEAR(res.position.z, 0,
EPS);
302 EXPECT_NEAR(res.orientation.x, trafo.transform.rotation.x,
EPS);
303 EXPECT_NEAR(res.orientation.y, trafo.transform.rotation.y,
EPS);
304 EXPECT_NEAR(res.orientation.z, trafo.transform.rotation.z,
EPS);
305 EXPECT_NEAR(res.orientation.w, trafo.transform.rotation.w,
EPS);
308 TEST(TfGeometry, doTransformVector3)
310 geometry_msgs::Vector3 v1, res;
315 geometry_msgs::TransformStamped trafo;
316 trafo.transform.translation.x = -1;
317 trafo.transform.translation.y = 2;
318 trafo.transform.translation.z = -3;
323 EXPECT_NEAR(res.x, 1,
EPS);
324 EXPECT_NEAR(res.y, -2,
EPS);
325 EXPECT_NEAR(res.z, 3,
EPS);
328 TEST(TfGeometry, doTransformWrench)
330 geometry_msgs::Wrench v1, res;
338 geometry_msgs::TransformStamped trafo;
339 trafo.transform.translation.x = -1;
340 trafo.transform.translation.y = 2;
341 trafo.transform.translation.z = -3;
345 EXPECT_NEAR(res.force.x, 1,
EPS);
346 EXPECT_NEAR(res.force.y, -2,
EPS);
347 EXPECT_NEAR(res.force.z, 3,
EPS);
349 EXPECT_NEAR(res.torque.x, 1,
EPS);
350 EXPECT_NEAR(res.torque.y, -2,
EPS);
351 EXPECT_NEAR(res.torque.z, 3,
EPS);
354 int main(
int argc,
char **argv){
355 testing::InitGoogleTest(&argc, argv);
363 t.transform.translation.x = 10;
364 t.transform.translation.y = 20;
365 t.transform.translation.z = 30;
366 t.transform.rotation.x = 1;
368 t.header.frame_id =
"A";
369 t.child_frame_id =
"B";
372 int ret = RUN_ALL_TESTS();
void setUsingDedicatedThread(bool value)
bool setTransform(const geometry_msgs::TransformStamped &transform, const std::string &authority, bool is_static=false)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
geometry_msgs::TransformStamped t
int main(int argc, char **argv)
tf2_ros::Buffer * tf_buffer
T & transform(const T &in, T &out, const std::string &target_frame, ros::Duration timeout=ros::Duration(0.0)) const