Pausing Simulink from Matlab to change control gains

2 views (last 30 days)
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.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 16 May 2013
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 Comment
X W
X W on 6 Aug 2017
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?

Sign in to comment.

Categories

Find more on General Applications in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!