torsdag den 16. september 2010

Lesson 2

For our second lesson we were to learn how to use the ultrasonic sensor for the NXT.
To that end the first part consisted of uploading a testing program for the sensor, which verified that the sensor was actually operational.

Tracker
Thereafter we uploaded a Tracker program demonstrating the use of said sensor. It is a reactive program, that causes the car to approach an object in range of the ultrasonic sensor until the distance to it is reduced to 35cm. Seeing no object in range it will drive forwards. If the object is closer than 35cm the car will back up. The car will however not at any point stand still.

Wall follower
The core of our second lesson was to program the car to follow a wall. We achieved this by using the tracker program as a basis. We ended up trying two different methods of implementation.
Both implementations work on the principle of letting the car constantly move forward while adjusting the power to the left and right wheels, depending on the correction (if any) to be made.
The first implementation involved adding a threshold (error margin) constant which let the car travel straight for a while before making a correction to the error that has been accumulating by not travelling parallel to the wall.
We did this after learning from lesson 1 and the results of other students efforts during the lesson, that correcting an error instantly results in a jagged and inefficient movement pattern.
Besides this and tweaking (mostly via trial and error) some other constants like the desired distance to the wall and the extent of the force with which an error was corrected, no other significant changes were made to the tracker program.
We were pleased to see that this implementation actually worked quite well and moved very efficiently along the wall.
In an effort to make the wall following routine more concise and allowing the car to correct different magnitudes of errors with an appropriate response, we implemented another solution based on a different principle.
This time the car would constantly correct its distance to the wall by adjusting the power to the wheels based on the square root of the error from the desired distance to the wall. After some erratic results and obtaining the insight that a form of threshold was still necessary we managed to make this solution work as well.
The primary objective behind our second attempt was to try a different and more implicit approach to allow the car to turn around corners, since implementing that behavior in the former approach would mean a lot of tweaking or the implementation of a new subroutine just for that purpose.
Unfortunately we did not manage to make either of these programs capable of turning around neither inside nor outside corners.
We found that our first solution worked better than the second one, although we suspect that we might have chosen the wrong function for correcting the error in the second one.

Comparison of NCQ implementation
Philippe Hurbains NCQ implementation of the wall follower uses the three state algorithm, which turns hard (read: in place), when it is too close to the wall and shallow when only a minor correction is needed.

Ingen kommentarer:

Send en kommentar