0
$\begingroup$

Rosanswers logo

Hello, I am trying to make a simple application of 2 robots moving around in the webots simulator using ROS2. I am using the logic described in the tutorials https://docs.ros.org/en/foxy/Tutorials/Advanced/Simulators/Webots.html which dictates the following:

  1. A description for each robot in the .wbt world file

  2. A URDF file for each robot with the connected devices and the plugin to the robot driver

  3. An obstacle avoider node for each robot

  4. And a controller node for each robot specified in the launch file.

I think that this last part is the source of the problem. This is the part of the launch file where I call the controller:

ros2_supervisor_robot1 = Node(
    package='webots_ros2_driver',
    executable='ros2_supervisor.py',
    output='screen',
    additional_env={'WEBOTS_CONTROLLER_URL': controller_url_prefix() + 'Ros2Supervisor'},
    name='Ros2Supervisor')

ros2_supervisor_robot2 = Node(
    package='webots_ros2_driver',
    executable='ros2_supervisor.py',
    output='screen',
    additional_env={'WEBOTS_CONTROLLER_URL': controller_url_prefix() + 'Ros2Supervisor'},
    name='Ros2Supervisor2')

In the tutorial this launcher for the Ros2Supervisor is used:

ros2_supervisor_robot1 = webots_ros2_driver.webots_launcher.Ros2SupervisorLauncher()

In both cases, the first robot works properly like in the tutorial but the second robot does not because it try as well to connect to the same Ros2Supercisor node and thus the process dies.

I would also like to add that in the .wbt world file, I have left the "controller" field of each robot exactly the same as in the tutorial (controller "")

What is it that I miss? Is there a way to fix this issue?

Thank you


Originally posted by smarn on ROS Answers with karma: 54 on 2023-03-01

Post score: 3

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

First, it is important to note that the ros2_supervisor.py controller should not be used as a robot controller. This node is a special node created and added to the simulation by the webots_ros2 interface to provide ROS services that allow the user to interact with the simulation, such as spawning robots. It is not intended to be used as a controller for your own robots and should not be started manually.

Furthermore, the way to use the ros2_supervisor.py node has changed in the latest version of the webots_ros2 package (version 2023.0.2), and the tutorial you referenced is not reflecting the current usage. We plan to add more advanced tutorials to the documentation in the near future.

It is correct and possible to have multiple robots, here is the way to do it:

  1. As you already did, the .wbt world should contain two robots with different names and the controller field set to <extern>.

  2. If the robots are the same, it is possible to use the same URDF file, especially if they both should use the same controller plugin, like the obstacle avoider. You can use the exact URDF given in the tutorial for both robots, as it adds the MyRobotDriver plugin and the two distance sensors. See this link. The name given in the URDF is not important and won't influence the simulation and the connection.

  3. The content of the URDF should be read into a variable robot_description, like shown in the tutorial.

  4. Finally, to start an obstacle avoider for each robot, you should start the two following nodes:

    my_robot_driver1 = Node(
        package='webots_ros2_driver',
        executable='driver',
        output='screen',
        additional_env={'WEBOTS_CONTROLLER_URL': controller_url_prefix() + 'robot_name_1'},
        parameters=[
            {'robot_description': robot_description},
        ]
    )
    
    my_robot_driver2 = Node(
        package='webots_ros2_driver',
        executable='driver',
        output='screen',
        additional_env={'WEBOTS_CONTROLLER_URL': controller_url_prefix() + 'robot_name_2'},
        parameters=[
            {'robot_description': robot_description},
        ]
    )
    

It is the driver node that is responsible to start the plugins and connect to the robot with the name given in the WEBOTS_CONTROLLER_URL variable.


Originally posted by ygoumaz with karma: 76 on 2023-03-02

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by smarn on 2023-03-02:
Thank you for the thorough explanation. I had indeed messed up in my head the role of the ros2_supervisor.py executable.

Thanks to your sample code I found another silly mistake I have done, I was indeed using the driver node for each robot but in the parameters of the second robot I had put in the key of the dictionary 'robot_desctiption2' so the second robot was never moving because the driver node was never alive.

Thanks again :)

$\endgroup$

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.