The goal to equip our NXT Robot with a light sensor and execute the exercises.
See more [1].
## Plan
Our plan is to follow the exercises exactly as described.
## Results
### Exercise 1
The goal of this exercise was to measure the light values for different colors. We collected lightsensor values for different colors and determined a threshold for black and white.
| Color | Value
|-------------|-------
| White | 58
| Grey 1 | 51
| Grey 2 | 47
| Grey 3 | 42
| Grey 4 | 37
| Black | 32
| Light Blue | 47
| Blue | 40
| Light Green | 38
| Dark Green | 35
| Red | 55
| Dark Red | 53
| Yellow | 56
| Dark Yellow | 56
Afterwards we set the `blackWhiteTreshold` to `white + black / 2 = (58 + 32) / 2 = 45` which is the median.
Note that the largest difference is 26.
### Exercise 2
In this exercise we experimented with the flood light setting of the light sensor. We started out by calling `light.setFloodLight(false)` which disables the flood light and then measured again.
| Color | Value | Value no FloodLight
|-------------|-------|----------------------
| White | 58 | 30
| Grey 1 | 51 | 25
| Grey 2 | 47 | 22
| Grey 3 | 42 | 19
| Grey 4 | 37 | 17
| Black | 32 | 17
| Light Blue | 47 | 27
| Blue | 40 | 26
| Light Green | 38 | 25
| Dark Green | 35 | 23
| Red | 55 | 30
| Dark Red | 53 | 27
| Yellow | 56 | 30
| Dark Yellow | 56 | 30
The maximum difference is halved to 13.
Thus we have double the accuracy with flood light turned on.
### Exercise 3
Now we had to test the effects of using different amounts of delay between the light sensor readings. Here are our results:
- 100 milliseconds
It gets to the opposite side of the black line and ends up turning all the way around to find the line again.
- 500 milliseconds
It only looks once every half second. If it's turning `right` looking for the black line and misses, it continues turning until black is observed.
- 1000 milliseconds
The same thing happens as described with 500 milliseconds.
One annoying side effect is that you have to hold Esc for at most (worst-case) 1000 milliseconds to stop the running NXT program.
### Exercise 4
In this exercise we used data logger [2], to log the measured light values. These values we then plotted in a graph to see the difference. We did this exercise on a circle track which is shown below.

Note that the `y`-axis is light registered from the light sensor where high numbers represent white and low numbers represent black. The `x`-axis is time.
> Here we see that our NXT missed the black line and kept looking in the white area for way too long.
### Exercise 5
In this exercise we experimented with the raw values from the light sensor which are between 0 and 1023. Let us return to our table and fill out raw values with FloodLight on.
These new values show us that the raw data can be used to get a more accurate measurement in comparison to the light percentage. A good example is the colors Grey 1 and Light Blue which both have a light percentage of 47. That would make them indistinguishable unless the raw values 537 and 550 were used.
### Exercise 6
When the variables `left` and `right` are predefined, the String is just called by reference. So when we send a new string object the `Runtime.getRuntime().freeMemory()` gets smaller and smaller faster because we keep throwing `Strings`-objects on top of the stack. When this value gets too large the strings get cleaned up by the JVM garbage collector.
The difference in time it takes to invoke the garbage collector is seen in the two following charts `New String` and `Reference String`.
The `y`-axis is free memory. The `x`-axis is time in milliseconds.
We equipped our LEGO car with a light sensor and we compiled and uploaded a program (`LineFollower.java`) to make it follow a black line on a white surface. We then extended its functionality by adding the `DataLogger`-class which made it easier to plot the data.
We have achieved a better understanding of how the NXT brick observes the world and how we can intercept and analyze it.