-
Notifications
You must be signed in to change notification settings - Fork 18
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
Simulink takes a lot of time in some iterations #160
Comments
Here there are two separate issues.
While the latter can be solved my modifying the code (as discussed f2f with @diegoferigo), the cause of the first needs to be investigated. |
@FabioBergonti Thanks for the very detailed analysis, great report!! For what concern this behavior, it is a mystery to me why every (more or less) 300 ms there is this dip. When I talked f2f with @S-Dafarra I was guessing it was due to the QP block, which computational time might significantly differ step by step, but the fact that this happens also with a trivial model concerns me. A possible explanation might be the scheduler or the OS which might prioritize by time to time other processes. However, the periodicity or the happening and the fact that happens on two different machines lead me to exclude this explanation. I need to think a bit more about it, in the meantime I tag @traversaro in the case he has a clever hypothesis. |
@FabioBergonti Do you think it make sense to add two YARP time blocks, one that is execute as the first block of the model, and one that is executed as the last one of the model? In CODESYS IEC 61131-3's SFC/CFC you can explicitly assign the order of execution, and @DanielePucci once told me that is possible to do something similar in Simulink. In this way we can check if the 50 ms delay is inside the simulink block, or is the Simulink thread that is not scheduled by the OS scheduler (or by any intermediate "scheduler"-like entity in matlab, Real-Time synchronizer, etc etc). |
https://it.mathworks.com/help/simulink/examples/block-priority.html |
I would try this on a macOS machine. |
Can you launch |
Still you can modify the bash script. |
If you are able to get (even in post processing) a time series of:
It could be interesting to plot this data. |
StranceI've performed an experiment using the command
Here the .txt. I've decided to analyse from 12:30:30 (line 34000) to 12:30:34 (line 34585) In the Every 250/300 ms a long operation occurs Here below a part of the
Post Processing on Yarp TimeI did some post processing on the data that I've stored during the simulation In this graph is possible to see the delta of the
Starting from that graph I evaluated the distance between the peaks with an amplitude higher than 0.015 s
The result are shown here |
As mentioned on Telegram, if when you run the model and collect data with For example, on my machine I can find all the process that contain the string "firefox" in ther command that has been used to create those process as in:
I can then get the open file descriptors of the first instance of firefox using the following command:
I guess you can get the MATLAB PID using the command |
I would suggest to plot without interpolation (option |
@nunoguedelha It is possible that this is the same behavior that you saw when using the bindings? |
Is @FabioBergonti using the bindings? |
@traversaro I'm not sure. I was having constantly high delays. As soon as I closed Firefox and other MIPS hungry processes, the timing intervals dropped down to 150ms, and I haven't noticed spikes. But anyway, the thread timing I'm using is not the exactly similar to SImulink's synchronizer. I'll perform a few tests to check. @FabioBergonti the last plots you've posted come from the test we've done on the mac, or the data you were getting on linux? |
No
If you are talking about this comment, yes because they were done using the tests that we've done one the mac |
First TestI've repeated the test using my laptop top
ps -aux | grep MATLAB
ls -l /proc/30555/fd
The problem is still present, but is reduce a lot with respect to the previous simulation Second TestAnother test but this time saving the results of strace on a
ls -l /proc//fd
Third experimentI've repeated another time the experiment but this time I've closed all the applications and I've launched the simulation with the command Launching the simulation from the command window could be a solution |
In light of the above, definitely. I wonder if the problem is still present by generating the C++ code @diegoferigo |
A bit of recap on why we decided to go for launching The delay on the simulation of the Simulink model seems to be extremely correlated (even from data that @FabioBergonti did not posted in the issue) to long blocking I am not an expert of these, but it seems from the documentation that Clearly using Simulink expecting any kind of reliable real-time behaviour is using Simulink widely outside its specification: the In general, it would be ideal if the Real Time Synchronizer could provide some kind of feedback to the user about the average/peak delay at the end of the simulation, but I am not sure if this is doable. |
as discussed with @S-Dafarra, we sometimes observed apparently inexplicable failures while running the Yoga ++ (e.g. after several successful Yoga demos, we run it once again and the robot this time fails to move the CoM above the stance foot). We usually blamed the FT sensors or the joints fine calibration, but it seems that also this issue may explain these failures. Looking at the plots coming from Simulink I never noted something strange (but the yoga movements are smoother than the jumping ones, so maybe that's why I didn't see something like this). |
Can we close this issue now that the source was sorted out and we have a static gui for avoiding it? |
Ok for me. |
Ok also for me. |
@VenusPasandi was also affected by this when playing a simple sine wave in Simulink. I guess this problem was not present (at least in this form) in older version of Simulink. |
Interesting, so probably also the experiments I run last week with @anqingd that were showing a similar result were affected by this. Me and @gabrielenava were blaming mostly gain tuning, but apparently the source of the problem was something else. Btw, I was not aware that the matlab version in the robot setup has been updated. |
Have a look at the Simulink static GUI I've created for Be aware that there is a bug in the GUI (but you must be a very bad person to trigger it): robotology/whole-body-controllers#58 |
If the recent problems that @GiulioRomualdi found (namely, scattering behaviours when controlling from simulink the robot in position direct, right @GiulioRomualdi ?) are not addressed by making a static GUI, I guess we should consider to re-open this issue |
There is no need for a static GUI, you can mitigate the problem just by running the Simulink model without a GUI. However, this is just a mitigation, as Simulink never offered any kind of real time assurance, so for what we know the next version of Simulink (or the existing Simulink in different conditions) could have the same problems even when running without GUI. As far as I understand, the only "proper" (for a given definition of "proper") way of running Simulink models in real-time is either to use Simulink Real Time or to generate, compile and run the corresponding C code using the Simulink Coder. |
Description
I've noticed that during my experiments with the real robot in some iterations simulink takes a lot of time.
I understood this behaviour comparing the desired simulink time (
tou
) with the output of the blockYarp Time
.This behaviour has an impact on my results because due to this problem I see spikes in the joints state.
I thought that could be a problem of my model (which is a little bit complex), so I've increased the simulink sampling time (from 0.01 s to 0.02 s) in order to give more time for the resolution, but the problem was still present.
Then I've generated a very simple model where I command in velocity only one joint, there were no scope, no get measurement.
The problem was still present
Here below some graph
Zoom
From the graph I've noticed that in some iteration simulink takes a lot of time, then it tries to recover the delay (where the slope of the blue points is higher).
But after some iteration the phenomena reappers
Platform
I've performed my tests on
iCubGenova02
Reproducibility
I did a some tests and it happens every time
Additional information
Ubuntu 16.04
v4.0
]2018a
and2016b
cc @gabrielenava @S-Dafarra @fiorisi @DanielePucci
The text was updated successfully, but these errors were encountered: