cyberbotics / webots_ros2

Webots ROS 2 packages
Apache License 2.0
398 stars 147 forks source link

How to connect several robots in the same simulation? #450

Closed Realtic12 closed 2 years ago

Realtic12 commented 2 years ago

Hi to everyone!

I am programming an autonomous vehicle in Webots and I want to do a dynamic simulation with multiple cars. But I don't know how to connect to each robot with an external controller. I use as a base the Tesla package, created in this page, so the launch and urdf files are the same as the inicial ones. The documentation in Webots, says this:

If you are running multiple simulations simultaneously on the same machine, then you need to indicate to your controller to which instance of Webots it should try to connect. This can be achieved by setting an environment variable named WEBOTS_PID with the PID (Process ID) of the running Webots instance to which you want to connect your controller. If that simulation has more than one extern controller, you may also set the WEBOTS_ROBOT_NAME environment variable to specify the robot to which your controller should connect.

https://cyberbotics.com/doc/guide/running-extern-robot-controllers

My problem comes from the fact that I don't know how to extract vehicle process' id to be able to connect to it.¿Any idea?

Thank you

System

Realtic12 commented 2 years ago

Hi! In order to have multiples robots in the same simulation,I only had to add to the launch file, the next line of code:

                     **additional_env={'WEBOTS_ROBOT_NAME': 'name_robot'}**

And inside the Webots Simulation, I had to put the same name to the robot which I want to control.

I hope this issue, would help somebody in the future.