Control Report 1
Control Report 1
TECHNOLOGY(JKUAT)
INTRODUCTION
This report presents a simulation of a pendulum system implemented using MATLAB. The goal
of the simulation is to model the motion of a simple pendulum under the influence of gravity.
The pendulum system will be modeled as a simple pendulum, neglecting friction and air
resistance. We will solve the equation of motion for the pendulum using MATLAB's ODE
solvers and visualize the results.
THEORY
A pendulum is a device made of a weight suspended from a pivot so that it can swing
freely. When a pendulum is displaced sideways from its resting, equilibrium position, it is
subject to a restoring force due to gravity that will accelerate it back toward the equilibrium
position. When released, the restoring force acting on the pendulum's mass causes it
to oscillate about the equilibrium position, swinging back and forth. The time for one complete
cycle, a left swing and a right swing, is called the period. The period depends on the length of the
pendulum and also to a slight degree on the amplitude, the width of the pendulum's swing.
The regular motion of pendulums was used for timekeeping and was the world's most accurate
timekeeping technology until the 1930s. The pendulum clock invented by Christiaan Huygens in
1656 became the world's standard timekeeper, used in homes and offices for 270 years, and
achieved accuracy of about one second per year before it was superseded as a time standard by
the quartz clock in the 1930s. Pendulums are also used in scientific instruments such
as accelerometers and seismometers. Historically they were used as gravimeters to measure
the acceleration of gravity in geo-physical surveys, and even as a standard of length. The
word pendulum is Neo-Latin, from the Latin pendulus, meaning 'hanging'.
APPARATUS
1. MATLAB
Pendulum Dynamics
The dynamics of a simple pendulum can be described by the following second-
order ordinary differential equation (ODE):
θ'' + (g / L) * sin(θ) = 0,
IMPLEMENTATION
The simulation was implemented in MATLAB using the provided code. The parameters used in
the simulation are as follows:
Eig (A)
Control Strategy:
To stabilize the pendulum system, a control law is designed using the Linear Quadratic Regulator
(LQR) method. The LQR controller minimizes a cost function that considers the deviations of
the system states and control effort. The weighting matrices Q and R are chosen to specify the
relative importance of the states and control input in the cost function.
The LQR controller gains (K) are computed using the MATLAB function , which takes the
system dynamics (A, B) and the weighting matrices (Q, R) as inputs. These gains are used to
calculate the control input that drives the system towards the desired state.
Q = [10 0 0 0;
0 10 0 0;
0 0 100 0;
0 0 0 1000];
R = 10;
Simulation Results
The simulation is run for a time span of 0 to 10 seconds with a time step of 0.001 seconds. The
initial conditions for the system states are set differently based on the value of the scaling factor
(s). If s = -1, the initial conditions are [0; 0; 0; 0], otherwise, if s = 1, the initial conditions are [-
3; 0; π+0.1; 0].
The ODE solver ode45() is used to numerically solve the system's ODEs. It approximates the
state variables' values at discrete time points based on the dynamics equations and the control
input calculated using the LQR controller gains.
The simulation results are visualized using the draw cart pendulum function. This function
generates a plot that represents the cart-pendulum system. The cart is depicted as a rectangle, and
the pendulum is represented by a line segment. The plot is updated at regular intervals to display
the system's behavior over time.
The simulation is repeated for different time points to observe the system's response. The draw
cart pendulum function is called at specific time intervals to visualize the system's state at those
points.
DISCUSSION
The simulation results demonstrated the effectiveness of the LQR control strategy in stabilizing
the pendulum in the upright position. The system's response was visualized through the
generated plots and graphical representation.
In the pendulum up scenario, the initial conditions were set to initiate the pendulum in a
downward position. The control input applied through the cart's position successfully stabilized
the pendulum in the upright position. The system maintained this equilibrium throughout the
simulation time span.
In the pendulum down scenario, the initial conditions were adjusted to start the pendulum in an
upright position. The control input aimed to maintain the pendulum in this position. The
simulation results showcased the robustness of the control strategy, as the pendulum remained
stable despite minor disturbances.
CONCLUSION
The simulation demonstration provided a comprehensive understanding of the pendulum-cart
system's dynamics and the effectiveness of the LQR control technique in stabilizing the
pendulum in the upright position. The simulation results confirmed the robustness of the control
strategy and its ability to handle disturbances. This study contributes to the field of control
systems and offers insights into the practical applications of control techniques in pendulum-like
systems. Further investigations could explore alternative control techniques or analyze the
system's behavior under different parameter variations or external disturbances.
REFERENCES
1. Mouratis, K., Fasoulas, J., & Sfakiotakis, M. (2018, September). Development and
Control of a Low-Cost Cart-Pendulum Educational Platform. In Proc. 17th International
Symposium on Ambient Intelligence and Embedded Systems (AmiEs’ 18).
2. Yu, H., Yang, T., Liu, Y., & Wane, S. (2008). A further study of control for a pendulum-
driven cart. International Journal of Advanced Mechatronic Systems, 1(1), 44-52.
Give the meaning of the following commands and examples
1. jacobian,
2. ctrb,
3. obsv,
4. rank,
5. det,
6. place/acker
7. lqr
1. jacobian:
The Jacobian is a mathematical matrix that represents the partial derivatives of a set of functions.
In the context of control systems, the Jacobian is often used to linearize nonlinear systems
around an operating point. It provides information about the system's local behavior and can be
used for stability analysis and control design.
Example:
syms x y z;
f = [x^2 + y*z; x*y^2 + z; x*z^2 + y];
J = jacobian(f, [x, y, z]);
In this example, the Jacobian matrix J is calculated for the vector function f with respect to the
variables x, y, and z.
2. ctrb (Controllability):
The ctrb function is used to check the controllability of a linear time-invariant (LTI) system. It
determines whether all the states of the system can be controlled by applying suitable control
inputs.
Example
A = [1 2; 3 4];
B = [1; 0];
C = eye (2);
D = 0;
sys = ss (A, B, C, D);
controllable = ctrb (sys);
In this example, the controllable matrix controllable is obtained using the ctrb function for the
state-space system defined by matrices A, B, C, and D. The matrix controllable has full rank if
the system is controllable
3. obsv (Observability):
The obsv function is used to check the observability of a linear time-invariant (LTI) system. It
determines whether all the states of the system can be observed or estimated from the system's
outputs.
Example:
A = [1 2; 3 4];
B = [1; 0];
C = eye (2);
D = 0;
sys = ss (A, B, C, D);
observable = obsv(sys);
In this example, the observable matrix observable is obtained using the obsv function for the
state-space system defined by matrices A, B, C, and D. The matrix observable has full rank if the
system is observable.
4. rank:
The rank function is used to determine the rank of a matrix, which represents the maximum
number of linearly independent rows or columns in the matrix. It is often used to assess the
controllability or observability of a system by checking if certain matrices have full rank.
Example:
A = [1 2 3; 4 5 6; 7 8 9];
rank_A = rank(A);
In this example, the rank of matrix A is calculated using the rank function, and the result is stored
in the variable rank_A.
5. det (Determinant):
The det function is used to calculate the determinant of a square matrix. The determinant
provides information about the matrix's linear independence, invertibility, and scaling factor.
Example:
A = [1 2; 3 4];
determinant_A = det(A);
In this example, the determinant of matrix A is computed using the det function, and the result is
stored in the variable determinant_A.
6. place/acker:
The place or acker function is used for pole placement control, where the objective is to assign
the closed-loop poles of a system to desired locations. This allows controlling the system's
stability and dynamic response.
Example:
A = [1 2; 3 4];
B = [1; 0];
desired_poles = [-1 -2];
K = place(A, B, desired_poles);
In this example, the place function is used to calculate the gain matrix K for the state-space
system defined by matrices A and B. The desired poles are specified as desired_poles, and the
resulting gain matrix K positions the system's poles at the desired locations.
In this example, the lqr function is used to compute the optimal control gain matrix K for the
state-space system defined by matrices A and B. The weighting matrices Q and R specify the
relative importance of state variables and control effort, respectively