Tuesday, March 12, 2013

Proportional Control

On Friday, we worked on the new concept of Proportional Control. Instead of reacting to feedback with a simple "on or off," proportional control allows more nuanced reactions by scaling the reaction (the power level, in our case) proportionally to the error (how far the car is from an ideal state, as measured by the sensors).
Our first example of using proportional control was to revisit using the ultrasonic sensor to make the car follow a moving object like a piece of cardboard. Previously, we had a simple program of moving the car backward if the sensor read less than 15 (it was closer than 15 ultrasonic-sensor-units to the object in front of it) and forward if the sensor read more than 15, and stop if it was exactly 15. This resulted in a very choppy motion in that if you moved the leading object only a little bit, the car would surge forward and overshoot the ideal position of 15, and have to back up again (at full power).
Implementing proportional control, we introduced an "error" variable that was the reading of the sensor minus the ideal, i.e. 15. Then, the power of the car was set to be the error times an arbitrary gain variable that scales the units of error to a reasonable scale for power.
After trying this, we found that the car worked well in the forward direction, but went very slowly in the backwards direction because the sensor, as we found, will never read less than 9, and therefore the error will never be less than -6. Since this error value corresponded to such a small power, the car could never "run away" from the leading object at full speed. To solve this issue, we changed our "gain" variable and used two variables, "fgain" for forward and "bgain" for backward, and by making bgain>fgain, the car could react well to being both too close or too far away.
The program for the proportional-control object follower.
Here is a demonstration of our program:
Then we tried to implement a similar adjustment for our line follower program. Unfortunately, we couldn't even get our original line follower program to work, due to changes in the tape shade. Since we wanted the amount that the car turned to be proportional to the error, we tried to lower the power on one wheel proportionally with the error, which would make the car turn towards the lower-powered wheel. To do this, we made a new variable, dpower, which is the amount that the power decreases for the slower wheel, and set the slower wheel's power to 75-dpower. I am still not sure whether this is actually a use of proportional control, since the actual power of that wheel is not purely proportional to the error. However, I can't think of a way to structure proportional turning or "bearing" to one side where the power is 0 when the error is 0, which is a necessary result of pure proportionality.
Regardless of whether the program should have worked in theory, in practice, it was unable to "see" the line effectively and we didn't have time to work out the right numbers for the ideal range and the gain.
The proportional control line follower
Finally, we learned about the motors' ability to report their position in terms of "counts." We wrote a program that moves the axle to position 100 using both types of control, as seen below. However, we were unable to make the axle fully stop in either program, and it continued to twitch slightly back and forth after reaching the position. We tried to fix this problem by giving a range of 2-4 counts that would not cause the wheel to turn, but this was unsuccessful. For example, our proportional control program should turn the motor off if the error is between -2 and +2.
Returning the axle to position "100"




No comments:

Post a Comment