Notebook 07


Lab Notebook

Date: 29/03 2012
Group members participating: Falk, Jeppe and Jakob
Duration of activity: 3 hours


Analyze the


  1. Add the ultrasonic sensor
  2. Try the program
  3. Analyze the three classes: RandomDrive, AvoidFront, PlaySound.
  4. How is SuppressCount used to implement the suppression in Behavior.
  5. Implement "drive towards Light


Adding the ultrasonic sensor

The robot has been built accordingly to the manual 9797 page 28-30

Run the program

The was transferred to the robot and run and the following observations was made:
The program seems to make the robot drive in small intervals in random directions - but always forward. The intervals also seems to be random length, and the robot makes some random sounds aswell.
If the ultrasonic sensor detects an obstacle within 20 cm (approx) the robot backs off and turns left.
When an event triggers the robot shows this on the LCD

  • The motors are either s(stop) or f(forward).
  • The avoid shows the measurement from the ultrasonic sensor and when the robot avoids something it shows b(back), f(forward) and s(stop).
  • The sound displays s(sound) when it plays a sound.

In addition there is a column that shows '1' when the behavior is suppressed (0 otherwise).
By observing the suppression the sounds seems to have highest priority, and second avoid and drive is last.


The RandomDrive is triggered by driving with a random amount of power for a random amount of time and standing still a random amount of time. All the 'random amounts' are on the form constant1+constant2*random. The effect of this is that the interval is no longer between 0 and (constant1+constant2, but are between constant1 and constant1+constant2. This is a great advantage e.g if the power was sat to 10 the robot would not move, so by using this form a triggered behavior will always have an effect (unless it is suppressed).


The AvoidFront is triggered by the readings from the ultrasonic sensor, so as long as the distance is larger than a threshold the thread is in a busy-wait loop. Once the distance is lower than the threshold it suppresses lower priority behaviors, drives backwards, turns left and stops.


The PlaySounds is triggered by a fixed time delay. Every 10 seconds it suppresses lower priority behaviors, plays a random amount of notes (between 5 and 25).



The extends Thread and then calls the this.setDaemon(true). This makes sure that ones the main thread exits, all daemons will be terminated aswell, which makes the handling of threads a bit easier.

The suppressCount is incremented every time a behavior i suppressed by a higher priority behavior and decremented each time it's released.
It works some what like a semaphor and the behavior is suppressed if the suppressCount is higher than 0 and not suppressed otherwise.
This, rather than a boolen, makes sure that a behavior that is suppressed more than once has to be released the same amount of times before it can behave freely again.
If the behavior is suppressed it's blocked from calling the car's forward and backward method with a simple "if (! isSuppressed())" check.
The use of suppressCount is illustrated in the picture to the right, where the suppressCount is represented as the red numbers.

Fred Martin's [4] arbiter holds an array named "process_enable", that works like the suppressCount. The array holds an integer for every process; 0 if the process is deactivated and the priority of the process if it's active. It's not possible to determine whether a process have been blocked more than once, but as all the blocking (scheduling) is done by a central unit, the arbiter, this is not a problem.

Drive towards light

The class was implemented and the corresponding lines were inserted in to the modified SoundCar. The uses a busy-wait loop which is triggered by light reading above the threshold.

while (leftLight < lightThreshold && rightLight < lightThreshold) {

The priority was sat to be higher than RandomDrive and less than AvoidFront. This makes the overall behavior of the robot to be driving around until it measures a light value above the threshold. Of course it still have precedens to avoid to drive int to something and to play sounds.


The functionality of the prioritized suppression was explored and a new behavior was developed.


1. Braitenberg, V. 1984. Vehicles, Experiments in Synthetic Psychology London, Cambridge: The MIT Press.
3. Rodney Brooks, A robust layered control system for a mobile robot, IEEE Journal of Robotics and Automation, RA-2(1):14-23, 1986, also MIT AI Memo 864, September 1985.
4. Fred G. Martin, Robotic Explorations: A Hands-on Introduction to Engineering, Prentice Hall, 2001.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License