I have a model with a cam-follower running at a certain rpm and compressing a spring attached to the follower. I want to grab the value of the force exerted on the spring at time t=20s, and use it as an input to a function block for a different component elsewhere in the same model.
I am trying to using a 'dynamic controlled write' (SIGWRITE1) to trigger a write command to an output file ('force_at_t20.data') when the simulation time equals 20s and read this file to provide the input to my function block.
When I run my model, I see that the trigger to write the data to a file occurs at the desired time (t=20s) but I do not see any data stored in 'force_at_t20.data'.
Any suggestion/advice on how to go about this?
Is there a better way to implement this? Some way to store the value into a variable and use it in the simulation instead of writing to a file and reading it elsewhere?
Thanks in advance!
Solved! Go to Solution.
if you just want the value at 20 sec you could try using a sampler with a variable sample rate. When the simulation time is lower than 20 seconds (+something small) you sample at 20 sec and after that you don't sample.
If you want to have the continuous force after 20 sec you just use a f(x,y) block taking the time into account, it will look like this:
Actually there is a simpler solution. You could also multiply your sensor signal by a step signal which will switch from 0 to 1 at time 20 sec...
In any case, do not use data files to communicate data between 2 submodels that are part of the
At the beginning of the simulation, the submodel reading the file will open an empty (or obsolete)
version of the data file. In other words, the file will be opened and read before containing the relevant
Using a sensor and a sampler is the correct way to do it.