common.cpp
Go to the documentation of this file.
1 /*
2  * common.cpp
3  *
4  * Created on: Apr 11, 2013
5  * Author: jorge
6  */
7 
8 #include "../../include/yocs_math_toolkit/common.hpp"
9 #include "../../include/yocs_math_toolkit/geometry.hpp"
10 
11 
12 namespace mtk
13 {
14 
15 
16 void tf2pose(const tf::Transform& tf, geometry_msgs::Pose& pose)
17 {
18  pose.position.x = tf.getOrigin().x();
19  pose.position.y = tf.getOrigin().y();
20  pose.position.z = tf.getOrigin().z();
21  tf::quaternionTFToMsg(tf.getRotation(), pose.orientation);
22 }
23 
24 void tf2pose(const tf::StampedTransform& tf, geometry_msgs::PoseStamped& pose)
25 {
26  pose.header.stamp = tf.stamp_;
27  pose.header.frame_id = tf.frame_id_;
28  tf2pose(tf, pose.pose);
29 }
30 
31 void pose2tf(const geometry_msgs::Pose& pose, tf::Transform& tf)
32 {
33  tf.setOrigin(tf::Vector3(pose.position.x, pose.position.y, pose.position.z));
35  tf::quaternionMsgToTF(pose.orientation, q);
36  tf.setRotation(q);
37 }
38 
39 void pose2tf(const geometry_msgs::PoseStamped& pose, tf::StampedTransform& tf)
40 {
41  tf.stamp_ = pose.header.stamp;
42  tf.frame_id_ = pose.header.frame_id;
43  pose2tf(pose.pose, tf);
44 }
45 
46 char ___buffer___[256];
47 
48 const char* point2str(const geometry_msgs::Point& point)
49 {
50  sprintf(___buffer___, "%.2f, %.2f, %.2f", point.x, point.y, point.z);
51  return (const char*)___buffer___;
52 }
53 
54 const char* pose2str(const geometry_msgs::Pose& pose)
55 {
56  sprintf(___buffer___, "%.2f, %.2f, %.2f", pose.position.x, pose.position.y, yaw(pose));
57  return (const char*)___buffer___;
58 }
59 
60 const char* pose2str(const geometry_msgs::PoseStamped& pose)
61 {
62  sprintf(___buffer___, "%.2f, %.2f, %.2f", pose.pose.position.x, pose.pose.position.y, yaw(pose));
63  return (const char*)___buffer___;
64 }
65 
66 std::string vector2str3D(const geometry_msgs::Vector3& vector)
67 {
68  sprintf(___buffer___, "%.2f, %.2f, %.2f", vector.x, vector.y, vector.z);
69  return std::string(___buffer___);
70 }
71 
72 std::string vector2str3D(const geometry_msgs::Vector3Stamped& vector)
73 {
74  return vector2str3D(vector.vector);
75 }
76 
77 std::string point2str2D(const geometry_msgs::Point& point)
78 {
79  sprintf(___buffer___, "%.2f, %.2f", point.x, point.y);
80  return std::string(___buffer___);
81 }
82 
83 std::string point2str2D(const geometry_msgs::PointStamped& point)
84 {
85  return point2str2D(point.point);
86 }
87 
88 std::string point2str3D(const geometry_msgs::Point& point)
89 {
90  sprintf(___buffer___, "%.2f, %.2f, %.2f", point.x, point.y, point.z);
91  return std::string(___buffer___);
92 }
93 
94 std::string point2str3D(const geometry_msgs::PointStamped& point)
95 {
96  return point2str3D(point.point);
97 }
98 
99 std::string pose2str2D(const geometry_msgs::Pose& pose)
100 {
101  sprintf(___buffer___, "%.2f, %.2f, %.2f", pose.position.x, pose.position.y, yaw(pose));
102  return std::string(___buffer___);
103 }
104 
105 std::string pose2str2D(const geometry_msgs::PoseStamped& pose)
106 {
107  return pose2str2D(pose.pose);
108 }
109 
110 std::string pose2str3D(const geometry_msgs::Pose& pose)
111 {
112  sprintf(___buffer___, "%.2f, %.2f, %.2f, %.2f, %.2f, %.2f",
113  pose.position.x, pose.position.y, pose.position.z, roll(pose), pitch(pose), yaw(pose));
114  return std::string(___buffer___);
115 }
116 
117 std::string pose2str3D(const geometry_msgs::PoseStamped& pose)
118 {
119  return pose2str3D(pose.pose);
120 }
121 
122 } /* namespace mtk */
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
void pose2tf(const geometry_msgs::Pose &pose, tf::Transform &tf)
Definition: common.cpp:31
char ___buffer___[256]
Definition: common.cpp:46
double pitch(const tf::Transform &tf)
Definition: geometry.cpp:43
Definition: common.hpp:18
std::string pose2str2D(const geometry_msgs::Pose &pose)
Definition: common.cpp:99
double yaw(const tf::Transform &tf)
Definition: geometry.cpp:62
std::string pose2str3D(const geometry_msgs::Pose &pose)
Definition: common.cpp:110
std::string vector2str3D(const geometry_msgs::Vector3 &vector)
Definition: common.cpp:66
double roll(const tf::Transform &tf)
Definition: geometry.cpp:24
std::string point2str3D(const geometry_msgs::Point &point)
Definition: common.cpp:88
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
static void quaternionMsgToTF(const geometry_msgs::Quaternion &msg, Quaternion &bt)
static void quaternionTFToMsg(const Quaternion &bt, geometry_msgs::Quaternion &msg)
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
Quaternion getRotation() const
void tf2pose(const tf::Transform &tf, geometry_msgs::Pose &pose)
Definition: common.cpp:16
ECL_DEPRECATED const char * pose2str(const geometry_msgs::Pose &pose)
Definition: common.cpp:54
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
ECL_DEPRECATED const char * point2str(const geometry_msgs::Point &point)
Definition: common.cpp:48
std::string frame_id_
std::string point2str2D(const geometry_msgs::Point &point)
Definition: common.cpp:77


yocs_math_toolkit
Author(s): Jorge Santos
autogenerated on Mon Jun 10 2019 15:53:40