32 #ifndef TF2_GEOMETRY_MSGS_H
33 #define TF2_GEOMETRY_MSGS_H
38 #include <geometry_msgs/PointStamped.h>
39 #include <geometry_msgs/QuaternionStamped.h>
40 #include <geometry_msgs/TransformStamped.h>
41 #include <geometry_msgs/Vector3Stamped.h>
42 #include <geometry_msgs/Pose.h>
43 #include <geometry_msgs/PoseStamped.h>
44 #include <geometry_msgs/PoseWithCovarianceStamped.h>
45 #include <geometry_msgs/Wrench.h>
46 #include <geometry_msgs/WrenchStamped.h>
47 #include <kdl/frames.hpp>
66 return KDL::Frame(KDL::Rotation::Quaternion(
t.transform.rotation.x,
t.transform.rotation.y,
67 t.transform.rotation.z,
t.transform.rotation.w),
68 KDL::Vector(
t.transform.translation.x,
t.transform.translation.y,
t.transform.translation.z));
82 geometry_msgs::Vector3
toMsg(
const tf2::Vector3& in)
84 geometry_msgs::Vector3 out;
97 void fromMsg(
const geometry_msgs::Vector3& in, tf2::Vector3& out)
99 out = tf2::Vector3(in.x, in.y, in.z);
125 const std::string&
getFrameId(
const geometry_msgs::Vector3Stamped&
t) {
return t.header.frame_id;}
134 geometry_msgs::Vector3Stamped
toMsg(
const geometry_msgs::Vector3Stamped& in)
145 void fromMsg(
const geometry_msgs::Vector3Stamped& msg, geometry_msgs::Vector3Stamped& out)
158 geometry_msgs::Vector3Stamped out;
159 out.header.stamp = in.
stamp_;
161 out.vector.x = in.getX();
162 out.vector.y = in.getY();
163 out.vector.z = in.getZ();
175 out.
stamp_ = msg.header.stamp;
177 out.
setData(tf2::Vector3(msg.vector.x, msg.vector.y, msg.vector.z));
191 geometry_msgs::Point&
toMsg(
const tf2::Vector3& in, geometry_msgs::Point& out)
205 void fromMsg(
const geometry_msgs::Point& in, tf2::Vector3& out)
207 out = tf2::Vector3(in.x, in.y, in.z);
233 const std::string&
getFrameId(
const geometry_msgs::PointStamped&
t) {
return t.header.frame_id;}
241 geometry_msgs::PointStamped
toMsg(
const geometry_msgs::PointStamped& in)
252 void fromMsg(
const geometry_msgs::PointStamped& msg, geometry_msgs::PointStamped& out)
265 out.header.stamp = in.
stamp_;
267 out.point.x = in.getX();
268 out.point.y = in.getY();
269 out.point.z = in.getZ();
281 out.
stamp_ = msg.header.stamp;
283 out.
setData(tf2::Vector3(msg.point.x, msg.point.y, msg.point.z));
299 geometry_msgs::Quaternion out;
342 const std::string&
getFrameId(
const geometry_msgs::QuaternionStamped&
t) {
return t.header.frame_id;}
350 geometry_msgs::QuaternionStamped
toMsg(
const geometry_msgs::QuaternionStamped& in)
361 void fromMsg(
const geometry_msgs::QuaternionStamped& msg, geometry_msgs::QuaternionStamped& out)
374 geometry_msgs::QuaternionStamped out;
375 out.header.stamp = in.
stamp_;
377 out.quaternion.w = in.getW();
378 out.quaternion.x = in.getX();
379 out.quaternion.y = in.getY();
380 out.quaternion.z = in.getZ();
405 out.
stamp_ = in.header.stamp;
447 out.
setOrigin(tf2::Vector3(in.position.x, in.position.y, in.position.z));
474 const std::string&
getFrameId(
const geometry_msgs::PoseStamped&
t) {
return t.header.frame_id;}
482 geometry_msgs::PoseStamped
toMsg(
const geometry_msgs::PoseStamped& in)
493 void fromMsg(
const geometry_msgs::PoseStamped& msg, geometry_msgs::PoseStamped& out)
506 out.header.stamp = in.
stamp_;
508 toMsg(in.getOrigin(), out.pose.position);
509 out.pose.orientation =
toMsg(in.getRotation());
521 out.
stamp_ = msg.header.stamp;
548 const std::string&
getFrameId(
const geometry_msgs::PoseWithCovarianceStamped&
t) {
return t.header.frame_id;}
556 geometry_msgs::PoseWithCovarianceStamped
toMsg(
const geometry_msgs::PoseWithCovarianceStamped& in)
567 void fromMsg(
const geometry_msgs::PoseWithCovarianceStamped& msg, geometry_msgs::PoseWithCovarianceStamped& out)
580 out.header.stamp = in.
stamp_;
582 toMsg(in.getOrigin(), out.pose.pose.position);
583 out.pose.pose.orientation =
toMsg(in.getRotation());
595 out.
stamp_ = msg.header.stamp;
614 geometry_msgs::Transform out;
658 const std::string&
getFrameId(
const geometry_msgs::TransformStamped&
t) {
return t.header.frame_id;}
666 geometry_msgs::TransformStamped
toMsg(
const geometry_msgs::TransformStamped& in)
676 void fromMsg(
const geometry_msgs::TransformStamped& msg, geometry_msgs::TransformStamped& out)
689 geometry_msgs::TransformStamped out;
690 out.header.stamp = in.
stamp_;
692 out.transform.translation =
toMsg(in.getOrigin());
693 out.transform.rotation =
toMsg(in.getRotation());
706 out.
stamp_ = msg.header.stamp;
721 void doTransform(
const geometry_msgs::Point& t_in, geometry_msgs::Point& t_out,
const geometry_msgs::TransformStamped& transform)
727 tf2::Vector3 v_out =
t * v_in;
739 void doTransform(
const geometry_msgs::PointStamped& t_in, geometry_msgs::PointStamped& t_out,
const geometry_msgs::TransformStamped& transform)
742 t_out.header.stamp = transform.header.stamp;
743 t_out.header.frame_id = transform.header.frame_id;
754 void doTransform(
const geometry_msgs::Quaternion& t_in, geometry_msgs::Quaternion& t_out,
const geometry_msgs::TransformStamped& transform)
757 fromMsg(transform.transform.rotation,
t);
761 t_out =
toMsg(q_out);
772 void doTransform(
const geometry_msgs::QuaternionStamped& t_in, geometry_msgs::QuaternionStamped& t_out,
const geometry_msgs::TransformStamped& transform)
774 doTransform(t_in.quaternion, t_out.quaternion, transform);
775 t_out.header.stamp = transform.header.stamp;
776 t_out.header.frame_id = transform.header.frame_id;
788 void doTransform(
const geometry_msgs::Pose& t_in, geometry_msgs::Pose& t_out,
const geometry_msgs::TransformStamped& transform)
809 void doTransform(
const geometry_msgs::PoseStamped& t_in, geometry_msgs::PoseStamped& t_out,
const geometry_msgs::TransformStamped& transform)
812 t_out.header.stamp = transform.header.stamp;
813 t_out.header.frame_id = transform.header.frame_id;
841 cov_in[6], cov_in[7], cov_in[8],
842 cov_in[12], cov_in[13], cov_in[14]);
844 cov_in[9], cov_in[10], cov_in[11],
845 cov_in[15], cov_in[16], cov_in[17]);
847 cov_in[24], cov_in[25], cov_in[26],
848 cov_in[30], cov_in[31], cov_in[32]);
850 cov_in[27], cov_in[28], cov_in[29],
851 cov_in[33], cov_in[34], cov_in[35]);
860 geometry_msgs::PoseWithCovariance::_covariance_type output;
861 output[0] = result_11[0][0];
862 output[1] = result_11[0][1];
863 output[2] = result_11[0][2];
864 output[6] = result_11[1][0];
865 output[7] = result_11[1][1];
866 output[8] = result_11[1][2];
867 output[12] = result_11[2][0];
868 output[13] = result_11[2][1];
869 output[14] = result_11[2][2];
871 output[3] = result_12[0][0];
872 output[4] = result_12[0][1];
873 output[5] = result_12[0][2];
874 output[9] = result_12[1][0];
875 output[10] = result_12[1][1];
876 output[11] = result_12[1][2];
877 output[15] = result_12[2][0];
878 output[16] = result_12[2][1];
879 output[17] = result_12[2][2];
881 output[18] = result_21[0][0];
882 output[19] = result_21[0][1];
883 output[20] = result_21[0][2];
884 output[24] = result_21[1][0];
885 output[25] = result_21[1][1];
886 output[26] = result_21[1][2];
887 output[30] = result_21[2][0];
888 output[31] = result_21[2][1];
889 output[32] = result_21[2][2];
891 output[21] = result_22[0][0];
892 output[22] = result_22[0][1];
893 output[23] = result_22[0][2];
894 output[27] = result_22[1][0];
895 output[28] = result_22[1][1];
896 output[29] = result_22[1][2];
897 output[33] = result_22[2][0];
898 output[34] = result_22[2][1];
899 output[35] = result_22[2][2];
912 void doTransform(
const geometry_msgs::PoseWithCovarianceStamped& t_in, geometry_msgs::PoseWithCovarianceStamped& t_out,
const geometry_msgs::TransformStamped& transform)
915 fromMsg(t_in.pose.pose.position, v);
917 fromMsg(t_in.pose.pose.orientation, r);
922 toMsg(v_out, t_out.pose.pose);
923 t_out.header.stamp = transform.header.stamp;
924 t_out.header.frame_id = transform.header.frame_id;
937 void doTransform(
const geometry_msgs::TransformStamped& t_in, geometry_msgs::TransformStamped& t_out,
const geometry_msgs::TransformStamped& transform)
940 fromMsg(t_in.transform, input);
946 t_out.transform =
toMsg(v_out);
947 t_out.header.stamp = transform.header.stamp;
948 t_out.header.frame_id = transform.header.frame_id;
959 void doTransform(
const geometry_msgs::Vector3& t_in, geometry_msgs::Vector3& t_out,
const geometry_msgs::TransformStamped& transform)
963 tf2::Vector3 v_out =
t.getBasis() * tf2::Vector3(t_in.x, t_in.y, t_in.z);
977 void doTransform(
const geometry_msgs::Vector3Stamped& t_in, geometry_msgs::Vector3Stamped& t_out,
const geometry_msgs::TransformStamped& transform)
980 t_out.header.stamp = transform.header.stamp;
981 t_out.header.frame_id = transform.header.frame_id;
995 const std::string&
getFrameId(
const geometry_msgs::WrenchStamped&
t) {
return t.header.frame_id;}
999 geometry_msgs::WrenchStamped
toMsg(
const geometry_msgs::WrenchStamped& in)
1005 void fromMsg(
const geometry_msgs::WrenchStamped& msg, geometry_msgs::WrenchStamped& out)
1012 geometry_msgs::WrenchStamped
toMsg(
const tf2::Stamped<std::array<tf2::Vector3, 2>>& in, geometry_msgs::WrenchStamped & out)
1014 out.header.stamp = in.stamp_;
1015 out.header.frame_id = in.frame_id_;
1016 out.wrench.force =
toMsg(in[0]);
1017 out.wrench.torque =
toMsg(in[1]);
1025 out.stamp_ = msg.header.stamp;
1026 out.frame_id_ = msg.header.frame_id;
1028 fromMsg(msg.wrench.force, tmp);
1030 fromMsg(msg.wrench.torque, tmp1);
1031 std::array<tf2::Vector3, 2> tmp_array;
1033 tmp_array[1] = tmp1;
1034 out.setData(tmp_array);
1039 void doTransform(
const geometry_msgs::Wrench& t_in, geometry_msgs::Wrench& t_out,
const geometry_msgs::TransformStamped& transform)
1042 doTransform(t_in.torque, t_out.torque, transform);
1044 tf2::Vector3 offset = {transform.transform.translation.x, transform.transform.translation.y,
1045 transform.transform.translation.z};
1046 tf2::Vector3 added_torque = offset.cross({t_out.force.x, t_out.force.y, t_out.force.z});
1047 t_out.torque.x += added_torque.getX();
1048 t_out.torque.y += added_torque.getY();
1049 t_out.torque.z += added_torque.getZ();
1055 void doTransform(
const geometry_msgs::WrenchStamped& t_in, geometry_msgs::WrenchStamped& t_out,
const geometry_msgs::TransformStamped& transform)
1057 doTransform(t_in.wrench, t_out.wrench, transform);
1058 t_out.header.stamp = transform.header.stamp;
1059 t_out.header.frame_id = transform.header.frame_id;
1064 #endif // TF2_GEOMETRY_MSGS_H