diff options
author | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-22 16:47:28 +0100 |
---|---|---|
committer | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-22 16:47:28 +0100 |
commit | 49d41773fc990a6b878543fac2c5cda328bf7d78 (patch) | |
tree | c569a891afdaba69c6ba0975bd377134acbb984c /src/platforms | |
parent | 8c4fce3654bbf4cb31314f1fb596f4fd17772589 (diff) | |
download | px4-firmware-49d41773fc990a6b878543fac2c5cda328bf7d78.tar.gz px4-firmware-49d41773fc990a6b878543fac2c5cda328bf7d78.tar.bz2 px4-firmware-49d41773fc990a6b878543fac2c5cda328bf7d78.zip |
ros wrapper port callback to methods and subscriber without callback
Diffstat (limited to 'src/platforms')
-rw-r--r-- | src/platforms/px4_nodehandle.h | 43 | ||||
-rw-r--r-- | src/platforms/px4_subscriber.h | 3 |
2 files changed, 22 insertions, 24 deletions
diff --git a/src/platforms/px4_nodehandle.h b/src/platforms/px4_nodehandle.h index a25d57845..e619623b9 100644 --- a/src/platforms/px4_nodehandle.h +++ b/src/platforms/px4_nodehandle.h @@ -91,34 +91,33 @@ public: /** * Subscribe with callback to class method - * @param topic Name of the topic * @param fb Callback, executed on receiving a new message + * @param obj pointer class instance */ - // template<typename M, typename T> - // Subscriber<M> *subscribe(const char *topic, void(T::*fp)(const M &), T *obj) - // { - // SubscriberBase *sub = new SubscriberROS<M>(std::bind(fp, obj, std::placeholders::_1)); - // ros::Subscriber ros_sub = ros::NodeHandle::subscribe(topic, kQueueSizeDefault, &SubscriberROS<M>::callback, - // (SubscriberROS<M> *)sub); - // ((SubscriberROS<M> *)sub)->set_ros_sub(ros_sub); - // _subs.push_back(sub); - // return (Subscriber<M> *)sub; - // } + template<typename T, typename C> + Subscriber<T> *subscribe(void(C::*fp)(const T &), C *obj) + { + SubscriberBase *sub = new SubscriberROS<T>(std::bind(fp, obj, std::placeholders::_1)); + ros::Subscriber ros_sub = ros::NodeHandle::subscribe(T::handle(), kQueueSizeDefault, + &SubscriberROS<T>::callback, (SubscriberROS<T> *)sub); + ((SubscriberROS<T> *)sub)->set_ros_sub(ros_sub); + _subs.push_back(sub); + return (Subscriber<T> *)sub; + } /** * Subscribe with no callback, just the latest value is stored on updates - * @param topic Name of the topic */ - // template<typename M> - // Subscriber<M> *subscribe(const char *topic) - // { - // SubscriberBase *sub = new SubscriberROS<M>(); - // ros::Subscriber ros_sub = ros::NodeHandle::subscribe(topic, kQueueSizeDefault, &SubscriberROS<M>::callback, - // (SubscriberROS<M> *)sub); - // ((SubscriberROS<M> *)sub)->set_ros_sub(ros_sub); - // _subs.push_back(sub); - // return (Subscriber<M> *)sub; - // } + template<typename T> + Subscriber<T> *subscribe() + { + SubscriberBase *sub = new SubscriberROS<T>(); + ros::Subscriber ros_sub = ros::NodeHandle::subscribe(T::handle(), kQueueSizeDefault, + &SubscriberROS<T>::callback, (SubscriberROS<T> *)sub); + ((SubscriberROS<T> *)sub)->set_ros_sub(ros_sub); + _subs.push_back(sub); + return (Subscriber<T> *)sub; + } /** * Advertise topic diff --git a/src/platforms/px4_subscriber.h b/src/platforms/px4_subscriber.h index d03b3edee..c499712a9 100644 --- a/src/platforms/px4_subscriber.h +++ b/src/platforms/px4_subscriber.h @@ -130,11 +130,10 @@ protected: void callback(const typename std::remove_reference<decltype(((T*)nullptr)->data())>::type &msg) { /* Store data */ - this->_msg_current = (T)msg; + this->_msg_current.data() = msg; /* Call callback */ if (_cbf != NULL) { - // _cbf(_msg_current); _cbf(this->get()); } |