Introduction to Experimental Robotics CSCI 1108 — Lecture 15 PID Controller CSCI 1108 Lecture 15 1 / 18
PID Controller Introduction PID Controller is a common technique to control a wide variety of machinery, including vehicles, robots and even rockets We will see example of how to create a PID controller to do line following Once created, the same PID controller can be used with some modifications for various different tasks CSCI 1108 Lecture 15 2 / 18
PID Controller: Line Following We will use a single ground sensor Want to track the line very precisely even if the line has curves Will apply left-hand line follower method Steps: building P controller, PI controller, and PID controller Constant parameters: Kp, Ki, and Kd, will need to be calibrated CSCI 1108 Lecture 15 3 / 18
Parameters: SETPOINT SETPOINT: average of white and black light sensor readings. You need to measure the light levels of “black” and “white” values with your robot, calculate the average and put it into SETPOINT constant. SPEED: controls robot speed. You need to find maximum SPEED that robot can use, and still be able to track a line with sharp curves. Kp, Ki, and Kd: tunable parameters that control how fast robot moves when it moves away from the line. CSCI 1108 Lecture 15 4 / 18
Using Integer Arithmetic Remember that Aseba does not support numbers with decimal point Must use integers Example: if parameter Kp should have value 1 . 5 , we cannot set it to this value, but instead use values KP = 15 and KPd = 10 and remember that the actual value is Kp = KP / KPd Have in mind the integer range [ − 32768 , 32767] and the use of native function math.muldiv to compute multiplication-division using internal 32-bit precision CSCI 1108 Lecture 15 5 / 18
Illustrative Example for math.muldiv Assume that we need to calculate circumference of a circle of diameter d = 80mm Formula c = π · d , and we know π ≈ 3 . 14159 Correct value: c ≈ 251 . 3274 ≈ 251mm We can use a very coarse integer approximation π ≈ 3 and get c ≈ 240 Other solution: represent π = PI / PId , where PI = 31416 and PId = 10000 However, “ c = d * PI / PId ” does not work well Why? How can we solve this problem? CSCI 1108 Lecture 15 6 / 18
“P” in “PID”: Proportion(al) Consider the following program: CSCI 1108 Lecture 15 7 / 18
“P” in “PID”: Proportion(al) (2) CSCI 1108 Lecture 15 8 / 18
LineFollow-P: Parameters Save the program as “ LineFollow-P ” Constant SPEED: is the target speed for straight line, set to 250 Constant SETPOINT: average of white and black readings, typically a value between 450 and 550 Constants: KP and KPd: represent the Kp parameter; typically KP between 350 and 500 (maximum error), and KPd = 500 (maximum speed) CSCI 1108 Lecture 15 9 / 18
“P” Controller This is “proportional” controller You can try it, and may need to experiment with the Kp parameter Explain how the program works and why it is called “proportional” CSCI 1108 Lecture 15 10 / 18
Adding “I” to the Controller: The PI Controller “I” is the integral term, it is the running sum of error Let us consider the program for PI controller CSCI 1108 Lecture 15 11 / 18
PI Controller Program CSCI 1108 Lecture 15 12 / 18
PI Controller Program (2) CSCI 1108 Lecture 15 13 / 18
LineFollow-PI Constants SPEED: target speed, e.g., 250 SETPOINT: average of white and black light, same as before KP and KPd: same value as in P controller KI and KId: Ki should be 1/10 of Kp intitially Save program as LineFollow-PI Explain the program. Why we need to zero integral variable? Experiment with the parameters What is robot behaviour when changing Kp or Ki, while keeping other parameter constant? CSCI 1108 Lecture 15 14 / 18
Adding “D” to the Controller: The PID Controller “D” is the derivative term, it tries to look ahead in time and correct the error that has not occured yet Let us consider the program for PID controller CSCI 1108 Lecture 15 15 / 18
PID Controller Program CSCI 1108 Lecture 15 16 / 18
PID Controller Program (2) CSCI 1108 Lecture 15 17 / 18
LineFollow-PID Constants SPEED: target speed, e.g., 250 SETPOINT: average of white and black light, same as before KP and KPd: same value as in PI controller KI and KId: same value as in PI controller KD and KDd: Kd parameter, start with about the same as Ki Save program as LineFollow-PID Explain the program. What is the role of error and lasterror variables? Experiment with the parameters What is robot behaviour when changing Kd with optimal Kp and Ki values? CSCI 1108 Lecture 15 18 / 18
Recommend
More recommend