Error linearizing Simulink model with an m-file
11 views (last 30 days)
Show older comments
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.
0 Comments
Answers (5)
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
0 Comments
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');
Min Zhao
on 20 Nov 2014
1 Comment
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!