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

subscribe one variable from big topic msg

asked 2016-04-24 14:51:32 -0500

pmarinplaza gravatar image

Hi,

I am using PID pkg that requires a std_msgs float type from topic but I am publishing this variable from a big topic that is the state of the plant (has several floats, integers and booleans)

When I try to subscribe to the variable, a new topic appears with the same namespace but without data.

For example:

The velocity is publishing inside movement_manager/velocity which is a custom msg called: StatusPlant.msg with movement_manager/status, movement_manager/config , etc.

I want to link the PID float message subscribed from movement_manager topic in order to do the PID controller but without luck.

The way I am doing it is with a parameter in a launchfile:

<node name="pid_controller" pkg="pid" type="controller" output="screen">
  <param name="state_topic" value="movement_manager/velocity"/>
  ...
</node>

I tried with remap too but nothing changed.

Anybody knows the way to do it without publishing again the same velocity in a separate float message?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2016-04-24 23:06:48 -0500

lucasw gravatar image

updated 2016-04-24 23:09:27 -0500

That would be a nice feature, though there could be ambiguous cases with the same names (it could always default to the actual topic which it looks like rostopic echo does, unless it doesn't match the expected type then try the message field), or some other character than / could be required.

topic_tools transform can relay message fields:

rostopic pub /test geometry_msgs/Point "{x: 1.0, y: 2.0, z: 3.0}" -r 1

Then

rosrun topic_tools transform /test /test/z std_msgs/Float64 'm.z'

This is neat:

rosrun topic_tools transform /test /test/xy opencv_apps/Point2D 'm.x, m.y'

or

rostopic pub /test sensor_msgs/Image "{header: auto, height: 0, width: 0, encoding: '', is_bigendian: 0, step: 0, data: ''}"  -r 1

rosrun topic_tools transform /test /test/header std_msgs/Header 'm.header'

and then test/z, test/xy, or test/header exist for any node that wants them.

If ros could do it automatically ideally it would not do it in the subscriber (requiring the overhead of transporting and receiving an entire Image for example just for a few bytes of a field), but would be essentially launching something like the topic_tools transform behind the scenes.

edit flag offensive delete link more

Comments

1

Thak works properly. Thanks. The way I did it is by roslaunch:

<node name="publish_velocity" pkg="topic_tools" type="transform"
args="/movement_manager/status_info /movement_manager/velocity std_msgs/Float64 m.trc.velocity" />
pmarinplaza gravatar image pmarinplaza  ( 2016-04-25 08:07:29 -0500 )edit
1

Those who got the error ERROR: Wrong input topic (or topic field):, please be aware of a namespace bug in transform.

samarth.robo gravatar image samarth.robo  ( 2019-12-19 10:16:31 -0500 )edit

The namespace bug has been fixed, but there is another issue with transform that appears only the first time transform is run for a given roscore session #q349655

lucasw gravatar image lucasw  ( 2021-10-11 09:18:17 -0500 )edit
3

answered 2016-04-24 21:02:20 -0500

ahendrix gravatar image

updated 2016-04-25 02:22:49 -0500

You cannot subscribe to part of a message. The publisher and subscriber types must match, and you have to subscribe to the whole topic.

(rostopic echo and rqt_plot make it seems like you can subscribe to one field, but they're actually subscribing to the entire message and only printing part of it. This is the exception; very few other parts of ROS can do this.)

If you have a subscriber that accepts a particular topic type, you must publish a topic with that type. That might mean modifying your existing publisher to publish a second topic, or writing a very small relay node which subscribes to the entire topic and republishes on a new topic with the desired type and data.

edit flag offensive delete link more
0

answered 2016-04-25 02:07:25 -0500

pmarinplaza gravatar image

Then, rqt_plot is subscribing to the whole message the same way rostopic echo is doing it?

How can I develop a node like rostopic echo that dynamically can subscribe to any kind of message by topic?

edit flag offensive delete link more

Comments

Yes, rqt_plot also subscribes to the entire message. Generic subscribers like this are generally not a good idea, because they break the message typing system, and they're generally only a good idea for debugging or introspection tools.

ahendrix gravatar image ahendrix  ( 2016-04-25 02:22:20 -0500 )edit

If you really want to do this, be aware that it can only be done in Python (the static typing in C++ does not allow it), and then read the source code for rostopic echo and topic_tools transform

ahendrix gravatar image ahendrix  ( 2016-04-25 02:24:03 -0500 )edit

Ok, I'll use topic tools transform to do the magic trick. Thanks for the answer.

pmarinplaza gravatar image pmarinplaza  ( 2016-04-25 03:17:42 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-04-24 14:51:32 -0500

Seen: 2,496 times

Last updated: Apr 25 '16