Sample Time and simOut Interaction

Hey Guys
so i have a Simulink-Simscape model that runs for 5 sec. During the time i have a Transform sensor measuring the distance between 2 points. This x,y,z-coordinates are saved in my workspace with simout (To Workspace). The problem is that this matrix varies between the size 900x3 and 1300x3, depending on the parameters of my Block. I think the matix size changes because the automatic generated sample time is changing because of parameter changes. I want the matrix to always be 1000x3, no matter how my model changes. So i got to Model Settings and changed the Solvertype from "Variable-step" to "Fixed-step" and changed the the "Fixed-step size" to 5/1000 (or 0.005), to have 1000 steps over 5 sec. But when i run the model now, the model is not simulating and i dont know why the simout doesnt work with fixed-step. if i set the Fixed step size to "auto", the model is simulating but only with an output of 1x3
The other thing i tried is to leave it on Fixed-step size and just change Max, Min and Initial step size from "auto" to "0.005", but then its also not simulating
I hope my Problem is understandable

 Accepted Answer

Usually it is because the fixed step size is too big for the model to simulate accurately.
There are many solution to this. The easiest is to specify the sample time of the "To Workspace" block to be 0.005.

10 Comments

Hey Fangjun,
i just tried it. Unfortunately the matrix is still changing when i set the "To Workspace" sample time to 0.005.
Is it maybe because of interactions with other blocks, because some are continuous and others are discret based?
My simulink Model only includes :
-solver configuration, world Frame, mechanism Configuration
- A Rotational drive, many Revolute Joints, solids and Rigid transformations
- A transform sensor with the three to Workspaces
If you need any more infos, dont hesitate.
That doesn't sound right.
Open the example model 'f14', add a "To Workspace" block to any signal. Press Ctrl+E, click "Data Import/Export", check "Time" on the right.
Run a Simulation, in the base workspace, check the variable "tout", that is the simulation time stamps. It is not evenly distributed. Check the variable "simout". It should have the same length as "tout".
Now change the sample time of the "To Workspace" block to be 0.1. Run simulation again, the length of "simout" should correspond to SimulationTime/0.1, while "tout" didn't change.
Hey Fangjun,
Thank you, i just found my problem. I realised that my models is not always running the 5 seconds. My models runs for 1.8794 sec and then has 376x3 matrix, thats exactly the 1.8794/0.005 i want.
Just another question: is there a way so increase my simulink speed ? so far i disabled the mechanic explorer to make it faster.
My idea is to put it in an optimization Tool to get the best parameters, so i want the simout = sim..... function to run as fast as possible
My experience has been that changing the sample time of a To Workspace block can definitely change the results of the simulation, at least with a variable step solver. If the solver parameters are defined to give an accurate solution, the solution won't change by very much, but it can change. After all, the solver now has to hit the Sample Times of the To Workspace block when the Sample Time is changed from -1 to some positive value. As a result, the solver has to take different steps and there will be small differences in the result. I can't speadk to he f14 example specifically (does it use a fixed step or variable step solver?), but with variable step solvers changing the Sample Time of any block can affect the solution.
@Paul, I kind agree with you, but that probably only applies to fix-step simulation.
I tried the 'f14' model, no changes from the built-in example file, variable-step, ode45.
Between those two simulations (change "To Workspace" block sample time from -1 to 0.1)
"tout" didn't change. The time stamps are not evenly distributed and are not hitting every 0.1 second grid.
The time stamps of "simout" are exactly every hit of 0.1 second.
I believe ode45 has 'minor' time step, but that would be a whole lot more discussion.
@Marcus Heßeling, run simulation in "Accelerator" mode.
Paul
Paul on 4 Feb 2021
Edited: Paul on 4 Feb 2021
I'm using 2019a. I loaded f14 and checked the sample times. There is one block in the Dryden Wind Gust subsystem that has a Sample Time of 0.1. Ran the simulation for 10 seconds (after checking Time on Data Import/Export in the Configuration Parameters. tout had variable steps but hit at every 0.1 second as expected.
Unless the f14 model is different in your version, I don't see how tout can't hit every 0.1 seconds.
Added a To Workspace block with Sample Time of 0.11 seconds. tout had variable step and hit at every 0.1 second and every multiple of 0.11 seconds. simout.Time = 0:0.11:1.
That is weird. I ran it in both R18b and R19b. For 10 second simulation, here is the tout. variable step, auto step size, ode45
9.5000
9.6000
9.6842
9.7000
9.7414
9.7827
9.8000
9.8450
9.8886
9.9000
9.9483
9.9889
10.0000
What was the Sample Time of the To Workspace block in this run?
My result, 2019a, no additional To Workspace block, matches your result:
>> tout(tout>=9.5)
ans =
9.5000
9.6000
9.6842
9.7000
9.7414
9.7827
9.8000
9.8450
9.8886
9.9000
9.9483
9.9889
10.0000
My result, added To Workspace block on the alpha signal, Sample Time = 0.11
>> tout(tout>=9.5)
ans =
9.5000
9.5700
9.6000
9.6800
9.7000
9.7413
9.7827
9.7900
9.8000
9.8458
9.8894
9.9000
9.9482
9.9889
10.0000
which as hits at every 0.1 second and additional hits due to the 0.11 Sample Time in the To Workspace:
>> xx=0:.11:10;
>> xx(xx>=9.5)'
ans =
9.5700
9.6800
9.7900
9.9000
Okay, I got the point now. I agree with you completely regarding "changing the sample time of a To Workspace block can definitely change the results of the simulation" and "the solver now has to hit the Sample Times of the To Workspace block when the Sample Time is changed from -1 to some positive value".
In my case, the added "To Workspace" block has a sample time of 0.1, which coinsides with an existing 0.1 sample time.
Also, in my previous comments regarding "weird" result, I was expecting that "tout" hits AND ONLY hits the 0.1 grid. Now I realize that should not be the expectation.
All is good. Thank you for your comments. It deepens my understanding of the topic.

Sign in to comment.

More Answers (1)

Paul
Paul on 3 Feb 2021
Edited: Paul on 3 Feb 2021
Keep the orginal solver settings you had (assuming they gave you an acceptable solution). Set the Sample Time parameter in the To Workspace block to 0.005.

Categories

Find more on Configure Simulation Conditions in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!