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

Have two nodes publish to same topic

asked 2019-03-18 12:01:25 -0600

lidar_help gravatar image

So I have two nodes publishing to the topic /mavros/setpoint_position/local and I want one to have priority over the other. Right now it just switches between the two. Is there a way to have them both publish then assign priority to one?

More info on my particular problem. I have a exploration node sending to the topic, then have another node which sends only when battery is too low. I don't want to change anything in the exploration alghoritm, just have the battery node publish to the topic /mavros/setpoint_position/local and overwrite what the exploration node publishes.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-03-18 12:31:13 -0600

jayess gravatar image

It sounds like multiplexing may help. From the description on the wiki

mux is a ROS node that subscribes to a set of incoming topics and republishes incoming data from one of them to another topic, i.e., it's a multiplexer that switches an output among 1 of N inputs. Services are offered to switch among input topics, and to add and delete input topics. At startup, the first input topic on the command line is selected.

To use it with rosrun:

rosrun topic_tools <outopic> <intopic1> [intopic2...] [standard ROS arguments]

and to use it with roslaunch see #q84386.

edit flag offensive delete link more


I solved the problem. What I did was to change the topic names of the two nodes then simply have a new control node subscribe to both of those topics. This control node would then decide which of the two topics to publish. From what I can read this method is very similar to what jayess described above, and that method seems easier than creating a whole new node.

lidar_help gravatar image lidar_help  ( 2019-03-19 12:18:06 -0600 )edit

You can also consider using nodelets for this as it provides features as zero copy of data and reduced networking (nodelets wiki). There is already nodelet for similar use case and that is yocs_waypoints_navi

Dyson sphere gravatar image Dyson sphere  ( 2019-03-19 23:24:49 -0600 )edit

Question Tools


Asked: 2019-03-18 12:01:25 -0600

Seen: 2,293 times

Last updated: Mar 19 '19