How to programmatically tune this closed loop system with desired response time and robustness?

4 views (last 30 days)
I have a closed loop system with a transfer function:
I can pid tune using the tuner app and specify robustness and response time or bandwidth and phase margin. I would like to do this programmatically so it can retune for slightly different input coeffiecients in the transfer function. The tranfer function coefficients are applied programmatically, I have linearized the system and saved it to a variable ClosedPID. I can output the step response of this system using step(ClosedPID). I am trying to use the pidTuner function to open to tuner and update the block but it I don't know how to programmatically change phase margin and bandwidth and apply it to the block. On top of this the plant it uses is slightly different and doesn't produce the same PID values even after manualy entering in the phase margin and bandwidth values. I am wondering what I am doing wrong.
TLDR; How can I programmatically automate the process of:
Clicking on the PID controller in simulink
Clicking Tune... (next to Transfer Function Based)
Entering Xrad/s for bandwidth and Ydeg for phase margin (where X and Y are numbers I choose)
Update block

Accepted Answer

Siddharth Jawahar
Siddharth Jawahar on 2 Nov 2020
Edited: Siddharth Jawahar on 3 Nov 2020
Hi Jack,
You can do the list of actions you mentioned by using the pid, pidtuneOptions, pidtune functions. As an example, using a similar third order system you have shown, you can do something like this:
sys = tf(1,[1 3 3 1]);
C_0 = pid(1,1,1); % Parallel form PID controller object with initial gains
gm = 0.80 % Gain margin
pm = 45 % Phase margin
opts = pidtuneOptions('PhaseMargin',pm,'DesignFocus','disturbance-rejection');% Set your tuning options
[C,info] = pidtune(sys,C_0, gm,opts);
>> C
C =
1
Kp + Ki * --- + Kd * s
s
with Kp = 1.99, Ki = 1.11, Kd = 0.885
Continuous-time PID controller in parallel form.
>> info
info =
struct with fields:
Stable: 1
CrossoverFrequency: 0.8000
PhaseMargin: 45
  5 Comments
Jack York
Jack York on 3 Nov 2020
That does work better and is faster than set_param however I realised that for my particular application I need the simulink model to work independently after tuning without the original Matlab script being present or being ran and set_param works for this.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!