Title: DC motor Control
1DC motor Control
- Using PID
- (proportional-integral-derivative) control
2PID (proportional-integral-derivative) control
- A more formal and precise method
- Used in most modern machines
3Introduction
- 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
4values to evaluate a control system
Steady state error
overshoot
Target value
Typically value10 Depends on application
undershoot
time
Settling time
0
Rise time
5control 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
6 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)
7 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)
8PD (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)
9PID (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)
10values to evaluate a control system
Steady state error
overshoot
Target value
Typically value10 Depends on application
undershoot
time
Settling time
0
Rise time
11Use 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.
12Reason 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
13Reason 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
14Example 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
15Example 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.
16Reason 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
17Example 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
18Effects (in matlab)
- Reduce Kp
- Kp100
- 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
high much overshoot
19General 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.
20Effects of increasing parametershttp//en.wikiped
ia.org/wiki/PID_controller
21PID
22ISR 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 -
23Checking overflow
- Checking overflow of terms is essential to make
the system reliable
24 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)
252) 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)
263) 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
27Calculate 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
284) 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
-
-
29PID Tuning
Accepted performance
Motor speed V1 (V1)/2
- Tune (adjust manually)
- proportional_gain (Kp),
- integral_gain (Ki)
- derivative_gain (Kd),
- Set constant speed V1 for a while (5 seconds) and
stop at T1 - Record the speed by the computer after T1 and see
if it is ok - Yes (accept Kp,Ki,Kd)
- No (tune again)
unstable
done
30Summary
- Studies PID control theory and implementation