10 #ifndef DYNAMIC_GRAPH_ROS_QUEUED_SUBSCRIBE_HH 11 #define DYNAMIC_GRAPH_ROS_QUEUED_SUBSCRIBE_HH 15 #include <boost/shared_ptr.hpp> 16 #include <boost/thread/mutex.hpp> 18 #include <dynamic-graph/command.h> 19 #include <dynamic-graph/entity.h> 20 #include <dynamic-graph/signal-ptr.h> 21 #include <dynamic-graph/signal-time-dependent.h> 31 class RosQueuedSubscribe;
35 namespace rosQueuedSubscribe
37 using ::dynamicgraph::command::Command;
38 using ::dynamicgraph::command::Value;
40 #define ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(CMD) \ 41 class CMD : public Command \ 44 CMD(RosQueuedSubscribe& entity, const std::string& docstring); \ 45 virtual Value doExecute(); \ 48 ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Add);
49 ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Clear);
50 ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(List);
51 ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Rm);
52 ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(ClearQueue);
53 ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(QueueSize);
54 ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(ReadQueue);
56 #undef ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND 61 class RosQueuedSubscribe;
70 typedef boost::shared_ptr<ros::Subscriber> Subscriber_t;
79 virtual void clear() = 0;
80 virtual std::size_t size()
const = 0;
82 Subscriber_t subscriber;
86 template <
typename T,
int BufferSize>
89 typedef dynamicgraph::Signal<T, int> Signal_t;
90 typedef boost::shared_ptr<Signal_t> SignalPtr_t;
91 typedef std::vector<T> buffer_t;
92 typedef typename buffer_t::size_type size_type;
104 std::cout << signal->getName() <<
": Delete" << std::endl;
117 last = buffer[BufferSize - 1];
119 last = buffer[backIdx - 1];
123 frontIdx = backIdx = 0;
130 return frontIdx == backIdx;
135 return ((backIdx + 1) % BufferSize) == frontIdx;
138 size_type size()
const 140 if (frontIdx <= backIdx)
141 return backIdx - frontIdx;
143 return backIdx + BufferSize - frontIdx;
153 boost::mutex wmutex, rmutex;
157 template <
typename R>
158 void writer(
const R& data);
159 T& reader(T& val,
int time);
166 DYNAMIC_GRAPH_ENTITY_DECL();
167 typedef boost::posix_time::ptime ptime;
170 typedef boost::shared_ptr<internal::BindedSignalBase> bindedSignal_t;
175 virtual std::string getDocString()
const;
176 void display(std::ostream& os)
const;
178 void rm(
const std::string& signal);
181 void clearQueue(
const std::string& signal);
182 void readQueue(
int beginReadingAt);
183 std::size_t queueSize(
const std::string& signal)
const;
185 template <
typename T>
186 void add(
const std::string& type,
187 const std::string& signal,
188 const std::string& topic);
190 std::map<std::string, bindedSignal_t>& bindedSignal()
192 return bindedSignal_;
195 ros::NodeHandle& nh()
200 template <
typename R,
typename S>
201 void callback(boost::shared_ptr<dynamicgraph::SignalPtr<S, int> > signal,
204 template <
typename R>
205 void callbackTimestamp(
206 boost::shared_ptr<dynamicgraph::SignalPtr<ptime, int> > signal,
209 template <
typename T>
218 static const std::string docstring_;
219 ros::NodeHandle& nh_;
220 std::map<std::string, bindedSignal_t> bindedSignal_;
225 template <
typename T,
int BufferSize>
size_type backIdx
Index of the slot where to write next value (does not contain valid data).
Definition: ros_queued_subscribe.hh:151
Definition: ros_queued_subscribe.hh:68
size_type frontIdx
Index of the next value to be read.
Definition: ros_queued_subscribe.hh:148
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
Definition: ros_queued_subscribe.hh:66
Definition: ros_queued_subscribe.hh:87
void clear()
See comments in reader and writer for details about synchronisation.
Definition: ros_queued_subscribe.hh:110
Publish ROS information in the dynamic-graph.
Definition: ros_queued_subscribe.hh:164