Slide 1

advertisement
Automatic Control
Mike Robinson
You can measure the distance from
the RC car to some target.
What could your program do to keep
the car as close to the target as
possible?
Proportional control
Error = target position – current position
kp = proportional gain
Duty cycle = kp*error
Think back to your vibrations class.
What does the proportional response
look like? Why is this not surprising?
What could we do to reduce the
oscillations we see?
Proportional control
X
F
m
𝐹 = −𝑘𝑝 𝑋
𝑚𝑋 = 𝐹
𝑚𝑋 = −𝑘𝑝 𝑋
𝑚 𝑋 + 𝑘𝑝 𝑋 = 0
Proportional + Derivative control
error = target position – current position
derivative = (error – past error)/change in time
kp = proportional gain
kd = derivative gain
Duty cycle = kp*error + kd*derivative
Why has adding derivative
control made the car more
jittery?
D = Derivative, D = Danger!
Beware of noise when you are taking a
numerical derivative
4
2
0
0
-2
-4
-6
-8
5
10
15
20
25
What would happen if we only had
derivative control?
Would the car still move to the target?
Would the control do anything
noticeable?
What could we add to get rid of
the errors in position at steady
state?
Proportional + Integral + Derivative
control
error = target position – current position
derivative = (error – past error)/change in time
integral = past error + error* change in time
kp = proportional gain
ki = integral gain
kd = derivative gain
Duty cycle = kp*error+ki*integral+kd*derivative
What would happen if we only
had integral control?
A few words about commenting
BAD
//Code for lab 3
int input = 0; //Declare variable input
int inDist = 0; //Declare variable inDist
GOOD
/*
This code reads an analog voltage from an ultrasonic sensor,
converts the voltage to a distance in centimeters and prints the
distance to the serial monitor
Circuit:
Connect +5 and ground to sensor
Connect analog output from sensor to pin A0
Last edit: MDR 2/11/13
*/
int ultrasonicPin = 0; //Analog input pin for ultrasonic sensor
int ultrasonicDist = 0; //distance measurement in centimeters
Preview of this weeks lab
+5V
Motor
Preview of this weeks lab
Motor inductance
+5V
Motor resistance
𝑉𝑒𝑚𝑓
Download