geometry_msgs.hpp
Go to the documentation of this file.
1 #pragma once
2 
15 #include <vector>
16 
17 #include <geometry_msgs/Point.h>
18 #include <geometry_msgs/Point32.h>
19 #include <geometry_msgs/Pose.h>
20 #include <geometry_msgs/Quaternion.h>
21 #include <geometry_msgs/Transform.h>
22 #include <geometry_msgs/Vector3.h>
23 
24 namespace cras {
25 
26 #define DEFINE_CONVERTING_GET_PARAM_ROS_VECTOR3(resultType, scalarType, defaultUnit) \
27 DEFINE_CONVERTING_GET_PARAM(resultType, std::vector<scalarType>, defaultUnit, [](const ::std::vector<scalarType>& v){ \
28  if (v.size() != 3) \
29  throw ::std::runtime_error( \
30  ::cras::format("Cannot load %s parameter from an array of length %lu", #resultType, v.size())); \
31  resultType m; m.x = v[0]; m.y = v[1]; m.z = v[2]; \
32  return m; \
33 })
34 
35 DEFINE_CONVERTING_GET_PARAM_ROS_VECTOR3(::geometry_msgs::Vector3, double, "")
38 
39 DEFINE_CONVERTING_GET_PARAM(::geometry_msgs::Quaternion, ::std::vector<double>, "", [](const ::std::vector<double>& v) {
40  if (v.size() != 3 && v.size() != 4)
41  throw ::std::runtime_error(::cras::format("Cannot load %s parameter from an array of length %lu",
42  "geometry_msgs::Quaternion", v.size()));
43  ::geometry_msgs::Quaternion m;
44  if (v.size() == 4)
45  {
46  m.x = v[0]; m.y = v[1]; m.z = v[2]; m.w = v[3];
47  }
48  else
49  {
50  ::tf2::Quaternion q; q.setRPY(v[0], v[1], v[2]);
51  m.x = q.getX(); m.y = q.getY(); m.z = q.getZ(); m.w = q.getW();
52  }
53  return m;
54 })
55 
56 DEFINE_CONVERTING_GET_PARAM(::geometry_msgs::Transform, ::std::vector<double>, "", [](const ::std::vector<double>& v) {
57  if (v.size() != 6 && v.size() != 7 && v.size() != 16)
58  throw ::std::runtime_error(::cras::format("Cannot load %s parameter from an array of length %lu",
59  "geometry_msgs::Transform", v.size()));
60  ::geometry_msgs::Transform m;
61  if (v.size() == 6 || v.size() == 7)
62  {
63  m.translation.x = v[0]; m.translation.y = v[1]; m.translation.z = v[2];
64  if (v.size() == 6)
65  {
66  ::tf2::Quaternion q; q.setRPY(v[3], v[4], v[5]);
67  m.rotation.x = q.getX(); m.rotation.y = q.getY(); m.rotation.z = q.getZ(); m.rotation.w = q.getW();
68  }
69  else
70  {
71  m.rotation.x = v[3]; m.rotation.y = v[4]; m.rotation.z = v[5]; m.rotation.w = v[6];
72  }
73  }
74  else
75  {
76  m.translation.x = v[3]; m.translation.y = v[7]; m.translation.z = v[11];
77  ::tf2::Matrix3x3 r(v[0], v[1], v[2], v[4], v[5], v[6], v[8], v[9], v[10]);
79  r.getRotation(q);
80  m.rotation.x = q.getX(); m.rotation.y = q.getY(); m.rotation.z = q.getZ(); m.rotation.w = q.getW();
81  }
82  return m;
83 })
84 
85 DEFINE_CONVERTING_GET_PARAM(::geometry_msgs::Pose, ::std::vector<double>, "", [](const ::std::vector<double>& v) {
86  if (v.size() != 6 && v.size() != 7 && v.size() != 16)
87  throw ::std::runtime_error(::cras::format("Cannot load %s parameter from an array of length %lu",
88  "geometry_msgs::Pose", v.size()));
89  ::geometry_msgs::Pose m;
90  if (v.size() == 6 || v.size() == 7)
91  {
92  m.position.x = v[0]; m.position.y = v[1]; m.position.z = v[2];
93  if (v.size() == 6)
94  {
95  ::tf2::Quaternion q; q.setRPY(v[3], v[4], v[5]);
96  m.orientation.x = q.getX(); m.orientation.y = q.getY(); m.orientation.z = q.getZ(); m.orientation.w = q.getW();
97  }
98  else
99  {
100  m.orientation.x = v[3]; m.orientation.y = v[4]; m.orientation.z = v[5]; m.orientation.w = v[6];
101  }
102  }
103  else
104  {
105  m.position.x = v[3]; m.position.y = v[7]; m.position.z = v[11];
106  ::tf2::Matrix3x3 r(v[0], v[1], v[2], v[4], v[5], v[6], v[8], v[9], v[10]);
108  r.getRotation(q);
109  m.orientation.x = q.getX(); m.orientation.y = q.getY(); m.orientation.z = q.getZ(); m.orientation.w = q.getW();
110  }
111  return m;
112 })
113 
114 }
cras
Definition: any.hpp:15
tf2::Quaternion::getW
const TF2SIMD_FORCE_INLINE tf2Scalar & getW() const
tf2::Quaternion::setRPY
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
geometry_msgs
cras::DEFINE_CONVERTING_GET_PARAM
DEFINE_CONVERTING_GET_PARAM(::Eigen::Vector3d, ::std::vector< double >, "", [](const ::std::vector< double > &v){ checkSize(v, 3, "vector");return ::Eigen::Vector3d(v.data());}) DEFINE_CONVERTING_GET_PARAM(
Definition: param_utils/get_param_specializations/eigen.hpp:31
cras::format
inline ::std::string format(::std::string format,...)
Definition: string_utils.hpp:280
DEFINE_CONVERTING_GET_PARAM_ROS_VECTOR3
#define DEFINE_CONVERTING_GET_PARAM_ROS_VECTOR3(resultType, scalarType, defaultUnit)
Definition: geometry_msgs.hpp:26
std
tf2::Quaternion
tf2::Matrix3x3


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04