dynamic_graph_manager
ros_publish.hxx
Go to the documentation of this file.
1 
10 #ifndef DYNAMIC_GRAPH_ROS_PUBLISH_HXX
11 #define DYNAMIC_GRAPH_ROS_PUBLISH_HXX
12 #include <std_msgs/Float64.h>
13 #include <vector>
14 
15 #include "dynamic_graph_manager/Matrix.h"
16 #include "dynamic_graph_manager/Vector.h"
17 
18 #include "dg_to_ros.hh"
19 
20 #include <iostream>
21 
22 namespace dynamic_graph
23 {
24 template <>
25 inline void RosPublish::sendData<std::pair<MatrixHomogeneous, Vector> >(
26  boost::shared_ptr<realtime_tools::RealtimePublisher<
27  DgToRos<std::pair<MatrixHomogeneous, Vector> >::ros_t> > publisher,
28  boost::shared_ptr<
29  DgToRos<std::pair<MatrixHomogeneous, Vector> >::signalIn_t> signal,
30  int time)
31 {
32  DgToRos<std::pair<MatrixHomogeneous, Vector> >::ros_t result;
33  if (publisher->trylock())
34  {
35  publisher->msg_.child_frame_id = "/dynamic_graph/world";
36  converter(publisher->msg_, signal->access(time));
37  publisher->unlockAndPublish();
38  }
39 }
40 
41 template <typename T>
42 void RosPublish::sendData(
43  boost::shared_ptr<realtime_tools::RealtimePublisher<
44  typename DgToRos<T>::ros_t> > publisher,
45  boost::shared_ptr<typename DgToRos<T>::signalIn_t> signal,
46  int time)
47 {
48  typename DgToRos<T>::ros_t result;
49  if (publisher->trylock())
50  {
51  converter(publisher->msg_, signal->access(time));
52  publisher->unlockAndPublish();
53  }
54 }
55 
56 template <typename T>
57 void RosPublish::add(const std::string& signal, const std::string& topic)
58 {
59  typedef typename DgToRos<T>::ros_t ros_t;
60  typedef typename DgToRos<T>::signalIn_t signal_t;
61 
62  // Initialize the bindedSignal object.
63  bindedSignal_t bindedSignal;
64 
65  // Initialize the publisher.
66  boost::shared_ptr<realtime_tools::RealtimePublisher<ros_t> > pubPtr =
67  boost::make_shared<realtime_tools::RealtimePublisher<ros_t> >(
68  nh_, topic, 1);
69 
70  // Initialize the signal.
71  boost::shared_ptr<signal_t> signalPtr(new signal_t(
72  0, MAKE_SIGNAL_STRING(name, true, DgToRos<T>::signalTypeName, signal)));
73  boost::get<0>(bindedSignal) = signalPtr;
74  DgToRos<T>::setDefault(*signalPtr);
75  signalRegistration(*boost::get<0>(bindedSignal));
76 
77  // Initialize the callback.
78  callback_t callback =
79  boost::bind(&RosPublish::sendData<T>, this, pubPtr, signalPtr, _1);
80  boost::get<1>(bindedSignal) = callback;
81 
82  bindedSignal_[signal] = bindedSignal;
83 }
84 
85 } // namespace dynamic_graph
86 
87 #endif
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.