dynamic_graph_manager
ros_publish.hh
Go to the documentation of this file.
1 
10 #ifndef DYNAMIC_GRAPH_ROS_PUBLISH_HH
11 #define DYNAMIC_GRAPH_ROS_PUBLISH_HH
12 #include <iostream>
13 #include <map>
14 
15 #include <boost/interprocess/sync/interprocess_mutex.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/tuple/tuple.hpp>
18 
19 #include <dynamic-graph/command.h>
20 #include <dynamic-graph/entity.h>
21 #include <dynamic-graph/signal-time-dependent.h>
22 
23 #include <ros/ros.h>
24 
25 #include <realtime_tools/realtime_publisher.h>
26 
29 
30 namespace dynamic_graph
31 {
32 class RosPublish;
33 
34 namespace command
35 {
36 namespace rosPublish
37 {
38 using ::dynamicgraph::command::Command;
39 using ::dynamicgraph::command::Value;
40 
41 #define ROS_PUBLISH_MAKE_COMMAND(CMD) \
42  class CMD : public Command \
43  { \
44  public: \
45  CMD(RosPublish& entity, const std::string& docstring); \
46  virtual Value doExecute(); \
47  }
48 
49 ROS_PUBLISH_MAKE_COMMAND(Add);
50 ROS_PUBLISH_MAKE_COMMAND(Clear);
51 ROS_PUBLISH_MAKE_COMMAND(List);
52 ROS_PUBLISH_MAKE_COMMAND(Rm);
53 
54 #undef ROS_PUBLISH_MAKE_COMMAND
55 
56 } // namespace rosPublish
57 } // end of namespace command.
58 
60 class RosPublish : public dynamicgraph::Entity
61 {
62  DYNAMIC_GRAPH_ENTITY_DECL();
63 
64 public:
65  typedef boost::function<void(int)> callback_t;
66 
67  typedef boost::tuple<boost::shared_ptr<dynamicgraph::SignalBase<int> >,
68  callback_t>
69  bindedSignal_t;
70 
71  static const double ROS_JOINT_STATE_PUBLISHER_RATE;
72 
73  RosPublish(const std::string& n);
74  virtual ~RosPublish();
75 
76  virtual std::string getDocString() const;
77  void display(std::ostream& os) const;
78 
79  void add(const std::string& signal, const std::string& topic);
80  void rm(const std::string& signal);
81  std::string list() const;
82  void clear();
83 
84  int& trigger(int&, int);
85 
86  template <typename T>
87  void sendData(boost::shared_ptr<realtime_tools::RealtimePublisher<
88  typename DgToRos<T>::ros_t> > publisher,
89  boost::shared_ptr<typename DgToRos<T>::signalIn_t> signal,
90  int time);
91 
92  template <typename T>
93  void add(const std::string& signal, const std::string& topic);
94 
95 private:
96  static const std::string docstring_;
97  ros::NodeHandle& nh_;
98  std::map<std::string, bindedSignal_t> bindedSignal_;
99  dynamicgraph::SignalTimeDependent<int, int> trigger_;
100  ros::Duration rate_;
101  ros::Time lastPublicated_;
102  boost::interprocess::interprocess_mutex mutex_;
103 };
104 } // namespace dynamic_graph
105 
106 #include "ros_publish.hxx"
107 #endif
boost::function< void(int)> callback_t
Simple shortcut for code writing convenience.
Definition: ros_robot_state_publisher.hpp:43
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
DgToRos trait type.
Definition: dg_to_ros.hh:64
Publish dynamic-graph information into ROS.
Definition: ros_publish.hh:60