Hello, i'm working with Simulink and I have a problem: I start a simulation and every 'T' time I need to stop it, save the state of the system as Simstate, and then restore the system state by changing a few variables. For example, I am working with the base model 'Inverted Pendulum with Animation' (penddemo.mdl), and when I restore the state I must change the mass of the pendulum, here's some code:
set_param('penddemo','LoadInitialState','on','InitialState','init_state'); % load the initial state
set_param('penddemo','SaveFinalState','on','FinalStateName', 'xFinal','SaveCompleteFinalSimState', 'on'); % save the complete simstate
set_param('penddemo/Pendulum','Mcart','0.600'); % change the mass
sim('penddemo',time); %starting the simulation
The problem is that I get this error:
can not load the Simulink SimState Because The initial model, 'penddemo', was changed after the SimState was saved. Run the simulation again and resave the SimState.
I know that there are limitations in the use of Simstate:
You cannot make any structural changes to the model between the time at which you save the SimState and the time at which you restore the simulation using the SimState. For example, you cannot add or remove a block after saving the SimState without repeating the simulation and saving the new SimState.
but I do not think changing a single variable is a structural change and Mcart is a tunable parameter. Maybe someone knows another way to change some variables before the recovery of Simstate.

댓글 수: 1

Abdullah Mohiuddin
Abdullah Mohiuddin 2017년 10월 4일
Hi,
I came across a similar problem, I also wish to change some parameters before resuming the simulation. Did you find a workaround? Is there any other way we can change some variables and resume the simulation?

댓글을 달려면 로그인하십시오.

 채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 5월 24일

0 개 추천

The parameter 'Mcart' on the block 'penddemo/Pendulum' is used under the mask in a Fcn block in the "Expression" parameter, which is non-tunable (ie. cannot change between a SimState save and restore). So you cannot change the value of 'Mcart' because it counts as a structural change.

댓글 수: 4

Robert Garnett
Robert Garnett 2012년 9월 3일
Simstate is basically useless. I run a model with only Mathworks blocks. Without making ANY changes to the model when I try to run the model again I get:
"Because the stop time of model 'TestSimState' is less than or equal to the simulation time stored in the initial SimState, the simulation stopped. Increase the stop time if you want to continue the simulation from the SimState". The absolute time is irrelevant to IC's. I am quite happy to start the sim from time 0. The only time I should have to rebuild the IC's is if I have added additional states. In any case these new state variables could be preset to 0 for the first run or the value in the mask IC could be used.
It is understood that if a gain is changed or if an additional input was added to the model then the states will not be valid, however the model will in most cases rebalance and time can be saved by not having to go back to scratch. I change IC values all the time to get models to work at particular set points. You get a bump at the start but so what?
The whole point of saving the sim states is so you can have a good start point for your model so you can test changes in parameters to improve response.
We used to use the states output as our IC's. It was cumbersom but it worked.
Kaustubha Govind
Kaustubha Govind 2012년 9월 5일
Robert: Regarding the error message pertaining to the model's stop time, would you agree that the absolute time may have an impact on model states for some models (i.e. certainly not all models are time-invariant)? In that case, maybe an improvement to the product would be to allow changing this error message to a warning. If you agree, I encourage you to submit a tech support case to request such functionality.
Robert Garnett
Robert Garnett 2014년 2월 9일
Hi,
Yes I would agree however in my view the absolute time starting point is simply an initial condition so what's the problem? If you select "Structure With Time" you have the end time anyway
We have a power plant simulator that models a boiler and turbine including combustion from first principles. There are ten's of thousands of states in this model. This model has absolute time and we can save states for use as plant initial conditions and then reload them without any issues.
We cannot of course use initial conditions generated with a different model structure, however we can make gain changes and whilst this will cause an initial disturbance at start-up usually the model will still converge and run normally.
The problem with using the initial final states as initial conditions in simulink is that the very act of checking the "Initial State" Load from Workspace checkbox in the Config Pars dialog seems to make the model "dirty" which stops it from using the xFinal states variable in the workspace.
I hope this explanation is of assistance.
Regards
Rob
Abdullah Mohiuddin
Abdullah Mohiuddin 2017년 10월 4일
Hi, so is there anything we can change before resuming the state and how?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

질문:

2012년 5월 12일

댓글:

2017년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by