Upload
rosalyn-ellis
View
217
Download
1
Tags:
Embed Size (px)
Citation preview
Purpose
•Program a robot that could follow a black line and stop when the line came to an end
•Sense the difference between the colors on ground
•Make a U-turn and to run through the path again and stop.
Resources
•Handyboard•Ac adapter•Serial connection
cables •Board connection
cable•2 LEGO motors
and finders•2 light sensors•Kit of LEGOS
Handyboard
Serial Interface board
/*Programmers: Briana Warschun, Will Gottschalk, Michaella Gaines, Erin Halseth. The robot is to follow a black curved path, make a U-turn, and return back to the starting point and stop. */void main(){ int sensor2, sensor3, flag=1, x=0, y=0; while(start_button()==0); //program waits until the start button is pressed to run program while(flag==1) { sensor2=analog(2); sensor3=analog(3); if(sensor2<200 && sensor3<200) //when both sensors see white both motors move forward at 35% power {motor(1,35); motor(3,35); } if(sensor2>200 && sensor3<200) //when sensor 2 sees black and sensor 3 sees white, turns towards the left { motor(3,80); motor(1,-25); sleep(0.1); //sleeps for 0.1 seconds } else if(sensor3>200 && sensor2<200) //when sensor 2 sees white and sensor 3 sees black, turns towards the right { motor(1,80); motor(3,-25); sleep(0.1); //sleeps for 0.1 seconds } else if(sensor2>200 && sensor3>200) //when both sensors see black, stops for 2 seconds before making a U-turn, then terminates { printf("\n sen2 %d sen3%d",analog(2),analog(3)); ao(); flag=0; x=1; } else { printf("\n sen2 %d sen3
%d",analog(2),analog(3)); } } while(x==1) {sleep(2.0); motor(3,-100); motor(1,5); sleep(1.5); ao(); x=0; y=1; } while(y==1) { sensor2=analog(2); sensor3=analog(3); if(sensor2<200 && sensor3<200) //when both sensors see white both motors move forward at 35% power {motor(1,35); motor(3,35); } if(sensor2>200 && sensor3<200) //when sensor 2 sees black and sensor 3 sees white, turns towards the left { motor(3,80); motor(1,-25); sleep(0.1); //sleeps for 0.1 seconds } else if(sensor3>200 && sensor2<200) //when sensor 2 sees white and sensor 3 sees black, turns towards the right { motor(1,80); motor(3,-25); sleep(0.1); //sleeps for 0.1 seconds } else if(sensor2>200 && sensor3>200) //when both sensors see black, stops for 2 seconds before making a U-turn, then terminates { printf("\n sen2 %d sen3 %d",analog(2),analog(3)); ao(); y=0; } else { printf("\n sen2 %d
sen3%d",analog(2),analog(3)); } }}
Procedures to Implement the Robot
Design Team
•Wheels
•Low to ground
•Wide sensors
•Light weight
•Two people per job
•Both jobs at same time
Sensorvoid main (){ while (!start_button()); //wait for start button to be pressed while (1) { printf("?\n sen3 %d?", analog (3)); //read the output from analog port 3 sleep(0.4); }}
Motorvoid main (){ int a, b, c; //declare integers a, b, and c while (start_button() ==0); //wait for start button to be pressed for ( a=0; a<=100; a=a+10) //ramp up in intervals of 10 until 100 { motor (1,a); sleep (0.5); } sleep (5.0); for (b=0; b<=100; b=b+10) //ramp down in intervals of 10 until 0 { c=100-b; motor (1,c); sleep (0.5); }}