Wednesday, 19 September 2007

NXT Programming - Lesson 2


Date: 2007.09.13
Duration of activity: 6 hours
Group members: Alessandro, Daniela, Samuele


Goals of this session:
  1. Trying the lego ultrasonic sensor

  2. Trying different strategies for wall following systems
After having set up our lego workstation on our laptop, we started working on our goals.

We added the ultrasonic sensor to the model, and uploaded the first sample program (Avoider).
Q: What kind of control is it?
A: A proportional control. It has indeed sudden starts and stops, and it moves jerkily.

Then we rotated the ultrasonic sensor, and tried to upload the second sample program (WallFollower). We soon discovered that there was no sample program, so we rewrote in java the two suggested solutions for it.

We tried the algorithm from the F.G.Martin's book, and it didn't work, since the model rotated too fast, and it often lost the wall, even with the gentle turn patch.

We then tried the Philippe Hurbain code. We couldn't make it work well, probably because the lego sensor often doesn't see obstacles when their surface is rotated of a too big angle.

After some vain changes to the constants, that only made the robot spin, we thought that we could have done much better by making the robot rotate its "head".

We attached the third motor on the top of the model, with the ultrasonic sensor on it, and wrote an algorithm to make it avoid obstacles while following the wall.
Our code simply made the robot always look toward the wall, and every second rotate the head, sample the distance ahead, and then rotate it back.


After many tries, we decided that the rotation of the head was not enough precise to make the head return in the previous position, so we later made the whole model rotate, and not only its head, to avoid the synchronization problem.

Another variation on the algorithm was to make the robot decide, every time it looked around, what was the position in which it was the most parallel to the wall, by choosing the one in which it sampled the shortest distance to it.
<<youtube video coming soon>>

The only problem left was that when the robot came across a corner and it didn't see any obstacle, it started spinning around.
We then chose to made the robot describe an arc until it founds something again. To make it be an arc of a circle and not of a spiral, we calculated the speeds of the two wheels, as a function of the expected distance from the wall and the (constant) distance between the two wheels.


Since it was too late, and we were almost satisfied of our work, we forgot writing the lab report (and this is why we're writing it nearly a week later), and after having found someone with the key to open the gate, we went home.

No comments: