søndag den 26. februar 2012

Lab 4

Lab session 4,

Date: 23. feb. 2012.

Duration of activity: 5 hours.

Group members participating: Stefan og Thomas


Goal

Do exercises from the webpage http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson4.dir/Lesson.html

Plan (how and why)

Do exercises from the webpage http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson4.dir/Lesson.html

because it is this week’s assignment.

Black White Detection

Assignment wording:
First, you should mount the sensor on the LEGO 9797 car as described in LEGO Mindstorms Education NXT Base Set 9797 building instruction page 32 to page 34. Second, make a program that use and test the class BlackWhiteSensor.java. Place the car with the light sensor over different dark and bright areas and investigate how well the BlackWhiteSensor works.

Assignment solution:

Meassurements are taken with the robot standing still, with light sensor directly over colors on Lego Mindstorms for Schools Training Missions Activity Pad. Lightsensors distance is as it is when light sensor is mounted on the robot as described on pages 32-34 in LEGO Mindstorms Education NXT Base Set 9797 building instruction.


Software calibration results


Black

35



White

57



Threshold

46







Measurement results




Light

Black

White

Grøn

42

True

False

Rød

56

False

True

Grå

49

False

True

Lighter B.

39

True

False

Black

36

True

False

White

57

False

True



Line Follower with Calibration

As an application of the BlackWhiteSensor try the program LineFollowerCal.java. The program uses the simple class Car.java to move the car

We tried the robot on both two of the tracks that was set up in the lab after we had compiled and uploaded the program to the robot. The robot was driving pretty smoothly along the right side of the black line, oscillating a bit to the middle of the black line and outside of it.

ColorSensor with Calibration

Use the idea and structure of the BlackWhiteSensor to program a ColorSensor that can detect three colors: black, green and white. Make a test program that investigate the usefulness of the class.

The test program we used was the one in the next point.

Line Follower that stops in a Goal Zone

Use the ColorSensor to make a line follower that stops in a green goal zone.

We added another light sensor to the robot, so that we had two light sensors with equal distance in the front of the robot. If both light sensors detected white we would drive forward, if the sensor on the right (looking from behind) detected black or green we would drive right and left if the opposite was the case. When both light sensors detected green we would stop the car. The distance between the two censors where 6,5 cm.

We tried the robot on all of the tracks in the lab and it succeeded on all of them reaching the green goal without any problems.

PID Line Follower

It is possible to make a line follower with just one light sensor that follows the line more smoothly and drive faster if a PID regulator is used, [1]. Try this.

We created a pid regulated robot where we set the goal value to be the blackWhiteThreashold-variable in the BlackWhiteSensor class. The speed of both wheels when the goal value was reached was set to 60. This unfortunately made the robot move forward quite slowly, but it followed the line very well when we used the following value f to put extra power or remove power from the motors:

int f = (int)((1.5*error) + (1.00)*error_dif);

leftMotor.controlMotor(power - f, 1);

rightMotor.controlMotor(power + f, 1);

The power variable was 60 in our program.

torsdag den 16. februar 2012

Lab 3






Lab session 3,

Date: 16. feb. 2012.
Duration of activity: 3 hours.
Group members participating: Jeppe, Stefan og Thomas

Goal
  • Mount sound sensor on lego car.
  • Tryout the microphone sensor.
  • Get familiar with data logging.
  • Run the SoundCtrCar program
  • Implement the Clap Controlled Car

Plan (how and why)

  • We will start by mounting the microphone so we can implement and upload a program for measuring sound (exercise 1).
  • Then we upload the SoundCtrCar program so we can observe the behavior of the program. (exercise 2).
  • Implementing the Clap Controlled Car using the pattern devised by Sivan Toldo so we can compare it with the SoundCtrCar.

Exercises
  1. Using SonicSensorTest.java, place the car at a fixed position and make sounds of
    a) different loudness and
    b) different distances.
    c) Use this to give a description of the readings from the sound sensor

  2. The sound controlled car (SoundCtrCar.java)
    a) Describe the behavior of the car as you make sounds:
    - Clapping, shouting
    b) Describe how the program interprets readings from the sound sensor as loud sounds.

  3. In the program the ESCAPE button is polled in the outermost loop so that the ESCAPE button can be used to stop the program. This does not work when the program loops in one of the four inner loops. You can make the ESCAPE button always work as a program terminator if you also poll the state of the button in the inner loops. But you can also use the ButtonListener mechanism to listen for the ESCAPE button and exit when ESCAPE is pressed. Try this in the program.

  4. Implement the Clap Controlled Car
    A clap is a pattern that starts with a low-amplitude sample (say below 50), followed by a very-high amplitude sample (say above 85) within 25 milliseconds, and then returns back to low (below 50) within another 250 milliseconds.

    a) Try to use his method to detect claps and
    b) compare it to the method used in the program SoundCtrCar.java.
    Use the DataLogger class to record and investigate clap patterne.


Results

Exercise 1
Normal talk 30 cm from microphone, gives readings between 0 and 30 (peaks at 50).
Normal talk 200 cm from microphone, gives readings between 0 and 20.
A clap results in various readings between 30 and 90, but they are all peaks.

We used the datalogger to monitor the claps. We have plotted the data on the graph below:


Exercise 2
The robot alternates between, going forward, right, left or stops on a loud noise, also the program did not terminate the first time we started the robot, so we had to be quiet (avoid activating the robot) while dismantling the robot to take out the battery.

We also observed that even though the robot is only supposed to start on loud noises, the robot actually started while there were no loud noises.

The program has a threshold value "loudSound" that makes the robot wait for a loud sound.
However the sleep in the method is set to measure

Exercise 3
We used the button listener on the escape button and a "alive" variable to exit the program.

Button.ESCAPE.addButtonListener(new ButtonListener() {
public void buttonPressed(Button b) {
alive = false;
}
public void buttonReleased(Button b) { });
...
while ( soundLevel < soundThreshold && alive);

Conclusion

References
[1], http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson3.dir/Lesson.html