10 #ifndef DYNAMIC_GRAPH_ROS_SUBSCRIBE_HXX 11 #define DYNAMIC_GRAPH_ROS_SUBSCRIBE_HXX 12 #include <dynamic-graph/linear-algebra.h> 13 #include <dynamic-graph/signal-cast-helper.h> 14 #include <dynamic-graph/signal-caster.h> 15 #include <std_msgs/Float64.h> 16 #include <boost/bind.hpp> 17 #include <boost/date_time/posix_time/posix_time.hpp> 19 #include "dynamic_graph_manager/Matrix.h" 20 #include "dynamic_graph_manager/Vector.h" 27 template <
typename R,
typename S>
28 void RosSubscribe::callback(
29 boost::shared_ptr<dynamicgraph::SignalPtr<S, int> > signal,
const R& data)
34 signal->setConstant(value);
38 void RosSubscribe::callbackTimestamp(
39 boost::shared_ptr<dynamicgraph::SignalPtr<ptime, int> > signal,
42 ptime time = rosTimeToPtime(data->header.stamp);
43 signal->setConstant(time);
51 void operator()(RosSubscribe& RosSubscribe,
52 const std::string& signal,
53 const std::string& topic)
55 typedef typename DgToRos<T>::dg_t dg_t;
56 typedef typename DgToRos<T>::ros_const_ptr_t ros_const_ptr_t;
57 typedef typename DgToRos<T>::signalIn_t signal_t;
60 RosSubscribe::bindedSignal_t bindedSignal;
63 boost::format signalName(
"RosSubscribe(%1%)::%2%");
64 signalName % RosSubscribe.getName() % signal;
66 boost::shared_ptr<signal_t> signal_(
new signal_t(0, signalName.str()));
67 DgToRos<T>::setDefault(*signal_);
68 bindedSignal.first = signal_;
69 RosSubscribe.signalRegistration(*bindedSignal.first);
72 typedef boost::function<void(const ros_const_ptr_t& data)>
callback_t;
74 boost::bind(&RosSubscribe::callback<ros_const_ptr_t, dg_t>,
79 bindedSignal.second = boost::make_shared<ros::Subscriber>(
80 RosSubscribe.nh().subscribe(topic, 1, callback));
82 RosSubscribe.bindedSignal()[signal] = bindedSignal;
87 struct Add<
std::pair<T, dg::Vector> >
89 void operator()(RosSubscribe& RosSubscribe,
90 const std::string& signal,
91 const std::string& topic)
93 typedef std::pair<T, dg::Vector> type_t;
100 RosSubscribe::bindedSignal_t bindedSignal;
103 boost::format signalName(
"RosSubscribe(%1%)::%2%");
104 signalName % RosSubscribe.getName() % signal;
106 boost::shared_ptr<signal_t> signal_(
new signal_t(0, signalName.str()));
108 bindedSignal.first = signal_;
109 RosSubscribe.signalRegistration(*bindedSignal.first);
112 typedef boost::function<void(const ros_const_ptr_t& data)>
callback_t;
113 callback_t callback =
114 boost::bind(&RosSubscribe::callback<ros_const_ptr_t, dg_t>,
119 bindedSignal.second = boost::make_shared<ros::Subscriber>(
120 RosSubscribe.nh().subscribe(topic, 1, callback));
122 RosSubscribe.bindedSignal()[signal] = bindedSignal;
125 typedef dynamicgraph::SignalPtr<RosSubscribe::ptime, int>
127 std::string signalTimestamp =
128 (boost::format(
"%1%%2%") % signal %
"Timestamp").str();
131 RosSubscribe::bindedSignal_t bindedSignalTimestamp;
134 boost::format signalNameTimestamp(
"RosSubscribe(%1%)::%2%");
135 signalNameTimestamp % RosSubscribe.name % signalTimestamp;
137 boost::shared_ptr<signalTimestamp_t> signalTimestamp_(
138 new signalTimestamp_t(0, signalNameTimestamp.str()));
140 RosSubscribe::ptime zero(rosTimeToPtime(ros::Time(0, 0)));
141 signalTimestamp_->setConstant(zero);
142 bindedSignalTimestamp.first = signalTimestamp_;
143 RosSubscribe.signalRegistration(*bindedSignalTimestamp.first);
146 typedef boost::function<void(const ros_const_ptr_t& data)>
callback_t;
147 callback_t callbackTimestamp =
148 boost::bind(&RosSubscribe::callbackTimestamp<ros_const_ptr_t>,
153 bindedSignalTimestamp.second = boost::make_shared<ros::Subscriber>(
154 RosSubscribe.nh().subscribe(topic, 1, callbackTimestamp));
156 RosSubscribe.bindedSignal()[signalTimestamp] = bindedSignalTimestamp;
161 template <
typename T>
162 void RosSubscribe::add(
const std::string& signal,
const std::string& topic)
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
Definition: ros_queued_subscribe.hh:66
DgToRos trait type.
Definition: dg_to_ros.hh:64
void converter(D &dst, const S &src)
Handle ROS <-> dynamic-graph conversion.
Definition of the command.
Definition: ros_robot_state_publisher.hpp:164