Skip to content

Commit f049ad8

Browse files
committed
[tf2_geometry_msgs] Point and Vector convert
Taken from ROS 1.
1 parent c75f9b3 commit f049ad8

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tf2_geometry_msgs/include/tf2_geometry_msgs/tf2_geometry_msgs.hpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@
3535
#include <tf2/convert.h>
3636
#include <tf2/LinearMath/Quaternion.h>
3737
#include <tf2/LinearMath/Transform.h>
38+
#include <tf2/LinearMath/Vector3.h>
3839
#include <tf2_ros/buffer_interface.h>
3940
#include <geometry_msgs/msg/point_stamped.hpp>
4041
#include <geometry_msgs/msg/quaternion_stamped.hpp>
4142
#include <geometry_msgs/msg/transform_stamped.hpp>
43+
#include <geometry_msgs/msg/vector3.hpp>
4244
#include <geometry_msgs/msg/vector3_stamped.hpp>
4345
#include <geometry_msgs/msg/pose.hpp>
46+
#include <geometry_msgs/msg/point.hpp>
4447
#include <geometry_msgs/msg/pose_stamped.hpp>
4548
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
4649
#include <kdl/frames.hpp>
@@ -60,6 +63,35 @@ KDL::Frame gmTransformToKDL(const geometry_msgs::msg::TransformStamped& t)
6063
KDL::Vector(t.transform.translation.x, t.transform.translation.y, t.transform.translation.z));
6164
}
6265

66+
/*************/
67+
/** Vector3 **/
68+
/*************/
69+
70+
/** \brief Convert a tf2 Vector3 type to its equivalent geometry_msgs representation.
71+
* This function is a specialization of the toMsg template defined in tf2/convert.h.
72+
* \param in A tf2 Vector3 object.
73+
* \return The Vector3 converted to a geometry_msgs message type.
74+
*/
75+
inline
76+
geometry_msgs::msg::Vector3 toMsg(const tf2::Vector3 & in)
77+
{
78+
geometry_msgs::msg::Vector3 out;
79+
out.x = in.getX();
80+
out.y = in.getY();
81+
out.z = in.getZ();
82+
return out;
83+
}
84+
85+
/** \brief Convert a Vector3 message to its equivalent tf2 representation.
86+
* This function is a specialization of the fromMsg template defined in tf2/convert.h.
87+
* \param in A Vector3 message type.
88+
* \param out The Vector3 converted to a tf2 type.
89+
*/
90+
inline
91+
void fromMsg(const geometry_msgs::msg::Vector3 & in, tf2::Vector3 & out)
92+
{
93+
out = tf2::Vector3(in.x, in.y, in.z);
94+
}
6395

6496
/********************/
6597
/** Vector3Stamped **/
@@ -124,6 +156,35 @@ void fromMsg(const geometry_msgs::msg::Vector3Stamped& msg, geometry_msgs::msg::
124156
}
125157

126158

159+
/***********/
160+
/** Point **/
161+
/***********/
162+
163+
/** \brief Convert a tf2 Vector3 type to its equivalent geometry_msgs representation.
164+
* This function is a specialization of the toMsg template defined in tf2/convert.h.
165+
* \param in A tf2 Vector3 object.
166+
* \return The Vector3 converted to a geometry_msgs message type.
167+
*/
168+
inline
169+
geometry_msgs::msg::Point & toMsg(const tf2::Vector3 & in, geometry_msgs::msg::Point & out)
170+
{
171+
out.x = in.getX();
172+
out.y = in.getY();
173+
out.z = in.getZ();
174+
return out;
175+
}
176+
177+
/** \brief Convert a Vector3 message to its equivalent tf2 representation.
178+
* This function is a specialization of the fromMsg template defined in tf2/convert.h.
179+
* \param in A Vector3 message type.
180+
* \param out The Vector3 converted to a tf2 type.
181+
*/
182+
inline
183+
void fromMsg(const geometry_msgs::msg::Point & in, tf2::Vector3 & out)
184+
{
185+
out = tf2::Vector3(in.x, in.y, in.z);
186+
}
187+
127188

128189
/******************/
129190
/** PointStamped **/

0 commit comments

Comments
 (0)