Click here to load reader

Software PID Control of an Inverted Pendulum Using

  • Upload
    em330

  • View
    109

  • Download
    2

Embed Size (px)

Citation preview

Software PID Control of an Inverted Pendulum Using the PIC16F684

1

2010/7/28

IntroduceThe purpose of this application note is to describe how a PIC16F684 can be used to implement a positional Proportional-Integral-Derivative (PID) feedback control in an inherently unstable system.

2

2010/7/28

Base platformy

1. 3-point platform 2.2wheels ( one of which is geared and attached to a DC motor) 3.audio jack a. it is used as the axis of rotation for the base platform b. it is to bring commutated power to the controller board

3

2010/7/28

PendulumThe pendulum is attached to the base platform by a 360o free rotating potentiometer. The pendulums base is attached to the potentiometer in such a fashion that when the pendulum is balance (completely vertical), the potentiometer center tap is biased to VERF/2. For the rest of this application note will be used to denote the displacement angle of the pendulum with respect to the vertical axis.

4

2010/7/28

Controller boardy

1. The motor is controlled by an H-bridge which is driven by the PIC16F684 Enhanced Capture/ Compare/PWM Module (ECCP). The output of the ECCP are connected to FET drivers that produce the proper drive voltage and reduce the transition time for the FETs in the H-bridge. 2. 5 1. KP KI KD 2. 3.2010/7/28

y

5

PID

6

2010/7/28

y Proportional Term y Integral Term

KPE(t)

KIE(t)dt

y Derivative Term

KDdE(t)/dt

7

2010/7/28

The frequency of the PID control loop is also going to be selected to simplify the math routines. The Integral term, in Equation 3, shows that each error term needs to be multiplied by the sample. By choosing a sampling frequency in power of 2s, a very fast divide routine can be done by using the right shift command, where each right shift is a divide by 2. Knowing this, choose 256Hz as the sampling frequency.

8

2010/7/28

PID in a digital systemy Converting over to a digital system,Y(t) is measured by an

A/D converter. In order to implement the PID controller, the PICmicro microcontroller will have to do some approximations of integral and derivative terms.

9

2010/7/28

Low-pass filtery The input filter is a low-pass Bessel

1. cut-off frequency of 60Hz The cut-off frequency was chosen to be at least twice the expected frequency of the pendulum. 2. voltage gain of 6 The gain of the filter was chosen to increase the resolution of the A/D converter. With the 360 potentiometer and 10-bit A/D converter, with no gain, one LSb equals 0.35. With the gain set to 6, the displacement angle is limited to 30 which gives a resolution of 0.059 per.10 2010/7/28

Modeling the inverted pendulumy In order to proper implement the control algorithm the user

y y y y

needs to look at how the mechanical and electrical system are going to interface together. Dynamic modeling the inverted pendulum is not a simple task. Select a motor (with proper torque, rpms and gear ration to the drive wheel) The angular acceleration of the pendulum with respect to the displacement angle is =(g/R) MAX is controlled by both hardware and software.The boundary of hardware The boundary of software 30 or 0.523 radians 20 or 0.349 radians2010/7/28

11

y y y y

EPU9 4.6~7.2V 2 inch 8.6:1

y decrease MAX in the software y increase the length of the pendulum y Increase the coefficient of friction between the drive wheel

and the base

12

2010/7/28

Subtleties in the software1.The interrupt service routine is set to run off the Timer0 interrupt. 2.Timer0 is an 8-bit timer that will increment the TMR0 register every instruction clock. 3.When the TMR0 register overflow, the Timer0 interrupt flag is set. 4.The speed at which the interrupt should occur is every 3.9millisecond.

13

2010/7/28

PIDThe derivative term is crucial in order to bring the inherently unstable system into stability. In any PID control the derivative terms acts as an anticipator. By checking the current error against the previous error, the controller can tell if the error term is getting large or small. 1. If the error term is getting large , the derivative term adds to the output of the controller much like that of the proportional and integral, but to a lesser effect. 2. If the error term is getting smaller, this term will subtract from the output of the control in anticipation of an over-shoot condition.

14

2010/7/28

C codey //calculate the differential term y Derivative_term = ec0 en3; y If(derivative_term > 120){ y y } y If(derivative_term < -120){ y derivative_term = -120; y } y y y y y y y y y15

derivative_term = 120;

derivative_term = derivative_term * Kd; derivative_term = derivative_term >>5; // divide by 32 if(derivative_term >120){ derivative_term = 120; } if(derivative_term> -120){ derivative_term = -120; }2010/7/28

y

y

16

2010/7/28

y Why use E(n)-E(n-3) instead of E(n)-E(n-1)?

The main reason for doing this is to limit the variation in the error angle measurement. There will always be an amount of uncertainty associated with the error measurement, some of which can be attributed to A/D error, Bessel filter throughput, mechanical vibration.17 2010/7/28

PID1. Kp Ki Kd 2. 12V( 3. PID 4. 5. Kp Ki Kp Ki Ki 3 3 ) 90

18

2010/7/28

6.

Kd

Kp

Ki PID

7.

19

2010/7/28

ConclusionPIC16F684 PID ECCP A/D

PID 2 /

20

2010/7/28