Error linearizing Simulink model with an m-file

11 views (last 30 days)
I have some difficulties on linearzing Simulink model with an m-file.
Since there is additional parameters in my simulink model, I predefine C in the model, and think workspace will transfer C value to simulink model. However, when I start with m file, where C is predefined in before simulink, the linearization of model is failed, and display " Error using ParameterManager.sim (line 261) Undefined function or variable 'C'."
It wll be highly appreciated that you could help me with this problem.

Answers (5)

Arkadiy Turevskiy
Arkadiy Turevskiy on 15 Jul 2014
In general, if you have C in your MATLAB workspace, Simulink model should have no problems finding it. Can you see variable C in your MATLAB workspace?
If you can share your files, this will make it easier to troubleshoot

Min Zhao
Min Zhao on 15 Jul 2014

It is my pleasure to receive your reply so fast.

The attachments are my function code and simulink model.

The main function is "MDO_controller". I want use this function to obtain parameters (Kp, Ki, Kd) instead of PID tuner in GUI. However, I face two question:

(1) If I direct type MDO_controller in Matlab Command Windows, errors are following:

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

Error using linearize (line 328) Error due to multiple causes.

Error in MDO_controller (line 19) sys = linearize(model,ios);

Caused by: .......................................

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

However, if I copy all the codes of MDO_controller an paste in Matlab Command Windows, it works and obtain:

        1 
  Ki * ---
        s 
with Ki = -0.412

I do not why? And what I want is to obtain parameters with MDO_controller function.

(2) As you can seen the parameters obtained above, which is different from the parameters obtained from PID tuner in GUI. The results are as following and aslo showed in "Results of PID Tuner. JPG"

Kp = 0.71209 Ki = 0.071139 Kd = -1.1675

I hope you could help me solve two problems, and use MDO_controller function to obtain the same parameters as PID tuner in GUI. Thank you very much!


Min Zhao
Min Zhao on 16 Jul 2014
Besides, I think that the different values from PID tuner in GUI are due to uncorrect linio.
In "Tuning PI controller from Simulink model with an m-file" (<http://www.mathworks.co.uk/matlabcentral/answers/106136-tuning-pi-controller-from-simulink-model-with-an-m-file)>. You cleared that PID Tuner linearizes the model from PID controller output to PID controller input, so I write the followsing codes in MDO_controller
ios(2) = linio('V3plusangleLplan_PID/Sum',1,'out'); ios(1) = linio('V3plusangleLplan_PID/PID Controller',1,'in');
io(1) is set to the controller output and io(2) to the controller input.
I do not know whether my thinking is right or not, and hope it could be completely sovled by Matlab expert like you.

Arkadiy Turevskiy
Arkadiy Turevskiy on 16 Jul 2014
There are several different issues here.
1. Your code is setup as a function, but there are no input arguments, thus I really do not see a need to write it as a function. So step 1- make it a script to make life easier.
2. PID Tuner linearizes the model to include all the blocks between controller output and controller input (error signal). This doc section explains this, but is not clear enough. We will make it more clear in the future. The plant PID Tuner sees is from PID output to PID input, you got that part right. However, the input linearization point is an open loop input, not an input perturbation as you have. You need to make it open loop input in order to open the loop, otherwise, when you linearize, PID controller itself will be included in the linearization result. Another thing that doc does not make clear is that when PID Tuner linearizes the model as I described, it multipliues linearization result by -1, because it assumes negative feedback.
3. Finally, when you have the right linearized plant model, to get the same design as PID Tuner produces, you need to use pidtune function and specify controller type as 'pidf' - PID with derivative filter. This is because the block is also setup as PID with derivative filter in your model.
The end result of all this is this code that produces the same design as the PID Tuner app.
C = [0.2973 3.5939 0.0427 0.1336;
-21.5542 -0.0300 -0.1972 -7.5615;
0.1268 0.1074 201.2985 3.0900;
0 0 0 36.5476;
0.1001 3.4233 3.4233 0;
0 0 0 0.1753;
0.8209 0.0510 0.6842 21.6633;
30.6932 0.0030 29.8241 29.8300];
Kp =1; Ki = 1; Kd =1;
theta0 = 10/180*pi;
model = 'V3plusangleLplan_PID';
%%Create the linearization I/O as specified in V3plusangleLplan_PID
ios(2) = linio('V3plusangleLplan_PID/Sum',1,'openoutput');
ios(1) = linio('V3plusangleLplan_PID/PID Controller',1,'in');
%%Linearize the model
sys = linearize(model,ios);
sys=-sys;
ABC = pidtune(sys,'pidf');
  2 Comments
Min Zhao
Min Zhao on 18 Jul 2014
Arkadiy Turevskiy, Thank you for your help, I succeed in obtaining the same value from script code. However, I still have a liitle problem.
Since pidtuner can output "Rise time, settling time, Overshoot, Peak" in GUI, how can I obtain these value from script code. Waiting for your reply. Thanks.
Arkadiy Turevskiy
Arkadiy Turevskiy on 18 Jul 2014
use function stepinfo.
[y,t]=step(feedback(ABC*sys,1));
S=stepinfo(y,t)

Sign in to comment.


Min Zhao
Min Zhao on 20 Nov 2014
Dear Arkadiy Turevskiy, sorry to disturb you again. after integrating PIDTUNE in my code, I face a new problem.
waring: Cannot keep loop gain above 1 at low frequency and below 1 at high frequency. Try adding integrators to the loop.
How can I deal with this problem. Waiting for your reply. Thanks.
  1 Comment
Arkadiy Turevskiy
Arkadiy Turevskiy on 20 Nov 2014
Not all systems can be well controlled by a PID compensator. Sounds like this might be your case. As the warning recommends, try adding an integrator to your compensator. So add an integrator block in addition to PID controller, and try again.
If any of the answers above were helpful, please accept them so others can see that this thread is worth reading.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!