Wednesday, September 29, 2010

Whiney Goes Sober!

Our next challenge was to help Whiney pass the sobriety test. Our original line following program did help Whiney follow a line, however Whiney didn't walk straight or smoothly but he followed a rather crooked path along the line.

For this challenge, Whiney had to smoothly follow this path.
 This challenge was a lengthy process. We had many versions of how to do this and many of them failed in some way or the other, but we tried to learn from our mistakes and we finally created a program that worked...(for the most part).

We started by writing simple stacks that defined for Whiney how to turn.
We implemented these turn blocks through out the code we wrote for this new line following program telling Whiney at which circumstances to go straight, turn right, or turn left. Professor Berg suggested a model to help our robots walk in a smoother, straighter line. Using his method, we implemented the turn counters in the wheels to count how many times each motor/wheel is turning. If a robot is going completely straight, each of its motors (left and right) should turn exactly the same number of times for a given time period or distance. However, due to effects of the physical world (friction of the wheel, something caught in the motor etc) sometimes one motor turns more than the other. Thus, as in our own driving, the robot starts to drift to one side instead of going straight.
When we are driving, we use our eyes to notice that we are drifting and we correct this behavior by adjusting our wheels to turn towards the direction opposite of our drift. For this challenge, we want to write a program that does a similar auto-correction when the robot is drifting. To accomplish this we used the counters to compare how many times each motor had turned. Our program told Whiney to constantly continue checking if one motor had turned more than the other and if so, Whiney would turn the opposite way of the motor that had turned more. Since the program is constantly checking to see if one counter is greater than the other, Whine would not be making these turns for long because as soon as this other counter turned more than the original one, Whiney would turn back the other way. The computer performs this code so fast that Whiney is forced to walk in a straight line.
The challenge, however, is not yet complete. We have accomplished the task of Whiney going straighter, but we still have to make him follow a straight line. To do this, we implemented the ideas from our original line following program. However we included the code from this program in "if, then, else" statements instead of "wait until" statements. Thus, the code would constantly be going through all the "if" statements in the loop constantly, instead of slowing down and pausing to perform one step.
The challenge here was in how we placed these if then statements and how we set them up. Ultimately we created three versions of the Sobriety Test code. One of which worked much better than the others.
Version 1 - Winner




 This is the version of our sobriety test that worked the best. Here we have arranged the if statements so that the program checks for 3 different conditions in two "if" statements. The first "if" statement can be excecuted if either one of it's two conditions are satisfied. If count a [counter for the left motor] is greater than count b [counter for the right motor] then the robot is drifting to the right in which case the robot should auto-correct and turn left. If sensor3 [the value of left sensor] is greater than 700, then the robot sees the black line with it's left sensor thus the robot should turn to the left so that it is straddling the line. Since these conditions warrant the same reaction, we grouped them into a single "if" statement using the "or" operator. This "if" statement will cause the robot to turn left if either of these are true. The second "if" statement checks to see whether sensor 1 [the right sensor] has seen the black line or not, because if this is the case we want the robot to turn right. This program correctly checks for all the conditions, keeping Whiney's driving straight and smooth and also following a path guided by a black line.
The problem with this version however is that Whiney cannot fully make all turns. We could only start the Whiney from one side of the course because starting from the straighter side, Whiney could not make the last, wider angled turn. To account for this, we tried making two more versions of the sobriety test, this time implementing "wait until" statements.

Version 2 & 3 - SobFail & SobFail2




These two programs were essentially the same as the original sobriety program but this time the "if" statements are split up and we have now added "wait until" statements to two of the "if" statements. We added these "wait until" statements to allow Whiney to make more of a variety of turns, such as the large turn at the end of the track our challenge was based on. These "wait until" statements were added to elongate Whiney's turns so that at any given moment, if one of Whiney's sensors saw the black line, Whiney would turn the opposite way [of the way it had just been turning] and keep turning until that same sensor was off the black line. SobFail then tells Whiney to turn the opposite way of the turn it just made, while SobFail2 tells Whiney to now continue with the "forever-loop" to continue checking the other "if" statements. SobFail didn't work because we reealized we were wrong to make Whiney turn back in the same direction it had turned away from immediately after the sensor was once again off the line. SobFail2, on the other hand, was tempramental. When we first tested SobFail2, it had seemed to work, including the last turn and everything! The problem with it was that the path it had taken along the black line was no longer as smooth as we had in our original sobriety test. Whiney had returned to his original habit of zigzagging.
[Perhaps Whiney had reverted back to his addiction of alchohol?]
After we went back to try and fix this zigzagging error by increasing Whiney's speed, we tested SobFail2 again. However, this time, Whiney no longer followed the program correctly. Not only did Whiney still zig-zag, but he also did not complete the last turn. After changing back the speed to it's original value, we tested Whiney again. ALAS!! It seems that Whiney had gotten tired of going along that path time after time trying to please us. Whiney refused to work again! We tried this a few more times before giving up and reverting back to our original Sobriety Test which, ultimately, regardless of it's glitches [i.e. inability to make all turns], worked the best.

No comments:

Post a Comment