Professional Documents
Culture Documents
Midterm Report
Midterm Report
BE 1200 Midterm
Dr. Shreve
Team 6
BE 1200 Midterm
Dr. Shreve
Team 6
BE 1200 Midterm
Dr. Shreve
Team 6
BE 1200 Midterm
Dr. Shreve
Team 6
BE 1200 Midterm
Dr. Shreve
Team 6
BE 1200 Midterm
Dr. Shreve
3.
4.
5.
6.
7.
8.
9.
and within this function, we want to say that when the Light Sensor is placed on the
green, play a sound for 3 seconds and until the next sound is played, place it on the
next color, and then the last color. Also, we want to define the Light Sensor in input 3
on the NXT as EYE to make coding easier throughout this program.
With the Line Following task, we want the NXT to move forward on the Black Line, but
while true, if the NXT falls off track, and notices that its falling off the track (Or the
value of the Light Sensor is less than the value of the Black Line), to turn right and
turn left when the value of the Light Sensor is greater than the White value. If
everything seems to be correct with the Light Sensor values, the NXT will move
forward on the track.
Besides the NXT following the track, we want the NXT to stop on the Green Square
when the Light Sensor detects it. However, we also want the NXT to go past the
Green Square the first time around the track and stop on it the second time around
the track. In order to do that, we want the NXT to count the Green Square twice for
each time it detects it. To do this, we first compose an integer, call it green count,
and place it before the while true statement were about to have. Within the while
true statement, if the Light Sensor detects a value of between the green value minus
1 (Minimum Green Value) and the green value plus 1 (Maximum Green Value), wait
10/1000 of a second, then if the Light Sensor detects that same value in between the
minimum and maximum value of our specified values, play a sound, turn off both
motors, and begin counting increments of 1 and play a tone for each time the Light
Sensor detects green. If the green count becomes greater than or equal to 2, the NXT
will play 5 different tones for 5 seconds at 1 second for each tone, turn off both
motors, and finally stop all tasks from executing. Add the line following task in the
Precedes command within task main.
Test the program, check for errors, and record your results.
For the obstacle, we want to use the Touch Sensor, so we create a task for the Touch
Sensor that says while true, if the Touch Sensor is pressed, to stop the line follow
task, turn off both motors, play a sound to indicate the obstacle is pressed, put the
motors in reverse for a certain amount of distance, have motor A move forward and
have motor C move backwards until the Light Sensor recognizes the Black Line. This
allows the NXT to turn itself with the Ultrasonic Sensor facing the obstacle. Then once
it does recognize the Black Line, for the NXT to start the tasks for the Ultrasonic
Sensor and for the Light Sensor to count how many times it goes over the Black Line.
Add this task for the Touch Sensor to the Precedes command in task main.
Test the program, check for errors with the Touch Sensor and the reaction the NXT
does with the motor commands that were designed.
The Ultrasonic Sensor should be designed to circle the can whether its getting closer
or farther away from the can. Since we want 1 vehicle length away from the obstacle,
we define the closest distance to the obstacle as NEAR and define its value at 8cm
and for the farthest distance as FAR and its value at 18cm. This establishes a range
for the NXT to stay within when circling the obstacle. Create a task for the NXT to
circle the obstacle. So, white true, if the Ultrasonic Sensor is between the range we
defined, to have both motors move forward, but with motor C moving slightly faster,
getting closer to the obstacle. Or else, if the Ultrasonic Sensor detects that its value
is below the NEAR value, for the motor outputs to switch. In other words, both motors
will move forward, but motor A will move slightly faster instead of motor C, causing
the NXT to move away from the obstacle.
Next we construct a task for the Light Sensor to count the number of times it crosses
over the Black Line because we want the NXT to circle the obstacle twice. We
construct a code that sets an integer, well call it count, equal to 0. Then while true, if
the Light Sensors value is below the Black Lines value, begin counting increments of
1 and play a sound for each time the Light Sensor recognizes the Black Line. Then if
Team 6
BE 1200 Midterm
Dr. Shreve
7
the count becomes greater than or equal to 12, stop the ultrasonic task and exit this
line counting task to the line following task. This will allow the NXT to begin re-finding
the Black Line after it has maneuvered around the obstacle and continue with the line
following task.
10. Test the program with the updated tasks, check for any errors within the newly
written tasks, and record your results.
11. After all of these steps have been completed, youre NXT should be able to perform a
dynamic line following system, be able to detect an obstacle, maneuver around the
obstacle a certain amount of times you prefer, re-find the track and perform the line
following command, and finally either stop on the Green Square or have the NXT
make a second lap around the track and then stop on the Green Square then. If all
errors have been corrected and all results recorded, the assignment is now
completed!
Debugging Procedures:
1. The first issue that we ran into was the Ultrasonic Sensor and its task of circling the
obstacle. We added the Ultrasonic Sensor to the NXT on a vertical standpoint. That
seemed to work, but the probability of it actually working properly was very low. The
NXT would run into the obstacle and would get fastened to the obstacle itself while
the motors were running. So we reconstructed it to be placed horizontally and
because of this change, the NXT began to maneuver much better around the
obstacle without causing any unwanted collisions.
2. Second problem we faced was that the distance of what is NEAR and FAR played a
minor role in how well the NXT would maneuver around the can. If the initial distance
of the Ultrasonic Sensor was too far then the NXT would begin coasting off track and
wouldnt be able to recognize the obstacle itself. If the initial distance was too close,
the NXT would again, cause some soft of collision with the obstacle. We changed the
values a few times and found out changing them to 8cm (NEAR) and 18cm (FAR)
were suitable values for our program.
3. Another complication we dealt with was during the second lap around the track, the
task for the Touch Sensor was not being executed. When the Touch Sensor is pressed
a second time, the NXT would move forward, reverse, move forward, reverse, and
move forward again as if it were looking for a line to follow. Thus, meaning the task
for counting the number of times crossing over the Black Line was not being stopped
nor was the line following task. The answer to this fix was within the code for the line
counting itself. We had a stop command to stop the line counting itself, but in the
NXC tutorial, a task can not be stopped within itself. So we removed that stop
command, added an ExitTo(name of task) and the NXT performed the Touch Sensor
task properly. Causing the NXT to make the second lap without any errors.
4. Our final dilemma consisted of stopping on the Green Square due to the fact that the
integer count on the Green Square was random by the Light Sensors detection. Each
time we tested the program, the Light Sensor would give us different readings of how
many times it counted the Green Square, whether it was 2 or 4 times. We changed
the specified count value to 3 so that if the Green Square was counted for twice or
once at the end of the first lap, the third count would be a constant given to the Light
Sensor and the NXT would stop on the Green Square at the end of the second lap.
Team 6
BE 1200 Midterm
Dr. Shreve
Team 6
BE 1200 Midterm
Dr. Shreve
9
greencount ++ ;
PlayTone(1000, 30);
Wait(300);
}
if(greencount >= 2)
{
PlayTone(262,400);
PlayTone(294,400);
PlayTone(330,400);
PlayTone(294,400);
PlayTone(220,400);
Off(OUT_AC);
StopAllTasks();
}
}
}
}
Wait(1000);
Wait(1000);
Wait(1000);
Wait(1000);
Wait(1000);
task ultra_sound()
//Task to CIRCLE the can
{
while(true)
{
if((SensorUS(IN_4) >= NEAR) && (SensorUS(IN_4) < FAR))
//If NXT is in between the range, Turn
slightly RIGHT
{
OnFwd(OUT_A, 20);
OnFwd(OUT_C, 32);
}
else if (SensorUS(IN_4) <= NEAR)
//If NXT is too close to can, Turn slightly LEFT or away from the
can
{
OnFwd(OUT_A, 32);
OnFwd(OUT_C, 20);
}
}
}
task black_count()
//Task to re-find the Black Line and follow the Black Line
{
int count = 0;
//Set count number to 0; This will determine the number of times the NXT
goes over the Black Line
while(true)
{
if(SENSOR_3 < Black)
//If NXT goes over the Black Line, Add the number of times it
goes over each time
{
count ++ ;
PlaySound(SOUND_UP);
Wait(400);
}
if (count >= 12)
//When the count is greater than the significant number of counts specified,
STOP other tasks, START line follow task
{
StopTask(ultra_sound);
ExitTo(line_follow);
//Exits to line following task when the Black Line count is greater than 8
}
}
}
Team 6
BE 1200 Midterm
Dr. Shreve
10
task turn_around()
//Task for when the NXT hits an object, Reverse and turn LEFT
{
SetSensorTouch(IN_1);
while(true)
{
if (SENSOR_1 == 1)
//When NXT hits obstacle, Turn slightly LEFT, then Start tasks ultra
sound and refind line
{
StopTask(line_follow);
Off(OUT_AC);
PlaySound(SOUND_DOUBLE_BEEP);
OnRev(OUT_AC, 50);
Wait(350);
OnFwd(OUT_A, 25);
Wait(100);
OnRev(OUT_C, 25);
until(EYE <= Black);
StartTask(ultra_sound);
StartTask(black_count);
}
}
}
task main()
//Main Task that sets up all Sensors, variable set up, and Starts line follow and
turn around tasks
{
SetSensorLight(IN_3);
SetSensorTouch(IN_1);
SetSensorLowspeed(IN_4);
setup();
Precedes(line_follow, turn_around);
}
Programming Table:
Preprocessor Directives
EYE
NEAR
FAR
Global Variables
Team 6
BE 1200 Midterm
Dr. Shreve
11
Green
Black
White
Data value indicating the percentage of light reflected by the
White posterboard.
greencount
Variable used as a counter to sense the amount of times the bot
has passed over the green square
count
Variable used as a counter to sense the amount of times the bot
has passed over the black line while circling the can.
Tasks
Line_follow()
Task to follow the edge of the black line using the variables
BLACK and WHITE as defined in setup() function. The bot uses
both variables to correct its course if off track, otherwise,
continues in a straight line on the edge of the black line. The bot
will continue to move forward unless the if conditions are met.
If the bot goes too far left, onto the line, it will correct its course
by turning right. If the bot goes too far right, onto the
posterboard, it will correct its course by turning left. Used in the
beginning of the program after void setup() until the
turn_around() task. Continues after the black_count() task.
Ultra_sound()
black_count()
Task to turn around the edge of the can.This task uses the
preprocessor directives NEAR and FAR to circle the can, by
continuously turning slightly right if the can is in the NEAR and
FAR range. However if the can is too close, it will turn slightly
left, guiding itself away from the car. This task is stopped by the
task black_count() once the bot has circled the can twice. Task
black_count() will then exit to task line_follow().
Task to count the number of times the bot crosses over the
black line. It uses the count variable, with an initial value of 0 to
count the line, and adds each time the bot crosses the black
line. When the count is greater than the number specified, it
stops all tasks. It will then start the line_follow() task again to refind the line.
Team 6
BE 1200 Midterm
Dr. Shreve
12
turn_around()
Task to back up and turn left once the bot hits the number. This
task works with the touch sensor in port 1. When the bot hits an
obstacle, it will back up and slightly turn left. At this time it will
also start tasks ultra_sound(), and black_count(). Once task
black_count() has reached a specified number, it will exit to task
line_follow().
Functions
void_setup()
Before the main task is started, this setup gives definition to the
variables GREEN, BLACK, and WHITE. The bot is first placed
on the Green Square, where it saves the reflected light as
GREEN and plays a sound to confirm. Within three seconds,
the bot must be placed on the White posterboard, where it
saves the light reflected as WHITE, and plays a sound to
confirm. Within three seconds, the bot must be placed on the
Black line where it says the light reflected as BLACK, and plays
a sound to confirm. Within the next three seconds, the bot
executes the main task.
Testing Table:
Performance
Parameters
Testing Results
Refinements
Retest/Explanations
Adjustments
Final Results
Team 6
BE 1200 Midterm
Dr. Shreve
13
Touch Sensor Detecting Can (touching
can then reversing and
trying to detect the can
with the ultrasound
sensor)
1.
2.
3.
4.
5.
6.
7.
8.
Distance
Distance
Distance
Distance
Distance
Distance
Distance
Distance
was
was
was
was
was
was
was
was
1000.
700.
300.
100.
180.
250.
320.
350.
Overall: 100%
Overall: 62.5%
Extra Credit:
Overall: 33.33%
1. Bad, NXT doesnt turn
around after hitting the
can the second time.
2. Bad, NXT doesnt turn
around after hitting the
can the second time.
3. Good, NXT maneuvered
around the can during
second lap.
Extra Credit:
1. Added task
turnaround2 to Precedes
command.
2. Separated task
greensquare to its own
and set it from precedes.
3. Replaced
StopTask(black_hunt);
and
StartTask(line_follow);
with
ExitTo(line_follow);.
Extra Credit:
Overall: 100%
1. NXT shut down after
hitting the can (did
this several times on
3/23--too many tasks
trying to control the
bot).
2. NXT did not can
follow and ultrasound
task did not work. NXT
just started turning
without aim.
3. NXT conducted
second turn around
task properly.
Overall: 100%
Extra Credit:
1. Added ultrasound2
task.
2. Put task refind_line
(name later changed to
black_count) in task
turn_around.
Extra Credit:
Overall: 90%
1. Circles the can
infinitely.
2. Circles the can
infinitely.
3. Only circled can
Overall: 59%
Extra Credit:
Overall: 20%
1. Bad, Stops after hitting
can second time.
2. Bad, Keeps circling the
can without stopping.
Team 6
BE 1200 Midterm
Dr. Shreve
14
3. Bad, Circles can
infinitely.
4. Bad, Does not can
follow during the second
lap.
5. Good.
1. Good.
No adjustments needed.
Overall: 100%
1. Incorrect program.
2. Incorrect program.
3. Incorrect program.
4. Changed START/STOP
tasks.
5. Changed START/STOP
tasks.
6. Changed START/STOP
tasks.
7. Added count
variable so every time
light sensor noticed the
black line, NXT added 1
count.
8. No adjustments.
Overall: 100%
Overall: 100%
Overall: 62.5%
Extra Credit:
Overall: 25%
1. Bad, Cracks in line
detected as black line.
2. Bad, NXT cannot re-find
line after hitting the can.
3. Bad, Stops on black line
right after being on green
(counts the green square
twice).
4. Good.
Extra Credit:
1. Increased count
requirements to get it to
follow the line again.
2. Changed green
thresholds threshold.
3. Count value in if
statement changed.
4. Changed reversing
time to get the turn to
be. Smoother but it got
caught on the handle.
Extra Credit:
Overall: 100%
Team 6
BE 1200 Midterm
Dr. Shreve
15
Green Square - NXT will
stop on the Green
Square
Overall: 100%
Extra Credit:
Overall: 50%
1. Stopped after first
lap.
2. Did not even count
the green square a
single time during
both laps.