MATLAB Answers

How can i get the control effort/output of the PID?

70 views (last 30 days)
Rupali Gawde
Rupali Gawde on 21 Sep 2020
Commented: Jon on 28 Oct 2020 at 14:23
sys = (2.293*s + 9.172)/(s^2 + 10.29*s + 25.17);
Kp = 5; Ki = 50; Kd = 0.5;


Show 4 older comments
Jon on 22 Sep 2020
One thought, in case this helps. Assuming you are modeling , analyzing and simulating this using transfer functions in MATLAB you may have to do a little block diagram algebra first to get the transfer functions of interest.
Let's say you have defined appropriate transfer functions for your PID controller and lets call that C, along with your plant G, and perhaps some transfer function in the feedback path H. Then with some block diagram algebra you could find that the relationship between the reference input r, and the controller output u would be given by u = Cr/(1 +CGH). So the closed loop transfer function would be C/(1 + CHG) Please check my math I did this quickly.You could then make this closed loop transfer function between the reference and the output u in MATLAB for example (assuming you have already defined the transfer functions C,G and H
Tclr = C/(1+C*H*G)
And then analyze and simulate this. Note the step response of this transfer function would give you the control effort that result from a step change in the reference (setpoint) value.
Similarly if you were looking for the response of the controller output to a disturbance at the plant output, some block diagram algebra would give the appropriate transfer function Tcld = -CH/(1+CHG) Please check this too. And you could similarly define this in MATLAB using
Tcld = -C*H/(1 + C*H*G)
again the output for example step(Tcld) would give you the response of the control output a step change in the disturbance value.
Rupali Gawde
Rupali Gawde on 22 Sep 2020
Find code in attachment. Please help and check the last section "Control Effort". Please help correct the code if needed. I need to find the output from all the 4 controllers -ZN-PID, GA-PID, PSO-PID, ABC-PID, TLBO-PID.
Jon on 22 Sep 2020
Now I see what you are doing I will post my response as an "Answer". Hope this helps. If it answers your question you can accept it. Otherwise please follow up with further comments to the "Answer".

Sign in to comment.

Accepted Answer

Jon on 22 Sep 2020
So I see you are on the right track, you are trying to define the appropriate closed loop transfer functions but using MATLAB's feedback function instead of doing the block diagram algebra by hand. That seems like a good approach. I think you just need to look more at the details of how you are applying the feedback function.
I see you want the closed loop output of the controller to a setpoint change. In this case the forward path would be the PID controller's transfer function, but the feedback path would be the rest of the elements in the closed loop, in this case, the plant or as you call it sys. Note in your case the closed loop always consists of two elements the controller and the plant, but what part of it is the forward path and what part is the feedback path depends upon what output you are interested in. When you are interested in the plant output as the "output" then the controller and the system are in the forward path with unity feedback, that is 1 in the feedback path. When you want the controller output as the "output" then the forward path is just the controller, and the feedback path is the system.
So, for example for your y_zn calculation you should use
y_zn = lsim(feedback(zn_cont,sys),sp,t);
similar for the others.


Show 5 older comments
Jon on 26 Oct 2020 at 13:16
Hi I think you should be able to use the norm command for this. On the command line you can type doc norm to bring up the detailed documentation. In particular you will find
n = norm(v,p)
where v is the vector of values, for example the error signal you want to compute the norm of and
p = 1 gives the 1-norm, p = 2, gives the 2-Norm (Euclidean Norm), and p = inf gives the infinity norm (maximum absolute value)
Rupali Gawde
Rupali Gawde on 28 Oct 2020 at 10:53
Can you please confirm if the below code is correct:
norm1 = norm((sp - y_zn'),1)
norm2 = norm((sp - y_zn'),2)
normi = norm((sp - y_zn'),inf)
Also, the values for the norms are in attachment. They look incorrect to me.
Jon on 28 Oct 2020 at 14:23
I think that these expressions will give the 1, 2, and infinity norm respectively of the argument you provide (sp - y_zn'). Be sure that both sp and y_zn' are both either row vectors or column vectors. Current versions of MATLAB allow you to subtract a column vector from a row vector, or a row vector from a column vector but this gives a matrix result, not what you want. To be sure they are both columns it is safest to subtract (sp(:) - y_zn(:)). I think from your earlier code that sp is a row and so is y_zn' so I don't think this is a problem for you, but you should check to be sure, as otherwise you will get the norm of a matrix rather than the vector which you wanted.
Otherwise I think it is a matter of how you are intrepreting the results and how you are using these norms. In some cases it may be more appropriate to normalize by the number of elements, for example the root mean square error is closely related to the 2-norm but includes a further normalization by the number of elements

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!