robotology / gazebo-fmi

FMI import plugins for the Gazebo Simulator.
GNU Lesser General Public License v3.0
23 stars 5 forks source link

Add FMIActuatorPluginKnownInputTest #29

Closed traversaro closed 5 years ago

traversaro commented 5 years ago

For now, this test just simulates the pendulum + FMU transmission with a constant input, and saves the result in .mat file to simplify the inspection.

It is already useful on its own for developers, but the idea is that it can be extended to more inputs (such as as sine) and to check the behavior of simple models + transmission against their nominal behavior.

traversaro commented 5 years ago

For example, this is how I verified that the acceleration feedback for https://github.com/robotology/gazebo-fmi/issues/17 had the correct sign (to replicate this plots, just go in the build/plugins/actuator/test directory, load the desired .mat file and run the plotKnownInputData.m script: ode

Note that there some strange spikes in acceleration that I guess are some kind of numerical integration artifacts due to ODE (probably it is possible to get rid of them by tuning the physics parameters as described in http://gazebosim.org/tutorials?tut=physics_params&branch=physics_params . It would be interested anyhow to investigate them, as the system is extremely simple and such spike are quite surprising/scary, but this is out of the scope of this PR.

traversaro commented 5 years ago

I added a test using a Modelica.Blocks.Nonlinear.FixedDelay block, and the tests are now faiing because the resulting FMU exported from OpenModelica is actually generating a NaN, which I guess it is an OpenModelica problem.

traversaro commented 5 years ago

I tried to inspect the DelayTransmission.fmu (generated in build/plugins/actuator/test) with the FMPy gui (python3 -m fmpy.gui) and I obtained a strange error:

straversaro@iiticublap103:~/src/gazebo-fmi/build/plugins/actuator/test$ python3 -m fmpy.gui
JSON object expected ',' or '}', got: "lineEnd":3,"colStar
Aborted (core dumped)

I discovered that FMUs generated by OpenModelica have a bug (https://trac.openmodelica.org/OpenModelica/ticket/4020) and are sensitive to the system's locale, a problem similar to https://github.com/robotology/idyntree/issues/288 . Indeed launching LANG=en_US.utf8 LC_ALL=C.UTF-8 python3 -m fmpy.gui everything works fine. Interesting, I see no NaN in the output

I tried to launch the tests in this PR as: LANG=en_US.utf8 LC_ALL=C.UTF-8 ctest -VV -R Known, but the problem is still there, so this is probably not the problem. I am starting to wonder if the problem is actually in the FMILibrary or in how we use it. If someone has a Simulink license, it would be interesting to try to load the DelayTransmission.fmu model (see https://it.mathworks.com/help/simulink/in-product-solutions.html ) in Simulink and try a couple simulations.

traversaro commented 5 years ago

@prashanthr05 for some reason I am unable to reply to your comment https://github.com/robotology/gazebo-fmi/pull/29#discussion_r218817254 . I addressed it in https://github.com/robotology/gazebo-fmi/pull/29/commits/5fd1da17185c362a667d9cbacde5e755cf5c074f .

traversaro commented 5 years ago

The tests with the DelayTransmission are working as intended in OpenModelica 1.14.0~dev-375-ge9bb8d6, so the problem with DelayTransmission was probably a OpenModelica specific problem.

traversaro commented 5 years ago

For some reason in Travis there is still the problem of the Delay test, I have disabled it in https://github.com/robotology/gazebo-fmi/pull/29/commits/abe72f31b07628258c05b391d412dca66a9cbdd8 and I opened a new issue for it in https://github.com/robotology/gazebo-fmi/issues/58 .

traversaro commented 5 years ago

cc @prashanthr05

traversaro commented 5 years ago

@prashanthr05 merging as this are just tests, feel free to comment later.

prashanthr05 commented 5 years ago

For some reason in Travis there is still the problem of the Delay test, I have disabled it in abe72f3 and I opened a new issue for it in #58 .

This seems like a strange issue given the fact that the test passes locally.

traversaro commented 5 years ago

This seems like a strange issue given the fact that the test passes locally.

We unfortunately still use the Nightly build of OpenModelica, so it is possible that the version I have on my laptop is different from the one in Travis. I think we can wait for OpenModelica 1.14 stable release and check if we can switch to that.