Pausing Simulink from Matlab to change control gains

So I am looking to change the gains of a proportional control block in Simulink at a point where my system begins to lose stability (in an attempt to restore its stability). I want to do this after a period of time determined by Matlab. After this period of time I want to pause the simulink model, update workspace parameters and the control gains in simulink too.
The code I'm using is below:
clear all;
clc;
close all;
% Load parameters to workspace
main();
% Start the simulink model
set_param(gcs,'SimulationCommand','start');
% Wait ~6 seconds
for i = 1 : 2e9;
end
% Pause the model
set_param(gcs,'SimulationCommand','pause');
% Change the gains
set_param('quad_Step_plot/P_pr','Gain','-600');
P_pr = -600;
% Continue
set_param(gcs,'SimulationCommand','continue');
The loop is so Matlab wait's 6 seconds (approximately) before pausing and attemping to change the control gains at the command line and in the Simulink model (I understand this could probably be done more efficiently).
However, when I used the set_param() command in Matlab the simulink model does not appear to run... Does gcs refer to the current open Simulink window. Furthermore, requesting simulink to continue doesn't do anything.
I am much better at Matlab than Simulink hence would like to try and get this working via the command line. Are there any obvious reasons why this is not doing what I would like it to do? Thanks in advance.

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2013년 5월 16일
Yes, gcs refers to the currently open system (could also be a subsystem). You can use bdroot if you only want to refer to the main model (and not subsystems). I wonder if your model takes less than 6 (wall-clock) seconds to complete, which could be why the pause/continue don't work. You can create a Pause block and place it in your model to make it pause after simulating for 6 secs (note that this does not necessarily coincide with 6 seconds on the wall-clock). You can time your simulation (by the wall-clock) by using something like:
tic, sim(bdroot), toc

댓글 수: 1

X W
X W 2017년 8월 6일
Can you please show us the explicit construction, how to go from the info on this page's picture http://www.mathworks.com/help/simulink/ug/assertion_for_pause.png, to pausing it for (6 here) seconds, and issuing the continue?

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

카테고리

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

제품

질문:

2013년 5월 16일

댓글:

X W
2017년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by