I am trying using Webots in combination with stable-baselines3 for reeinforcment-learning purpose. I tried using Webot with multiple instances, but connecting the controller to a specific one doesn't work. It mostly connects to the newest one. I wrote a runtime.ini giving the WEBOT_PID manually looking like
[environment variables]
WEBOTS_PID=1492
and even tried setting the environment variable in my Python code like
os.environ["WEBOTS_PID"] = str(1492)
self.simulation = WebotsInterface()
it doesn't connect to desired Instance.
The WEBOTS_PID
environment variable should be set before you start the robot controller, otherwise it is not taken into account. So, you cannot set it in the runtime.ini
(which is anyhow ignored when launching extern controllers) nor in the controller itself. I would recommend you to write a script that sets the WEBOTS_PID
first and then starts the controller program as an extern controller.