Docsity

Balancing the Inverted Pendulum - Laboratory #3 | ECE 147B, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
University of California, Santa Barbara
Department of Electrical & Computer Engineering
ECE 147b: Digital Control
Lab 3: Balancing the Inverted Pendulum
1 Overview
In this lab you will attempt to balance the inverted pendulum. The pendulum is a classic
example in differential equations in general, and control systems in specific. This is due to
the fact that it has two equilibria, one stable and one unstable. The stable equilibrium—
when the pendulum hangs down—is not as interesting as the unstable one, but it is a lot
easier to use for debugging your implementation. The ultimate objective is to get a balanced
upright pendulum and this will require a good state-feedback/estimator based design.
2 Modeling
A schematic of the inverted pendulum is shown in Figure 1. You are already familiar with
the motor cart. The pendulum is attached to the pivot on top of the cart and the angle
measurements are obtained via a quadrature encoder, similar to the one used to obtain cart
position measurements.
θ
p
Pendulum
Cart Track
Figure 1: Inverted Pendulum
A free body diagram of the system is shown in Figure 2, and defines the forces and moments
considered below. Applying Newton’s second law to the motor cart yields
mc¨p=F−N . (1)
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Balancing the Inverted Pendulum - Laboratory #3 | ECE 147B and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

University of California, Santa Barbara Department of Electrical & Computer Engineering

ECE 147b: Digital Control

Lab 3: Balancing the Inverted Pendulum

1 Overview

In this lab you will attempt to balance the inverted pendulum. The pendulum is a classic example in differential equations in general, and control systems in specific. This is due to the fact that it has two equilibria, one stable and one unstable. The stable equilibrium— when the pendulum hangs down—is not as interesting as the unstable one, but it is a lot easier to use for debugging your implementation. The ultimate objective is to get a balanced upright pendulum and this will require a good state-feedback/estimator based design.

2 Modeling

A schematic of the inverted pendulum is shown in Figure 1. You are already familiar with the motor cart. The pendulum is attached to the pivot on top of the cart and the angle measurements are obtained via a quadrature encoder, similar to the one used to obtain cart position measurements.

θ

p

Pendulum

Cart (^) Track

Figure 1: Inverted Pendulum

A free body diagram of the system is shown in Figure 2, and defines the forces and moments considered below. Applying Newton’s second law to the motor cart yields

mc p¨ = F − N. (1)

R

N

P

F

mc g

N

P mp g

Figure 2: Free Body Diagram for Cart/Pendulum System

Applying Newton’s second law to the pendulum in both the horizontal and vertical directions we obtain

N = mp

d^2 dt^2

(p + l sin(θ))

= mp(¨p + l cos(θ)θ¨ − l sin(θ)( θ˙)^2 ) (2)

P − mpg = mp

d^2 dt^2

(l cos(θ))

= mpg + mpl(− sin(θ)θ¨ − cos(θ)( θ˙)^2 ). (3)

Balancing the moments about the pendulum’s center of mass gives

I θ¨ = P l sin(θ) − N l cos(θ). (4)

By substituting Equation 2 into Equation 1 we obtain

F = (mc + mp)¨p + mpl cos(θ)θ¨ − mpl sin(θ)( θ˙)^2. (5)

Substituting Equations 2 and 3 into Equation 4 yields

θ¨(I + mpl^2 ) = mpgl sin(θ) − mpl p¨ cos(θ). (6)

For simplicity, define the constants

M = mc + mp

L =

I + mpl^2 mpl

Substituting values from Table 1 yields the linearized system

   

δ x˙ 1 δ x˙ 2 δ x˙ 3 δ x˙ 4

   

   

   

   

δx 1 δx 2 δx 3 δx 4

   

   

   

V (9)

[ y 1 y 2

]

[ 1 0 0 0 0 0 1 0

]

   

δx 1 δx 2 δx 3 δx 4

   

Having obtained a linear model, we are now ready to design a controller to balance the inverted pendulum.

3 Design Example

For the following design, a plant different from Equation 9 is considered. You will need to replicate what follows for the inverted pendulum system. Note that there may be some specific implementation issues not dealt with below that you will need to take care of.

For the following design, we will assume our plant is given by

x˙ = Ax + Bu (11)   

x ˙ 1 x ˙ 2 x ˙ 3 x ˙ 4

   =

  

  

  

x 1 x 2 x 3 x 4

   +

  

   V

y = Cx (12) [ y 1 y 2

]

[ 1 0 0 0 0 0 1 0

]

  

x 1 x 2 x 3 x 4

  .

If we define the feedback input to be u = −Kx, then Equation 11 becomes

x˙ = Ax + B(−Kx) = (A − BK)x.

By examining the above equation we can see that it is possible to arbitrarily place the system poles by selecting the feedback gain matrix K. (This is subject to some technical conditions which will not be addressed here. For a full discussion, look up the subject of controllability in any linear systems text.) This is referred to as full-state feedback control, since we assume all the states are available for measurement. Note that this works for discrete-time systems as well (simply replace ˙x by x(k + 1)).

The zero-order hold equivalent, using a sample period of Ts = 0.01 seconds, for Equations 11 and 12 has poles at z = 0.6682, 0.9806, 1, and 1.0230. This system is obviously unstable (since it has a pole located outside the unit circle). Using the Matlab command place, we obtain a feedback gain matrix,

K = [6. 62 − 0. 35 − 3. 53 − 0 .87]

which places the closed-loop system poles at z = 0.67, 0.96, and 0. 98 ± j 0 .01. You should check this.

4 Observer Design

The above approach has an implementation problem; we do not have all of the states available for measurement. A simple, and somewhat crude, fix would be to notice that the states we don’t have available (x 2 and x 4 ) are derivatives of the states we do have available (x 1 and x 3 ). Therefore, we could use numerical differentiation to obtain an estimate of the unmeasured states.

For example, denote the cart velocity by v(k). We can get a crude estimate of v(k) via,

v(k) ≈

p(k) − p(k − 1) T

where p(k) is the measured cart position and T is the sample period. This estimate is susceptible to noise.

However, we have quite a bit of information about the system which may allow us to do something more intelligent. We know the system, the system input, and the system output. We can construct a copy of the system given in Equations 11 and 12, driven by an extra term:

xˆ˙ = Aˆx + Bu + L(y − ˆy) (14) yˆ = C xˆ (15)

x_ = Ax + B u y = C x

y ^ = C ^x

x_^ = A x^ + B u + L(y y^ ) 



K

r u y

y ^

^x

Observer-Controller

Figure 3: Observer-Controller Configuration

−0.02 0 0.5 1 1.5 2 2.5 3 3.5 4

0

Position and Angle Responses (Measured and Estimated)

Position(m)

time(sec)

Measured Estimate

0 0.5 1 1.5 2 2.5 3 3.5 4

0

Angle(rad)

time(sec)

Measured Estimate

Figure 4: Response for Sample System Design

5 Lab Schedule: Week 1

The first week will focus on trying to get a simple state-feedback controller to work. Imple- menting a state-feedback controller requires measurements of all four states (cart position, cart velocity, pendulum angle and pendulum angular velocity). Use a simple differencing scheme (as in Equation 13) to estimate the unmeasured values.

It’s much easier to debug the system if the plant is stable. So we will first try to design a controller for driving the pendulum to the down position.

When you have that working you can start looking at trying to control to the pendulum-up position. Note that these two control problems will require different plant models, as the linearizations are taken at different operating points.

5.1 Prelab: week 1

You will need to write Matlab scripts to do the design, analysis and simulations. Attach copies of these scripts to your prelab.

  1. Create a linearization of the pendulum system with the pendulum hanging down as the operating point.
  2. Design a discrete-time state-feedback controller for the pendulum-down case. Check the position of the closed-loop poles. Use Ts = 0.0005 seconds as your sampling rate.
  3. Simulate your design for the pendulum-down case. Make sure that the actuator voltage does not saturate if you start the controller when the cart is at either end of the track, or when the pendulum is up to 45 degrees off of vertical. If your simulation shows significant saturation, repeat step two.
  4. Also do a simulation with the cart position at zero and the pendulum 45 degrees off of vertical with the controller turned off. This is an open-loop response that you can use for comparison with your closed-loop system.
  5. Repeat the steps 1 through 3 above for the pendulum-up case. Test it with the cart about 30 cm from center (and the pendulum vertical) and the pendulum 5 degrees of off vertical (and the cart at zero).

5.2 Lab: week 1

  1. Build (in Simulink) differencing systems to estimate the two states that are not mea- sured.

6.2 Lab: week 2

  1. Implement your estimator in the pendulum-down case, with the controller off. Record plots of the estimated states and the two measured states. Try to use experimental situations which match those in step 1 of your prelab simulations.
  2. Now connect your pendulum-down estimator to your pendulum-down controller. Again take data for the experiments which give a close match to your step 2 prelab simula- tions.
  3. Try connecting your pendulum-up estimator to your pendulum-up state feedback con- troller. This might require some adjustment of gains to get right. Debugging the estimator is difficult because the system may be going unstable and you only get a record of the first second or two. Try turning the controller off and seeing if the esti- mator tracks the states as the pendulum falls. This will only be good until the angle reaches 45 degrees. Beyond this point the linearization is not even close to valid.
  4. If you get it balanced, try tapping it lightly and recording the data. Try also starting the pendulum slightly off-vertical. In your lab report you should try and simulate these two experiments and compare the data.

7 Lab Schedule: Week 3

The objective here is to design a reduced order estimator to estimate only the two velocities. The two measured states will be used directly in the state-feedback design.

7.1 Prelab: week 3

  1. Design a reduced order estimator for the pendulum-up case.
  2. Analyze the closed-loop pendulum-up control system with the reduced-order estimator. Use unfiltered position and angle measurements for those parts of the state vector in calculating the state-feedback. Include a small amount of noise in the simulations.

7.2 Lab: week 3

  1. Implement your reduced-order pendulum-up estimator and your pendulum-up state feedback controller.
  2. Run a similar set of closed-loop experiments to those performed for the full order pendulum-up estimator/controller in week 2. The objective is to collect data to com- pare these two control schemes in your lab report.

7.3 More Challenging Problems

Once you have balanced the inverted pendulum, you may wish to try the following experi- ments:

  1. Try to find the minimum sampling time needed to balance the system. Assuming you created an m-file to obtain your observer and feedback gain matrices, it shouldn’t be difficult to calculate values for different sampling periods.
  2. Try closing a feedback loop around the cart position so that the cart will track a reference signal. You must simulate this before attempting it.

8 System Parameters

These parameters should be checked for your particular system. They may differ slightly.

Parameter Symbol Value Units Motor Torque Constant Km 0.00767 (^) AmpN m Gear-box Ratio Kg 3.7 N/A Motor Armature Resistance R 2.6 Ω Motor Pinion Radius r 0.00635 m Cart Mass mc 0.455 kg Pendulum Mass mp 0.210 kg Rotational Inertia I 0.00651 kg m^2 Half-Length of Pendulum l 0.305 m

Table 1: System Parameters for Cart/Pendulum System