comp417 introduction to robotics and intelligent systems ...dudek/417/pid_lecture1.pdf · “ai for...
TRANSCRIPT
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
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
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.
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
Closing the loop• Let’s measure the actual angular velocities.
• Now we can compensate for changes in load by
feeding back some information.
Early Example of Feedback
System
• James Watt’s
“Centrifugal
Governor” in 1788.
• Regulates the steam
engine speed.
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…
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.
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
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
Classic Feedback Diagram
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!)
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”?
Common Laplace TransfomName f(t) F(s)
Impulse d
Step
Ramp
Exponential
Sine
1
Damped Sine
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
Block Diagram
• Expresses flows and relationships between
elements in system.
• Blocks may recursively be systems.
• Rules
– Cascaded elements: convolution.
– Summation and difference elements
Laplace Transform of Classic
Feedback Sysem
Key Transfer Functions
First Order System
Feedback Control
Main question: what are the controls that will take the system from state A to B?
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.
Why bother with wall/line following?
• Because it enables arbitrary path following where the line is the local tangent of the (curvy) path
Idea 1: bang-bang control
What’s wrong with this?
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?
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
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
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?
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:
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.
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
PID controller
Perhaps the most widely used controller in industry and robotics.Perhaps the easiest to code.
You will also see it as:
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.
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
Control Performance (2nd O), P-type
Kp = 20
Kp = 200
Kp = 50
Kp = 500
Steady-state Errors, P-type
Kp = 200 Kp = 50
Control Performance, PI - type
Kp = 100
Ki = 50 Ki = 200
You’ve been integrated...
Kp = 100
instability &
oscillation
Control Performance, PID-typeKp = 100
Ki = 200 Kd = 2
Kd = 10 Kd = 20
Kd = 5
PID final control
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:
Layered Approach to Control
• Robotic systems often have a layered approach
to control:
movie
Multiple Loops
Inner loops are generally “faster” that outer loop.
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.
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
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
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.
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
Example applications: self-driving cars
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.