Pause and play simulink in programming

Is it possible to pause and play again Simulink block diagram through programming? For more clarification I have to say that I want to pause (not stop) my Simulink which is run with sim command in a script file. Is it possible and if so how?

댓글 수: 2

MatlabPro
MatlabPro 2012년 11월 22일
are you allowed to use a GUI?
Pouya Jamali
Pouya Jamali 2012년 11월 22일
No I just have to use programming commands!

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

 채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 11월 26일

1 개 추천

See this page for information on using the SET_PARAM command to do what you need. In particular:
set_param('modename','SimulationCommand','start')
set_param('modename','SimulationCommand','pause')
set_param('modename','SimulationCommand','continue')
set_param('modename','SimulationCommand','stop')

댓글 수: 10

Pouya Jamali
Pouya Jamali 2012년 11월 26일
Thanks a lot Kaustubha for your useful support. Is it possible to define pause time as well as stop time? I need the block diagram be paused in specific simulation time.
Kaustubha Govind
Kaustubha Govind 2012년 11월 26일
편집: Kaustubha Govind 2012년 11월 26일
You should probably create a Pause block to do this. You can set the "Constant" value in that sample diagram from command prompt using set_param('path/to/block', 'Value', num2str(desiredTime)). Note that SET_PARAM takes string arguments for the value, which is why I am using num2str.
Pouya Jamali
Pouya Jamali 2012년 11월 27일
Wow thanks a lot. It works. But there is a problem still. when the simulation is started programmatically using set_param(Name,'SimulationCommand','start') The next command is run before the simulation is reached to pause point. How can I hold the execution process until the simulation is paused?
Kaustubha Govind
Kaustubha Govind 2012년 11월 27일
You should probably use the SIM command instead of set_param(Name,'SimulationCommand','start') if you want the simulation to run its course until the Pause block takes effect.
Pouya Jamali
Pouya Jamali 2012년 11월 27일
It doesn't work with sim command. The sim command neglect the pause and play the simulation again. Actually it forces the simulation to run until simulation end time is reached. I don't know maybe I'm in a wrong way.
Kaustubha Govind
Kaustubha Govind 2012년 11월 29일
That shouldn't happen. Can you post your code?
Pouya Jamali
Pouya Jamali 2012년 12월 8일
편집: Pouya Jamali 2012년 12월 8일
Of course here it is take a look please:
% Run Simulink Block Diagram Interactively
clear all; close all; clc;
Name='Suspended_Pouya_Biped';
% Simulation time
t0=0;
tstop=10;% Simulation Time
st=1;% Sample Time
N=floor(tstop/st); % The Number of steps
T_in=[0 0 0 0 40 0 0 0];% system input vector (From workspace)
ftime=t0+st;
flag=0;
for k=1:1:N
switch flag
case 0
% set the pause time
set_param([Name '/Pause/Constant'],'Value',num2str(ftime));
sim(Name) % run the simulation
Foot_R % system output vector (To workspace)
flag=1;
otherwise
ftime=ftime+st;
% set the pause time
set_param([Name '/Pause/Constant'],'Value',num2str(ftime));
%continue
set_param(Name,'SimulationCommand','continue');
Foot_R % system output vector (To workspace)
end
end
During first loop matlab command window warns me about detecting assertion a lot of times. Thank you
Pouya Jamali
Pouya Jamali 2012년 12월 16일
You don't have any idea, do you? I'm still looking forward for your answer.
Kaustubha Govind
Kaustubha Govind 2012년 12월 27일
Sorry, I was away on vacation. Before you run the SIM command, could you run get_param(Name, 'StopTime') and make sure that the time returned is larger than the Pause block setting?
Pouya Jamali
Pouya Jamali 2013년 2월 2일
Ow thanks for your answer. I haven't got any notification email about your comment so I saw it really late. In order to answer your question I have to say yes, it is. It seems like a bug. If you agree with me please let me know how can I report it to mathworks respondents?
I've been struggling on interfacing programming environment and simulink block diagram for controller design objective but I haven't got a good solution. the only way which works properly is to run the simulink block diagram using sim command in each loop and export the system states. then use the last states as the initial states for the new time span and run it again by using sim command. this method is not satisfactory because the Initialization phase cause to rise run time. As I use the whole system in a objective function for a evolutionary optimization algorithm the run time is really important for me. It tooks for example 3 month to run the algorithm for small sample times like 0.005(s)(small sample times cause a lot of initialization). If I compass the Initialization phase the run time will be decreased to 3 days. Which is a significant value.
You are the only person who can help me Kaustubha. My master thesis has been stopped due to this problem. I would be more grateful if you communicate with me through email. Because this forum doesn't send notification email for comments.
Thanks in advance

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

추가 답변 (1개)

Nadir BOUTASSETA
Nadir BOUTASSETA 2013년 2월 10일

1 개 추천

I think that the problem you are facing can be solved by using S-Functions such that at each iteration you change reference values and compute your cost function.

카테고리

도움말 센터File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by