@@ -91,51 +91,9 @@ geometry_msgs::msg::TransformStamped eigenToTransform(const Eigen::Isometry3d &
9191
9292namespace impl
9393{
94- /* * \brief Template for Eigen::Isometry3d and Eigen::Affine3d conversion.
95- * \tparam mode Mode argument for Eigen::Transform template
96- */
97- template <int mode>
98- struct EigenTransformImpl
99- {
100- /* * \brief Convert a Transform message to an Eigen type.
101- * \param[in] msg The message to convert.
102- * \param[out] out The converted message, as an Eigen type.
103- */
104- static void fromMsg (
105- const geometry_msgs::msg::Transform & msg, Eigen::Transform<double , 3 , mode> & out)
106- {
107- Eigen::Quaterniond q;
108- Eigen::Vector3d v;
109- tf2::fromMsg<>(msg.rotation , q);
110- tf2::fromMsg<>(msg.translation , v);
111- out = Eigen::Translation3d (v) * q;
112- }
113-
114- /* * \brief Convert an Eigen Transform to a Transform message.
115- * \param[in] in The Eigen Transform to convert.
116- * \param[out] msg The converted Transform, as a message.
117- */
118- static void toMsg (
119- const Eigen::Transform<double , 3 , mode> & in, geometry_msgs::msg::Transform & msg)
120- {
121- tf2::toMsg<>(Eigen::Quaterniond (in.linear ()), msg.rotation );
122- tf2::toMsg<>(Eigen::Vector3d (in.translation ()), msg.translation );
123- }
124- };
125-
126- // / \brief Conversion implementation for geometry_msgs::msg::Transform and Eigen::Affine3d.
127- template <>
128- struct ConversionImplementation <Eigen::Affine3d, geometry_msgs::msg::Transform>
129- : EigenTransformImpl<Eigen::Affine>
130- {
131- };
132-
133- // / \brief Conversion implementation for geometry_msgs::msg::Transform and Eigen::Isometry3d.
134- template <>
135- struct ConversionImplementation <Eigen::Isometry3d, geometry_msgs::msg::Transform>
136- : EigenTransformImpl<Eigen::Isometry>
137- {
138- };
94+ // ---------------------
95+ // Vector
96+ // ---------------------
13997
14098// / \brief Conversion implementation for geometry_msgs::msg::Point and Eigen::Vector3d.
14199template <>
@@ -167,6 +125,11 @@ struct DefaultMessageForDatatype<Eigen::Vector3d>
167125 using type = geometry_msgs::msg::Point;
168126};
169127
128+
129+ // ---------------------
130+ // Quaternion
131+ // ---------------------
132+
170133// / \brief Conversion implementation for geometry_msgs::msg::Quaternion and Eigen::Quaterniond.
171134template <>
172135struct ConversionImplementation <Eigen::Quaterniond, geometry_msgs::msg::Quaternion>
@@ -200,51 +163,57 @@ struct DefaultMessageForDatatype<Eigen::Quaterniond>
200163 // / \brief Default return type of tf2::toMsg() for Eigen::Quaterniond.
201164 using type = geometry_msgs::msg::Quaternion;
202165};
203- } // namespace impl
204166
205- /* * \brief Apply a geometry_msgs TransformStamped to an Eigen-specific Quaterniond type.
206- * This function is a specialization of the doTransform template defined in tf2/convert.h,
207- * although it can not be used in tf2_ros::BufferInterface::transform because this
208- * functions rely on the existence of a time stamp and a frame id in the type which should
209- * get transformed.
210- * \param t_in The vector to transform, as a Eigen Quaterniond data type.
211- * \param t_out The transformed vector, as a Eigen Quaterniond data type.
212- * \param transform The timestamped transform to apply, as a TransformStamped message.
167+
168+ // ---------------------
169+ // Transform
170+ // ---------------------
171+
172+ /* * \brief Template for Eigen::Isometry3d and Eigen::Affine3d conversion.
173+ * \tparam mode Mode argument for Eigen::Transform template
213174 */
214- template <>
215- inline
216- void doTransform (
217- const Eigen::Quaterniond & t_in,
218- Eigen::Quaterniond & t_out,
219- const geometry_msgs::msg::TransformStamped & transform)
175+ template <int mode>
176+ struct EigenTransformImpl
220177{
221- Eigen::Quaterniond t;
222- fromMsg (transform.transform .rotation , t);
223- t_out = t * t_in;
224- }
178+ /* * \brief Convert a Transform message to an Eigen type.
179+ * \param[in] msg The message to convert.
180+ * \param[out] out The converted message, as an Eigen type.
181+ */
182+ static void fromMsg (
183+ const geometry_msgs::msg::Transform & msg, Eigen::Transform<double , 3 , mode> & out)
184+ {
185+ Eigen::Quaterniond q;
186+ Eigen::Vector3d v;
187+ tf2::fromMsg<>(msg.rotation , q);
188+ tf2::fromMsg<>(msg.translation , v);
189+ out = Eigen::Translation3d (v) * q;
190+ }
225191
226- /* * \brief Apply a geometry_msgs TransformStamped to an Eigen-specific Quaterniond type.
227- * This function is a specialization of the doTransform template defined in tf2/convert.h.
228- * \param t_in The vector to transform, as a timestamped Eigen Quaterniond data type.
229- * \param t_out The transformed vector, as a timestamped Eigen Quaterniond data type.
230- * \param transform The timestamped transform to apply, as a TransformStamped message.
231- */
192+ /* * \brief Convert an Eigen Transform to a Transform message.
193+ * \param[in] in The Eigen Transform to convert.
194+ * \param[out] msg The converted Transform, as a message.
195+ */
196+ static void toMsg (
197+ const Eigen::Transform<double , 3 , mode> & in, geometry_msgs::msg::Transform & msg)
198+ {
199+ tf2::toMsg<>(Eigen::Quaterniond (in.linear ()), msg.rotation );
200+ tf2::toMsg<>(Eigen::Vector3d (in.translation ()), msg.translation );
201+ }
202+ };
203+
204+ // / \brief Conversion implementation for geometry_msgs::msg::Transform and Eigen::Affine3d.
232205template <>
233- inline
234- void doTransform (
235- const tf2::Stamped<Eigen::Quaterniond> & t_in,
236- tf2::Stamped<Eigen::Quaterniond> & t_out,
237- const geometry_msgs::msg::TransformStamped & transform)
206+ struct ConversionImplementation <Eigen::Affine3d, geometry_msgs::msg::Transform>
207+ : EigenTransformImpl<Eigen::Affine>
238208{
239- t_out.frame_id_ = transform.header .frame_id ;
240- tf2::fromMsg (transform.header .stamp , t_out.stamp_ );
241- doTransform (
242- static_cast <const Eigen::Quaterniond &>(t_in),
243- static_cast <Eigen::Quaterniond &>(t_out), transform);
244- }
209+ };
245210
246- namespace impl
211+ // / \brief Conversion implementation for geometry_msgs::msg::Transform and Eigen::Isometry3d.
212+ template <>
213+ struct ConversionImplementation <Eigen::Isometry3d, geometry_msgs::msg::Transform>
214+ : EigenTransformImpl<Eigen::Isometry>
247215{
216+ };
248217
249218/* * \brief Pose conversion template for Eigen types.
250219 * \tparam T Eigen transform type.
@@ -308,6 +277,11 @@ struct DefaultMessageForDatatype<Eigen::Isometry3d>
308277 using type = geometry_msgs::msg::Pose;
309278};
310279
280+
281+ // ---------------------
282+ // Twist
283+ // ---------------------
284+
311285// / \brief Conversion implementation for geometry_msgs::msg::Twist and Eigen::Matrix<double, 6, 1>.
312286template <>
313287struct ConversionImplementation <Eigen::Matrix<double , 6 , 1 >, geometry_msgs::msg::Twist>
@@ -349,6 +323,11 @@ struct DefaultMessageForDatatype<Eigen::Matrix<double, 6, 1>>
349323 using type = geometry_msgs::msg::Twist;
350324};
351325
326+
327+ // ---------------------
328+ // Wrench
329+ // ---------------------
330+
352331// / \brief Conversion implementation for geometry_msgs::msg::Wrench and Eigen::Matrix<double, 6, 1>.
353332template <>
354333struct ConversionImplementation <Eigen::Matrix<double , 6 , 1 >, geometry_msgs::msg::Wrench>
@@ -417,6 +396,27 @@ geometry_msgs::msg::Vector3 toMsg2(const Eigen::Vector3d & in)
417396 msg.z = in[2 ];
418397 return msg;
419398}
399+
400+ /* * \brief Apply a geometry_msgs TransformStamped to an Eigen-specific Quaterniond type.
401+ * This function is a specialization of the doTransform template defined in tf2/convert.h,
402+ * although it can not be used in tf2_ros::BufferInterface::transform because this
403+ * functions rely on the existence of a time stamp and a frame id in the type which should
404+ * get transformed.
405+ * \param[in] t_in The vector to transform, as a Eigen Quaterniond data type.
406+ * \param[in,out] t_out The transformed vector, as a Eigen Quaterniond data type.
407+ * \param[in] transform The timestamped transform to apply, as a TransformStamped message.
408+ */
409+ template <>
410+ inline
411+ void doTransform (
412+ const Eigen::Quaterniond & t_in,
413+ Eigen::Quaterniond & t_out,
414+ const geometry_msgs::msg::TransformStamped & transform)
415+ {
416+ Eigen::Quaterniond t;
417+ tf2::fromMsg<>(transform.transform .rotation , t);
418+ t_out = Eigen::Quaterniond (t.toRotationMatrix () * t_in.toRotationMatrix ());
419+ }
420420} // namespace tf2
421421
422422#endif // TF2_EIGEN__TF2_EIGEN_H_
0 commit comments