CEG2400 Chapter 11 - PowerPoint PPT Presentation

1 / 107
About This Presentation
Title:

CEG2400 Chapter 11

Description:

Study open-loop and closed-loop control. Study other motors with applications ... Require speed encoder to read back the real speed of the wheel at real time. ... – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 108
Provided by: khw9
Category:
Tags: ceg2400 | chapter

less

Transcript and Presenter's Notes

Title: CEG2400 Chapter 11


1
CEG2400Chapter 11
  • Feedback control of motors
  • Based on PIDRobotDemo.c
  • http//www.cse.cuhk.edu.hk/khwong/ceg2400/PIDRobot
    Demo093.c
  • Reference www.tic.ac.uk/micromouse/PRESENTATIONS
    /Heretic.ppt

2
Objectives
  • Study different types of motors
  • Study motor control methods
  • Study open-loop and closed-loop control
  • Study other motors with applications

3
1) different types of motors
  • DC motors
  • Stepping motors

4
Motors
  • DC motors Direct current motor, easy to control
    and use. For making wheeled robots
  • Servo motors for making robot legs
    http//www.lynxmotion.com/

5
Stepping motor
  • For precision control
  • E.g. printer, scanner, robot arm, clock.

6
Small Direct Current D.C. motors
  • Speed ( 2000 rpm).
  • Operates on a 35Volt, current300500mA when in
    motion. (1A during start-up)
  • Can use gear box (e.g. ratio 581) to increase
    torque
  • Use H-bridge circuit to boost up current from the
    TLL level to motor driving level.

7
DC motors for robot,each motor 2 inputs LEN,
LDIR

The robot Rear side
Left motor (Front side) right motor
8
Exercises
  • Exercise 1 Why does the robot use front wheel
    drive?
  • Ans it is difficult to control the steering
    otherwise.
  • Exercise 2 Estimate how many power stabilizer
    systems are needed for the whole system. Draw a
    block diagram showing the power stabilizer
    circuits and the sub-modules of the robot systems
    including DC motors, Servomotors, and an
    ultra-sonic radar system.
  • Ans The idea case is each sub-system is powered
    by a 7805 regulator

9
2) motor control methods
  • Power electronic interfaces to motors

10
Power electronic system for the DC motors
  • Mechanical and solid state relay
  • Power transistor
  • H-Bridge circuit

11
Relays mechanical and solid state types
  • Problem not durable and limited on/off frequency

12
Power transistors
  • One direction

From 2
13
Power transistors
  • Bi-directional , from 2

14
Power transistors
  • Analogue, from 2

15
Motor control chip
  • L293D H-bridge circuit, up 2A
  • LDIR left motor direction RDIR right motor
    direction
  • LEN left motor enable REN right motor enable
  • H-bridge Chips

16
Motor control methodusing PWM

Left -motor
17
Exercises
  • Exercise 3 Give the states of LEN, LDIR, REN and
    RDIR for turning the robot clockwise.
  • Exercise 4 What alternatives other than PWM are
    available for controlling the speed of the DC
    motors
  • Ans analog methods?

18
3) open-loop and closed-loop control
  • Feedback control
  • PID theory and implementation

19
Open-loop motor control and its problems
  • Change motor supply power change speed
  • Problem How much power is right?
  • Ans dont know , depends on internal/external
    frictions of individual motors.
  • Problem How to make the robot move straight?
  • How to control power (Ton) by ISR an MCU?
  • Solution Use feedback control to read actual
    wheel
  • Slower, increase power ( Ton)
  • Faster, reduce power (- Ton)

20
Exercise
  • When using the open-loop control method with a
    constant PWM signal for both wheels, explain why
    the robot would slow down when climbing up hill.
  • Ans When climbing up hill, energy is used to act
    against gravity, hence the robot is running
    slower.

21
Feedback control
  • The real solution to real speed control is
    feedback control
  • Require speed encoder to read back the real speed
    of the wheel at real time.

22
First you need to have speed encoders
  • Read wheel speed.
  • Use photo interrupter
  • Use reflective disk to save space
  • Based on interrupts

23
Wheel encoder
Our motor and speed encoder Each wheel
rotation 88 on/off changes
IR receiver
Darkened part blocks light
IR light source
24
(No Transcript)
25
Control methods
  • I) Proportional feedback control
  • II) PID (proportional-integral-derivative)
    control

26
I) Proportional closed-loop feed back control
system
  • Show the left motor control only

if (leftErr gtdeadband) leftPWM increase by
(Pgain leftErr)
leftPWM
Required speed leftRPMset
leftErr
Motor
Alter PWM for driver L293
-
leftRPM
27
II) PID (proportional-integral-derivative) control
  • A more formal and precise method
  • Used in most modern machines

28
control methodPID (proportional-integral-derivat
ive) control
Motor
integral control Igain leftErr dt
Required speed leftRPMset
IR wheel Speed encoder

generates PWM for driver L293
Proportional control PgainleftErr dt
-
sum
leftErr
Derivative control Dgaind(leftErr)/dt
leftPWM
LeftRPM
leftRPM
29
Introduction
  • Control for better performance
  • Use PID, choose whatever response you want

Too much overshoot/undershoot, not stable
Motor speed (w)
Good performance Criteria depends on users and
applications
required
Response too slow
time
30
Values to evaluate a control system

Steady state error
overshoot
Target value
Typically value10 Depends on application
undershoot
time
Settling time
0
Rise time
31
Use of PIDcontrol terms are intertwinedhttp//en
.wikipedia.org/wiki/PID_controller
  • Kp (P) Proportional Gain - Larger Kp typically
    means faster response since the larger the error,
    the larger the Proportional term compensation. An
    excessively large proportional gain will lead to
    process instability and oscillation.
  • Ki (I) Integral Gain - Larger Ki implies steady
    state errors are eliminated quicker. The
    trade-off is larger overshoot any negative error
    integrated during transient response must be
    integrated away by positive error before we reach
    steady state.
  • Kd (D) Derivative Gain - Larger Kd decreases
    overshoot, but slows down transient response and
    may lead to instability due to signal noise
    amplification in the differentiation of the
    error.

32
Effects of increasing parametershttp//en.wikiped
ia.org/wiki/PID_controller

33
Software
  • PIDrobotdemo.c
  • (at course webpage)
  • http//www.cse.cuhk.edu.hk/khwong/ceg2400/PIDRobot
    Demo.c

34
PID control algorithm using interrupt
IR receiver Speed Encoder sensor
interrupts
1000 interrupts per second
time
Main( ) Setup( )
_IRQ( )//1000Hz read wheel speed PID
35
Overview
  • //////////////main ///////////////////////////////
    ///////
  • Main()
  • setup()
  • forward (Lstep, Rstep, Lspeed, Rspeed)..
  • ////////////subroutine ///////////////////////////
    ///////////////
  • forward (Lstep, Rstep, Lspeed, Rspeed)
  • lcount0
  • if (lcountgtLstep)
  • Stop left motor
  • same for right motor
  • .
  • //////////timer triggered , instrrupt service
    routine, 1000Hz///////
  • __irq exception// Interrupt() running at 1000HZ
  • lcount
  • read wheel speeds
  • PID control to achieve L/Rspeed
  • .same for right motor.

Interrupt rate 10004Hz
_IRQ see next slide
36
Speed encoder interfacing(show left motor only)
  • Block diagram

ARM- LPC2183
1000Hz timer interrupt
/int0 CPU
GPIO Parallel interface
IR transmitter IR receiver (speed encoder
sensor)
In our robot 88 pattern changes in one rotation
37
_irq interrupt programming method for the main
PID loop, using a counter (intcount)
  • __irq() exception //timer interrupt 1000HZ,
  • intcount //intcount
  • //increases at 1000 times/sec
  • //update the motor speed in every 1/4 seconds
  • if(intcount250) // happens at every ¼
    seconds
  • read wheel speed
  • Control the PWM using PID, PID CORE
  • intcount0

38
Speed control interrupt core _irq()part 1 Find
motor speed, leftRPM
Speed encoder sensor
lefttimeval
  • void __irq IRQ_Exception()
  • ms intcount
  • //get the current wheel sensor values
  • lcurIO0PIN LWheelSenrcurIO0PIN RWheelSen
  • if(lcur!lold) lcountloldlcurlefttimeval
  • //update motor speed by PID feed back control in
    every ¼ Seconds
  • if(intcount250) //caculate the speed of left
    motor in RPM
  • leftRPMlefttimeval
  • intcount0
  • lefttimeval0

time
Interrupts 1000 Hz
PID core See following slides
  • lcount steps of wheel
  • lcur sensor read 1 or 0
  • lefttimeval time lapsed since sensor last change
    of state
  • leftRPM left wheel RPM

39
What is the value of leftRPM ? Answer18240/88?
Reset intcount here
¼ seconds
Reset intcount here
Interrupts 1000Hz

Intcount 0123 71 . 83
255 01234 Lcur 0 1 0 1
0 1 0 1 0 0 1 0 1
0. Lcount 11 12 13 14 . 1819 20 21 22
28 29 Lefttimeval 1 2 3 4
8 9 10 11 12 18 0 1

Speed encoder sensor
if (lcur!lold) //sensor changes state (0-gt1)
or (1-gt0)
time
Intcount 71 72 73 74 75 76 77 78 79 80 81 82
83 Lcur 0 1 1 1 1 0 0 0 1
1 1 1 0 lcount 18 18 19 19 19 19 20 20 20
21 21 21 21 22 Lefttimeval 9 9 9 9
10 10 10 11 11 11 11 12
Interrupt rate 1024 Hz
40
part 2 PID core
PID core
  • if(intcount250)
  • //caculate the speed of left motor in RPM
  • leftRPMlefttimeval
  • leftErr leftRPMset - leftRPM //caculate
    left error
  • if((leftErrltDeadBand(-1))(leftErrgtDeadBand))
    //see next slide
  • //if left error gt deadband
  • leftP Pgain leftErr //calculate P
    Proportional term
  • leftI Igain leftaccErr //calculate I
    Integral term
  • leftD Dgain (leftErr - leftlastErr) //calcul
    ate D Derivative term
  • leftPWM (leftP leftI leftD)//update left
    motor PWM using PID
  • if(leftPWMgtPWM_FREQ)
  • leftPWMPWM_FREQ//prevent over
    range (max.PWM_FREQ)
  • if(leftPWMlt0) leftPWM 0 // (min. 0)
  • leftaccErr leftErr //
    accumulate error
  • leftlastErr leftErr //update left last
    error
  • // handle right motor similarly.
  • current_leftRPM leftRPM240/88
  • current_leftPWM leftPWM

PProportional
I Integral
D Derivative
Pgain, Igain, Dgain are constants found by a
trial and error method, here we have Pgain
8000 Igain 6000 Dgain 5000
41
Inside the PID core, we will study these lines
  • 5) if((leftErrltDeadBand(-1))(leftErrgtDeadBand))
  • 7) leftP Pgain leftErr //calculate
    P Proportional term
  • 8) leftI Igain leftaccErr //calculate
    I Integral term
  • 9) leftD Dgain (leftErr - leftlastErr)//calcu
    late D Derivative term
  • 10) leftPWM (leftP leftI leftD)//update
    motorPWM by PID
  • 14) leftaccErr leftErr // accumulate error

42
Dead bandline5) if((leftErrltDeadBand(-1))(left
ErrgtDeadBand))
  • Dead-band A Dead-band (sometimes called a
    neutral zone) is an area of a signal range or
    band where no action occurs
  • only enable motor when leftErrgt a small value
    (deadband, ie 1 in our robot )
  • Otherwise may oscillate when leftErr is small

leftErr leftRPM - leftRPMset //calculate left
error if(leftErrgtDeadBand ) activate
motor
Dead-band
43
Example of a dead banddo nothinbg if
30-1ltleftPRM lt301
In our experiment leftPWM276000 at the
beginning and 192800 at steady state

Steady state error
Dead band /- 1
overshoot
Target speed leftRPMset 10
Typically value10 Depends on application
undershoot
time
Settling time
0
Rise time
When leftRMPset10, the real RPM is
RPM240/8827.3., see line 18
44
(line 7) Effects of increasing
Kp(P)http//en.wikipedia.org/wiki/PID_controller

45
Example t0?t1, The proportional term when the
measurement is below the set point (leftRPMset),
proportional P term is ve

Usage of the P proportional term Each ¼ seconds a
new left RPM (speed of wheel) is measured
overshoot
Target speed leftRPMset 10
8
e.g. Pgain 8000 Igain 6000 Dgain 5000
6
undershoot
leftErr leftRPMset leftPRM 30-282
leftErr leftRPMset leftPRM 10-64
P is ve
P is ve
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
t1
t3
t2
t4
0
time
Rise time
leftP Pgain leftErr leftP 8000 (10-4)
80006 is positive This term pushing up
leftPWM (more energy delivered to the wheel).
leftP Pgain leftErr leftP 8000 (0-8)
80002 is positive This term pushing up
leftPWM (more energy delivered to the wheel).
46
Example t0?t1, The proportional term when the
measurement is below the set point (leftRPMset),
proportional P term is ve

Usage of the P proportional term Each ¼ seconds a
new left RPM (speed of wheel) is measured
overshoot
Target speed leftRPMset 10
8
e.g. Pgain 8000 Igain 6000 Dgain 5000
6
undershoot
leftErr leftRPMset leftPRM 10-82
leftErr leftRPMset leftPRM 10-64
P is ve
P is ve
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
t1
t3
t2
t4
0
time
Rise time
leftP Pgain leftErr leftP 8000 (10-4)
80006 is positive This term pushing up
leftPWM (more energy delivered to the wheel).
leftP Pgain leftErr leftP 8000 (10-8)
80002 is positive This term pushing up
leftPWM (more energy delivered to the wheel).
47
Example t1?t3,The proportional termwhen the
measurement is below the set point (leftRPMset),
the proportional P term is ve

Usage of the P proportional term Each ¼ seconds a
new left RPM (speed of wheel) is measured
P is -ve
overshoot
13
Target speed leftRPMset 10
leftErr leftRPMset leftPRM 10-13 -3
e.g. Pgain 8000 Igain 6000 Dgain 5000
undershoot
P is ve
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
t1
t3
t2
t4
0
time
Rise time
leftP Pgain leftErr leftP 8000 (10-13)
8000(-3) is negative This term lowering down
leftPWM (less energy delivered to the wheel).
48
Understanding PID a little summary for the P
proportional term
  • When the measurement is below the set point
    (leftRPMset)
  • The motor is slow
  • The P proportional term is ve, pushing the speed
    higher
  • When the measurement is above the set point
    (leftRPMset)
  • The motor is running too fast
  • The P proportional term is -ve, lowering down the
    speed.
  • Decrease rise time , steady state error (study it
    later)
  • But increase overshoot

49
(line 9 ) Effects of increasing Kd
(D)http//en.wikipedia.org/wiki/PID_controller
dx/dt

dx/dt
50
Example time 0? t1, the Derivative termWhen the
measurement is rising, the Derivative term is -ve

Target Value leftRPMset 10
Usage of the D Derivative term Each ¼ seconds a
new left RPM (speed of wheel) is measured
¼ seconds
overshoot
leftRPMset 10
leftErr leftRPMset leftPRM 10-73
e.g. Pgain 8000 Igain 6000 Dgain 5000
7
undershoot
3
leftlastErr leftRPMset eftlastPRM 10-37
D is -ve
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
t1
t3
t2
t4
0
time
Rise time
leftD Dgain (leftErr leftlastErr) leftD
5000 (3-7) 5000( -4) is negative This term
lowering down leftPWM (less energy delivered
to the wheel).
51
Example time t1?t2, the Derivative termWhen the
measurement is rising, the Derivative term is -ve

leftErr leftRPMset -leftPRM 10-15 -5
Usage of the D Derivative term Each ¼ seconds a
new left RPM (speed of wheel) is measured
¼ seconds

overshoot
leftPRM
15
12
leftRPMset 10
leftlastErr leftRPMset -leftlastPRM 10-12 -2
e.g. Pgain 8000 Igain 6000 Dgain 5000
undershoot
D is -ve
D is -ve
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
t1
t3
t2
t4
time
0
Rise time
leftD Dgain (leftErr leftlastErr) leftD
5000 (-5- (-2)) 5000(-3) is negative This
term lowering down leftPWM (less energy
delivered to the wheel).
52
Example time t2?t3, the Derivative termWhen the
measurement is falling, the Derivative term is ve

Usage of the D Derivative term Each ¼ seconds a
new left RPM (speed of wheel) is measured
¼ seconds

overshoot
leftPRM
14
11
leftRPMset 10
leftlastErr leftRPMset -leftlastPRM 10-14 -4
leftErr leftRPMset -leftPRM 10-11 -1
undershoot
D is ve
D is -ve
e.g. Pgain 8000 Igain 6000 Dgain 5000
D is -ve
t1
t3
t2
t4
time
0
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
Rise time
leftD Dgain (leftErr leftlastErr) leftD
5000 (-1- (-4)) 50003 is positive This term
pushing up leftPWM (more energy delivered to
the wheel).
53
Example time t2?t3, the Derivative termWhen the
measurement is falling, the Derivative term is ve

Usage of the D Derivative term Each ¼ seconds a
new left RPM (speed of wheel) is measured
¼ seconds

overshoot
leftPRM
leftRPMset 10
9
7
undershoot
leftErr leftRPMset -leftPRM 10-7 3
D is ve
D is ve
leftlastErr leftRPMset -leftlastPRM 10-9 1
D is -ve
e.g. Pgain 8000 Igain 6000 Dgain 5000
D is -ve
t1
t2
time
t3
t4
0
Rise time
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
leftD Dgain (leftErr leftlastErr) leftD
5000 (3-1) 50002 is positive This term pushing
up leftPWM (more energy delivered to the
wheel).
54
Understanding PID a little summary for the D
derivative term
  • When the measurement (leftRPM) is rising,
  • The motor is gaining speed
  • The D derivative term is ve, so lowering the
    motor speed.
  • When the measurement (leftRPM) is falling,
  • The motor is reducing speed
  • The Derivative term is ve, so pushing the motor
    speed higher.
  • In conclusion, the gradient of the error (Err)
    determines the adjustment. Depends on whether
    d(Err)/dt is ve or ve.
  • Decrease overshoot and settling time

55
(line 8)Effects of increasing Ki (I)
http//en.wikipedia.org/wiki/PID_controller

56
Values to evaluate a control system
near steady state See next slide

Steady state error
overshoot
Target value
Typically value10 Depends on application
undershoot
time
Settling time
0
Rise time
57
Time ? near steady state leftRPMsetleftRPMhence
leftErr 0, leftlastErr0? leftP0, leftD0
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
e.g. Pgain 8000 Igain 6000 Dgain 5000
  • leftErr leftRPMset leftRPM0
  • So as leftlastErr 0
  • Therefore
  • Steps
  • 7) leftP Pgain leftErr0 //calculate P
    Proportional term
  • 8) leftI Igain leftaccErr //calculate I
    Integral term
  • 9) leftD Dgain (leftErr - leftlastErr)0 //cal
    culate D Derivative term
  • 10) leftPWM (leftP leftI leftD)//update
    left motor PWM using PID
  • The only valid term is the integral term leftI
  • leftPWM leftI
  • The main idea is to create a small term (leftI)
    to maintain the leftPWM value

0 0
58
The integral term is found by adding all previous
errors leftaccErrsumleftErr(t0)leftErr(t1).
. leftErr(tnow)
  • 14) leftaccErr leftErr//LeftaccErr is the
    summation of all previous errors
  • 8) leftIIgainleftaccErr// integral term,
  • 10) leftPWM leftI // near steady state, only
    leftI is valid
  • Dont worry it will not become infinitive, one
    measure to safeguard this is
  • 11) if(leftPWMgtPWM_FREQ)
  • 12) leftPWMPWM_FREQ//prevent over range

  • (max.PWM_FREQ)
  • Also, because near steady state , leftaccErr will
    adjust itself automatically, see next slide

e.g. Pgain 8000 Igain 6000 Dgain 5000
In our experiment leftPWM276000 at the
beginning and 192800 at steady state
59
How the integral term adjusts itself
automatically near steady state
Pgain 8000 Igain 6000 Dgain 5000
  • Near steady state
  • 8) leftIIgainleftacceErr
  • 10) leftPWM leftI
  • If measured speed (leftRPM) gt set point
  • leftErr is -ve
  • leftaccErr (Acculumation) decreases, hence
    reducing leftaccErr at a suitable value to
    maintain leftPWM
  • If measured speed (leftRPM) lt set point
  • leftErr is ve
  • leftaccErr (Acculumation) increases, hence
    increasing leftaccErr at a suitable value to
    maintain leftPWM

In our experiment leftPWM276000 at the
beginning and 192800 at steady state
60
Understanding PID a little summary for the I
Integral term
  • When the measurement is below the set point
    (leftRPMset)
  • The motor is slow
  • The I Intergral term is ve, pushing the speed
    higher
  • When the measurement is above the set point
    (leftRPMset)
  • The motor is running too fast
  • The I intergral term is -ve, lowering down the
    speed.
  • It is similar to the P term (see above two
    points)
  • So increase overshoot, settling time
  • and decrease rise time
  • However, the main function is to reduce steady
    state error

61
Example Step response to evaluate a system-- ask
the motor to change from 0 to unit
speedhttp//www.engin.umich.edu/group/ctm/PID/PID
.html
  • Matlab code
  • Kp350
  • Ki300
  • Kd50
  • numKd Kp Ki
  • den1 10Kd 20Kp Ki
  • t00.012
  • step(num,den,t)

speed
Good smooth PID control result
time
Matlab code to valuate the system
62
Effects (in matlab)
  • Reduce Kp
  • Kp100
  • Ki300
  • Kd50
  • Kp350
  • Ki300
  • Kd50

Too slow Settling time too long
Best, near to ideal
  • Kp350
  • increase Ki
  • Ki3000
  • Kd50

Kp350 Ki300 Reduce Kd Kd10
Bad , too much overshoot
too much overshoot
63
PID Tuning
Motor speed V1 (V1)/2
Accepted performance
  • Tune (adjust manually)
  • Pgain proportional_gain (Kp),
  • Igain integral_gain (Ki)
  • Dgain derivative_gain (Kd),
  • Set constant speed V1 for a while (5 seconds) and
    reduced to (V1)/2 at T1
  • Record the speed by the computer after T1 and see
    if the performance is ok or not
  • Yes (accept Kp,Ki,Kd)
  • No (tune Kp,Ki,Kd again)

time
T1
unstable
done
64
Application of
  • PID

65
Robot Turning (for smooth concern
turn)http//micromouse.cannock.ac.uk/dynamics/smo
othcorners.htm
  • Required speed V (meters per minute)
  • Turning radius R (meters), from a point to robot
    center
  • Wheel diameter a (meters)
  • Use similar triangle
  • V1/(RD/2)V/R
  • V1V(VD)/2R
  • V2/(R-D/2)V/R
  • V2V-(VD)/2R
  • wirotations per minute of wheel i
  • Result
  • w1V1/(2?a/2)(2RVVD)/(2R?a)
  • w2V2/(2?a/2)(2RV-VD)/(2R?a)

66
Other motors
  • With applications

67
Use of servo motor
  • Positional control of robot range scanner.

68
Stepping motor
  • Stepping motors are good positional control
    motors used widely in digital controlled
    machineries such as digital arm-clocks, printers,
    disk drives etc.

69
Theoryzone.ni.com/devzone/cda/ph/p/id/248
  • the stator (stationary winding) has four poles,
    and the rotor has six poles (three complete
    magnets)..

Rotation sequence
70
4-phase Stepping motor Circuit
71
Stepping motor control table

72
Control method comparisons
73
Usage
  • Robot building, micro mouse

74
Stepping motor smooth control method
  • Control method

75
Summary
  • Studied various motors and control methods
  • Studied
  • PID control theory and
  • PID implementation

76
references
  • 1 Data sheet of H-bridge driver circuit device
    by Texas instrument http//www.ti.com/sc/docs/prod
    ucts/analog/l293.htmlDatasheets
  • 2 Schultz , C and 8051 building efficient
    applications , Prentice Hall
  • http//www.hitex.co.uk/c166/pidex.html
  • http//en.wikipedia.org/wiki/PID_controller
  • http//www.jashaw.com/pid.html
  • http//www.htservices.com/Applications/Process/PID
    2.htm

77
Appendix
  • PID theory

78
DC motor Control
  • Using PID
  • (proportional-integral-derivative) control

79
PID (proportional-integral-derivative) control
  • A more formal and precise method
  • Used in most modern machines

80
Introduction
  • Control for better performance
  • Use PID, choose whatever response you want

Too much overshoot/undershoot, not stable
Motor speed (w)
Good performance Criteria depends on users and
applications
required
Response too slow
time
81
values to evaluate a control system

Steady state error
overshoot
Target value
Typically value10 Depends on application
undershoot
time
Settling time
0
Rise time
82
control methodPID (proportional-integral-derivat
ive) control
Required speed Wsl_speed_input (u)
Motor
Iintegral control delta_speed dt
IR wheel Speed encoder

eerror term delta_speed
Amplifier K1 and Alter PWM for driver L293
Pproportional and integral control delta_speed
dt
-
sum
speed (w)
wsl_t_on
Dderivative control d(delta_speed)/dt
Wsl_speed_measured
83

control method Theory of a feedback control
system
Required speed Wsl_speed_input (u)
Motor
IR wheel Speed encoder

eerror term
B Plant use control parameters to derive the
system
sum
A Controller Collect error to drive the plant
-
speed (w)
speed (w)
84

P (proportional) control of speed
Required speed Wsl_speed_input (u)
Motor
Set KpA
IR wheel Speed encoder

eerror term
sum
Kpe
-
speed (w)
speed (w)
85
PD (proportional-derivative) control of
speedalternative names Pre-act or rate control
Required speed Wsl_speed_input (u)
Motor
A
IR wheel Speed encoder

eerror term
sum
Kpe
-
speed (w)
Kdd(e)/dt
speed (w)
86
PID (proportional-derivative-integral) control of
speed
Required speed Wsl_speed_input (u)
Motor
Ki (e)dt
A
IR wheel Speed encoder

eerror term
sum
Kpe
-
speed (w)
Kdd(e)/dt
speed (w)
87
values to evaluate a control system

Steady state error
overshoot
Target value
Typically value10 Depends on application
undershoot
time
Settling time
0
Rise time
88
Use of PIDcontrol terms are intertwinedhttp//en
.wikipedia.org/wiki/PID_controller
  • Kp Proportional Gain - Larger Kp typically means
    faster response since the larger the error, the
    larger the Proportional term compensation. An
    excessively large proportional gain will lead to
    process instability and oscillation.
  • Ki Integral Gain - Larger Ki implies steady
    state errors are eliminated quicker. The
    trade-off is larger overshoot any negative error
    integrated during transient response must be
    integrated away by positive error before we reach
    steady state.
  • Kd Derivative Gain - Larger Kd decreases
    overshoot, but slows down transient response and
    may lead to instability due to signal noise
    amplification in the differentiation of the
    error.

89
Reason for proportional controlhttp//www.jashaw.
com/pid.html
  • Bigger error will give more input to the plant to
    enable the output to reach the target faster
  • Improve risetime

90
Reason for Derivative controlor called Pre-act
or rate controlhttp//www.jashaw.com/pid.html
  • Adjust output based on the rate of change the
    error
  • Decrease overshoot (caused by the integral term
    and proportional term)
  • But also amplifier noise, may make system
    unstable.
  • See http//www.controlguru.com/wp/p76.html

91
Example to show how derivative control reduces
overshoothttp//www.controlguru.com/wp/p76.html
  • usetpoint,
  • wt, motor speed measured
  • etu-wt,-----(1)
  • If u is stable , w rises from 0 to u
  • Differentiate (1) we get
  • d(et)/dt -d(wt)/dt ---(2)
  • When w is increasing, the system suppresses its
    growth, hence reduces overshoot

speed
Setpoint u
w
time
92
Example to show how derivative control reduces
oscillation
rock
u
wt-1 wt wt1
  • Stable requirement u, changing motor speed w
  • The robot is moving at a constant speed w?u
  • A small rock hiders its motion, so reduces the
    motor speed wt, usetpoint,
  • etu-wt,-----(1),
  • d(et)/dt -d(wt)/dt ---(2)
  • From (1) when wt decreases, e increases, so the
    system increases power to the motor to enable
    wt1 approach u.
  • The reverse is also true, e.g. the robot suddenly
    goes downhill (or just overcome the small rock)
    and speed increases, the system should decease
    the power to the motors.
  • Changing requirement u, stable motor speed w
  • It is also true for a stable w and increasing u,
    since de/dtdu/dt, so power is increased to keep
    up with the required u.

93
Reason for Integral controlor called automatic
resethttp//www.jashaw.com/pid.html
  • In proportional only control the output cannot
    reach the target value (setpoint) without using a
    bias.
  • Outputgainerror bias, E.g.
  • wkp(u-w) bias, do the following exercise
  • without bias u10, Kp100, bias0,so wgt9.99009
  • With bias u10, Kp100, w10, so Bgt10
  • Without a computer the bias is set manually
  • With the computer, the bias can be calculated by
    the integral term
  • Decrease steady state error
  • It helps the system quickly reaches the set point
  • But it increases overshoot because of the
    cumulated term
  • Integral Windup problem (http//www.controlguru.co
    m/2008/021008.html)
  • If error is positive/negative for too long
    accumulated error will saturate the system or is
    over the limit that the system can response to
    (can damage the motor, ie. when the motor is
    driven by an analog voltage)
  • Solution Set maximum and minimum values for the
    integral term

94
Example Step response to evaluate a system-- ask
the motor to change from 0 to unit
speedhttp//www.engin.umich.edu/group/ctm/PID/PID
.html
  • Matlab code
  • Kp350
  • Ki300
  • Kd50
  • numKd Kp Ki
  • den1 10Kd 20Kp Ki
  • t00.012
  • step(num,den,t)

speed
Good smooth PID control result
time
Matlab code to valuate the system
95
Effects (in matlab)
  • Reduce Kp
  • Kp100
  • Ki300
  • Kd50
  • Kp350
  • Ki300
  • Kd50

Too slow Settling time too long
Best, near to ideal
  • Kp350
  • increase Ki
  • Ki3000
  • Kd50

Kp350 Ki300 Reduce Kd Kd10
Bad , too much overshoot
too much overshoot
96
General tips for designing a PID
controllerhttp//www.engin.umich.edu/group/ctm/PI
D/PID.html
  • When you are designing a PID controller for a
    given system, follow the steps shown below to
    obtain a desired response.
  • Obtain an open-loop response and determine what
    needs to be improved. (Step input, see output)
  • Add a proportional control (Kp) to improve the
    rise time
  • Add a derivative control (Kd) to improve the
    overshoot
  • Add an integral control (Ki) to eliminate the
    steady-state error
  • Adjust each of Kp, Ki, and Kd until you obtain a
    desired overall response. See the table in the
    next slide.

97
Effects of increasing parametershttp//en.wikiped
ia.org/wiki/PID_controller

98
PID
  • Implementation

99
ISR for PID controlhttp//www.hitex.co.uk/c166/pi
dex.html
  • Main()
  • derivative_gain, proportional_gain,
    integral_gain should be set in the main program
  • Interrupt service routine ISR() // set a cycle
    freq , e.g. 1KHz
  • 0) measure error
  • 1) Calculate Proportional Term
  • 2) Calculate derivative term
  • 3) Calculate Integral Term
  • 4) Sum Up Proportional derivative Integral
    and use it to control the output

100
Checking overflow
  • Checking overflow of terms is essential to make
    the system reliable

101
1) Calculate Proportional Term
(Kpproportional_gain) http//www.hitex.co.uk/c16
6/pidex.html
  • To make sure the error term does not overflow
  • / Calculate Proportional Term /
  • proportional_term_temp ((long)this_error
    (long)proportional_gain)
  • / Check For Proportional Term Out Of Range
    Apply Saturation /if(proportional_term_temp
    gt (long)((long)32767 Inputs_Scale_Factor))
    proportional_term 32767 else
    if(proportional_term_temp lt (long)((long)-32768
    Inputs_Scale_Factor)) proportional_term
    -32768 else proportional_term
    (short)((long)proportional_term_temp/Inp
    uts_Scale_Factor)

102
2) Calculate derivative term (Kdderivative_gain)
  • //The derivative term is simply calculated /
    Calculate Derivative Term /derivative_term
    ((long)(this_error - PID.last_error)
    derivative_gain)/(long)Inputs_Scale_Factor

Required speed Wsl_speed_input (u)
Motor
A
IR wheel Speed encoder
eerror tem
sum
Kp
-
Kdd(e)/dt
Motor
speed (w)
103
3) Calculate Integral Term (Kiintegral_gain)
  • / Find Accumulated Error / acc_error_temp
    ((long)PID.accumulated_error)
    (long)this_error / Check For Accumulated
    Error Out Of Range / if(acc_error_temp gt
    (long)32767) // Is error gt maximum value?
    acc_error_temp 32767 // Limit to max
    ve value if(acc_error_temp lt (long)-32768)
    // Is error lt minimum value?
    acc_error_temp -32768 // Limit to max
    -ve value PID.accumulated_error (short)
    acc_error_temp

104
Calculate Integral Term -- calculate and check
for overflow
  • / Calculate Integral Term /
    integral_term_temp ((long)PID.accumulated_erro
    r (long)integral_gain) / Check For
    Integral Term Out Of Range Apply Saturation
    / if(integral_term_temp gt (long)((long)32767
    Inputs_Scale_Factor)) integral_term
    32767 else if(integral_term_temp lt
    (long)((long)-32768 Inputs_Scale_Factor))
    integral_term -32768 else
    integral_term integral_term_temp/Inputs_Scale_F
    actor

Integral Windup problem If error is
positive/negative for too long accumulated error
will saturate the system Solution Set maximum
and minimum values for the integral term
105
4) Sum Up Control Terms
  • / Sum Up Control Terms /
  • control_output_temp (long) integral_term
  • control_output_temp (long)derivative_term
  • control_output_temp (long) proportional_term
  • / Limit Value Of Control Term /
  • if(control_output_temp gt 32767)
  • control_output_temp 32767
  • else
  • if(control_output_temp lt 0)
  • control_output_temp 0

106
PID Tuning
Motor speed V1 (V1)/2
Accepted performance
  • Tune (adjust manually)
  • Pgain proportional_gain (Kp),
  • Igain integral_gain (Ki)
  • Dgain derivative_gain (Kd),
  • Set constant speed V1 for a while (5 seconds) and
    reduced to (V1)/2 at T1
  • Record the speed by the computer after T1 and see
    if the performance is ok or not
  • Yes (accept Kp,Ki,Kd)
  • No (tune Kp,Ki,Kd again)

time
T1
unstable
done
107
Summary
  • Studies PID control theory and implementation
Write a Comment
User Comments (0)
About PowerShow.com