Robotics StackExchange | Archived questions

How to Subscribe to a topic that one node is publishing on while publishing on the same topic for a different node?

Hi,

I am working on a leader-follower turtlebot program and I have two turtlebots that will be sending information back and forth to one another.

My question arises because while writing the code it looks like I will run into issues with the follower turtlebot when trying to publish to the cmd_vel topic to make it move.

My leader turtlebot script is coded and working to be operated with a bluetooth controller. The leader turtlebot is subscribed to the cmdvel topic, and my matlab script is publishing to the cmdvel topic and the turtlebot moves and operates using:

lets call it X1-Velocity and Z1_Velocity.

What I want the follower turtlebot to do is to subscribe to the same topic that the leader is subscribed to but I need to also subscribe from my follower matlab script to edit things like velocity relative to a distance threshold on the follower bot.

My follower script needs to take the X1Velocity and Z1Velocity as inputs and change them based on certain conditions (easy enough), but when republishing the new values: X2Velocity and Z2velocity I need to publish those for the follower bot, and not the leader as the leader is strictly controlled by the bluetooth controller.

Is there any way of publishing to a different topic in the follower matlab script and having the follower turtlebot subscribed to that topic?

Basically is there any way to do this:

Leader Bot: Subscribed to cmdvel1 Leader Code: Publishing to cmdvel1

Follower Bot: Subscribed to cmdvel2 Follower Code: Subscribed to cmdvel1 and Publishing to cmdvel2

I hope I explained well!?

Asked by Previn on 2019-09-23 13:50:07 UTC

Comments

Instead of describing your code can you show it? That'll make things much clearer

Asked by jayess on 2019-09-23 19:23:34 UTC

Not sure about the explained well part, I'm getting a strong XY problem vibe from it. You talk a lot about what you have, but not much about what you want to achieve. From what I understand you are trying to make one robot follow the other one? If so I would suggest something like this:

  1. Leader bot is subscribed to cmd_vel_1, does not publish anything.
  2. There is a node that subscribes to cmd_vel_1 and does the "change based on certain conditions" and publishes cmd_vel_2
  3. Follower bot subscribes to cmd_vel_2.

If you want your second bot to only use messages that have definitely been consumed by the leader you can adjust point 1 to publish cmd_vel_received and in point 2 subscribe to that topic instead.

would that solve your problem or am I misunderstanding something?

It is possible to subscribe to a topic that is published to by multiple nodes and only use the messages coming from one specific node, but this is most probably not the use-case for your application.

Asked by Reamees on 2019-09-26 06:48:37 UTC

Answers