9 #ifndef DYNAMIC_GRAPH_ROS_CONVERTER_HH 10 #define DYNAMIC_GRAPH_ROS_CONVERTER_HH 16 #include <std_msgs/Header.h> 29 #include <boost/date_time/date.hpp> 30 #include <boost/date_time/posix_time/posix_time.hpp> 31 #include <boost/static_assert.hpp> 33 #define DG_TO_ROS_IMPL(T) \ 35 inline void converter(DgToRos<T>::ros_t& dst, const DgToRos<T>::dg_t& src) 37 #define ROS_TO_DG_IMPL(T) \ 39 inline void converter(DgToRos<T>::dg_t& dst, const DgToRos<T>::ros_t& src) 43 inline void makeHeader(std_msgs::Header& header)
46 header.stamp = ros::Time::now();
47 header.frame_id =
"/dynamic_graph/world";
57 template <
typename D,
typename S>
61 DG_TO_ROS_IMPL(
double)
66 ROS_TO_DG_IMPL(
double)
72 DG_TO_ROS_IMPL(
unsigned int)
77 ROS_TO_DG_IMPL(
unsigned int)
83 DG_TO_ROS_IMPL(Vector)
85 dst.data.resize(src.size());
86 for (
int i = 0; i < src.size(); ++i) dst.data[i] = src(i);
89 ROS_TO_DG_IMPL(Vector)
91 dst.resize(src.data.size());
92 for (
unsigned int i = 0; i < src.data.size(); ++i) dst(i) = src.data[i];
96 DG_TO_ROS_IMPL(specific::Vector3)
104 if (src.size() > 2) dst.z = src(2);
109 ROS_TO_DG_IMPL(specific::Vector3)
118 DG_TO_ROS_IMPL(Matrix)
122 dst.width = (
unsigned int)src.rows();
123 dst.data.resize(src.cols() * src.rows());
124 for (
int i = 0; i < src.cols() * src.rows(); ++i)
125 dst.data[i] = src.data()[i];
128 ROS_TO_DG_IMPL(Matrix)
130 dst.resize(src.width,
131 (
unsigned int)src.data.size() / (
unsigned int)src.width);
132 for (
unsigned i = 0; i < src.data.size(); ++i) dst.data()[i] = src.data[i];
136 DG_TO_ROS_IMPL(MatrixHomogeneous)
138 VectorQuaternion q(src.linear());
139 dst.translation.x = src.translation()(0);
140 dst.translation.y = src.translation()(1);
141 dst.translation.z = src.translation()(2);
143 dst.rotation.x = q.x();
144 dst.rotation.y = q.y();
145 dst.rotation.z = q.z();
146 dst.rotation.w = q.w();
149 ROS_TO_DG_IMPL(MatrixHomogeneous)
152 src.rotation.w, src.rotation.x, src.rotation.y, src.rotation.z);
153 dst.linear() = q.matrix();
156 dst.translation()(0) = src.translation.x;
157 dst.translation()(1) = src.translation.y;
158 dst.translation()(2) = src.translation.z;
162 DG_TO_ROS_IMPL(specific::Twist)
165 throw std::runtime_error(
"failed to convert invalid twist");
166 dst.linear.x = src(0);
167 dst.linear.y = src(1);
168 dst.linear.z = src(2);
169 dst.angular.x = src(3);
170 dst.angular.y = src(4);
171 dst.angular.z = src(5);
174 ROS_TO_DG_IMPL(specific::Twist)
177 dst(0) = src.linear.x;
178 dst(1) = src.linear.y;
179 dst(2) = src.linear.z;
180 dst(3) = src.angular.x;
181 dst(4) = src.angular.y;
182 dst(5) = src.angular.z;
188 #define DG_BRIDGE_TO_ROS_MAKE_STAMPED_IMPL(T, ATTRIBUTE, EXTRA) \ 190 inline void converter(DgToRos<std::pair<T, Vector> >::ros_t& dst, \ 191 const DgToRos<std::pair<T, Vector> >::dg_t& src) \ 193 makeHeader(dst.header); \ 194 converter<DgToRos<T>::ros_t, DgToRos<T>::dg_t>(dst.ATTRIBUTE, src); \ 200 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n 205 dst.child_frame_id =
"";);
214 #define DG_BRIDGE_MAKE_SHPTR_IMPL(T) \ 216 inline void converter( \ 217 DgToRos<T>::dg_t& dst, \ 218 const boost::shared_ptr<DgToRos<T>::ros_t const>& src) \ 220 converter<DgToRos<T>::dg_t, DgToRos<T>::ros_t>(dst, *src); \ 222 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n 236 #define DG_BRIDGE_MAKE_STAMPED_IMPL(T, ATTRIBUTE, EXTRA) \ 238 inline void converter(DgToRos<std::pair<T, Vector> >::dg_t& dst, \ 239 const DgToRos<std::pair<T, Vector> >::ros_t& src) \ 241 converter<DgToRos<T>::dg_t, DgToRos<T>::ros_t>(dst, src.ATTRIBUTE); \ 247 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n 257 #define DG_BRIDGE_MAKE_STAMPED_SHPTR_IMPL(T, ATTRIBUTE, EXTRA) \ 259 inline void converter( \ 260 DgToRos<std::pair<T, Vector> >::dg_t& dst, \ 261 const boost::shared_ptr<DgToRos<std::pair<T, Vector> >::ros_t const>& \ 264 converter<DgToRos<T>::dg_t, DgToRos<T>::ros_t>(dst, src->ATTRIBUTE); \ 270 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n 286 template <
typename U,
typename V>
290 BOOST_STATIC_ASSERT(
sizeof(U) == 0);
293 typedef boost::posix_time::ptime ptime;
294 typedef boost::posix_time::seconds seconds;
295 typedef boost::posix_time::microseconds microseconds;
296 typedef boost::posix_time::time_duration time_duration;
297 typedef boost::gregorian::date date;
299 boost::posix_time::ptime rosTimeToPtime(
const ros::Time& rosTime);
301 ros::Time pTimeToRostime(
const boost::posix_time::ptime& time);
#define DG_BRIDGE_MAKE_STAMPED_SHPTR_IMPL(T, ATTRIBUTE, EXTRA)
This macro generates a converter for a shared pointer on a stamped type.
Definition: converter.hh:257
#define DG_BRIDGE_MAKE_STAMPED_IMPL(T, ATTRIBUTE, EXTRA)
This macro generates a converter for a stamped type.
Definition: converter.hh:236
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
void converter(D &dst, const S &src)
Handle ROS <-> dynamic-graph conversion.
#define DG_BRIDGE_MAKE_SHPTR_IMPL(T)
This macro generates a converter for a shared pointer on a ROS type to a dynamic-graph type...
Definition: converter.hh:214
#define DG_BRIDGE_TO_ROS_MAKE_STAMPED_IMPL(T, ATTRIBUTE, EXTRA)
This macro generates a converter for a stamped type from dynamic-graph to ROS.
Definition: converter.hh:188