34 #include <Eigen/Geometry>
35 #include <geometry_msgs/msg/point_stamped.hpp>
36 #include <geometry_msgs/msg/pose_stamped.hpp>
37 #include <geometry_msgs/msg/quaternion_stamped.hpp>
38 #include <geometry_msgs/msg/twist.hpp>
39 #include <geometry_msgs/msg/point.hpp>
40 #include <geometry_msgs/msg/quaternion.hpp>
53 return Eigen::Isometry3d(Eigen::Translation3d(t.translation.x, t.translation.y, t.translation.z)
54 * Eigen::Quaterniond(t.rotation.w, t.rotation.x, t.rotation.y, t.rotation.z));
73 geometry_msgs::msg::TransformStamped t;
74 t.transform.translation.x = T.translation().x();
75 t.transform.translation.y = T.translation().y();
76 t.transform.translation.z = T.translation().z();
78 Eigen::Quaterniond q(T.linear());
79 t.transform.rotation.x = q.x();
80 t.transform.rotation.y = q.y();
81 t.transform.rotation.z = q.z();
82 t.transform.rotation.w = q.w();
94 geometry_msgs::msg::TransformStamped t;
95 t.transform.translation.x = T.translation().x();
96 t.transform.translation.y = T.translation().y();
97 t.transform.translation.z = T.translation().z();
99 Eigen::Quaterniond q(T.rotation());
100 t.transform.rotation.x = q.x();
101 t.transform.rotation.y = q.y();
102 t.transform.rotation.z = q.z();
103 t.transform.rotation.w = q.w();
119 void doTransform(
const Eigen::Vector3d& t_in, Eigen::Vector3d& t_out,
const geometry_msgs::msg::TransformStamped& transform)
130 geometry_msgs::msg::Point
toMsg(
const Eigen::Vector3d& in)
132 geometry_msgs::msg::Point msg;
145 void fromMsg(
const geometry_msgs::msg::Point& msg, Eigen::Vector3d& out)
158 geometry_msgs::msg::Vector3&
toMsg(
const Eigen::Vector3d& in, geometry_msgs::msg::Vector3& out)
172 void fromMsg(
const geometry_msgs::msg::Vector3& msg, Eigen::Vector3d& out)
189 const geometry_msgs::msg::TransformStamped& transform) {
192 transform.header.frame_id);
203 geometry_msgs::msg::PointStamped msg;
206 msg.point =
toMsg(
static_cast<const Eigen::Vector3d&
>(in));
219 fromMsg(msg.point,
static_cast<Eigen::Vector3d&
>(out));
234 Eigen::Affine3d& t_out,
235 const geometry_msgs::msg::TransformStamped& transform) {
242 Eigen::Isometry3d& t_out,
243 const geometry_msgs::msg::TransformStamped& transform) {
253 geometry_msgs::msg::Quaternion
toMsg(
const Eigen::Quaterniond& in) {
254 geometry_msgs::msg::Quaternion msg;
268 void fromMsg(
const geometry_msgs::msg::Quaternion& msg, Eigen::Quaterniond& out) {
269 out = Eigen::Quaterniond(msg.w, msg.x, msg.y, msg.z);
284 Eigen::Quaterniond& t_out,
285 const geometry_msgs::msg::TransformStamped& transform) {
286 Eigen::Quaterniond t;
287 fromMsg(transform.transform.rotation, t);
288 t_out = t.inverse() * t_in * t;
298 geometry_msgs::msg::QuaternionStamped msg;
301 msg.quaternion =
toMsg(
static_cast<const Eigen::Quaterniond&
>(in));
314 fromMsg(msg.quaternion,
static_cast<Eigen::Quaterniond&
>(out));
327 const geometry_msgs::msg::TransformStamped& transform) {
328 t_out.
frame_id_ = transform.header.frame_id;
330 doTransform(
static_cast<const Eigen::Quaterniond&
>(t_in),
static_cast<Eigen::Quaterniond&
>(t_out), transform);
339 geometry_msgs::msg::Pose
toMsg(
const Eigen::Affine3d& in) {
340 geometry_msgs::msg::Pose msg;
341 msg.position.x = in.translation().x();
342 msg.position.y = in.translation().y();
343 msg.position.z = in.translation().z();
344 Eigen::Quaterniond q(in.linear());
345 msg.orientation.x = q.x();
346 msg.orientation.y = q.y();
347 msg.orientation.z = q.z();
348 msg.orientation.w = q.w();
358 geometry_msgs::msg::Pose
toMsg(
const Eigen::Isometry3d& in) {
359 geometry_msgs::msg::Pose msg;
360 msg.position.x = in.translation().x();
361 msg.position.y = in.translation().y();
362 msg.position.z = in.translation().z();
363 Eigen::Quaterniond q(in.linear());
364 msg.orientation.x = q.x();
365 msg.orientation.y = q.y();
366 msg.orientation.z = q.z();
367 msg.orientation.w = q.w();
379 geometry_msgs::msg::Vector3
toMsg2(
const Eigen::Vector3d& in) {
380 geometry_msgs::msg::Vector3 msg;
393 void fromMsg(
const geometry_msgs::msg::Pose& msg, Eigen::Affine3d& out) {
394 out = Eigen::Affine3d(
395 Eigen::Translation3d(msg.position.x, msg.position.y, msg.position.z) *
396 Eigen::Quaterniond(msg.orientation.w,
408 void fromMsg(
const geometry_msgs::msg::Pose& msg, Eigen::Isometry3d& out) {
409 out = Eigen::Isometry3d(
410 Eigen::Translation3d(msg.position.x, msg.position.y, msg.position.z) *
411 Eigen::Quaterniond(msg.orientation.w,
423 geometry_msgs::msg::Twist
toMsg(
const Eigen::Matrix<double,6,1>& in) {
424 geometry_msgs::msg::Twist msg;
425 msg.linear.x = in[0];
426 msg.linear.y = in[1];
427 msg.linear.z = in[2];
428 msg.angular.x = in[3];
429 msg.angular.y = in[4];
430 msg.angular.z = in[5];
440 void fromMsg(
const geometry_msgs::msg::Twist &msg, Eigen::Matrix<double,6,1>& out) {
441 out[0] = msg.linear.x;
442 out[1] = msg.linear.y;
443 out[2] = msg.linear.z;
444 out[3] = msg.angular.x;
445 out[4] = msg.angular.y;
446 out[5] = msg.angular.z;
462 const geometry_msgs::msg::TransformStamped& transform) {
479 const geometry_msgs::msg::TransformStamped& transform) {
491 geometry_msgs::msg::PoseStamped msg;
494 msg.pose =
toMsg(
static_cast<const Eigen::Affine3d&
>(in));
501 geometry_msgs::msg::PoseStamped msg;
504 msg.pose =
toMsg(
static_cast<const Eigen::Isometry3d&
>(in));
518 fromMsg(msg.pose,
static_cast<Eigen::Affine3d&
>(out));
526 fromMsg(msg.pose,
static_cast<Eigen::Isometry3d&
>(out));
542 geometry_msgs::msg::Pose
toMsg(
const Eigen::Affine3d& in) {
547 geometry_msgs::msg::Pose
toMsg(
const Eigen::Isometry3d& in) {
552 void fromMsg(
const geometry_msgs::msg::Point& msg, Eigen::Vector3d& out) {
557 geometry_msgs::msg::Point
toMsg(
const Eigen::Vector3d& in) {
562 void fromMsg(
const geometry_msgs::msg::Pose& msg, Eigen::Affine3d& out) {
567 void fromMsg(
const geometry_msgs::msg::Pose& msg, Eigen::Isometry3d& out) {
572 geometry_msgs::msg::Quaternion
toMsg(
const Eigen::Quaterniond& in) {
577 geometry_msgs::msg::Twist
toMsg(
const Eigen::Matrix<double,6,1>& in) {
582 void fromMsg(
const geometry_msgs::msg::Twist &msg, Eigen::Matrix<double,6,1>& out) {
588 #endif // TF2_EIGEN_H