Combine two controllers in ODE45 environment

2 ビュー (過去 30 日間)
Telema Harry
Telema Harry 2022 年 6 月 7 日
コメント済み: Telema Harry 2022 年 6 月 8 日
Hi,
Please I need idea on how to implement the following problem on MATLAB.
My aim is to stabilize a plant using two dynamic controllers. Only one controller is implemented at a time. The controller to be implemented is depended on a logic variable q = 1 or q = 0.
If q = 0, controller 1 is implemented and if q = 1, controller 2 is implemented.
The controller output is given by:
u = q* K2(x) + (1 - q) * K1(x).
K1 and K2 are dynamic controllers. so they are solved using ODE45.
By default controller 1 will be triggered at the start of the program until output variable is less than 5. and the second controller is triggered.
The main challenge:
The last output of controller 1 (The output just before controller 2 is triggered) should be used as the initial condition of controller 2 when controller 2 is triggered.
  6 件のコメント
Sam Chak
Sam Chak 2022 年 6 月 7 日
編集済み: Sam Chak 2022 年 6 月 7 日
Thanks for clarifying the matter. I think I understand that the dynamics is something like , where , in order to preserve the continuity of the control action. Actually, I'm thinking, "if this is a state-space, where do I put ?"
Telema Harry
Telema Harry 2022 年 6 月 7 日
@Sam Chak. Sorry, that I did not write the controller dynamics. Please see below a simplified version of the problem. Please let me know if it is not clear.
I am currently trying to code the problem using Euler's numerical technique. In the past, I used if statement in the ODE environment. But it did not work as intended.
Controller 2:
when q = 1,
when q = 0
u = K1
State Space Representation:
Assuming a linear system

サインインしてコメントする。

採用された回答

Sam Chak
Sam Chak 2022 年 6 月 8 日
Since you are unable to provide more info, here is a very simple example, which I'm not sure if this is what you want.
System: , where is a sinusoidal disturbance.
function dxdt = odefcn(t, x)
dxdt = zeros(2, 1);
h = 0.2; % activation if x < |h|
q = (sign(x(1) + h) - sign(x(1) - h))/2; % trigger condition for K2
u1 = sign(x(1)); % K1
u2 = x(1)/h; % K2
u = (1 - q)*u1 + q*u2;
d = 0.75*cos(t*2*pi/10) + 0.5*sin(t*2*pi/5); % disturbance
dxdt(1) = d + x(2);
dxdt(2) = (- u - x(2))/0.01;
end
Solving ODE
tspan = linspace(0, 20, 2001)';
x0 = [1 -1];
[t, x] = ode45(@odefcn, tspan, x0);
Plotting the results
plot(t, x, 'linewidth', 1.5)
  1 件のコメント
Telema Harry
Telema Harry 2022 年 6 月 8 日
@Sam Chak Thank you so much for your help. Though I did not provide enough information (model) of my problem as it is my graduate school research project. You still managed to provide great help. I will say, your solution gave me another insight.
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by