Tuesday, March 29, 2016

SciBorgs and Proportional Control

For the rest of our time with ropSciBorgs we were tasked with changing the sketches we did using bang bang control to sketches that used proportional control instead. 

Proportional control is a feedback and control system where power is proportional to the error (how far reality is from the goal). Power can be calculated with the equation:

Power = Kp *  error
Error = goal - reality
Kp= gain coefficient; 

When the gain coefficient is too big the power becomes much larger than needed and there is an overshoot and then the gain coefficient is too small there is an undershoot. 

Task #1: Drive straight

In order to make our SciBorg drive straight using proportional control, we used the difference between the positions of each motor to be the error of the speed of motor 1 since motor 1 was determined to be faster than motor 2. We then set motor 2 to have a constant speed of 225.  In order to get the speed of motor 1, we added its speed error to the speed of motor 2 and multiplied it by our gain coefficient of -1. So when motor 1 has a larger position than motor 2, motor 1's speed undershoots and becomes set to a little slower than motor 2 and when motor 2 has a larger position than motor 1, motor 1's speed overshoots and becomes a little faster than motor 2.




Using the motor encoder, we were able to read that with our sketch, the difference between the positions of motor 1 and 2 went down to 3. Before, the difference would exponentially grow to over 500.


Our SciBorg drove the straightest we had ever seen it! :D
Surprisingly, on a high friction surface our SciBorg did not drive very straight. :(
On a surface with high and low friction, the SciBorg drove straight when the low friction was on the left wheel (motor 1) but it did not drive straight at all when low friction was on the right wheel (motor 2).
Our SciBorg surprisingly was able to go up most of the ramp. Using bang bang control, it could barely go up a foot of the ramp before falling off. :)
Our SciBorg was able to successfully go down the ramp :)


Task #2: Drive 10 feet and nudge

In order to make our SciBorg drive straight 10 feet and stop, we used the difference between our 10 feet position 12650 and the average of the positions of the two motors. We then used a gain coefficient of 0.01. The power was then added to 100 so that as the SciBorg got closer and closer to the 10 feet mark, it would slow down.

Our SciBorg ended up being about 3 inches away from the 10 feet mark.



We then used a function called nudge that would make the SciBorg  go at a constant speed for 1 second to help it get to the finish line. When the position of motor 2 was less than  12000, the speed of the motors is given by the speed we calculated before and when the average of the position of the two motors was more than 12000 but less than 12650, the function nudge would be performed. The function nudge would make the SciBorg travel at a constant speed of 106 for motor 1 and 120 for motor 2 for 1 second.


Our SciBorg reached the line!! :D


Task #3: Following using ultrasonic sensor

In order to make our SciBorg follow other Sciborgs using an ultrasonic sensor, we calculated the power to be 5 (the gain coeffiecient) times the error (analog reading of the sensor minus 11 (the lowest reading of the sensor)). We then set the speeds of the motors to be the power. Because we did not give a different speed for each motor, our SciBorg did not drive straight but it was able to smoothly follow a piece of Delrin.




Task #4: Following the line

In order to make our SciBorg follow the white line, we made the speed of motor 1 to be 5 (the gain coefficient) times the error (the light reading value minus 75 and then added to the speed of motor 2). Our SciBorg was able to follow the line much more smoothly and faster than when we used bang bang control. :D



Overall, I found proportional control to be much better than bang bang control because it made our SciBorg perform the tasks much better. Writing the sketches using proportional control was difficult at first but as we got more experience with it, it became much simpler and easier to use than bang bang control.

1 comment:

  1. Cool! I liked that you showed the output of the motor encoders to demonstrate how your sketch improved the SciBorg's ability to move straight. I'm also impressed by how well your nudge function worked! Why did you set the wheels to move forward at different speeds (106 and 120) in your nudge function? Is that just from inherent differences in the speed of the motors? Regardless, I'm very impressed.

    ReplyDelete