comp417 introduction to robotics and intelligent systems ...dudek/417/pid_lecture1.pdf · “ai for...

49
COMP417 Introduction to Robotics and Intelligent Systems Lecture 5: Feedback Control and PID control Guest lecture by José Ruiz Ascencio On slides by Professor Gregory Dudek

Upload: others

Post on 31-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

COMP417Introduction to Robotics and Intelligent Systems

Lecture 5: Feedback Control and PID control

Guest lecture by José Ruiz Ascencio

On slides by

Professor Gregory Dudek

Page 2: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Open-loop?• We want to spin a motor at a given angular

velocity. We can apply a fixed voltage to it, and

never check to see if it is rotating properly.

• Called "open loop control", but there isn't any

actual control because there is no feedback.

Key notion

Page 3: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Open-loop?• We want to spin a motor at a given angular

velocity. We can apply a fixed voltage to it, and

never check to see if it is rotating properly.

• Called open loop.

Page 4: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Open-loop?

• What if there is a changing load on the motor?

– Our output velocity will change!

torque t

speed wno torque at max speed

stall torque

Page 5: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Closing the loop• Let’s measure the actual angular velocities.

• Now we can compensate for changes in load by

feeding back some information.

Page 6: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Early Example of Feedback

System

• James Watt’s

“Centrifugal

Governor” in 1788.

• Regulates the steam

engine speed.

Page 7: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Other Simple Examples

• Body temperature regulation– If cold, shiver (muscles produce heat)

– If hot, sweat (evaporation takes away heat)

• Maintaining social peace– If a crime is found (sensor), the guilty party is

punished (actuator).

• Cruise control in cars– You set a speed, CC will increase fuel intake

uphill, and decrease it downhill.

• Etc…

Page 8: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Control Theory• Roots in another science: Cybernetics

Cybernetics is the study of feedback and derived

concepts such as communication and control in

living organisms, machines and organisations.

• Expression was coined by

Norbert Weiner in 1948.

Page 9: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Why Control Theory

• Systematic approach to analysis and design– Transient response

– Consider sampling times, control frequency

– Taxonomy of basic controllers (PID, open-loop, Model-based, Feedforward…)

– Select controller based on desired characteristics

• Predict system response to some input– Speed of response (e.g., adjust to workload changes)

– Oscillations (variability)

• Assessing stability of system

• JR

Page 10: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Characteristics of Feedback

System

• Power amplification

– Compare neural signal power (mW) vs muscle power

output (tens of W)

– Means it is an active system, as opposed to passive.

• Actuator

• Feedback

– measurement (sensor)

• Error signal

• Controller

Page 11: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Classic Feedback Diagram

Page 12: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Control System Goals

• Regulation

– thermostat

• Tracking

– robot movement, adjust TCP window to

network bandwidth

• Optimization

– best mix of chemicals, minimize response

times

• Each of these is slightly different:

understand and remember how (ask now if

necessary!)

Page 13: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Approaches to System Modeling

• First Principles

– Based on known laws.

– Physics, Queueing theory.

– Difficult to do for complex systems.

• Experimental (System Identification)

– Requires collecting data

– Is there a good “training set”?

Page 14: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Common Laplace TransfomName f(t) F(s)

Impulse d

Step

Ramp

Exponential

Sine

1

Damped Sine

Page 15: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Transfer Function

• Definition: H(s) = Y(s) / X(s)

• Relates the output of a linear system to its input.

• Describes how a linear system responds to an

impulse… called impulse response

– (remember! Convolving with impulse yields the same

thing. Hence probing a system with and impulse is

finding its transfer function…)

• All linear operations allowed

– Scaling, addition, multiplication

Page 16: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Block Diagram

• Expresses flows and relationships between

elements in system.

• Blocks may recursively be systems.

• Rules

– Cascaded elements: convolution.

– Summation and difference elements

Page 17: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Laplace Transform of Classic

Feedback Sysem

Page 18: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Key Transfer Functions

Page 19: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

First Order System

Page 20: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Feedback Control

Main question: what are the controls that will take the system from state A to B?

Page 21: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Example: wall/line following at fixed speed

cross-track error at time t = e(t)

You have to control the angular velocity

Cross-track error:CTEHow far from the wall you are.

Page 22: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Why bother with wall/line following?

• Because it enables arbitrary path following where the line is the local tangent of the (curvy) path

Page 23: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Idea 1: bang-bang control

What’s wrong with this?

Page 24: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Idea 2: proportional (P-)control

Will the car reach the target line?

Will the car overshoot the target line?

Is the asymptotic (steady-state) error zero?

Page 25: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Idea 2: proportional (P-)control

Will the car reach the target line? YES

Will the car overshoot the target line? YES

Is the asymptotic (steady-state) error zero? NO

Page 26: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Addressing the oscillation problem

• Need to reduce turning rate well before the line is approached

• Idea: have a small proportional gain

Problem: that means the car doesn’t turn very much

• Idea: need to predict the error in the near future

This is good, as long as the error does not oscillate at a very high

frequency

Page 27: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Idea 3: proportional-derivative (PD-)control

How do we set the gains?

What if there are systematic errors/biases?

What if the error estimate is very noisy?

Page 28: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Handling systematic biases:the integral term

• Examples of systematic biases: • wheels are misaligned• car is much heavier on one side

• Add integral of the error from the beginning of time:

• Can the PI-controller have nonzero error asymptotically (in steady-state)?

• NO. In steady state both the control and the error must be constant. If the asymptotic error is nonzero then the control is not constant:

Page 29: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Potential problem: integrator windup

• What happens if the control variable reaches the actuator’s limits?

• I.e. the car can’t turn as fast as the controller commands it.

• Actuator may remain at its limit for a long time while the controller modifies its commands

• Error increases, integral term winds up while controller goes back to issuing commands in the feasible region.

Page 30: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Potential problem: integrator windup

• Heuristic fixes:• Limit integral error values

• Stop integral error while the commands are in the non feasible region

• Reduce gain of integral error term

Page 31: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

PID controller

Perhaps the most widely used controller in industry and robotics.Perhaps the easiest to code.

You will also see it as:

Page 32: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Tips: how to implement PID

• Assume time is discrete

• Identify your error function e(t)= current_state(t)- target_state(t)

• Is the measurement of the state reliable?

• If the measurement of the current state is very noisy you might want to smooth/filter it, using:

• Moving average filter with uniform weights

Potential problem: the larger the window of the filter the slower it is going to register changes.

• Exponential filter

Potential problem: the closer is to 1 the slower it is going to register changes.

Page 33: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Tips: how to implement PID

• Approximate the integral of error by a sum

• Approximate the derivative of error by:• Finite differences

• Filtered finite differences, e.g.

• Limit the computed controls

• Limit or stop the integral term when detecting large errors and windup

Page 34: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Control Performance (2nd O), P-type

Kp = 20

Kp = 200

Kp = 50

Kp = 500

Page 35: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Steady-state Errors, P-type

Kp = 200 Kp = 50

Page 36: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Control Performance, PI - type

Kp = 100

Ki = 50 Ki = 200

Page 37: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

You’ve been integrated...

Kp = 100

instability &

oscillation

Page 38: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Control Performance, PID-typeKp = 100

Ki = 200 Kd = 2

Kd = 10 Kd = 20

Kd = 5

Page 39: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

PID final control

Page 40: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

PID Tuning

How to get the PID parameter values ?

(1) If we know the transfer function, analytical methods can

be used (e.g., root-locus method) to meet the transient and

steady-state specs.

(2) When the system dynamics are not precisely known, we

must resort to experimental approaches.

Using only Proportional control, turn up the gain until the system

oscillates w/o dying down, i.e., is marginally stable. Assume that K

and P are the resulting gain and oscillation period, respectively.

Then, use

Ziegler-Nichols Tuning

for second or higher

order systems

for P control for PI control for PID control

Kp = 0.6 K

Ki = 2.0 / P

Kd = P / 8.0

Kp = 0.45 K

Ki = 1.2 / P

Kp = 0.5 K

Ziegler-Nichols Rules for Tuning PID Controller:

Page 41: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Layered Approach to Control

• Robotic systems often have a layered approach

to control:

movie

Page 42: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Multiple Loops

Inner loops are generally “faster” that outer loop.

Page 43: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Advanced Control Topics

• Adaptive Control– Controller changes over time (adapts).

• MIMO Control– Multiple inputs and/or outputs.

• Predictive Control– You measure disturbance and react before measuring

change in system output.

• Optimal Control– Controller minimizes a cost function of error and

control energy.

• Nonlinear systems– Neuro-fuzzy control.

– Challenging to derive analytic results.

Page 44: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Tips: how to tune the PID

• Manually:• First, use only the proportional term. Set the other gains to zero.

• When you see oscillations slowly add derivative term• Increasing increases the duration in which linear error prediction

is assumed to be valid

• Add a small integral gain

Page 45: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Tips: how to tune the PID

• Ziegler-Nichols heuristic:• First, use only the proportional term. Set the other gains to zero.

• When you see consistent oscillations, record the proportional gain and the oscillation period

Page 46: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Tips: how to tune the PID

• After manual or Z-N tweaking you might want to use coordinate ascent to search for a better set of parameters automatically:

See Sebastian Thrun’s online class“AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle and it is in Lesson 5.

Page 47: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

When is PID insufficient?

• Systems with large time delays

• Controllers that require completion time guarantees• E.g. the system must reach target state within 2 secs

• Systems with high-frequency oscillations

• High-frequency variations on the target state

Page 48: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Example applications: self-driving cars

Page 49: COMP417 Introduction to Robotics and Intelligent Systems ...dudek/417/pid_lecture1.pdf · “AI for robotics” on Udacity for more details on this. He calls the algorithm Twiddle

Cascading PID

• Sometimes we have multiple error sources (e.g. multiple sensors) and one actuator to control.

• We can use a master PID loop that sets the setpoint for the slave PID loop. Master (outer loop) runs at low rate, while slave (inner loop) runs at higher rate.

• One way of getting hierarchical control behavior.