Modeling and Simulation of a DC Motor
Driven Rotary Inverted Pendulum
Course: Control Systems
Student Name: Moumita Paul
Roll Number: 24EC10103
1. Introduction
The inverted pendulum is a classical benchmark problem in control systems. It represents a
nonlinear and unstable electromechanical system that requires feedback control to
maintain stability. In this assignment, we derive the mathematical model of a DC motor
driven rotary inverted pendulum using the Lagrangian method, linearize the system around
the upright equilibrium point, and simulate it using MATLAB.
2. System Description
The system consists of a DC motor that rotates a horizontal arm. A pendulum is attached to
the end of the arm and can swing in a vertical plane. The input to the system is the motor
voltage V(t) and the output is typically the pendulum angle φ(t).
3. Mathematical Modeling
Using the Lagrangian formulation, the equations of motion are derived from L = T − V,
where T is kinetic energy and V is potential energy.
Arm equation:
(Ja + mpLa^2) θ¨ + mpLa lp cosφ φ¨ − mpLa lp sinφ φ̇^2 + Ba θ̇ = τ
Pendulum equation:
(Jp + mplp^2) φ¨ + mpLa lp cosφ θ¨ + Bp φ̇ − mp g lp sinφ = 0
4. State Space Representation
Define state variables: x1 = θ, x2 = θ̇, x3 = φ, x4 = φ̇. The input is motor voltage V. The
system is expressed as ẋ = Ax + Bu.
5. MATLAB Simulation Code
clc
clear
close all
Ja = 0.002;
Jp = 0.001;
mp = 0.2;
La = 0.3;
lp = 0.2;
Ba = 0.01;
Bp = 0.01;
Kt = 0.05;
Ke = 0.05;
R = 2;
g = 9.81;
M11 = Ja + mp*La^2;
M22 = Jp + mp*lp^2;
M12 = mp*La*lp;
Delta = M11*M22 - M12^2;
A = [0 1 0 0;
0 -(M22*(Ba+Kt*Ke/R))/Delta (M12*mp*g*lp)/Delta -(M12*Bp)/Delta;
0 0 0 1;
0 (M12*(Ba+Kt*Ke/R))/Delta -(M11*mp*g*lp)/Delta (M11*Bp)/Delta];
B = [0;
(M22*Kt)/(R*Delta);
0;
-(M12*Kt)/(R*Delta)];
C = [0 0 1 0];
D = 0;
disp('State Space Matrices:')
A
B
C
D
7. MPC controller code
clc;
clear;
close all;
% System parameters
M = 0.5;
m = 0.2;
b = 0.1;
I = 0.006;
g = 9.8;
l = 0.3;
p = I*(M+m) + M*m*l^2;
A = [0 1 0 0;
0 -(I+m*l^2)*b/p (m^2*g*l^2)/p 0;
0 0 0 1;
0 -(m*l*b)/p m*g*l*(M+m)/p 0];
B = [0;
(I+m*l^2)/p;
0;
m*l/p];
C = [1 0 0 0;
0 0 1 0];
D = [0;
0];
sys = ss(A,B,C,D);
% Sampling time
Ts = 0.01;
% Create MPC object
mpcobj = mpc(sys, Ts);
% Prediction and control horizon
[Link] = 20;
[Link] = 5;
% Constraints
[Link] = -10;
[Link] = 10;
% Weights
[Link] = [1 1];
[Link] = 0.1;
% Simulation
Tf = 5;
r = [0 0];
sim(mpcobj,Tf,r)
title('Inverted Pendulum MPC Control')lusion: