13) Test of Sensors 2

3) Test of Sensors 2

Image of the focus of the lesson

Date: 23/05 2012
Group members participating: Falk, Jeppe and Jakob
Duration of activity: 7 hours

3.1) Goal

The goal for today is to test the ultrasonic sensor and the color sensor and implementing a prototype prey robot.

3.2) Plan

3.3) Results

3.3.1) Ultrasonic Sensor

To test the Ultrasonic sensor the measured distance was printed on the LCD:

UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
 
LCD.drawString("Distance(cm) ", 0, 0);
 
while (! Button.ESCAPE.isPressed()) {
    LCD.drawInt(us.getDistance(),3,13,0);
    Thread.sleep(300);
}

Although it is mounted lower on our prey robot then on the default LEGO car, the test ran fine and the sensor works like expected.

3.3.2) Color Sensor

The color sensor was not available so the test must be done at a later time.

3.3.3) Prey Behaviors

The behavior based architecture of the robot is inspired by [Bibliography item krink not found.].

The different behaviors of the robot are

  • Avoid edge (Color sensor)
  • Avoid obstacles/other robots (Ultrasonic sensor)
  • Run away from predator (IR sensor)
  • Eat food (color sensor)
  • Wander around

(optional there could be a behavior "Listen for screams" using a microphone)

Choosing which behavior to perform should be motivation based. I.e. a detected obstacle which is really close to the robot should lead to a higher motivation to avoid it than one that is far away.
The different behaviors are implemented extending a superclass Behavior and are then called by an Arbitrator. Each behavior has a method getMotivation and a field with an unique priority. The robot is performing the action of the behavior with the highest motivation. If two behaviors have equal motivation the priority decides which action to perform. Arbitrator and behaviors are set to be daemon threads, so they run until the main thread is terminated.

Here is a list of all the actions a prey robot can execute and the sensor reading triggering the action

Action Motivation Sensor used Sensor value
Wander around 1 - -
Avoid obstacle 25 Ultrasonic <30
Avoid obstacle 50 Ultrasonic <20
Avoid obstacle 100 Ultrasonic <10
Back off (to avoid) 50 - -
Move to one side (to avoid)
Run away 25 IR 50
Run away 50 IR 100
Run away 100 IR 150
Avoid Edge 100 Light sensor >38

The arbitrator looks for the behavior with the highest motivation (priority as tie breaker). If this is different from the current behavior, then the old behavior will be stopped and the new one will be started. If it is the same, it will only be restarted if the motivation is higher than before and the behavior is self-interruptible.

3.4) Conclusion

The arbitrator and the prey behaviors were implemented, and the ultrasonic sensor was tested.
We had no color sensor, but we do expect to receive this for the next session, so this should be tested.
Next time we should figure out a way to interrupt a behavior even though it might be in the middle of an action, and the robot should be run on a test track.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License