Cs Manual 9
Cs Manual 9
EE340: Control
Lab# 9 Systems Lab
Experiment
Modeling 6
of Inverted Pendulum
Physical Setup
In this example we will consider a two-dimensional version of the inverted pendulum system with cart where the
pendulum is contrained to move in the vertical plane shown in the figure below. For this system, the control input is
the force that moves the cart horizontally and the outputs are the angular position of the pendulum and the
horizontal position of the cart .
Both the cart and the pendulum have one degree of freedom ( and , respectively). We will generate the differential
equations for these degrees of freedom from first principles employing Newton's second law ( ) as shown
below.
(1)
Department of Electrical Engineering University of Engineering & Technology Lahore
(2)
It is necessary, however, to include the interaction forces and between the cart and the pendulum in order to
fully model the system's dynamics. The inclusion of these forces requires modeling the - and -components of the
the translation of the pendulum's center of mass in addition to its rotational dynamics. In class lecture , the interaction
forces and were solved for algebraically.
In general, we would like to exploit the modeling power of Simulink to take care of the algebra for us. Therefore, we
will model the additional - and -component equations for the pendulum as shown below.
However, the position coordinates and are exact functions of . Therefore, we can represent their derivatives in
terms of the derivatives of . First addressing the -component equations we arrive at the following.
These expressions can then be substituted into the expressions for and from above as follows.
(3)
(4)
Simulink Model
We can build the inverted pendulum model in Simulink employing the equations derived above by following the steps
given below.
Begin by typing simulink into the MATLAB command window to open the Simulink environment. Then open a
new model window in Simulink by choosing New > Model from the File menu at the top of the open Simulink
Library Browser window or by pressing Ctrl-N.
Department of Electrical Engineering University of Engineering & Technology Lahore
Insert four Fcn Blocks from the Simulink/User-Defined Functions library. We will build the equations for , , ,
and employing these blocks.
Change the label of each Fcn block to match its associated function.
Insert four Integrator blocks from the Simulink/Continuous library. The output of each Integrator block is going to
be a state variable of the system: , , , and .
Double-click on each Integrator block to add the State Name: of the associated state variable i.e x . Also change
the Initial condition: for (pendulum angle) to "pi" to represent that the pendulum begins pointing straight up.
Insert four Multiplexer (Mux) blocks from the Simulink/Signal Routing library, one for each Fcn block.
Insert two Out1 blocks and one In1 block from the Simulink/Sinks and Simulink/Sources libraries, respectively.
Then double-click on the labels for the blocks to change their names. The two outputs are for the "Position" of the
cart and the "Angle" of the pendulum, while the one input is for the "Force" applied to the cart.
Connect each output of the Mux blocks to the input of the corresponding Fcn block.
Connect the output of the and Fcn blocks to two consecutive integrators to generate the cart's position and
the pendulum's angle. Your current model should now appear as follows.
Now we will enter each of the four equations (1), (2), (3), and (4) into a Fcn block. Let's start with equation (1) which
is repeated below.
Double-click on the first Fcn block and enter the equation for xddot as shown below.
Department of Electrical Engineering University of Engineering & Technology Lahore
Enter the above equation into the Fcn block, change the number of inputs of the Mux block, and connect the
correct signals to the Mux block in the correct order.
Repeat this process for equations (3) and (4) repeated below.
Department of Electrical Engineering University of Engineering & Technology Lahore
In order to save all of these components as a single subsystem block, first select all of the blocks, then select Create
Subsystem from the Edit menu. Your model should appear as follows.
PID controller
In the design process we will develop a PID controller and apply it to a single-input, single-output plant. More
specifically, the controller will attempt to maintain the pendulum vertically upward when the cart is subjected to a 1-
Nsec impulse. The cart's position will be ignored. Under these conditions, the design criteria are:
Pendulum should not move more than 0.05 radians away from the vertical
PID controller will be designed with proportional, integral, and derivative gains equal to 100, 1, and 20,
respectively.
Following the steps below, we will build a closed-loop model with reference input of pendulum position and a
disturbance force applied to the cart.
Insert two Add blocks from Simulink/Math Operations library.
Edit the PID block by doubleclicking on it. Change the Proportional (P): gain to "100", leave the Integral (I): gain
as "1", and change the Derivative (D): gain to "20".
Now connect the blocks as they appear in the following figure:
Department of Electrical Engineering University of Engineering & Technology Lahore
Now, start the simulation (select Start from the Simulation menu or enter Ctrl-T). After the simulation has run,
double-click on the scope and hit the Autoscale button. You should see the following response.
Assignment:
Adjust the parameters of inverted pendulum such that settling time is less than 4s and pendulum should not move more than 0.04 rad
away from vertical and attach the result.