imp

19
Pneumatic Inverted Pendulum Keywords: pneumatic, inverted pendulum, linear quadratic regulator BACK to my DASL website 1 Overview 2 Motivation and Audience 3 Parts List and Sources 4 Construction 5 Modeling 6 Measure System Parameter 7 Design a Full State Feedback Controller 8 Programming 9 DOWNLOAD 10 Final Words 11 Special Thanks 12 Contact 13 Bug 1 Overview Figure 1 VIDEO 1: overview

Upload: calin-adrian-stefan

Post on 14-Dec-2015

228 views

Category:

Documents


1 download

DESCRIPTION

jhgfd

TRANSCRIPT

Page 1: Imp

Pneumatic Inverted PendulumKeywords: pneumatic, inverted pendulum, linear quadratic regulator

BACK to my DASL website

1 Overview 2 Motivation and Audience 3 Parts List and Sources 4 Construction 5 Modeling 6 Measure System Parameter 7 Design a Full State Feedback Controller 8 Programming 9 DOWNLOAD 10 Final Words 11 Special Thanks 12 Contact 13 Bug

1 Overview

Figure 1 VIDEO 1: overview

(如果不能收看 YouTube 视频, 请点 击此处 收看优酷视频)

Figure 1 and VIDEO 1 depict an inverted pendulum driven by a pneumatic air cylinder. The big picture problem is maintaining the pendulum in its upright position. Solving this is important because an "inverted pendulum" is a classical model of

Page 2: Imp

control theories--robot arms or humanoid robots are often modeled as multi-link pendulums. This tutorial shows you how to build a pneumatic inverted pendulum, and takes approximately a few days to finish.

2 Motivation and Audience

The motivation of this tutorial is to show you how to build a pneumatic inverted pendulum. Readers are assumed to have the following background:

Interested in robotics Understand how to use DACs and inverters Know State Space modeling Know C language programming Know how to use MATLAB Know how to use Arduino

3 Parts List and Sources

To complete this tutorial, you'll need the following items (U.S.-based vendors, year 2011):

TABLE 1: parts needed for the pneumatic inverted pendulum

DESCRIPTION VENDOR PARTPRICE PER UNIT

QTY

controller ArduinoArduino Duemilanove (or UNO)

$30 1

digital-analog converter

 National Semiconductor

DAC0808 < $5 1

operational amplifier National Semiconductor

LM324 < $5 1

resistance   5.1 K Ohm < $0.1 3

capacitor   0.1 uF < $0.1 1

rotational encoder US digital 1250 count per circle $78 1

linear encoder     > $200 1

proportional valve FESTO MPYE-5-1/8-HF-010-B $650 1

connectors for the valve

FESTO   $5 3

Page 3: Imp

air cylinder GRAINGERpart #: 6W129 (3/4" bore, 6" stroke)

$27 1

clevis rod kit GRAINGER part #: 6W164 $3 1

bracket, pivot GRAINGER part #: 6W163 $3 1

flow control valve GRAINGER part #: 4X132 $38 2

polyurethane tube GRAINGER part #: 4HL92 $40 (100 ft) 1

connector GRAINGER part #: 4HN10 $4 4

carrier igus   $30 1

Some little parts such as screws and nuts are not listed...

And you will also need to have the following equipment:

voltage source: +5V, +12V, -12V. Note: If using separate power supplies, they must share a common ground.

some common tools such as a screwdriver, clamp and multi-meter air compressor

4 Construction

Mechanical structure

Compressed air comes from air compressor and goes in the proportional valve. Coming out from the proportional valve, there are two branches of air flow (one is

Page 4: Imp

compressor air, the other one is exhausted air) which connect to the air cylinder (pneumatic actuator). The pPneumatic actuator connects to a cart (the aluminum box) where the pendulum is attached, and underneath the cart lies the carrier, which guides the cart along moves in a straight line. The rotational encoder is inside the cart, and its shaft is fastened throught out the cart. The pPendulum is attached to the shaft and is able to rotate 360 degrees. At the back side of the cart, attached a linear encoder is attached. For more detail please refer to VIDEO 1.

carrier

Control circuit board

Arduino is used as the data acquisition board and control unit. Signals from the linear encoder and rotational encoder are acquired into the Arduino, and then then Arduino calculates an output voltage is calculated, which will then control the proportional valve through a digital-analog converter and operational amplifier. The circuit schematic diagram is shown belowas below:

Page 5: Imp

Note that the "black green red yellow" in the linear encoder diagram are just merely the color of wires., Yyou might have differnent ones, but after watching VIDEO 2, it should be clear on how to use a linear encoder--the connection and programming are similar to rotational encoder. The opamp depicted is used as an inverter and should be connected to the +12 and -12 power rails. As noted above, if using separate power supplies, they must share a common ground.

Arduino

Visit arduino.cc to learn more.

Rotational encoder

The rotational encoder used in this project is S1-1250-250-I-N-D (more detail available in TABLE 1).

This encoder has 1250 counts per 360 degree (2*pi). Therefore, we have:

1250/(2*pi)360 = angle_count/alphfa

Which gives us:

Page 6: Imp

alphfa = 0.00503288*angle_count (unit:radian degree)

And the angular velocity could be estimated via

Alternatively, a moving average can be utilized, in which an array of the last x average values are stored, and the average (or weighted average) of them is taken. This is more computationally heavy, but may filter out some of the noise.

How to read an encoder:?

When you rotate the encoder's shaft, there will be signals from Channels A and B. Channels A and B are square waves with the same amplitudte and frequency, but they have offset by a 90 degrees phase difference. Note that when rotating in a different direction, at the rising edge of channel A, channel B signal will be different--say, if rotating clockwise results a low valve of channel B at the rising edge of channel A; then when rotating counterclockwise, at the rising edge of channel A, channel B will give a high valve.

Linear encoder

Page 7: Imp

Inside the black box of the linear encoder, there is a rotational encoder. The black box travelles along a track. Therefore, linear encoder and rotational encoder are the same thing--there are also channel A and B in linear encoder, and their signals are the same as rotational encoder. The stroke of air cylinder is 0.1512m, and the linear encoder results 2993 counts travelling that distance. So, we have:

2993/0.1512 = pos_count/x_c

Which gives us:

x_c = 0.0000505*pos_count (unit: meter)

And we could estimate cart velocity using

Digital-analog converter and operational amplifier

The DAC in used is DAC0808, and the operational amplifier in used is LM324. Basicially what digital-analog converter (DAC) does is: given a digital signal from Arduino, DAC outputs an analog signal, which is used to control proportional valve. But because the DAC's output is current and has very little power, we need an amplifier to drive the proportional valve. DAC0808 is an 8-bit DAC, and we give VREF = 12V. If we want a 6.6V output, here is how to calculate the digital value for it:

12/256 = 6.6/digital_value

Which gives us:

digital_value = 141

Details on how DAC and amplifier work, please refer to VIDEO 2.

Proportional valve

Details of how to control proportional valve, please refer to VIDEO 2.

Acquire data from two encoders and controlling proportional valve

We will design a full-sate feedback controller to control the pendulum. Therefore, we need to know all the four states of the pendulum system. (Details about the

Page 8: Imp

mathematical modeling please refer to Modeling.) This video shows how to measure these states, and how to control the proportional valve:

VIDEO 2: measure states, digital analog converter, and proportional valve(如果不能收看 YouTube 视频, 请点 击此处 收看优酷视频)

5 Modeling

We use Lagrange's method to model the system.

Find total potential energy

According to the reference frame above, the cart has zero potential energy. Therefore, the total potential energy is:

Find total kinetic energy

Translational kinetic energy of the cart is:

Translational kinetic energy of the pendulum is:

Page 9: Imp

Rotational kinectic energy of the pendulum is:

Ignoringe the translational kinetic energy of the air cylinder, the total kinetic energy is:

Lagrange's equation

The Lagrangian is:

In this model, we ignore the force that the pendulum acts on the cart, and we ignore the friction on the cart, and the ignore friction on the shaft of the rotational encoder. So, the Lagrange's equations are:

Which will result in:

eq(1)

Model the proportional valve

Denote "a" as the area of pneumatic cylinder's piston and, "p" as the air pressure. From physics, we know that the total force that acts on piston is:

Page 10: Imp

Also, from the datasheet of the proportional valve, one could learn that the relationship between input voltage and output pressure is:

Here "-" in "-Pmax" indicates different output ports, it doesn't mean a negative value (for more detail, please refer to VIDEO 2). So, we have

Insert the above equation into eq(1), solve for

We will have the state space representation of the pneumatic inverted pendulum:

So, the result is:

Page 11: Imp

Select states as below:

Therefore,

Use Taylor's approximation to linearize the system at the following equilibrium point

So our linear time invariant state space model is:

Where

Note that

Page 12: Imp

I used software "Wolfram Mathematica 8" to solve the above equations., Tthe Mathematica file is available in DOWNLOAD section near the end of this webpage.

The input voltage is:

Note that in hardware, for aesthetic reasons, port 2 of the proportional valve is connected to the head port of the air cylinder, and port 4 to the base port; respectively. But according to our mathematical model, these connections should be revisereversed. So, I made a software change and --flipped the control input. Since the proportional valve is originally controlled by 0-10V, the flipped input will be:

So, this is the input voltage for the proportional valve. The Arduino should output the control signal to the DAC circuit to generate this voltage for the proportional valve. (Refer to Digital-analog converter and operational amplifier section)

6 Measure System Parameters

These are parameters we need to know, they are:

mass of the cart mass of the pendulum length of the pendulum from pivot to its center of gravity piston area maximum pressure that air compressor provides to the system

Page 13: Imp

Some parameters we could find out from datasheets, while others we need to measure by ourselves. For dDetails on how to measure system parameters, please refer to this video:

VIDEO 3: measure system paraemeters(如果不能收看 YouTube 视频, 请点 击此处 收看优酷视频)

7 Design a Full State Feedback Controller

Now, we have developed a mathematical model for the system--the linear time invariant state space model. Next, we are going to design a full state feedback controller in MATLAB. Insert A, B, C, D matrices, and make a state space model using command "ss". Then, assign value to the 4*4 matrix Q and scalar R. Then use command "lqr" (linear quadratic regulator--LQR) to calculate the feedback gains.

Note that we need to manually tune the gains: LQR only gives us gains according to Q and R value which were assigned by us, but we don't know what value for Q and R are the best. Therefore, tens of trial-and-error experiments are often unavoidable. The first try we should assign "Q = diag([1 1 1 1])", R = 1. Implement the gains in Arduino, look at the performance of the inverted pendulum, then adjust Q and R values. In Q matrix, each diagonal element relates to one state, the bigger value assigned, the greater effect on minimizing variation of that associated state. And the larger value of R, the greater effect on minimizing control input.

Attention: after we got the feedback gains, we could close MATLAB. Then, we usinge the gains we calculated from MATLAB, write a program using Arduino programming software, and complile it ointo the Arduino board. So, in the end, the Arduino board controls the pneumatic inverted pendulum off line--no computer needed, no MATLAB needed.

The MATLAB file is available in the DOWNLOAD section near the end of this webpage.

8 Programming

To program the Arduino, we need to use Arduino programming software.

Page 14: Imp

Note: that the programming codes had been refined after the day that videos were shot. So, some parts of the code shown in videos are different. However, the method or idea of writing the program is consistent as shown in videos.

Attention: it's important to open the code correctly. For example, if you are using Arduino 0022 (the programming software) Click "File"-->"Open", then choose "inverted_pendulum_v3.pde". And you should see that three .pde files will open automatically.

"inverted_pendulum_v3.pde": the main program. Defines all the variables and do all the initial settings. In the infinite loop, the program calculates control input value and outputs to DAC circuit."dac.pde": controls DAC."encoders.pde": acquires data from two encoders using interrupt functions. And estimates angular velocity and cart velocity using timer interrupt function.

Download the Arduino code in DOWNLOAD section.

9 DOWNLOAD

Download 1: Arduino code

Description: Arduino code for this project.

 

Download 2: Mathematica file

Description: linearizing to obtain a linear time invariant system.

 

Download 3: Matlab file

Page 15: Imp

Description: for finding the right gains of feedback control.

10 Final Words

This tutorial's objective was to show how to build a pneumatic inverted pendulum from mechanical, electronic to proagramming part. Once the concepts were conveyed the reader could do it themselves. This article try its best to present every details, however, reader might not have the same tools, same mechanical parts, or same circuit components, and the vendor link provided in TABLE 1 might be out of date. Therefore, reader might not be able to follow every step. But after reading this article, reader should gain enough knowledge to debug their own problems.

11 Special Thanks

Special thanks for Dr. Paul Y. Oh.

12 Contact

Mr. Jiyue He: post.orange@[at]hotmail.com

13 Bug

In section 4 Construction -> Rotational encoder, unit is wrong: following SI Systems of Units, alfa should be in unit radian:

1250/(2*pi) = angle_count/alfa -> alfa = 0.00503*angle_count (unit: radian)

I found this bug months after I finished this project, the mechanical structures has already been disassembled, so, I could not implement this correction to the actual inverted pendulum. As you see in VIDEO 1, the inverted pendulum worked fine even with this bug, that's the beauty of feedback control: has great tolerance with model inaccuracy/errors.

Page 16: Imp

Drexel Autonomous Systems Lab @ Drexel University