-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run two parallel simulations of a gz-sim-yarp-plugins-enabled robot #153
Conversation
In b460db8, two simualtions of the same world are instantiated and launched together, using TestFixture class provided by Notes:
|
5298c54
to
8886369
Compare
With bb537e5 the unit test Now the unit test fails, since there is an error when trying to set two devices in It is then time to make a modification to the way the keys are generated. @traversaro if I recall well you suggested prefixing the current device key with the memory address stored into the pointer in the call to: DeviceRegistry::setDevice(std::string deviceDatabaseKey, yarp::dev::PolyDriver* device2add) Moreover, I think that all the plugin singletons key should be updated in the same way, since for example, we should be able to store the data for the same controlboard device belonging to the same model used in two parallel simulations. Do you foresee any troubles in progressing on this path? |
8886369
to
bb537e5
Compare
…oncurrently In this first version no gz-sim-yarp-plugin is used
- introduced controlboard plugin - check that DeviceRegistry has the correct number of device keys --> FAILING
…set on DeviceRegistry Plugins modified: - basestate - camera - controlboard - forcetorque - imu - laser
This is done by: - removing the data singleton - adding a new header file containing the data structure and a custom interface to be implemented by force torque driver
78b794e
to
3b7e63b
Compare
3b7e63b
to
71589ef
Compare
Fix also `ControlBoardCommonsTest` to use `DeviceRegistry` in place of the singleton and remove expectations on device ids (since they are an internal implementation detail).
In the last 5 commits I've restructured the data management mechanisms of the plugins that previously made use of the singletons (see #147 (comment)). Now the only singleton in the codebase is constituted by the |
…en different simulations. - Update model used in unit test to a double pendulum (the two simulations outcomes diverge quickly) - Update unit test
With c345e4c I updated the unit test to use a double pendulum, such that the reading of the second joint would present numerical differences pretty quickly. Here's a video of the simulation of such model: 2024-04-16_09-49-00.mp4Now to make the unit test pass I used the uglier way possible, but also the only one that seems to work at the moment, i.e. using the I'm restructuring the code and the unit test in order to make them pass with the new modifications introduced, thing that is taking a bit of time. |
- Update DeviceRegistry::getDevicesAsPolyDriverList method - Add pragma once direcgtive to DeviceRegistry - Remove check to BaseStateDriver raising exeption with new data management - Move initialization of Camera buffers after Driver has been opened - Add test-helpers library and TestHelpers class - Fix Imu test - Update ControlBoardPositionDirectTest (still failing)
24b6e48
to
a901e0f
Compare
There are still three tests failing:
|
What was causing the strange errors (really difficult to debug) the unit test https://github.com/robotology/gz-sim-yarp-plugins/actions/runs/8718567060/job/23916088302#step:12:217 was the use of the gz-sim-yarp-plugins/tests/test-helpers/TestHelpers.hh Lines 14 to 32 in 9dc1044
I created this to help retrieve only a vector of devices already casted to the interface needed in the test. For example, if the model under test has different gz-sim-yarp-plugins defined, I want to perform tests only on Before it was easy to reconstruct manually the deviceId since it was only the composition of the device scoped name and the yarpDeviceName (even if this is a code smell since it was relying on the internal implementation of the key string). So maybe now we should find an easy way to query the |
In order to be sure that the two simulations are actually distinct the joint is controlled in position and different references are given to the two simulations.
Since leaving a pendulum freely swing was not giving clear evidence of having two different simulations running concurrently, to assess this in a clear way I updated the test as suggested by @S-Dafarra: now two simulations of a single pendulum (from the same model) in which the joint is position controlled, receive two different reference positions. in this way we can check if the two joints are able to reach their setpoint. Luckily this was the case! So I can finally conclude that we are able to simulate concurrently the same model on gazebo! 🥳 |
This is the outcome of the unit test in which in one simulation the reference position is 10 degrees, and in the other is 5 degrees:
|
I want to iterate a bit on the DeviceRegistry data structure, I will put again this PR into a draft. |
Also: - adapt all plugins and tests to use the new interface - ConfigurationParsingFromFileTest unit test has still an error in the controlboard assertions, it has been commented out for now
In cd0cd2f I have done substantial restrucuring of the DeviceRegistry interface and of its internal data structure. I adapted all the plugins to use the new interface and finally also the unit tests. I'm getting a strange behavior on the following unit test, in which is loaded a model containing all plugins we have developed, each one with its yarpConfigurationFile. The strange thing is that if I enable the lines related to the check of the ControlBoard (now commented out), the entire tests is messed up, with Gazebo logging errors in which it cannot find the plugins libraries and the DeviceRegistry holding only the driver related to the controlboard. gz-sim-yarp-plugins/tests/commons/ConfigurationParsingFromFileTest.cc Lines 41 to 48 in cd0cd2f
The error log I got on my machine is the following:
|
I was able to resolve the error I was getting in #153 (comment), by not including the Driver classes (also, some of them have only I'm not sure of the reason behind this strange behavior but it could be due to the include of Drivers cpp files that were messing up some library (like the |
The problem was probably some kind of consequences of us breaking the one definition rule (that is the reason why you always include .h header files with declarations or inline definitions and never .cpp with non-inline definitions). Anyhow, if this now works that is great, is this ready for review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments.
Yep, I agree with you, I had an unpleasant meeting with "undefined behavior" in C++ 🤣 Yep it's ready for review! |
I guess at some point we need to understand how to get the ecm pointer given the server, but for sure this is out of scope for this PR. |
Yes, exactly; for now, this is the elephant in the room. |
The unit test failing on the CI is quite scary:
gz-sim related issue: gazebosim/gz-sim#18 The unit test failing is launching two parallel Gazebo instances of different models (one sphere and one box bouncing on the ground). This error seems related to the ODE collision detector having issues due to some global variable. However it seems to happen only on the apt CI workflow on Ubuntu@Debug. |
Ah, that is an old foe. For parallel workflows we should either use another collision detection algorithm when using dart (dart supports several of them if I recall correctly), or using another physics engine. cc @diegoferigo as probably we experienced something similar when working on gym-ignition. |
…and collision detector to avoid exception in concurrent simulations
Now the models used by concurrent tests use Merging 🚀 |
That is nice for the tests, but it also means that users will start getting the problem if they start using our APIs for parallel computation. We should at least document this once we will document the possibility of running multiserver. See also the discussion in gazebosim/gz-sim#18 (comment) . |
Closes #147