Notebook 06


Lab Notebook

Image of the focus of the lesson

Date: 08/03 2012
Group members participating: Falk and Jakob
Duration of activity: 4 hours


Using [2] and [3] implement and experiment with the Braitenberg vehicles [1].


  1. Get a RCX light sensor to work with the NXT.
    • This is for the future 'Alishan train track' race.
  2. Build a robot suitable for the Braitenberg vehicles.
  3. Implement a simple solution for vehicle 1 using the readValue (i.e. not the raw value).
  4. Implement a calculator class that maps the raw values from the sensors to a meaningful power value for the motors, and use this for vehicle 1.
  5. Implement vehicle 2a and 2b, and experiment with other robots with lights on top of them.
  6. Implement vehicle 3.


RCX Light Sensor

Using the converter cable from the RCX light sensor to the NXT sensor port, the following code works:

RCXLightSensor sensor = new RCXLightSensor(SensorPort.S1);

The activate() method should be used even though it is deprecated.

Build the Robot

The robot has been built accordingly to the manual 9797 page 8-22.

Vehicle 1

A light sensor has been added to the robot pointing approximately 45 degrees upwards in front of the robot.

Developing the simple and obvious implementation resulted in the

The main loop looks like this:

while (running) {
    int light = sensor.getLightValue();
    Car.forward(light, light);
    LCD.drawString("Light:  " + light, 0, 0);

The robot drives a bit slow (power approx 60). Seeing that it is almost impossible to have a light reading above 85 unless a flashlight is used, adding a constant to the power value of about 15 to compensate friction in the system makes the robot drive at a decent pace and does only stop when it actually is dark around it. Another way to compensate for the friction is to multiply the light value by a number (f.i. 1.5).


A calculator class was developed to map an arbitrary sensor reading to the power value. I does this by having variable minimum and maximum values that adapts to the extreme values.
The main calculation is this:

public int normalize(int value) {
    return (int) (100 * (0.0 + value - min) / diff);

As an extra feature it uses a home made to draw the values to the LCD display in a graph.

The code from needed some minor modifications to run with this, such as using the readRawValue(), to have more accurate readings, and converting this with the normalize() call turned in to a new program.

Vehicle 2a and 2b

Using the new and adding the another sensor in the code, the main loop of looks like this:

while (running) {
    int leftLight = 1023 - SensorPort.S2.readRawValue();
    int rightLight = 1023 - SensorPort.S1.readRawValue();
    int lp = sc.normalize(leftLight);
    int rp = sc.normalize(rightLight);
    Car.forward(lp, rp);

To make the program for vehicle 2b the line Car.forward(lp, rp) should be change to Car.forward(rp, lp)

Vehicle 3

There was not enough time at the lab session to make vehicle 3.


Braitenbers vehicle 1, 2a and 2b was successfully constructed.
A subgoal for this exercise was to get the robots to interact with each other, but with the differences in the construction of the robots (f.i. the height of light and sensors) as well as the programmed sensitivity of the sensors, this became quite difficult.


1. Braitenberg, V. 1984. Vehicles, Experiments in Synthetic Psychology London, Cambridge: The MIT Press.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License