Rotary Inverted Pendulum State Space Model PID Control

23 ビュー (過去 30 日間)
Burak
Burak 2025 年 2 月 4 日
コメント済み: Sam Chak 2025 年 2 月 25 日 12:57
function dx = rip_state_space(x,u)
% System Parameters
m1 = 0.01154; % Arm mass (kg)
m2 = 0.02714; % Pendulum mass (kg)
m = m2 ;
g = 9.81; % Gravitational acceleration (m/s^2)
l1 = 0.085; % Arm length (m)
l2 = 0.2; % Pendulum length (m)
c1 = l1 / 2; % Arm center of mass distance (m)
c2 = l2 / 2; % Pendulum center of mass distance (m)
Br = 0.001; % Arm friction coefficient (Nm/(rad/s))
Bp = 0.001; % Pendulum friction coefficient (Nm/(rad/s))
I1 = 2.778e-5; % Arm moment of inertia (kg*m^2)
I2 = 9.048e-5; % Pendulum moment of inertia (kg*m^2)
% Effective Moment of Inertia
Ja = I1 + m1 * c1^2 + m2 * l1^2; % Arm moment of inertia
Jp = I2 + m2 * c2^2; % Pendulum moment of inertia
% A Matrix Elements
a22 = -Br / m;
a23 = (m * l1 * g) / Jp;
a24 = -(m * l1 * Bp)/Jp;
a42 = -(Br * l1) / (l2 * Jp);
a43 = ((m * l1^2 * g)/(Jp * l2)) + (g / l2);
a44 = -((m * l1 * Bp * ((l1 * l2)+1)) / (l2^2 * Jp));
% A Matrix
A = [0, 1, 0, 0;
0, a22, a23, a24;
0, 0, 0, 1;
0, a42, a43, a44];
% B Matrix Elements
b2 = 1 / Jp;
b4 = l1 / (l2 * Jp);
% B Matrix
B = [0;
b2;
0;
b4];
dx = A * x + B * u ;
end
Hello,
I am trying to control the rotary inverted pendulum system, with the given parameters above, using a classical PID controller. My goal is to keep the pendulum in the upright position while also controlling the system based on two different reference values. Despite trying various methods for days, I have not been able to resolve the error or achieve a stable system. I would greatly appreciate any help or suggestions you can provide.
Thank you.

回答 (1 件)

Sam Chak
Sam Chak 2025 年 2 月 5 日
If no other control requirements are specified, the objective is to "freely" find any combination of gain values for the single control input such that the closed-loop state matrix produces negative real eigenvalues. This situation essentially becomes a mini-game for a mathematician. The term "single control input" implies that only one non-equilibrium state can be regulated. Since [0, 0, 0, 0] is the equilibrium point, and it is desired to regulate State 1 at 30° and State 3 at 0°, only the first state needs to be regulated.
Given that the input matrix B is 4-by-1, the control gain matrix should be 1-by-4, indicating that only four gain values need to be determined. The presence of two PID controller blocks in your Simulink model implies that you need to find a total of control gains (P, I, D, and the filter gain for each block). I prefer not to complicate matters for the sake of good engineering practice; therefore, I will demonstrate the simulation in MATLAB rather than in Simulink.
[t, x] = ode45(@rip_state_space, [0 10], [0; 0; 0; 0]);
% Response for State 1
subplot(211)
plot(t, rad2deg(x(:,1))), grid on, title('\theta_{1}'), ylabel('degree')
% Response for State 3
subplot(212)
plot(t, rad2deg(x(:,3))), grid on, title('\theta_{2}'), ylabel('degree'), xlabel('Time')
function dx = rip_state_space(t, x)
% System Parameters
m1 = 0.01154; % Arm mass (kg)
m2 = 0.02714; % Pendulum mass (kg)
m = m2;
g = 9.81; % Gravitational acceleration (m/s^2)
l1 = 0.085; % Arm length (m)
l2 = 0.2; % Pendulum length (m)
c1 = l1/2; % Arm center of mass distance (m)
c2 = l2/2; % Pendulum center of mass distance (m)
Br = 0.001; % Arm friction coefficient (Nm/(rad/s))
Bp = 0.001; % Pendulum friction coefficient (Nm/(rad/s))
I1 = 2.778e-5; % Arm moment of inertia (kg*m^2)
I2 = 9.048e-5; % Pendulum moment of inertia (kg*m^2)
% Effective Moment of Inertia
Ja = I1 + m1*c1^2 + m2*l1^2; % Arm moment of inertia
Jp = I2 + m2*c2^2; % Pendulum moment of inertia
% A Matrix Elements
a22 = - Br/m;
a23 = (m*l1*g )/Jp;
a24 = - (m*l1*Bp)/Jp;
a42 = -(Br * l1) / (l2 * Jp);
a43 = ((m * l1^2 * g)/(Jp * l2)) + (g / l2);
a44 = -((m * l1 * Bp * ((l1 * l2)+1)) / (l2^2 * Jp));
% A Matrix
A = [0, 1, 0, 0;
0, a22, a23, a24;
0, 0, 0, 1;
0, a42, a43, a44];
% B Matrix Elements
b2 = 1/Jp;
b4 = l1/(l2*Jp);
% B Matrix
B = [ 0;
b2;
0;
b4];
% -------- Sam's Controller --------
r = [pi/6; 0; 0; 0]; % Reference (only 1 non-equilibrium state can be regulated)
K = [-1, -3, 65, 9]; % Control Gains
e = x - r; % Error
u = - K*e; % State-feedback controller (or equivalent to two parallel PD Controllers)
% ----------------------------------
% Dynamics
dx = A*x + B*u;
end
  3 件のコメント
Sam Chak
Sam Chak 2025 年 2 月 5 日
You can implement the state-feedback gains in the PID controllers, as they are conceptually similar to feedback mechanisms. However, you may observe some differences in the responses because the Simulink PID Controller derives State 2 from the measured State 1 signal and State 4 from the measured State 3 signal. In a state-feedback controller, we assume that all four states can be directly measured. Both the state-feedback controller and the PID controller can stabilize the system.
Sam Chak
Sam Chak 2025 年 2 月 25 日 12:57
I noticed that you posted a new question related to this one. Has the control issue been considered resolved? If you find the code and explanation helpful, please consider clicking 'Accept' ✔ on the answer and voting 👍 for it. Your support is greatly appreciated!

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

Community Treasure Hunt

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

Start Hunting!

Translated by