[[2013a/Member]] #define THRESHOLD 42 #define HIPOWER 7 #define LOWPOWER 2 #define set_power_H SetPower(OUT_AC,HIPOWER); #define set_power_L SetPower(OUT_AC,LOWPOWER); #define set_power_N SetPower(OUT_B,LOWPOWER); #define go_fwd set_power_H; OnFwd(OUT_AC); #define arm_fwd set_power_N; OnFwd(OUT_B);Wait(30);Off(OUT_B); #define arm_bwd set_power_N; OnRev(OUT_B);Wait(30);Off(OUT_B); #define turn_left1 set_power_L ;\ OnFwd(OUT_C);OnRev(OUT_A); #define turn_left0 set_power_L ;\ OnFwd(OUT_C);Off(OUT_A); #define turn_right0 set_power_L ;\ OnFwd(OUT_A);Off(OUT_C); #define turn_right1 set_power_L ;\ OnFwd(OUT_A);OnRev(OUT_C); #define STEP 1 #define nMAX 200 #define short_break Off(OUT_AC); Wait(100); #define CROSS_TIME 300 #define cross_line set_power_L;\ OnFwd(OUT_A);OnRev(OUT_C);\ Wait(CROSS_TIME);short_break; sub followline_l () { int nOnline=0; int MOVETIME; MOVETIME=0; SetSensor(SENSOR_2,SENSOR_LIGHT); PlaySound(SOUND_UP); MOVETIME=MOVETIME+600; while(nOnline < nMAX && FastTimer(0)<=MOVETIME){ if(SENSOR_2< THRESHOLD -14) { turn_right1; nOnline++; }else{ if(SENSOR_2< THRESHOLD -10){ turn_right0; }else if(SENSOR_2< THRESHOLD -7){ go_fwd; }else if(SENSOR_2< THRESHOLD -1){ turn_left0; }else{ turn_left1; } nOnline=0; } Wait(STEP*10); } } sub followline_r () { int nOnline=0; int MOVETIME; MOVETIME=0; SetSensor(SENSOR_2,SENSOR_LIGHT); MOVETIME=MOVETIME+600; PlaySound(SOUND_DOWN); while(nOnline < nMAX && FastTimer(0)<=MOVETIME){ if(SENSOR_2< THRESHOLD -14) { turn_right1; nOnline++; }else{ if(SENSOR_2< THRESHOLD -10){ turn_right0; }else if(SENSOR_2< THRESHOLD -7){ go_fwd; }else if(SENSOR_2< THRESHOLD -1){ turn_left0; }else{ turn_left1; } nOnline=0; } Wait(STEP*10); } } sub followline_l1 () { int MOVETIME; MOVETIME=0; SetSensor(SENSOR_2,SENSOR_LIGHT); MOVETIME=MOVETIME+600; PlaySound(SOUND_LOW_BEEP); while(FastTimer(0)<=MOVETIME){ if(SENSOR_2< THRESHOLD -14) { turn_left1; }else{ if(SENSOR_2< THRESHOLD -10){ turn_left0; }else if(SENSOR_2< THRESHOLD -7){ go_fwd; }else if(SENSOR_2< THRESHOLD -1){ turn_right0; }else{ turn_right1; } Wait(STEP*10); } } } sub catch_1 () { turn_right1;Wait(100); Off(OUT_AC);Wait(50); go_fwd;Wait(50); Off(OUT_AC);Wait(50); OnFwd(OUT_B);Wait(10); Off(OUT_B);Wait(10); turn_left1;Wait(100); Off(OUT_AC);Wait(50); } sub throw_1 () { OnFwd(OUT_B);Wait(20); Off(OUT_B);Wait(1); OnRev(OUT_B);Wait(50); } sub get_1() { OnFwd(OUT_B);Wait(20); Off(OUT_B);Wait(600); OnRev(OUT_B);Wait(50); } task main () { SetSensor(SENSOR_2,SENSOR_LIGHT); ClearTimer(0); int nOnline; int MOVETIME; turn_left1;Wait(200); Off(OUT_AC);Wait(10); while(FastTimer(0)<=600){ followline_l(); } Off(OUT_AC); Wait(50); PlaySound(SOUND_DOUBLE_BEEP); ClearTimer(0); OnRev(OUT_B);Wait(50); get_1(); turn_left1;Wait(50); Off(OUT_AC);Wait(50); throw_1(); while(FastTimer(0)<=600){ followline_l(); } Off(OUT_AC); Wait(50); PlaySound(SOUND_DOUBLE_BEEP); ClearTimer(0); while(FastTimer(0)<=600){ followline_l(); } Off(OUT_AC); Wait(50); PlaySound(SOUND_DOUBLE_BEEP); ClearTimer(0); while(FastTimer(0)<=600){ followline_l(); } Off(OUT_AC); Wait(50); PlaySound(SOUND_DOUBLE_BEEP); ClearTimer(0); while(FastTimer(0)<=600){ followline_l(); } Off(OUT_AC); Wait(50); PlaySound(SOUND_DOUBLE_BEEP); ClearTimer(0); turn_left1;Wait(50); throw_1(); turn_right1;Wait(100); while(FastTimer(0)<=600){ followline_l(); } Off(OUT_AC); Wait(50); PlaySound(SOUND_DOUBLE_BEEP); ClearTimer(0); catch_1(); }