Thursday, 27 September 2007

NXT Programming - Lesson 4


Date: 27.07.2007
Duration of activity: 4 hours
List of participants: Alessandro, Daniela, Samuele

Goal of this session: Build the fastest line follower and win the competition of the next week.

First of all we just wrote a simple program that uses the BlackWhiteSensor class, which just calibrates its threshold, and prints out values. Black is black, white is white, red, orange, green are white as well.
Since we have in mind of building our competition robot using more than one sensor, and we only have one NXT light sensor, we took some other old sensors from the lego room.
Then we modified our test program, and the BlackWhiteSensor class to check if both sensors behave the same (it could be a dangerous to do this assumption without verifying).

Values sampled by RCX and NXT light sensors are really different, so we decided to not use different types of sensors at the same time. NXT sensor seems more sensible, but we can get more of the old ones, so we had to find only an adapter for RCX sensors.
Let's try the old sensors.
We added the four sensors in a row, in place of the NXT one, and made few modifications to the robot structure (i.e. bigger wheels, to increase the speed) .
We also edited the BlackWhiteSensor class to a RCXBlackWhiteSensor, and then extended it as RCXColorSensor. It has a calibration phase which samples black, green and white, and then calculates two thresholds to distinguish the three colors.
Unfortunately it wasn't going to work: old RCX sensors sample the same value (around 34 with that ambient light) for white, green, red, and probably other colors we didn't try.
We must make the robot distinguish a green area, so we ended up with two possible solutions:
  1. Using the NXT sensor as main sensor, and two RCX sensors for auxiliary sensors. In this case the line following algorithm actually follows the border between black and white, and not the real thick line.
  2. Using two old RCX sensors as main sensors, and other two as auxiliary. In this case the line following algorithm would mainly have to keep the two main sensors inside the black line, and the two auxiliary sensors out of the line. To recognize the green area we can just assume that when we cannot see any black line at all, we are inside the green area.

Since we already had wondered too much about the four-sensor solution , and we believe that the first algorithm would be too slow for a speed competition, we chose the second solution.

The first naive attempt at low speed seemed to work well, so we managed to increase the speed, while keeping its line following accurate. We designed an algorithm to make the robot behave according to the four sensor readings, in a stateless way.
The following are the valid sensor states that we considered:
(one bit per sensor reading, 0 stands for sensing white, 1 for black)

forward
0110 on the line, fast forward
1111 maybe crossing another line, forward

right
0001 strange turn, probably recovering from a previous turn, gentle turn right
0011 normal turn, right
0111 possible 90° turn, fast turn right

left, same as above
1000 gentle turn left
1100 left
1110 fast turn left ->

stop
0000 no black line, stop

Every other state has been discarded as a glitch in sampling or an unknown state. In those cases the robot simply ignores the reading and keeps driving with no speed changes.

Since it wasn't that easy to make it work with higher speeds, a long discussion followed, about interpretation of robot readings , or alternative positioning of the sensors .

At last, we ran out of ideas, so we decided to stop working, and continuing later . It wasn't that bad, but we need some intuition, which is not easy to have, after four hours of work. Updates will follow.

No comments: