Quicklinks

Download Program:edgefinder-nxt-robot.rbt
This Page as PDF:edgefinder-nxt-robot.pdf
Video:Youtube Video

Edgefinder NXT Robot

Stefan Bracher

The light-sensor of the NXT is used to detect the edge of a table. This way, the robot can be programmed to stop at the edge without falling.

Edgefinder NXT-Robot

Videos

The NXT light-sensor

The NXT light-sensor in reflected light mode measures the amount of light that is reflected by an object in front of the sensor. If there is no object, of course there is no reflected light. This can be used to detect the edge of a table. By orienting the sensor downward, it measures the light that is reflected by the table. When the robot now approaches the edge of the table, almost no light will be reflected, as the floor usually is at a pretty far distance.

The programmed behavior

Using the light sensor as described above, we can detect the edge the table. The desired robot behavior for this program is to run straight ahead and stop at the edge. If the robot is replaced somewhere else on the table it will start running forward again.

NXT G-Code

NXT-G Code The program consists of a loop that runs forever. Within the loop, a switch command is used. The switch commands evaluates the amount of reflected light. If it is below a threshold value (let's say 20), all motors of the robot are stopped (upper branch). If the value is above the threshold, all motors are powered (lower branch) with a duration of "forever". "Forever" in this case of course means until the value is evaluated again in the next loop.

Tip

The robot can be tricked into falling over the edge by pointing a flashlight to the sensor.