PoE: Lab 3 -- PID Control


Objectives

  1. Use an analog IR reflective sensor to measure the angular position of a motor shaft.
  2. Create a closed-loop controller for a brushed DC motor with your DIY shaft encoder.
  3. Characterize and visualize the performance of your closed-loop motor controller.
In this lab, we used an analog infrared reflective sensor to build an encoder to measure the position of the shaft of a DC motor. With the sensor, the more IR light that is reflected back to the phototransistor, the closer Vout will be to zero (see schematic). We used the position reported by the encoder as a signal around which to design a feedback loop that ensures your motor will go to any position you command it to (even under load).

After setting up the sensor circuit with the Arduino, we began to build the encoder. An encoder is a circle with distinct patterns of black and white shapes, usually triangles, that signify on-off or high-low. We placed our 36-resolution*, carboard encoder right on the shaft of the motor for it to spin in relation to the motor's position.  (*Note: Determine by dividing circumference by sensor's width)

Rather than soldering longer wires onto the sensor for it to be mounted, we mounted the breadboard on which it lay and placed that directly across from the encoder for it to read. We had a few challenges in calibrating the sensor as we couldn't understand the schematic at first and forgot about the internal LED in relation to the 4 pins of the sensor. Once we started receiving readings from the sensor, we tried to find consistent values for High/Low or Black-White patterns. We build the motor's mount out of foam, leaving room for the encoder to spin and, on the other end, for the load (paperclip and hex nut) to oscillate during the 120-degree run.

In order to write our PID control code, encoderPID, we broke the logic down into several parts. First, we determined a threshold value for the sensor reading, indicating that when the sensor reading goes above or below this value, the encoder has changed position (switched from white to black, or vice versa). We determined this threshold by finding the min and max sensor readings as the encoder spun, and then chose the threshold to be in the center of this range. After the code inputs an analog reading from the sensor, it determines whether or not this value is less than or below the threshold, and records a current reading of 0 or 1 for white or black. The code then runs through a loop, noting if the current read is different than the previous reading­­ if it has changed, then that means that the encoder has moved position, which increases our position count by 1.

We can assign a target distance to the code, depending on how many degrees we want the encoder to rotate. For our 90 degree step function, our target value was 18. The code also keeps track of our error, which is the target position minus the position count. The position is supposed to continue updating until it reaches the target, but without a PID control, our error never reaches zero. Hence, PID control, first multiplying the error value by the proportional constant and converting this number into a speed input for the motor. We experimented with the value of the proportional constant (Kp), until it simply oscillated around the target position. We then experimented with derivative control to apply a break to proportional control, slowing the motor down as the output shaft position approaches the target position: multiplying the error difference by the derivative constant (Kd). However, with just P and D control, the position stays just below the target, so we implemented an integral control, which takes the integral of all error values and multiplies this by Ki, the integral constant. With the PID control in place, the motor just overshoots the target position slightly but then returns and stays steady at the target position.

Comments

Popular posts from this blog

Hackathon: TechTogether Boston

Women of Color in Graduate School

Truss Design (Final)