Midterm Final
Midterm Final
Fadi Basheer
Chris Mann
John Heinonen
BE 1200 Prof. Gina Shreve
Midterm Report
1. Clarify Objectives
#define EYE
#define LEFT
#define RIGHT
#define TOO_DARK
#define TOO_BRIGHT
main ()
Definitions
This defines SENSOR_1 as EYE
This defines OUT_C the name LEFT
This defines OUT_A the name RIGHT
This defines TOO_DARK as the
constant value of 48
This defines TOO_BRIGHT as the
constant value of 69
Tasks
This tasks strats the line following and
bump tasks, as well as sets the input
for the ultrasonic sensor
line_follow ()
ultrasonic ()
green ()
line count ()
bump ()
timer()
Pictures:
Video:
The video will be posted on the website.
Refine and Optimize Design:
While constructing the robot, there was few changes that had to be made;
however, the biggest change had to be moving the ultrasonic sensor lower on the robot.
When the ultrasonic sensor was moved lower, it was positioned at a different angle
which made the detection of the barrier a lot easier than it was. The ultrasonic sensor
was really high on the robot, and we moved it a lot lower near the wheels of the robot
which made it easier for detection.
Advanced Strategies:
The main advanced strategy that was used for this robot was using the ultrasonic
sensor. Even though it was used by many students, it was a difficult sensor to use
since there was not a lot of knowledge about it. After reading the NXT tutorial, it was
easier to get an idea of. Ultimately, it was the main reason why the robot was able to
detect the barrier and go around it.
Data Table:
1
Changes
The wait time on
multiple OnRev
and OnFwd codes.
Adjusting the light
sensor on the
robot to get it to
detect the line.
Placing the
ultrasonic sensor
lower on the robot.
Getting the right
speed values for
the motors as it
went around the
barrier.
Inserted a line
count program to
get the robot to
continue following
the line after
circling the barrier.
Making the robot
turn to the left to
follow the line after
circling barrier.
New Result
During multiple parts of the project, changing the wait time
allowed the robots to act on different functions during
appropriate times. This allowed the robot to get around
the track.
By lowering the light sensor, the robot was able to follow
the line better and not stop on random places on the track.
It was easier for the robot to detect different colors as well
in this case
This was one of the biggest issues as the ultrasonic
sensor would not detect the barrier. After moving the
ultrasonic sensor lower, the sensor detected the barrier
much easier than when it was higher on the robot.
This was also a tough challenge because the motors had
to rotate at a certain value in order to keep the robot in an
even circle around the barrier. We used multiple values to
finally perfect the speed for each motor around the barrier.
Prior to this, the robot could not keep track of the line that
it was following. This function allowed the robot to count
the lines and after passing the line a certain of times, it
continued the following the line.
10
Changing the
distance the robot
would be turning
around barrier.
Adding on Off
function to get the
robot to stop
immediately at
green when it
approaches it.
Added a timer
code to skip the
green square
once.
Increased the
frequency on the
Playtone.
Flowchart:
task line_count();
task ultrasonic();
task green();
task bump();
task timer();
task line_follow(){
SetSensorLight(IN_1);
OnFwd(OUT_AC, 75);
while(true){
if(EYE <= TOO_DARK){
Off(LEFT);
OnFwd(RIGHT, 75);
}else if(EYE >= TOO_BRIGHT){
Off(RIGHT);
OnFwd(LEFT, 75);
}else{
OnFwd(OUT_AC, 75);
}
}
}
task ultrasonic()
{
while(true){
if(SensorUS(IN_4) > 12) {
OnFwd(OUT_C, 40);
OnFwd(OUT_A, 30);
}
else if(SensorUS(IN_4) < 9){
OnFwd (OUT_A, 40);
OnFwd(OUT_C, 30);
}
else{
OnFwd(OUT_AC, 50);
}
}
task timer()
{
long t0, time;
t0 = CurrentTick();
do
{
time = CurrentTick()-t0;
}
while (time<160000);
StartTask(green);
}
task green()
{
while(true)
if(EYE >=59 && EYE <=62){
//
OnFwd(OUT_AC,40);
Wait(50);
Off(OUT_AC);
StopTask(line_follow);
StopTask(ultrasonic);
StopTask(bump);
StopTask(line_count);
Off(OUT_AC);
PlayTone(1900,6000);
Wait(6000);
break;
}
}
}
task line_count()
{
int count = 0;
while(true){
if(SENSOR_1 < TOO_DARK){
count ++ ;
Wait(400);
}
if (count >= 5){
OnRev(OUT_C, 75);
Off(OUT_A);
StopTask(ultrasonic);
OnRev(OUT_C, 75);
Off(OUT_A);
Wait(700);
StartTask(line_follow);
break;
}
}
}
task bump(){
SetSensorTouch(IN_2);
while(true){
if(SENSOR_2 == 0)
{
StopTask(line_follow);
StopTask(ultrasonic);
Off(OUT_AC);
OnRev(OUT_AC, 75);
Wait(300);
Off(OUT_AC);
OnFwd(OUT_A, 75);
Wait(600);
StartTask(ultrasonic);
StartTask(line_count);
}
}
}
task main(){
start line_follow;
start bump;
start timer;
//
start ultrasonic;
//
start line_count;
SetSensorLowspeed(IN_4);
}