![]() |
Some of the programs we wrote while exploring the PicoCricket |
We also learned how to use other sensors, such as the light sensor and the ultrasound sensor. The touch sensor is the only sensor that gives a boolean (the sensor is being pressed, or it is not). The light and ultrasound sensors both give numbers, so using them as feedback requires deciding on a range of values to assign to tasks. We had a lot of trouble with our display--it would only very sporadically show any numbers at all, and sometimes would show only the number 94--but finally got a replacement cord to attach it, which solved the problem.
Armed with this knowledge, we were given the task of making the car use the light sensor to follow a white tape line along a brown background. Our first step was to see what the values were for the light sensor when it was over the tape and over the brown. Then, we tried to make the car follow the line. Our initial idea was to have the car move slowly forward as long as it was on the white line, and if it lost sight of the line, it would scan first to the right, in a series of short turns, and then back to the left. Once it found the line again, it would continue forward.
To implement this idea, we wrote many iterations of the program. The first big problem we encountered was that we could not be checking for the line (asking if the light sensor was seeing a low value) while the car was turning, unless the car kept turning indefinitely until it found the line. This was a problem because if the car was to the right of the line, and it scanned to the right first, it would turn completely around before finding the line and setting off in the wrong direction. To fix this, we changed the way it scanned to turn to the right for .1 sec, check if the light sensor saw the line, and then turn right for another short burst and check again. Because we couldn't find a way to make the control exit the loop and return to the beginning if the car found the line, we made the method recursive as seen below.
![]() |
The scanning line follower |
After a lot of tweaking the numbers for the power of the motors, both going straight and turning, and the interval of time that the car turned while scanning, the car was able to traverse both the straight line and the simple one-turn track, regardless of whether it started on the line or slightly to either side. However, when we put it on the big track, it was able to successfully get about halfway along and then it would suddenly stop. At first, it seemed like a battery problem, but the same thing happened after Alex changed the batteries. Apparently, because our program implemented spins instead of gradual turns, and the motors were switching quickly from forward to backward, it somehow overloaded the motors and made the machine give up halfway through. We came back after class to troubleshoot and see if we could find a way to make the car go the full distance, but we were unsuccessful. This was a very disappointing setback but we could not find another way for this method to work.
Therefore, we turned to the method of following the edge, instead of the line, causing our car to be limited to starting on a certain side of the line and causing it to be unable to traverse the sharpest turn in the course, which our first design was able to do. This program took a surprisingly short time to create, and our only setbacks were trying to find the right speed for the car to "bear" left and right so that it would not overshoot the line.
![]() |
The edge follower |
No comments:
Post a Comment