0

I have read the Mathworks documentation carefully and tried to find a solution on forums as well. However, I have not been able to find a solution to my problem yet.

I am using Matlab/Simulink to simulate the dynamics of a vehicle, which picks up an object during operation. The way I am planning to do this is to:

  • Simulate the motions of the vehicle by itself at the start of the simulation;
  • Stop the simulation, save the final state, update the model parameters (so that they now represent the vehicle and the object)
  • Initialize the simulation again starting from the end time of the previous run and using the previous final state as input state to the new simulation.

To do this, I have been using the options FastRestart, SaveFinalState, SaveCompleteFinalSimState and update. Unluckily, the simulation runs seamlessly, but the model parameters are not updated.

The dynamics of the vehicle and vehicle+body are modelled by the same C-coded S-function. This function receives the parameters of the dynamic equations (e.g. inertia, damping, etc.) as parameters to the S-function block. I think this is the main problem with my approach: even though I run the update command, the S-function does not recognize the update of the parameters in the workspace. Do I need to recompile it? I guess that is not feasible under Fast Restart mode, is it?

Any advise is really appreciated! Thank you!

Enrico Anderlini
  • 447
  • 6
  • 21
  • Are the parameters in the S-Function defined as being tunable? – Phil Goddard Feb 07 '18 at 16:16
  • I think they are. However, by doing some trials and removing the `FastRestart` option (i.e. closing and reloading the simulation for the second part), I have realised the main problem is that somehow, the `update` command is not working. I update the value in the Matlab workspace, but for some reason even though I run `set_param(sfile,'SimulationCommand','update')`, the Simulink workspace is not updated. – Enrico Anderlini Feb 08 '18 at 10:27
  • You could try explicitly forcing the S-Function to update, using: `set_param(gcb,'Parameters',get_param(gcb,'Parameters'));` – Phil Goddard Feb 08 '18 at 17:00
  • Unluckily, it does not solve it. Could loading the previous final state (of the first part of the simulation) as an initial state (for the second part of the simulation) be a problem? And if so, how can I overcome it? – Enrico Anderlini Feb 09 '18 at 10:28

1 Answers1

0

I have a similar issue to this in a different situation. Trying to update the initial state target of a revolute joint, the fast restart option does not change the property.

I have had some luck updating the model in fastrestart with other parameters, however, using:

set_param('Model_Name','TunableVars','Variable Name')

Not sure if this will help in your situation, perhaps saving the final state as a variable and having the respective variables as initial parameters.

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39