How to get the output of a controller from MATLAB codes not simulink
11 次查看(过去 30 天)
显示 更早的评论
In simulink, it is easy to get the control output (or input to the actuator) by connecting a scope to the controller output. How do you get the output of the controller in MATLAB codes? I need the output to apply to another system as well as the plant infront of the controller.
Thanks.
0 个评论
采纳的回答
Sam Chak
2022-9-16
Since a sample plant is not provided, we will use a 1st-order plant as an example:
Gp = tf(1, [1 2])
step(Gp, 5)
If we want to improve the settling time at 1 second and to eliminate the steady-state error, we can try:
kp = 5;
ki = 10;
Gc = pid(kp, ki)
The closed-loop system is given by
Gcl = feedback(Gc*Gp, 1)
step(Gcl, 5)
And the output of the PI controller, is given by
Gu = feedback(Gc, Gp)
step(Gu, 5)
1 个评论
Sam Chak
2022-9-16
For the controller output, or in s-domain, we know the compensator transfer function,
... or .
To find the closed-loop transfer function relating the controller output to the input
we start from , and we need to find the error :
.
From the plant transfer function , we know that
.
Substituiting it back to , we get
.
Similarly, substituiting it back to , we get
Separating at one side and on another side
.
Rearranging that yields
This implies that is on the feedback loop, and thus, it can be obtained with the following syntax:
Gu = feedback(Gc, Gp)
更多回答(2 个)
Paul
2022-9-17
I suggest using interconnection functions to build a single system model that has the control input to the plant as one of the outputs from the overall system model
One approach, for example:
Define the plant
sysp = tf(1,[1 0],'InputName','u','OutputName','y');
Define the controller
sysc = tf(1,1,'InputName','e','OutputName','u');
Unitfy feedback to form the closed loop system. Specify the outputs from the closed loop system as the output and input to the plant
sysclosed = connect(sysc,sysp,sumblk('e = r - y'),'r',{'y' 'u'});
Now we can plot the step (or any other response)
step(sysclosed)
Also, sysclosed can then be connected to other systems to build a large model if desired.
ojonugwa adukwu
2022-9-16
1 个评论
Sam Chak
2022-9-16
You are welcome, @ojonugwa adukwu. If you find the solution in MATLAB code is helpful, please consider accepting ✔ and voting 👍 the Answer. Thanks!
I have added an explanation in the comment under my Answer. It's almost the same argument of why use to get the system output , but not the plant itself.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stability Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!