dynamic_graph_manager
ros_subscribe.hh
Go to the documentation of this file.
1 
10 #ifndef DYNAMIC_GRAPH_ROS_SUBSCRIBE_HH
11 #define DYNAMIC_GRAPH_ROS_SUBSCRIBE_HH
12 #include <iostream>
13 #include <map>
14 
15 #include <boost/shared_ptr.hpp>
16 
17 #include <dynamic-graph/command.h>
18 #include <dynamic-graph/entity.h>
19 #include <dynamic-graph/signal-ptr.h>
20 #include <dynamic-graph/signal-time-dependent.h>
21 
23 
24 #include <ros/ros.h>
25 
26 #include "converter.hh"
27 #include "dg_to_ros.hh"
28 
29 namespace dynamic_graph
30 {
31 class RosSubscribe;
32 
33 namespace command
34 {
35 namespace rosSubscribe
36 {
37 using ::dynamicgraph::command::Command;
38 using ::dynamicgraph::command::Value;
39 
40 #define ROS_SUBSCRIBE_MAKE_COMMAND(CMD) \
41  class CMD : public Command \
42  { \
43  public: \
44  CMD(RosSubscribe& entity, const std::string& docstring); \
45  virtual Value doExecute(); \
46  }
47 
48 ROS_SUBSCRIBE_MAKE_COMMAND(Add);
49 ROS_SUBSCRIBE_MAKE_COMMAND(Clear);
50 ROS_SUBSCRIBE_MAKE_COMMAND(List);
51 ROS_SUBSCRIBE_MAKE_COMMAND(Rm);
52 
53 #undef ROS_SUBSCRIBE_MAKE_COMMAND
54 
55 } // namespace rosSubscribe
56 } // end of namespace command.
57 
58 namespace internal
59 {
60 template <typename T>
61 struct Add;
62 } // namespace internal
63 
65 class RosSubscribe : public dynamicgraph::Entity
66 {
67  DYNAMIC_GRAPH_ENTITY_DECL();
68  typedef boost::posix_time::ptime ptime;
69 
70 public:
71  typedef std::pair<boost::shared_ptr<dynamicgraph::SignalBase<int> >,
72  boost::shared_ptr<ros::Subscriber> >
73  bindedSignal_t;
74 
75  RosSubscribe(const std::string& n);
76  virtual ~RosSubscribe();
77 
78  virtual std::string getDocString() const;
79  void display(std::ostream& os) const;
80 
81  void add(const std::string& signal, const std::string& topic);
82  void rm(const std::string& signal);
83  std::string list();
84  void clear();
85 
86  template <typename T>
87  void add(const std::string& signal, const std::string& topic);
88 
89  std::map<std::string, bindedSignal_t>& bindedSignal()
90  {
91  return bindedSignal_;
92  }
93 
94  ros::NodeHandle& nh()
95  {
96  return nh_;
97  }
98 
99  template <typename R, typename S>
100  void callback(boost::shared_ptr<dynamicgraph::SignalPtr<S, int> > signal,
101  const R& data);
102 
103  template <typename R>
104  void callbackTimestamp(
105  boost::shared_ptr<dynamicgraph::SignalPtr<ptime, int> > signal,
106  const R& data);
107 
108  template <typename T>
109  friend class internal::Add;
110 
111 private:
112  static const std::string docstring_;
113  ros::NodeHandle& nh_;
114  std::map<std::string, bindedSignal_t> bindedSignal_;
115 };
116 } // namespace dynamic_graph
117 
118 #include "ros_subscribe.hxx"
119 #endif
Publish ROS information in the dynamic-graph.
Definition: ros_subscribe.hh:65
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
Definition: ros_queued_subscribe.hh:66