DC motor Control

Download Report

Transcript DC motor Control

CENG4480_A4
DC motor Control
Using PID
(proportional-integral-derivative) control
PID a1
1
PID (proportional-integral-derivative)
control
A more formal and precise method
Used in most modern machines
PID a1
2
Introduction
• Control for better performance
• Use PID, choose whatever response you
want
Motor speed (w)
Too much overshoot/undershoot, not stable
Good performance
Criteria depends
on users and
applications
required
Response too slow
time
PID a1
3
values to evaluate a control system
•
Steady
state
error
overshoot
Target
value
Typically
value=10%
Depends
on application
undershoot
0
Settling time
Rise time
PID a1
time
4
control method:
PID (proportional-integral-derivative) control
Required speed=
Wsl_speed_input
(u)
• e=error term
=delta_speed
+
-
speed
(w)
Motor
I=integral control
 delta_speed dt
IR wheel
Speed
encoder
P=proportional and integral
control
delta_speed dt ;
sum
Amplifier
K1 and
Alter PWM
for driver
L293
wsl_t_on
D=derivative control
d(delta_speed)/dt ;
PID a1
Wsl_speed_measured
5
control method:
Theory of a feedback control system
Motor
Required speed=
IR wheel
Speed
encoder
Wsl_speed_input
(u)
•
+
-
e=error term
speed
(w)
A
Controller:
Collect error
to drive the plant
sum
p
2
p
(u  w) AB  w
w
 w
1   AB 
u
 u
w
AB  1  AB 
u
w
AB

u 1  AB
B
Plant:
K
use control
s  10s  20  K
parameters to
derive the system
speed
(w)
PID a1
6
P (proportional) control of speed
Required speed=
Motor
Set Kp=A
IR wheel
Speed
encoder
Wsl_speed_input
(u)
•
+
e=error term
Kpe
sum
Kp
s  10
B
s 120  K
2
-
speed
(w)
(u  w) AB  w
K pe  w
PID a1
p
speed
(w)
7
PD (proportional-derivative) control of speed
alternative names Pre-act or rate control
Motor
Required speed=
A
Wsl_speed_input
(u)
•
IR wheel
Speed
encoder
e=error term
Kpe
+
sum
Kp
s  10
B
s 120  K
2
-
speed
(w)
p
Kd*[d(e)/dt]
speed
(w)
de
K pe  Kd
w
dt
PID a1
8
PID (proportional-derivative-integral) control of speed
Required speed=

Ki*[ (e)dt]
Wsl_speed_input
(u)
•
e=error term
+
Motor
Kpe
A
IR wheel
Speed
encoder
sum
Kp
s  10
B
s 120  K
2
-
speed
(w)
p
Kd*[d(e)/dt]
speed
(w)
de
K pe  Kd
 K i  (e)dt  w
dt
PID a1
9
values to evaluate a control system
•
Steady
state
error
overshoot
Target
value
Typically
value=10%
Depends
on application
undershoot
0
Settling time
Rise time
PID a1
time
10
Use of PID
control terms are intertwined
•
•
•
http://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.
PID a1
11
Reason for proportional control
http://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
PID a1
12
Reason for Derivative control
or called Pre-act or rate control
http://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
PID a1
13
Example to show how derivative control
reduces overshoot
http://www.controlguru.com/wp/p76.html
•
•
•
•
u=setpoint,
wt, motor speed measured
et=u-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
PID a1
de
K pe  Kd
w
dt
dw
K pe  Kd
w
dt
speed
Setpoint
u
w
time
14
Example to show how derivative control
rock
u
reduces
oscillation
de
K eK
w
p
d
dt
wt-1 wt wt+1
• 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,
u=setpoint,
– et=u-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 wt+1 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/dt=du/dt, so
power is increased to keep up with the required u.
PID a1
15
Reason for Integral control
or called automatic reset
http://www.jashaw.com/pid.html
• In proportional only control the output cannot reach the target value
(setpoint) without using a bias.
• Output=gain*error + bias, E.g.
–
–
–
–
•
•
•
•
•
w=kp*(u-w) + bias, do the following exercise
without bias u=10, Kp=100, bias=0,so w=>9.99009
With bias u=10, Kp=100, w=10, so B=>10
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.com/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
PID a1
16
Example: Step response to evaluate a system-ask the motor to change from 0 to unit speed
http://www.engin.umich.edu/group/ctm/PID/PID.html
•
•
•
•
•
•
Matlab code
•
Kp=350;
Ki=300;
speed
Kd=50;
num=[Kd Kp Ki];
den=[1 10+Kd 20+Kp
Ki];
• t=0:0.01:2;
• step(num,den,t)
Matlab code to valuate the system
PID a1
Good smooth PID
control result
time
17
Effects (in matlab)
• Kp=350;
• Ki=300;
• Kd=50;
Kp=350;
increase Ki
Ki=3000;
Kd=50;
Best,
near to ideal
•
•
•
•
Reduce Kp
Kp=100;
Ki=300;
Kd=50;
Kp=350;
Ki=300;
Reduce Kd
Kd=10;
Bad ,
too much
overshoot
PID a1
Too slow
Settling time
too long
high much
overshoot
18
General tips for designing a PID controller
http://www.engin.umich.edu/group/ctm/PID/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.
PID a1
19
Effects of increasing parameters
http://en.wikipedia.org/wiki/PID_controller
Parameter
Rise Time
Overshoot
Settling
Time
Steady
state error
Kp
Decrease
step1
Increase
Small
Change
Decrease
Ki
Decrease
Increase
Increase
Eliminate
step3
Kd
Small
Change
Decrease
step2
Decrease
Small
Change
•
PID a1
20
PID
Implementation
PID a1
21
ISR for PID control
http://www.hitex.co.uk/c166/pidex.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
• }
PID a1
22
Checking overflow
• Checking overflow of terms is essential to
make the system reliable
PID a1
23
1) Calculate Proportional Term
(Kp=proportional_gain)
http://www.hitex.co.uk/c166/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 > (long)((long)32767 * Inputs_Scale_Factor))
{
proportional_term = 32767 ;
}
else
{
if(proportional_term_temp <= (long)((long)-32768 * Inputs_Scale_Factor))
{
proportional_term = -32768 ;
}
else
{
proportional_term =
(short)((long)proportional_term_temp/Inputs_Scale_Factor) ;
}
}
PID a1
24
2) Calculate derivative term
(Kd=derivative_gain)
• //The derivative term is simply calculated
/*** Calculate Derivative Term ***/
derivative_term = ((long)(this_error - PID.last_error) *
derivative_gain)/(long)Inputs_Scale_Factor ;
Motor
Required speed=
A
Wsl_speed_input
(u)
e=error tem
Kp
+
IR wheel
Speed
encoder
sum
Kp
s  10
B
s 120  K
2
-
speed
(w)
Kd*d(e)/dt
PID a1
p
Motor
25
3) Calculate Integral Term
(Ki=integral_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 > (long)32767)
{ // Is error > maximum value?
acc_error_temp = 32767 ;
// Limit to max +ve value
}
if(acc_error_temp < (long)-32768)
{
// Is error < minimum value?
acc_error_temp = -32768 ;
// Limit to max -ve value
}
PID.accumulated_error = (short) acc_error_temp ;
PID a1
26
Calculate Integral Term
-- calculate and check for overflow
•
/*** Calculate Integral Term ***/
integral_term_temp = ((long)PID.accumulated_error * (long)integral_gain) ;
/*** Check For Integral Term Out Of Range & Apply Saturation ***/
if(integral_term_temp > (long)((long)32767 * Inputs_Scale_Factor))
{
integral_term = 32767 ;
}
else
{
if(integral_term_temp <= (long)((long)-32768 * Inputs_Scale_Factor))
{
integral_term = -32768 ;
}
else
{
integral_term = integral_term_temp/Inputs_Scale_Factor ;
}
}
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
PID a1
27
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 > 32767)
{ control_output_temp = 32767 ; }
else
{
if(control_output_temp < 0)
•
•
•
{ control_output_temp = 0 ;
}
}
PID a1
28
PID Tuning
• Tune (adjust manually)
Motor speed V1
– proportional_gain (Kp),
– integral_gain (Ki)
– derivative_gain (Kd),
Accepted
performance
(V1)/2
• Set constant speed V1 for a while (5 seconds)
and stop at T1
unstable
– Record the speed by the computer after T1 and see if
it is ok
• Yes (accept Kp,Ki,Kd)
• No (tune again)
PID a1
done
29
Summary
• Studies PID control theory and
implementation
PID a1
30