21. control systems - university of texas at...

20
April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21. Control Systems Easy: Incremental Linear: P PI PID Intuitive: Fuzzy Logic 21.1 J V w Dad, I hate burned food! Not enough colors of black to describe your cooking. It says to cook your food until the center is no longer red. But, not my strawberry strudel! Doh!

Upload: others

Post on 01-Jan-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

21. Control Systems• Easy: Incremental• Linear: P PI PID• Intuitive: Fuzzy Logic

21.1

J Vw

Dad, I hateburned food!

Not enough colors of blackto describe your cooking.

It says to cook your food untilthe center is no longer red.

But, not mystrawberry

strudel!

Doh!

Page 2: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Monaco

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.2

Espana

Von Deutschland

Page 3: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Circuit of the Americas

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.3

Page 4: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

Performance measures

21.4

• Accuracy – Magnitude of the Error = Desired– Actual

• Stability– No oscillations

• Overshoot (underdamped, overdamped)– Ringing, slow

• Response Time to new steady state after– Change in desired setpoint– Change in load

Page 5: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

What to control?

21.5

• Motor speed– Error = Desired speed – Actual speed– Error = Desired period – Actual period

U

ActualSpeed

Tachometer

MeasuredSpeed

ControllerErrorDesired +

-

Sensor

Plant

Stateestimator

PWMcircuit

VActuator

R

L

emf-+

DCMotor

PeriodMeasurement

X’X* e=X*-X’

Disturbingforces

Page 6: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

What to control?

21.6

• Distance to one wall– Error = Desired distance – Actual distance

• Equal distances to both walls– Error = Left distance – Right distance

robot wall

dL

wall

wall

dR

Sensors- Time constant -> fs- Filters

Analog, digital- Signal/noise ratio- Calibration

accuracy, drift

Page 7: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

What to control?

21.7

• Angle to most open track– Error = Desired – Actual angle

robot wall

d1wall

wall

d2

d3

Turn so most open in front

Avoid making U-turns

Page 8: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

• Angle to wall

21.8

robot

wall

a

bC

Track the right wall if (aR+bR)<(aL+bL)Want to make AR = 90If AR=90, then bR/aR = cos CR

xR=100*cosCR is a calibration constant

error = (100*bR)/aR - xR

if error > 0, AR < 90, turn leftif error < 0, AR > 90, turn right

if min(aR,bR)<20, move left-right

A

a,b are measured distances from center of robot to the wall

heading

C is a fixed angle

speed is determined by distance,d, to object in front

d

b

a

CA

L

L

L

LR

R

R

R

Track the left wall if (aR+bR)>(aL+bL)Want to make AL = 90If AL=90, then bL/aL = cos CL

xL=100*cosCL is a calibration constant

error = (100*bL)/aL - xL

if error > 0, AL < 90, turn rightif error < 0, AL > 90, turn left

if min(aL,bL)<20, move right-left

What to control?

Page 9: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Incremental Controller

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.9

Periodic interrupt

Error = Desired-Measured

Too fastError >0

U=U-1

<0

U>2

2

Too slow

U=U+1

<249

=249U=0

Measured=StateEstimator

Faster than motor Slower than sensor sampling rate

Page 10: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Incremental Controllerlong Xstar; // desiredlong X; // actual, measured inputlong U; // PWM actuator outputvoid Timer0A_Handler(void){ long E;

E = Xstar-X; // error if(E < 0) U--; // too fastelse if(E > 1) U++; // too slow

// close enoughif(U < 2) U=2; // Constrain outputif(U > 249) U=249;PWM0_Duty(U); // output TIMER0_ICR_R = TIMER_ICR_CAECINT;

}

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.10

Page 11: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

Laplace Domain

21.11

U(n)

Tachometer

PID Controller+

-

SensorState estimator

PWMcircuit

Actuator

PeriodMeasurement

X’(s)X*

E(n)

X'(n)

Plant

m1+s

X(t)

U(s)E(s)

X(s)

Kp+Kis

+Kd s

)()(1)()(

)(*)(

sHsGsHsG

sXsX

s

KsKKsG idp )(

smsH

1

)(

Page 12: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

General Approach to PID

21.12

• Proportional Up = KpE• Integral Ui = Ui + KiEt• Derivative Ud = Kd(E(n)-E(n-1))/t• PID U = Up + Ui + Ud

• Run ten times faster than motor • Run slower or equal to sensor sampling rate

dttdEKdEKtEKtU d

t

ip)()()()(

0

Page 13: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Derivative Term

x(n) with noise

x(n)

TimeCalculated with noise

x(n) without noise

tnEnEKnD

dttdEKtD dd

)1()()()()(

tnEnE

tnEnEKnD d

)2()1(21

3)3()(

21)(

t

nEnEnEnEKnD d 6)3()2(3)1(3)()(

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.13

•Analog filter

•Digital filter

•Linear regression

Page 14: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

PI Controllervoid Timer0A_Handler(void){

E = Xstar-X; P = (105*E)/20; // Kp = 105/20I = I+(101*E)/640; // Kit = 101/640if(I < -500) I=-500; // anti-reset windupif(I > 4000) I=4000;U = P+I; // PI controllerif(U < 100) U=100; // Constrain outputif(U>19900) U=19900;PWM0_Duty(U); // output TIMER0_ICR_R = TIMER_ICR_CAECINT;

}

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.14

Page 15: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

Motor Parameters

21.15

• Invoke a step, measure response– Time lag, time constant,

• Plot speed in RPM versus duty cycle – Sensitivity m

Speed(RPM)

-120

-60

0

60

120

180

0 0.05 0.1 0.15 0.2 0.25 0.3

smsH

1

)(

Real ≠ Theory

Page 16: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

April 20, 2014 Jonathan Valvano EE445M/EE380L.6

Controller tuning

21.16

• Start with just a proportional term (Kp).- proportional controller will generate a smooth motor speed- choose the sign of the term Kp so the system is stable. - try different Kp constants until the response times are fast enough

• The next step is to add some integral term (Ki)- a little at a time- to improve the steady state controller accuracy - without adversely affecting the response time. - choose the sign of the term Ki so the system is stable.- Don’t change both Kp and Ki at once.

The last step is the derivative term (Kd)- a little at a time- reduce the overshoots/undershoots in the step response

- choose the sign of the term Kd so the overshoots/undershoots are reduced.Highly nonlinear -> empirical approach

Page 17: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Charging battery• Drain battery 10 25W resistor (or motor)• Charge than 8 hours

• Test battery across load– Measure voltage– Measure current– 3.8 Amp-hour

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.17

Sanyo8.4V- 3.8 AH

NiMH

positivetemperature

negative

redwhiteblack

red

black

+8.4V

red black

plugRC battery connectorCON-210P

striped solid

socketRC battery connectorCON-210S

12V250mA

wall-wart

red black

thumb wheelswitch

gnd

Page 18: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Under Battery Power• Current path battery-motor-battery• Ground• One +5V

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.18

+5V into ARMboard

DC motor

ARM board

solderedboard

Sanyo8.4V- 3.8 AH

NiMH

positivetemperature

negative

redwhiteblack

red

black

+8.4V

gnd

protoboard

red black

plugRC battery connectorCON-210P

male-maleheaderthumb wheel

switch

GND+5V

+8.4

gnd

+5

ARM board NOTconnected to PC

7805

L293

DC motor

+5

Ping))) IR’s Tach’s

Servo

Control

gnd

gnd

Floating grounddefined by battery

Page 19: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

While debugging with PC• Prevent motor current from going to board• Two +5V, not connected• Ground

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.19

DC motor

ARM board

solderedboard

Sanyo8.4V- 3.8 AH

NiMH

positivetemperature

negative

redwhiteblack

red

black

+8.4V

gnd

protoboard

red black

plugRC battery connectorCON-210P

male-maleheaderthumb wheel

switch+8.4

gnd

+5

ARM board ISconnected to PC

7805

L293

DC motor

+5

Ping))) IR’s Tach’s

Servo

Control

gnd

gnd

gnd

PC

Earth grounddefined by PC

Page 20: 21. Control Systems - University of Texas at Austinusers.ece.utexas.edu/~valvano/EE345M/view21_PID.pdf · DC motor ARM board soldered board Sanyo 8.4V- 3.8 AH NiMH positive temperature

Regulator• Drop out, Vd

• Calculate power loss, P=(8.4-5)*I

April 20, 2014 Jonathan Valvano EE445M/EE380L.6 21.20

7805

Vin OutIn +5VGnd

0.33F 0.1F

Vd = 2.5V

Vin > 7.5V

Iout <1A4.7 F 4.7 F