ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Subscribing and Publishing with generic type of message

asked 2012-07-17 02:48:19 -0500

Erwan R. gravatar image

Hello,

This question is subsequent to this one.

I'm still working on the connexion between Neural Network Simulator (Prométhé) and ROS. Now I know how to retrieve my publisher and subscriber pointers in the Prométhé comunicating functions. But the issue is the following :

When going from Prométhé to ROS, I have Groups of Neurons (i.e. a certain number of activity level <=> a table of floating values between 0 and 1) that I want to put them in a message to send them through a topic. But I can't know before execution what type of topic will be required because it depends on the link that is drawn in the network (ad the simulator will be compiled for a while). The problem is equivalent from ROS to Prométhé : to subscribe to a topic, I have to know which type it is to define the callback function.

So is there a way to be transparent from the type of topic (and compatible with C, meaning that I can't use templates) like a function that dynamically determines type or a "generic" type that gathers every other types (a "common_message" type) ? Or must I define a look-up table / switch case to use the right message depending on the input/output data (considering that I can get a user specified option giving the wanted type) ?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
1

answered 2012-07-17 05:55:00 -0500

dornhege gravatar image

For me that sounds like a design issue, where you don't need such a generic message. Something like an unknown number of activity levels and an unknown number of groups of that can easily be defined as a generic ROS message. Can you give a more concrete example of your data? I think we'll be able to come up with a generic message.

edit flag offensive delete link more

Comments

I agree. Much better to define a standard ROS message that is flexible enough for your application.

joq gravatar image joq  ( 2012-07-17 06:16:25 -0500 )edit

Thanks for answering. I think I wasn't precise enough. The problem is not to define an ad-hoc message for the neural activity. The problem is, in the compiled code of the NN simulator, not to know the type of message that will be defined at execution (by user input). A solution is to have a ...

Erwan R. gravatar image Erwan R.  ( 2012-07-19 00:25:51 -0500 )edit

switch case on each know ROS type but it's not a robust solution. For example, if in Prométhé I define a link from the simulator to ROS on the /base_controller/command topic with geometry_msgs::Twist type, I want my simulator box to advertise with this type. But if I change my mind and I want to ...

Erwan R. gravatar image Erwan R.  ( 2012-07-19 00:30:37 -0500 )edit

publish a TwistWithCovariance message (because it finally fits better), I just want to change the link "msgtype" field (during execution) and not to recompile the whole simulator.

Erwan R. gravatar image Erwan R.  ( 2012-07-19 00:34:21 -0500 )edit
1

In that case the only way out I see is to use something like @Lorenz' suggestion. With python you might be able to do it cleaner.

dornhege gravatar image dornhege  ( 2012-07-19 01:25:20 -0500 )edit
1

Still seems like a bad idea to me. Type safety for ROS messages is an important feature. It should not be given up lightly.

joq gravatar image joq  ( 2012-07-19 02:34:50 -0500 )edit

So does it means that any third-party software that want to communicate with ROS and being technically independent from the solution implements a look-up function with hard-coded message type list, to ensure that what's injected is secure ? It sounds quite static to evolutions ...

Erwan R. gravatar image Erwan R.  ( 2012-07-19 03:28:17 -0500 )edit

I clearly do not understand your question.

joq gravatar image joq  ( 2012-07-19 03:37:49 -0500 )edit
2

answered 2016-10-17 02:38:50 -0500

Davide Faconti gravatar image

I developed a package that extract information from ShapeShifter (i.e., provide introspection and deserialization). This should help you achieving your goal: ros_type_introspection. Take a look to the Wiki pages to see some code samples.

edit flag offensive delete link more

Comments

Kinetic noob here, trying to use this as in the example in ros wiki. But I get an error saying "‘ROSTypeList’ was not declared in this scope" I can't find ROSTypeList in the RosIntrospection namespace as well

teshansj gravatar image teshansj  ( 2018-08-27 23:47:17 -0500 )edit
0

answered 2012-07-17 04:36:02 -0500

Lorenz gravatar image

There is a generic message, the ShapeShifter. It allows you to subscribe to any topic and get the message as a binary blob. There is no way to do introspection at the moment, i.e. although you get the binary data of a message, you cannot access the message fields. It provides a method instantiate that allows you to convert it to a specific type. That means however that you need to have that type at compile time again.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-07-17 02:48:19 -0500

Seen: 3,295 times

Last updated: Oct 17 '16