1
$\begingroup$

I am following the tutorial of Setting up a robot simulation in Webots (Basic) which is in ROS2 humble documentation. Here I have a .wbt world file, .urdf file according to the tutorial. I have added another robot in the world file and change controller node for each robot specified in the launch file. In the tutorial they have mentioned "if you had more robots in the simulation, you would have to run one instance of this node per robot". This is the part of my launch file where I created the nodes:

my_robot_driver_1 = WebotsController(
    robot_name='my_robot_1',
    parameters=[
        {'robot_description': robot_description_path},
    ]
)
my_robot_driver_2 = WebotsController(
    robot_name='my_robot_2',
    parameters=[
        {'robot_description': robot_description_path},
    ]
)

After successfully running the code webots starts with 2 robots and the topic list is:

/cmd_vel
/my_robot_1/ds0
/my_robot_1/ds1
/my_robot_2/ds0
/my_robot_2/ds1
/parameter_events
/remove_urdf_robot
/rosout

Here there is 1 /cmd_vel but i need different /cmd_vel for each robot like (expected topic list):

/my_robot_1/cmd_vel
/my_robot_1/ds0
/my_robot_1/ds1
/my_robot_2/cmd_vel
/my_robot_2/ds0
/my_robot_2/ds1
/parameter_events
/remove_urdf_robot
/rosout

In the world file, "controller" field of each robot is exactly the same as in the tutorial controller "<extern>".

How to solve this problem? Thank you.

$\endgroup$
3
  • $\begingroup$ What's the actual error here? It's not clear what behavior you're observing vs. what behavior you're expecting. $\endgroup$
    – cst0
    Dec 24, 2023 at 4:10
  • $\begingroup$ There is no error. The problem is i have 2 robots but one /cmd_vel. So, if I give Twist message linear x=1 then both the robots move to x direction with value 1. But i need two /cmd_vel topic for those two robots so that I can move them independently. Like if i publish Twist message linear x=1 to /robot1/cmd_vel topic then only the 1st robot moves in x direction and 2nd robot remain in its place. $\endgroup$ Dec 25, 2023 at 5:58
  • $\begingroup$ I have edited my current topic list and expected topic list in the question. Hope it may help you to understand well. $\endgroup$ Dec 25, 2023 at 6:07

1 Answer 1

1
$\begingroup$

In general, you can either use a namespace or remappings or a combination of both. In your case, it would look something like:

my_robot_driver_1 = WebotsController(
    robot_name='my_robot_1',
    parameters=[
        {'robot_description': robot_description_path},
    ],
    remappings=[
            ('/cmd_vel', '/my_robot_1/cmd_vel'),
    ]
)
my_robot_driver_2 = WebotsController(
    robot_name='my_robot_2',
    parameters=[
        {'robot_description': robot_description_path},
    ],
    remappings=[
            ('/cmd_vel', '/my_robot_2/cmd_vel'),
    ]
)

Here is an example of a launch file spawning multiple robots in Webots: https://github.com/memristor/mep3/blob/b03b6aa0e0de5e5bfe5ec8694cf6f3d21cf697ce/mep3_simulation/launch/simulation_launch.py#L35-L73

$\endgroup$
1
  • $\begingroup$ I have tried your method. But the problem remain same. There is just one /cmd_vel topic and the name is /cmd_vel. No change happened in the topic list. $\endgroup$ Dec 25, 2023 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.