Allison Avrich and James Padgett
Ed Harcourt
Abstract
This project explores algorithmic and heuristic
techniques of pathfinding by programming a Lego
Mindstorms NXT Robot using the Not Exactly C(NXC)
programming language. The robot itself is a three-wheeled
(two powered, one support wheel) vehicle with a light and
color sensor adjacent to each other attached to the front
of the robot. By using a black tape track on a white
background, the robot is programmed it interpret the input
of its sensors to detect the track and follow it. A variety of
different tracks were used to test the capabilities of the
robot. Each track was designed to be more difficult to
navigate than the previous track. Topics within the scope
of this project include: different algorithmic and heuristic
search, pathfinding, and path-following techniques;
multitasking and concurrent programming; and advanced
levels of complexity, such as obstruction avoidance.
Advisor:
Diagram: From Conception to
Execution
Excerpt from Line Following Function:
sub FollowLine()
{
. . .
while (true) //Follow the line forever
{
. . .
// set speed for motor 2
if (SensorLight < ThresholdLight && SensorColor == ThresholdColor)
//if the light sensor is off the line and the color sensor is on the line
// Bob has gone off the line on the right side
OnFwd(OUT_B, SpeedFast); //make his right motor go fast so he can get back on line
else
OnFwd(OUT_B, SpeedSlow); //otherwise keep the right motor on the slow speed
Description
OnFwd(motor, speed);
Given a specified motor and speed, this function turns the given motor
at a given speed, forward.
OnRev(motor, speed);
Given a specified motor and speed, this function turns the given motor
at a given speed, in reverse.
RotateMotor(motor,
speed and direction,
degrees);
Given a specified motor, speed and direction, and number of degrees,
this function turns the motor at a given speed and direction for a certain
number of degrees
Off(motor);
Given a specified motor, this function uses the brakes of the motor and
stops the motor;
Float(motor);
Given a specified motor, this function stops the motor without using the
brakes.
Sources:
Benedettelli, Daniele. Programming LEGO NXT Robots using NXC. 2007.
Hansen, John. Not eXactly C (NXC) Programmer’s Guide. 2007.
Sourceforge.net. Next Byte Codes & Not eXactly C. 2007.
http://bricxcc.sourceforge.net/nbc/
Excerpt from Line Finding Function:
sub FindLine(){
while(SensorLight < ThresholdLight && SensorColor != ThresholdColor){
//while both the light and color sensors are off the line
int degrees = 25;
//the set number of degrees to turn to search for the line
int i = 1; // i is the counter and the number that the degrees are multiplied
// to in order to increase the number of degrees he is turning
while(i <= 10){ //while the counter is less that or equal to 10
if(SensorLight < ThresholdLight && SensorColor != ThresholdColor){
//check to see that both sensors are off the line
RotateMotor(OUT_B, 40, degrees*i);
//if they are, rotate the motor at speed 40 for 'degrees' * i degrees
SensorLight = SensorRaw(IN_1); //update sensor values
SensorColor = SensorUS(S2);
print(SensorLight, SensorColor); //print sensor values
if (SensorLight < ThresholdLight && SensorColor != ThresholdColor){
//if the light sensor and the color sensor are off the line in either direction
Off(OUT_BC);
FindLine(); //go to FindLine() so that he can get back on the line
}
// set speed for motor 1
if (SensorColor != ThresholdColor && SensorLight > ThresholdLight)
//if the color sensor is off the line and the light sensor is on the line
//Bob has gone off the line on the left side
OnFwd(OUT_C, SpeedFast); //make his left motor go fast so he can get back on line
else
OnFwd(OUT_C, SpeedSlow); //otherwise keep the left motor at the slow speed
Function Name
}
}
}
if(SensorLight < ThresholdLight && SensorColor != ThresholdColor){
//check to see that both sensors are off the line
RotateMotor(OUT_C, -40, degrees*i);
//if they are, rotate the motor at speed 40 for 'degrees' * i degrees
}
//Once these two if statements are complete, Bob has turned back to center
//He has gone for a certain number of degrees in one direction, then
//went the same number of degrees back in the other direction
i = i + 1; //increase the counter so Bob can double the number of degrees he is turning
//this allows us to have Bob search in a wide range in case he gets off the line by a lot
//end while
// end FindLine()
© Copyright 2026 Paperzz