Vous êtes sur la page 1sur 7

Devin Rose

Nick Cowen
Sarah Yee
Be 1200
Dr. Shreve
Homework #4
Program Table
#defne EYE SENSR!2 "his defnes "he sensor is in "he #2
s#o".
#defne $E%& '&!C &his defnes "he #e(" o)"*)" as "he
mo"or in "he C o)"*)"
#defne R+,H& '&!- &his defnes "he ri.h" o)"*)" as
"he mo"or in "he - o)"*)"
#defne ,REEN /0 &his defnes .een as "he va#)e o(
/01
in#ine void se")* 23 &his is a "ask "ha" wi## s"ar" )* "he
#i.h" sensor
"ask de"ec"!.reen 23 &his is where "he *ro.ram is
s"ar"in. "o fnd "he .reen4 "his is
r)n "hro).ho)" "he who#e "ime
)n"i# "he #i.h" sensor reads .reen
in" co)n" &his crea"s a co)n"in. varia5#e
wi"hin "he *ro.ram "ask
de"ec"!.reen 23
n%wd &his wi## move "he 5o" (orward
i(2co)n"6/3 &his is "e##in. 7o) "ha" i( "he
co)n"er was .rea"er "han / "hen
"he ro5o" wo)#d s"o*.
8hi#e2"r)e3 &his wi## a##ow "he (o##owin.
*ro.ram "o r)n on#7 i( "he *revio)s
#ine is "r)e.
9#a7So)nd &his is a##owin. "he ro5o" "o make
a so)nd as soon as i" is done
S"o*-##&asks &his wi## s"o* a## o( "he ()nc"ions o(
"he ro5o" and sh)" down "he
s7s"em as soon as "he sensor has
read .reen (or a co)n" o( 6/
&ask "o)ch23 &his wi## s"ar" "he *ro.ram wi"h
)sin. "he "o)ch sensor.
2SENSR!1 :: 13 +( "he sensor :1 "hen "he *ro.ram
wi## r)n and "he *ro.ram "o ")rn
"he ro5o" aro)nd and s"ar" 5ack on
"he #ine (o##owin..
&ask fnd23 &his is a main "ask "ha" wi## he#*
fnd "he "he #ine and make s)re
"ha" i" fnds "he #ine.
&ask check23 +" ;)s" checks "o make s)re "he #ine
is "here.
&ask (o##ow 23 &his "ask a##ows "he ro5o" "o (o##ow
"he #ine is "he e7e is .rea"er "han
"he #ine va#)e.
<2'&!-C3 &his wi## s"o* "he movin. o( "he
whee#s and a##owin. "he ro5o" "o
come "o a s"o*.
FLOW CHART
THE PROGRAM
#define EYE SENSOR_2
#define LEFT OUT_C
#define RIGHT OUT_A
#define Green 57
int lineValue;
int stopValue;
int sweepDir = 1;
inline void setup()
{
SetSensorLight(IN_2);
lineValue = EYE;
lineValue += 3;
}
task detect_green(){
int count = 0;
while(true){
if (SENSOR_2>(Green-5)&&SENSOR_2<(Green+5)){
count ++ ;
OnFwd(OUT_AC, 25);
PlaySound(SOUND_UP);
}else{
count = 0;
}
if(count > 5){
Off(OUT_AC);
StopAllTasks();
}
}
}
task touch()
{
if (SENSOR_1 == 1){
OnRev(OUT_AC, 75);
Wait(500);
OnFwd(OUT_A, 75);
} Wait(850);
}
task find()
{
if(sweepDir > 0){
OnFwd(LEFT, 25*sweepDir);
OnRev(RIGHT, 25*sweepDir);
}else{
OnFwd(RIGHT, 25*sweepDir);
OnRev(LEFT, 25*sweepDir);
}
int sweepTime = 20;
while(true){
Wait(sweepTime);
sweepTime *= 2;
sweepDir *= -1;
OnFwd(LEFT, 25*sweepDir);
OnRev(RIGHT, 25*sweepDir);
}
}
task check(){
while(true){
if(EYE < lineValue){
stop find;
OnFwd(OUT_AC, 75);
}
}
}
task follow(){
OnFwd(OUT_AC, 75);
while(true){
if(EYE > lineValue){
start find;
}
}
Off(OUT_AC);
}
task main(){
setup();
start check;
start follow;
start touch;
start detect_green;
//stop check;
PlaySound(SOUND_DOWN);
}
Implementation Plan
On our bot, we used one light sensor and one touch sensor to maneuver through
the course. We programmed the bot to read a line value (black line) and keep following
that value until it reached either the green square or the wall. he green square follows
the same concept as the black line onl! we programmed our bot to stop when it reads the
value of the color "green#. We also dealt with the wall on the obstacle as we attached a
touch sensor to the front of our bot. In the coding of the bot, we told it to turn around,
detect the value of the black line again, and continue straight until it hits the green square
where it will stop again.
$ebugging Procedure
he main things we had to ad%ust and work with was getting the bot to detect a
value and stop on green and detect a value and follow the black lines. he values changed
randoml! so we had to take make sure the! fit in properl! with the code. he wa! we
fi&ed this was b! checking the value of the black '( times and taking the mean value for
it. hen we e&perimented with the interval for green. )ike the black, we tested the value
for the green sheet '( times, then took the mean value. *ssuming that the bot will see
green in between the black tape and white board, we used a counter to stop the bot on
green. hrough e&perimentation with the stop value, and the actual interval in which the
bot will read "green#, we found the most efficient interval for green to be +,-., (percent)
and that the stop value of the count would be +.

Vous aimerez peut-être aussi