0% found this document useful (0 votes)
21 views6 pages

Cs Manual 9

The document describes modeling an inverted pendulum system in Simulink. It provides the equations of motion and details on building a Simulink model that includes the pendulum and cart subsystems. It also describes adding a PID controller to regulate the pendulum angle with the goal of less than 5 seconds settling time and excursion of no more than 0.05 radians. The assignment is to adjust PID parameters to achieve settling time less than 4 seconds and excursion less than 0.04 radians.

Uploaded by

bajwaumair320
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Cs Manual 9

The document describes modeling an inverted pendulum system in Simulink. It provides the equations of motion and details on building a Simulink model that includes the pendulum and cart subsystems. It also describes adding a PID controller to regulate the pendulum angle with the goal of less than 5 seconds settling time and excursion of no more than 0.05 radians. The assignment is to adjust PID parameters to achieve settling time less than 4 seconds and excursion less than 0.04 radians.

Uploaded by

bajwaumair320
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Department of Electrical Engineering University of Engineering & Technology Lahore

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 .

For this example, let's assume the following quantities:

Below are the two free-body diagrams of the system.

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.

Then addressing the -component equations gives us 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.

 This equation requires three inputs: , , and . Double-click on the corresponding


Mux block and change the Number of inputs: to "3".
 Connect these three inputs to this Mux block in the order prescribed in the previous step.

 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

Now, let's enter equation (2) which is repeated below.

 This equation also requires three inputs: , , and .

 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:

 Settling time of less than 5 seconds

 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.

 Change the List of signs: of one of the Add blocks to "+-".


 Insert a Constant block from Simulink/Sources library. Change its value to 0. This is the reference input that
corresponds to the pendulum vertically upward. Note, the non-Simscape model (and the rest of the pages in this
example) define the pendulum angle to equal pi when pointing straight up.

 Insert a PID Controller block from the Simulink/Continuous 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.

You might also like