forked from MOCAP4ROS2-Project/mocap4ros2_vicon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tf2_geometry_msgs.hpp.copy
671 lines (601 loc) · 27.1 KB
/
tf2_geometry_msgs.hpp.copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/*
* Copyright (c) 2008, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** \author Wim Meeussen */
#ifndef TF2_GEOMETRY_MSGS_HPP
#define TF2_GEOMETRY_MSGS_HPP
#include <tf2/convert.h>
#include <tf2/LinearMath/Quaternion.h>
#include <tf2/LinearMath/Transform.h>
#include <tf2_ros/buffer_interface.h>
#include <geometry_msgs/msg/point_stamped.hpp>
#include <geometry_msgs/msg/quaternion_stamped.hpp>
#include <geometry_msgs/msg/transform_stamped.hpp>
#include <geometry_msgs/msg/vector3_stamped.hpp>
#include <geometry_msgs/msg/pose.hpp>
#include <geometry_msgs/msg/pose_stamped.hpp>
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
#include <kdl/frames.hpp>
namespace tf2
{
/** \brief Convert a TransformStamped message to a KDL frame.
* \param t TransformStamped message to convert.
* \return The converted KDL Frame.
*/
inline
KDL::Frame gmTransformToKDL(const geometry_msgs::msg::TransformStamped& t)
{
return KDL::Frame(KDL::Rotation::Quaternion(t.transform.rotation.x, t.transform.rotation.y,
t.transform.rotation.z, t.transform.rotation.w),
KDL::Vector(t.transform.translation.x, t.transform.translation.y, t.transform.translation.z));
}
/********************/
/** Vector3Stamped **/
/********************/
/** \brief Extract a timestamp from the header of a Vector message.
* This function is a specialization of the getTimestamp template defined in tf2/convert.h.
* \param t VectorStamped message to extract the timestamp from.
* \return The timestamp of the message.
*/
template <>
inline
tf2::TimePoint getTimestamp(const geometry_msgs::msg::Vector3Stamped& t) {return tf2_ros::fromMsg(t.header.stamp);}
/** \brief Extract a frame ID from the header of a Vector message.
* This function is a specialization of the getFrameId template defined in tf2/convert.h.
* \param t VectorStamped message to extract the frame ID from.
* \return A string containing the frame ID of the message.
*/
template <>
inline
std::string getFrameId(const geometry_msgs::msg::Vector3Stamped& t) {return t.header.frame_id;}
/** \brief Apply a geometry_msgs TransformStamped to an geometry_msgs Vector type.
* This function is a specialization of the doTransform template defined in tf2/convert.h.
* \param t_in The vector to transform, as a timestamped Vector3 message.
* \param t_out The transformed vector, as a timestamped Vector3 message.
* \param transform The timestamped transform to apply, as a TransformStamped message.
*/
template <>
inline
void doTransform(const geometry_msgs::msg::Vector3Stamped& t_in, geometry_msgs::msg::Vector3Stamped& t_out, const geometry_msgs::msg::TransformStamped& transform)
{
KDL::Vector v_out = gmTransformToKDL(transform).M * KDL::Vector(t_in.vector.x, t_in.vector.y, t_in.vector.z);
t_out.vector.x = v_out[0];
t_out.vector.y = v_out[1];
t_out.vector.z = v_out[2];
t_out.header.stamp = transform.header.stamp;
t_out.header.frame_id = transform.header.frame_id;
}
/** \brief Trivial "conversion" function for Vector3 message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A Vector3Stamped message.
* \return The input argument.
*/
inline
geometry_msgs::msg::Vector3Stamped toMsg(const geometry_msgs::msg::Vector3Stamped& in)
{
return in;
}
/** \brief Trivial "conversion" function for Vector3 message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param msg A Vector3Stamped message.
* \param out The input argument.
*/
inline
void fromMsg(const geometry_msgs::msg::Vector3Stamped& msg, geometry_msgs::msg::Vector3Stamped& out)
{
out = msg;
}
/******************/
/** PointStamped **/
/******************/
/** \brief Extract a timestamp from the header of a Point message.
* This function is a specialization of the getTimestamp template defined in tf2/convert.h.
* \param t PointStamped message to extract the timestamp from.
* \return The timestamp of the message.
*/
template <>
inline
tf2::TimePoint getTimestamp(const geometry_msgs::msg::PointStamped& t) {return tf2_ros::fromMsg(t.header.stamp);}
/** \brief Extract a frame ID from the header of a Point message.
* This function is a specialization of the getFrameId template defined in tf2/convert.h.
* \param t PointStamped message to extract the frame ID from.
* \return A string containing the frame ID of the message.
*/
template <>
inline
std::string getFrameId(const geometry_msgs::msg::PointStamped& t) {return t.header.frame_id;}
/** \brief Apply a geometry_msgs TransformStamped to an geometry_msgs Point type.
* This function is a specialization of the doTransform template defined in tf2/convert.h.
* \param t_in The point to transform, as a timestamped Point3 message.
* \param t_out The transformed point, as a timestamped Point3 message.
* \param transform The timestamped transform to apply, as a TransformStamped message.
*/
template <>
inline
void doTransform(const geometry_msgs::msg::PointStamped& t_in, geometry_msgs::msg::PointStamped& t_out, const geometry_msgs::msg::TransformStamped& transform)
{
KDL::Vector v_out = gmTransformToKDL(transform) * KDL::Vector(t_in.point.x, t_in.point.y, t_in.point.z);
t_out.point.x = v_out[0];
t_out.point.y = v_out[1];
t_out.point.z = v_out[2];
t_out.header.stamp = transform.header.stamp;
t_out.header.frame_id = transform.header.frame_id;
}
/** \brief Trivial "conversion" function for Point message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A PointStamped message.
* \return The input argument.
*/
inline
geometry_msgs::msg::PointStamped toMsg(const geometry_msgs::msg::PointStamped& in)
{
return in;
}
/** \brief Trivial "conversion" function for Point message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param msg A PointStamped message.
* \param out The input argument.
*/
inline
void fromMsg(const geometry_msgs::msg::PointStamped& msg, geometry_msgs::msg::PointStamped& out)
{
out = msg;
}
/*****************/
/** PoseStamped **/
/*****************/
/** \brief Extract a timestamp from the header of a Pose message.
* This function is a specialization of the getTimestamp template defined in tf2/convert.h.
* \param t PoseStamped message to extract the timestamp from.
* \return The timestamp of the message.
*/
template <>
inline
tf2::TimePoint getTimestamp(const geometry_msgs::msg::PoseStamped& t) {return tf2_ros::fromMsg(t.header.stamp);}
/** \brief Extract a frame ID from the header of a Pose message.
* This function is a specialization of the getFrameId template defined in tf2/convert.h.
* \param t PoseStamped message to extract the frame ID from.
* \return A string containing the frame ID of the message.
*/
template <>
inline
std::string getFrameId(const geometry_msgs::msg::PoseStamped& t) {return t.header.frame_id;}
/** \brief Apply a geometry_msgs TransformStamped to an geometry_msgs Pose type.
* This function is a specialization of the doTransform template defined in tf2/convert.h.
* \param t_in The pose to transform, as a timestamped Pose3 message.
* \param t_out The transformed pose, as a timestamped Pose3 message.
* \param transform The timestamped transform to apply, as a TransformStamped message.
*/
template <>
inline
void doTransform(const geometry_msgs::msg::PoseStamped& t_in, geometry_msgs::msg::PoseStamped& t_out, const geometry_msgs::msg::TransformStamped& transform)
{
KDL::Vector v(t_in.pose.position.x, t_in.pose.position.y, t_in.pose.position.z);
KDL::Rotation r = KDL::Rotation::Quaternion(t_in.pose.orientation.x, t_in.pose.orientation.y, t_in.pose.orientation.z, t_in.pose.orientation.w);
KDL::Frame v_out = gmTransformToKDL(transform) * KDL::Frame(r, v);
t_out.pose.position.x = v_out.p[0];
t_out.pose.position.y = v_out.p[1];
t_out.pose.position.z = v_out.p[2];
v_out.M.GetQuaternion(t_out.pose.orientation.x, t_out.pose.orientation.y, t_out.pose.orientation.z, t_out.pose.orientation.w);
t_out.header.stamp = transform.header.stamp;
t_out.header.frame_id = transform.header.frame_id;
}
/** \brief Trivial "conversion" function for Pose message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A PoseStamped message.
* \return The input argument.
*/
inline
geometry_msgs::msg::PoseStamped toMsg(const geometry_msgs::msg::PoseStamped& in)
{
return in;
}
/** \brief Trivial "conversion" function for Pose message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param msg A PoseStamped message.
* \param out The input argument.
*/
inline
void fromMsg(const geometry_msgs::msg::PoseStamped& msg, geometry_msgs::msg::PoseStamped& out)
{
out = msg;
}
/*******************************/
/** PoseWithCovarianceStamped **/
/*******************************/
/** \brief Extract a timestamp from the header of a Pose message.
* This function is a specialization of the getTimestamp template defined in tf2/convert.h.
* \param t PoseWithCovarianceStamped message to extract the timestamp from.
* \return The timestamp of the message.
*/
template <>
inline
tf2::TimePoint getTimestamp(const geometry_msgs::msg::PoseWithCovarianceStamped& t) {return tf2_ros::fromMsg(t.header.stamp);}
/** \brief Extract a frame ID from the header of a Pose message.
* This function is a specialization of the getFrameId template defined in tf2/convert.h.
* \param t PoseWithCovarianceStamped message to extract the frame ID from.
* \return A string containing the frame ID of the message.
*/
template <>
inline
std::string getFrameId(const geometry_msgs::msg::PoseWithCovarianceStamped& t) {return t.header.frame_id;}
/** \brief Extract a covariance matrix from a PoseWithCovarianceStamped message.
* This function is a specialization of the getCovarianceMatrix template defined in tf2/convert.h.
* \param t PoseWithCovarianceStamped message to extract the covariance matrix from.
* \return A nested-array representation of the covariance matrix from the message.
*/
template <>
inline
std::array<std::array<double, 6>, 6> getCovarianceMatrix(const geometry_msgs::msg::PoseWithCovarianceStamped& t) {return covarianceRowMajorToNested(t.pose.covariance);}
/** \brief Apply a geometry_msgs TransformStamped to an geometry_msgs Pose type.
* This function is a specialization of the doTransform template defined in tf2/convert.h.
* \param t_in The pose to transform, as a timestamped Pose3 message with covariance.
* \param t_out The transformed pose, as a timestamped Pose3 message with covariance.
* \param transform The timestamped transform to apply, as a TransformStamped message.
*/
template <>
inline
void doTransform(const geometry_msgs::msg::PoseWithCovarianceStamped& t_in, geometry_msgs::msg::PoseWithCovarianceStamped& t_out, const geometry_msgs::msg::TransformStamped& transform)
{
KDL::Vector v(t_in.pose.pose.position.x, t_in.pose.pose.position.y, t_in.pose.pose.position.z);
KDL::Rotation r = KDL::Rotation::Quaternion(t_in.pose.pose.orientation.x, t_in.pose.pose.orientation.y, t_in.pose.pose.orientation.z, t_in.pose.pose.orientation.w);
KDL::Frame v_out = gmTransformToKDL(transform) * KDL::Frame(r, v);
t_out.pose.pose.position.x = v_out.p[0];
t_out.pose.pose.position.y = v_out.p[1];
t_out.pose.pose.position.z = v_out.p[2];
v_out.M.GetQuaternion(t_out.pose.pose.orientation.x, t_out.pose.pose.orientation.y, t_out.pose.pose.orientation.z, t_out.pose.pose.orientation.w);
t_out.header.stamp = transform.header.stamp;
t_out.header.frame_id = transform.header.frame_id;
t_out.pose.covariance = t_in.pose.covariance;
}
/** \brief Trivial "conversion" function for Pose message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A PoseWithCovarianceStamped message.
* \return The input argument.
*/
inline
geometry_msgs::msg::PoseWithCovarianceStamped toMsg(const geometry_msgs::msg::PoseWithCovarianceStamped& in)
{
return in;
}
/** \brief Trivial "conversion" function for Pose message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param msg A PoseWithCovarianceStamped message.
* \param out The input argument.
*/
inline
void fromMsg(const geometry_msgs::msg::PoseWithCovarianceStamped& msg, geometry_msgs::msg::PoseWithCovarianceStamped& out)
{
out = msg;
}
/** \brief Convert a tf2 TransformWithCovarianceStamped type to its equivalent geometry_msgs representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A instance of the tf2::Transform specialization of the tf2::WithCovarianceStamped template.
* \return The TransformWithCovarianceStamped converted to a geometry_msgs PoseStamped message type.
*/
template<>
inline
geometry_msgs::msg::PoseWithCovarianceStamped toMsg(const tf2::WithCovarianceStamped<tf2::Transform>& in)
{
geometry_msgs::msg::PoseWithCovarianceStamped out;
out.header.stamp = tf2_ros::toMsg(in.stamp_);
out.header.frame_id = in.frame_id_;
out.pose.covariance = covarianceNestedToRowMajor(in.cov_mat_);
out.pose.pose.orientation.x = in.getRotation().getX();
out.pose.pose.orientation.y = in.getRotation().getY();
out.pose.pose.orientation.z = in.getRotation().getZ();
out.pose.pose.orientation.w = in.getRotation().getW();
out.pose.pose.position.x = in.getOrigin().getX();
out.pose.pose.position.y = in.getOrigin().getY();
out.pose.pose.position.z = in.getOrigin().getZ();
return out;
}
/** \brief Convert a PoseWithCovarianceStamped message to its equivalent tf2 representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A PoseWithCovarianceStamped message type.
* \param out The PoseWithCovarianceStamped converted to the equivalent tf2 type.
*/
template<>
inline
void fromMsg(const geometry_msgs::msg::PoseWithCovarianceStamped& in, tf2::WithCovarianceStamped<tf2::Transform>& out)
{
out.stamp_ = tf2_ros::fromMsg(in.header.stamp);
out.frame_id_ = in.header.frame_id;
out.cov_mat_ = covarianceRowMajorToNested(in.pose.covariance);
tf2::Transform tmp;
fromMsg(in.pose.pose, tmp);
out.setData(tmp);
}
/****************/
/** Quaternion **/
/****************/
/** \brief Convert a tf2 Quaternion type to its equivalent geometry_msgs representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A tf2 Quaternion object.
* \return The Quaternion converted to a geometry_msgs message type.
*/
inline
geometry_msgs::msg::Quaternion toMsg(const tf2::Quaternion& in)
{
geometry_msgs::msg::Quaternion out;
out.w = in.getW();
out.x = in.getX();
out.y = in.getY();
out.z = in.getZ();
return out;
}
/** \brief Convert a Quaternion message to its equivalent tf2 representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A Quaternion message type.
* \param out The Quaternion converted to a tf2 type.
*/
inline
void fromMsg(const geometry_msgs::msg::Quaternion& in, tf2::Quaternion& out)
{
// w at the end in the constructor
out = tf2::Quaternion(in.x, in.y, in.z, in.w);
}
/***********************/
/** QuaternionStamped **/
/***********************/
/** \brief Extract a timestamp from the header of a Quaternion message.
* This function is a specialization of the getTimestamp template defined in tf2/convert.h.
* \param t QuaternionStamped message to extract the timestamp from.
* \return The timestamp of the message.
*/
template <>
inline
tf2::TimePoint getTimestamp(const geometry_msgs::msg::QuaternionStamped& t) {return tf2_ros::fromMsg(t.header.stamp);}
/** \brief Extract a frame ID from the header of a Quaternion message.
* This function is a specialization of the getFrameId template defined in tf2/convert.h.
* \param t QuaternionStamped message to extract the frame ID from.
* \return A string containing the frame ID of the message.
*/
template <>
inline
std::string getFrameId(const geometry_msgs::msg::QuaternionStamped& t) {return t.header.frame_id;}
/** \brief Apply a geometry_msgs TransformStamped to an geometry_msgs Quaternion type.
* This function is a specialization of the doTransform template defined in tf2/convert.h.
* \param t_in The quaternion to transform, as a timestamped Quaternion3 message.
* \param t_out The transformed quaternion, as a timestamped Quaternion3 message.
* \param transform The timestamped transform to apply, as a TransformStamped message.
*/
template <>
inline
void doTransform(const geometry_msgs::msg::QuaternionStamped& t_in, geometry_msgs::msg::QuaternionStamped& t_out, const geometry_msgs::msg::TransformStamped& transform)
{
tf2::Quaternion q_out = tf2::Quaternion(transform.transform.rotation.x, transform.transform.rotation.y,
transform.transform.rotation.z, transform.transform.rotation.w)*
tf2::Quaternion(t_in.quaternion.x, t_in.quaternion.y, t_in.quaternion.z, t_in.quaternion.w);
t_out.quaternion = toMsg(q_out);
t_out.header.stamp = transform.header.stamp;
t_out.header.frame_id = transform.header.frame_id;
}
/** \brief Trivial "conversion" function for Quaternion message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A QuaternionStamped message.
* \return The input argument.
*/
inline
geometry_msgs::msg::QuaternionStamped toMsg(const geometry_msgs::msg::QuaternionStamped& in)
{
return in;
}
/** \brief Trivial "conversion" function for Quaternion message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param msg A QuaternionStamped message.
* \param out The input argument.
*/
inline
void fromMsg(const geometry_msgs::msg::QuaternionStamped& msg, geometry_msgs::msg::QuaternionStamped& out)
{
out = msg;
}
/** \brief Convert as stamped tf2 Quaternion type to its equivalent geometry_msgs representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A instance of the tf2::Quaternion specialization of the tf2::Stamped template.
* \return The QuaternionStamped converted to a geometry_msgs QuaternionStamped message type.
*/
inline
geometry_msgs::msg::QuaternionStamped toMsg(const tf2::Stamped<tf2::Quaternion>& in)
{
geometry_msgs::msg::QuaternionStamped out;
out.header.stamp = tf2_ros::toMsg(in.stamp_);
out.header.frame_id = in.frame_id_;
out.quaternion.w = in.getW();
out.quaternion.x = in.getX();
out.quaternion.y = in.getY();
out.quaternion.z = in.getZ();
return out;
}
/** \brief Convert a QuaternionStamped message to its equivalent tf2 representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A QuaternionStamped message type.
* \param out The QuaternionStamped converted to the equivalent tf2 type.
*/
inline
void fromMsg(const geometry_msgs::msg::QuaternionStamped& in, tf2::Stamped<tf2::Quaternion>& out)
{
out.stamp_ = tf2_ros::fromMsg(in.header.stamp);
out.frame_id_ = in.header.frame_id;
tf2::Quaternion tmp;
fromMsg(in.quaternion, tmp);
out.setData(tmp);
}
/***************/
/** Transform **/
/***************/
/** \brief Convert a tf2 Transform type to its equivalent geometry_msgs representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A tf2 Transform object.
* \return The Transform converted to a geometry_msgs message type.
*/
inline
geometry_msgs::msg::Transform toMsg(const tf2::Transform& in)
{
geometry_msgs::msg::Transform out;
out.translation.x = in.getOrigin().getX();
out.translation.y = in.getOrigin().getY();
out.translation.z = in.getOrigin().getZ();
out.rotation = toMsg(in.getRotation());
return out;
}
/** \brief Convert a Transform message to its equivalent tf2 representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A Transform message type.
* \param out The Transform converted to a tf2 type.
*/
inline
void fromMsg(const geometry_msgs::msg::Transform& in, tf2::Transform& out)
{
out.setOrigin(tf2::Vector3(in.translation.x, in.translation.y, in.translation.z));
// w at the end in the constructor
out.setRotation(tf2::Quaternion(in.rotation.x, in.rotation.y, in.rotation.z, in.rotation.w));
}
/**********************/
/** TransformStamped **/
/**********************/
/** \brief Extract a timestamp from the header of a Transform message.
* This function is a specialization of the getTimestamp template defined in tf2/convert.h.
* \param t TransformStamped message to extract the timestamp from.
* \return The timestamp of the message.
*/
template <>
inline
tf2::TimePoint getTimestamp(const geometry_msgs::msg::TransformStamped& t) {return tf2_ros::fromMsg(t.header.stamp);}
/** \brief Extract a frame ID from the header of a Transform message.
* This function is a specialization of the getFrameId template defined in tf2/convert.h.
* \param t TransformStamped message to extract the frame ID from.
* \return A string containing the frame ID of the message.
*/
template <>
inline
std::string getFrameId(const geometry_msgs::msg::TransformStamped& t) {return t.header.frame_id;}
/** \brief Apply a geometry_msgs TransformStamped to an geometry_msgs Transform type.
* This function is a specialization of the doTransform template defined in tf2/convert.h.
* \param t_in The frame to transform, as a timestamped Transform3 message.
* \param t_out The frame transform, as a timestamped Transform3 message.
* \param transform The timestamped transform to apply, as a TransformStamped message.
*/
template <>
inline
void doTransform(const geometry_msgs::msg::TransformStamped& t_in, geometry_msgs::msg::TransformStamped& t_out, const geometry_msgs::msg::TransformStamped& transform)
{
KDL::Vector v(t_in.transform.translation.x, t_in.transform.translation.y,
t_in.transform.translation.z);
KDL::Rotation r = KDL::Rotation::Quaternion(t_in.transform.rotation.x,
t_in.transform.rotation.y, t_in.transform.rotation.z, t_in.transform.rotation.w);
KDL::Frame v_out = gmTransformToKDL(transform) * KDL::Frame(r, v);
t_out.transform.translation.x = v_out.p[0];
t_out.transform.translation.y = v_out.p[1];
t_out.transform.translation.z = v_out.p[2];
v_out.M.GetQuaternion(t_out.transform.rotation.x, t_out.transform.rotation.y,
t_out.transform.rotation.z, t_out.transform.rotation.w);
t_out.header.stamp = transform.header.stamp;
t_out.header.frame_id = transform.header.frame_id;
}
/** \brief Trivial "conversion" function for Transform message type.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in A TransformStamped message.
* \return The input argument.
*/
inline
geometry_msgs::msg::TransformStamped toMsg(const geometry_msgs::msg::TransformStamped& in)
{
return in;
}
/** \brief Convert a TransformStamped message to its equivalent tf2 representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param msg A TransformStamped message type.
* \param out The TransformStamped converted to the equivalent tf2 type.
*/
inline
void fromMsg(const geometry_msgs::msg::TransformStamped& msg, geometry_msgs::msg::TransformStamped& out)
{
out = msg;
}
/** \brief Convert a TransformStamped message to its equivalent tf2 representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param msg A TransformStamped message type.
* \param out The TransformStamped converted to the equivalent tf2 type.
*/
inline
void fromMsg(const geometry_msgs::msg::TransformStamped& in, tf2::Stamped <tf2::Transform>& out)
{
out.stamp_ = tf2_ros::fromMsg(in.header.stamp);
out.frame_id_ = in.header.frame_id;
tf2::Transform tmp;
fromMsg(in.transform, tmp);
out.setData(tmp);
}
/** \brief Convert as stamped tf2 Transform type to its equivalent geometry_msgs representation.
* This function is a specialization of the toMsg template defined in tf2/convert.h.
* \param in An instance of the tf2::Transform specialization of the tf2::Stamped template.
* \return The TransformStamped converted to a geometry_msgs TransformStamped message type.
*/
inline
geometry_msgs::msg::TransformStamped toMsg(const tf2::Stamped<tf2::Transform>& in)
{
geometry_msgs::msg::TransformStamped out;
out.header.stamp = tf2_ros::toMsg(in.stamp_);
out.header.frame_id = in.frame_id_;
out.transform.translation.x = in.getOrigin().getX();
out.transform.translation.y = in.getOrigin().getY();
out.transform.translation.z = in.getOrigin().getZ();
out.transform.rotation = toMsg(in.getRotation());
return out;
}
/**********/
/** Pose **/
/**********/
/** \brief Convert a tf2 Transform type to an equivalent geometry_msgs Pose message.
* \param in A tf2 Transform object.
* \param out The Transform converted to a geometry_msgs Pose message type.
*/
inline
/** This section is about converting */
void toMsg(const tf2::Transform& in, geometry_msgs::msg::Pose& out )
{
out.position.x = in.getOrigin().getX();
out.position.y = in.getOrigin().getY();
out.position.z = in.getOrigin().getZ();
out.orientation = toMsg(in.getRotation());
}
/** \brief Convert a geometry_msgs Pose message to an equivalent tf2 Transform type.
* \param in A Pose message.
* \param out The Pose converted to a tf2 Transform type.
*/
inline
void fromMsg(const geometry_msgs::msg::Pose& in, tf2::Transform& out)
{
out.setOrigin(tf2::Vector3(in.position.x, in.position.y, in.position.z));
// w at the end in the constructor
out.setRotation(tf2::Quaternion(in.orientation.x, in.orientation.y, in.orientation.z, in.orientation.w));
}
} // namespace
#endif // TF2_GEOMETRY_MSGS_HPP