robotology / gz-sim-yarp-plugins

YARP plugins for Modern Gazebo (gz-sim).
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

Try to run two parallel simulations of a gz-sim-yarp-plugins-enabled robot #147

Closed traversaro closed 2 months ago

traversaro commented 3 months ago

We can use the existing test infrastructure, and we should use a model without any nws as otherwise launching two different nws with the same ports will fail.

xela-95 commented 2 months ago

Potential refactoring of singletons

While thinking on how to implement this issue, I continue to stumble upon the fact that I don't like the singletons we have for every plugin.

I try to explain the main points I have in mind:

This suspect of useless code duplication made me think to potential alternatives involving different levels of code refactoring:

@traversaro what do you think about it? Do you have any other solutions in mind?

traversaro commented 2 months ago
  • To address the current issue I want to add to the DeviceRegistry key also the memory address of the PolyDriver instance, resulting in something like 0x5f4e865a8df8/model/force_torque_model/joint/joint_12/sensor/force_torque_sensor/forcetorque_plugin_device, but in principle this Id could be used also as key in the map of the plugin singleton class.

How does the robotinterface plugin work in this case? If you use the PolyDriver pointer instead of the gz::sim::Server pointer, you can't use it to filter the devices that belong to a given gz server.

xela-95 commented 2 months ago
  • To address the current issue I want to add to the DeviceRegistry key also the memory address of the PolyDriver instance, resulting in something like 0x5f4e865a8df8/model/force_torque_model/joint/joint_12/sensor/force_torque_sensor/forcetorque_plugin_device, but in principle this Id could be used also as key in the map of the plugin singleton class.

How does the robotinterface plugin work in this case? If you use the PolyDriver pointer instead of the gz::sim::Server pointer, you can't use it to filter the devices that belong to a given gz server.

Yes you're right, I got confused, it is the address of the server (or any other unique property of it) that has to be used to filter the plugins.

xela-95 commented 2 months ago

I'm trying to find a way to get the pointer to the actual gz::sim::Server running a world, but until now I didn't found a viable option.

I report here some questions I found related to launching parallel Gazebo (classic) simulations:

xela-95 commented 2 months ago

As an additional experiment I tried to launch from two terminals the same single pendulum world.

The result, as shown in the recording, is that by default the two Gazebo GUIs that open are simulating the same world. If I pause one simulations also the other pauses, so they're completely linked.

https://github.com/robotology/gz-sim-yarp-plugins/assets/57228872/32b61ca0-3c52-4a5a-b241-58141cff85b6

traversaro commented 2 months ago

I'm trying to find a way to get the pointer to the actual gz::sim::Server running a world, but until now I didn't found a viable option.

Probably we can use a pointer to another structure that is unique for every server, for example gz::sim::EntityComponentManager ? Note that then we will get the dual problem of getting the gz::sim::EntityComponentManager pointer given the gz::sim::Server pointer, however they may be workaround for this (see https://github.com/gazebosim/gz-sim/issues/248).

traversaro commented 2 months ago

By the way, apparently there is a test that tries to run two parallel servers, see https://github.com/gazebosim/gz-sim/blob/gz-sim8/test/integration/multiple_servers.cc .

xela-95 commented 2 months ago

By the way, apparently there is a test that tries to run two parallel servers, see https://github.com/gazebosim/gz-sim/blob/gz-sim8/test/integration/multiple_servers.cc .

Yep and that is also similar to the test I've implemented in https://github.com/robotology/gz-sim-yarp-plugins/blob/f0d224658bd884cd8836a9eda798092ba7eea778/tests/controlboard/ControlBoardOnMultipleGazeboInstances.cc

This can be a sign that this could be accomplished.