[ros-users] How to write a generic subscriber

Daniele Calisi daniele.calisi at gmail.com
Fri Apr 29 16:27:09 UTC 2011


Dear all,
I am in the process of linking ROS with our OpenRDK framework (
http://openrdk.sf.net). In order to do this, I am writing a plugin for
OpenRDK that is able to handle publishing/subscribing using the ROS protocol
(thus making an OpenRDK agent a ROS node). The publisher part is
straightforward. However, I need generic publishers/subscribers, since I do
not know the message type in advance (conversions between ROS types and
OpenRDK types are handled in an external library, so the core is not aware
of types).

The problem comes when I try to write a generic subscriber: I tried with
this:

                sub = new
ros::Subscriber(rosNodeHandle->subscribe(url.getPath(), 1000,
&RosAphModule::subscriptionCallback, this));

but this cannot be done, since the callback should be something like:

void RosAphModule::subscriptionCallback(const ros::Message::ConstPtr& msg)

that is not allowed, because ros::Message is an abstract type and the
compiler says:

In file included from /usr/include/boost/function/function_base.hpp:32,
                 from /usr/include/boost/function/detail/prologue.hpp:17,
                 from /usr/include/boost/function.hpp:24,
                 from
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/forwards.h:39,
                 from
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/common.h:37,
                 from
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/ros.h:43,
                 from
/mnt/lisablack-home/calisi/devel/sf-software/OpenRDK-next/src/apps/ragent2/modules/aph/rosaphmodule/rosaphmodule.h:10,
                 from
/mnt/lisablack-home/calisi/devel/sf-software/OpenRDK-next/src/apps/ragent2/modules/aph/rosaphmodule/rosaphmodule_aph.cpp:1:
/usr/include/boost/type_traits/alignment_of.hpp: In instantiation of
‘boost::detail::alignment_of_hack<ros::Message>’:
/usr/include/boost/type_traits/alignment_of.hpp:71:   instantiated from
‘const size_t boost::detail::alignment_of_impl<ros::Message>::value’
/usr/include/boost/type_traits/alignment_of.hpp:89:   instantiated from
‘boost::alignment_of<ros::Message>’
/usr/include/boost/smart_ptr/make_shared.hpp:41:   instantiated from
‘boost::detail::sp_ms_deleter<ros::Message>’
/usr/include/boost/smart_ptr/make_shared.hpp:102:   instantiated from
‘boost::shared_ptr<X> boost::make_shared() [with T = ros::Message]’
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message_event.h:54:
  instantiated from ‘boost::shared_ptr<X>
ros::DefaultMessageCreator<M>::operator()() [with M = ros::Message]’
/usr/include/boost/function/function_template.hpp:132:   instantiated from
‘static R boost::detail::function::function_obj_invoker0<FunctionObj,
R>::invoke(boost::detail::function::function_buffer&) [with FunctionObj =
ros::DefaultMessageCreator<ros::Message>, R =
boost::shared_ptr<ros::Message>]’
/usr/include/boost/function/function_template.hpp:913:   instantiated from
‘void boost::function0<R>::assign_to(Functor) [with Functor =
ros::DefaultMessageCreator<ros::Message>, R =
boost::shared_ptr<ros::Message>]’
/usr/include/boost/function/function_template.hpp:722:   instantiated from
‘boost::function0<R>::function0(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not::value, int>::type) [with
Functor = ros::DefaultMessageCreator<ros::Message>, R =
boost::shared_ptr<ros::Message>]’
/usr/include/boost/function/function_template.hpp:1064:   instantiated from
‘boost::function<R()>::function(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not::value, int>::type) [with
Functor = ros::DefaultMessageCreator<ros::Message>, R =
boost::shared_ptr<ros::Message>]’
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/node_handle.h:391:
  instantiated from ‘ros::Subscriber ros::NodeHandle::subscribe(const
std::string&, uint32_t, void (T::*)(const boost::shared_ptr<const M>&), T*,
const ros::TransportHints&) [with M = ros::Message, T =
RDK2::RAgent::RosAphModule]’
/mnt/lisablack-home/calisi/devel/sf-software/OpenRDK-next/src/apps/ragent2/modules/aph/rosaphmodule/rosaphmodule_aph.cpp:26:
  instantiated from here
/usr/include/boost/type_traits/alignment_of.hpp:42: error: cannot declare
field ‘boost::detail::alignment_of_hack<ros::Message>::t’ to be of abstract
type ‘ros::Message’
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message.h:50:
note:   because the following virtual functions are pure within
‘ros::Message’:
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message.h:60:
note:         virtual const std::string ros::Message::__getDataType() const
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message.h:61:
note:         virtual const std::string ros::Message::__getMD5Sum() const
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message.h:62:
note:         virtual const std::string
ros::Message::__getMessageDefinition() const
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message.h:66:
note:         virtual uint32_t ros::Message::serializationLength() const
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message.h:67:
note:         virtual uint8_t* ros::Message::serialize(uint8_t*, uint32_t)
const
/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/message.h:68:
note:         virtual uint8_t* ros::Message::deserialize(uint8_t*)

-- 
Daniele "MadMage" Calisi
"Your limit is always a bit beyond"



-- 
Daniele "MadMage" Calisi
"Your limit is always a bit beyond"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/ros-users/attachments/20110429/57ff5e8c/attachment-0001.html>


More information about the ros-users mailing list