[[2018a/Member]] [[2018a/Member]] **プログラム [#h14cdcee] *マスター [#i35369e3] #define CONN 1 // スレーブの接続番号 #define SIGNALON 11 // ハサミで持ち上げるためのメッセージ #define SIGNALOFF 12 // 缶を落とすためのメッセージ #define llt OnFwd(OUT_A,50); OnRev(OUT_C,30); Wait(1);//大きく左に回る #define lrt OnRev(OUT_A,30); OnFwd(OUT_C,50); Wait(1);//大きく右に回る #define ternleft OnFwd(OUT_A,50); OnRev(OUT_C,10);//左に回る #define ternright OnRev(OUT_A,10); OnFwd(OUT_C,50);//右に回る #define go OnFwd(OUT_A,50); OnFwd(OUT_C,50);//直進する #define back OnRev(OUT_A,50); OnRev(OUT_C,50);//後退する #define trase_R {if(SENSOR_2<36){lrt; n++;} else if(SENSOR_2<50) {go; n=0;} else {llt; n=0;}} #define trase_L {if(SENSOR_2<36){llt; n++;} else if(SENSOR_2<50) {go; n=0;} else {lrt; n=0;}} #define open RotateMotor(OUT_B,25,80); Off(OUT_B);Wait(1000); #define close RotateMotor(OUT_B,25,-80); Off(OUT_B);Wait(1000); #define UP RotateMotor(OUT_C,40,90); Off(OUT_C); Wait(1000); #define DOWN RotateMotor(OUT_C,20,-100);Off(OUT_C); Wait(1000); task main() { SetSensorLowspeed(S1); SetSensorLight(S2); int n=0; while(n<=100) { // H trase_R; } Off(OUT_AC); Wait(1000); OnFwdSync(OUT_AC, 50, 0); Wait(500); Off(OUT_AC); n=0; while(n<=100) { // s2 trase_R; } Off(OUT_AC); Wait(1000); OnFwd(OUT_AC,50); //線をまたぐ Wait(500); n=0; while(n<=90) { trase_L //L字路で止まる } Off(OUT_AC); Wait(1000); RotateMotor(OUT_A, 60, 300); Off(OUT_AC); n=0; while(n<=150) { //十字路で止まる trase_R } Off(OUT_AC); Wait(1000); RotateMotor(OUT_C, 60, 300); Off(OUT_AC); n=0; while(n<=70) { //Fで止まる trase_L } Off(OUT_AC); close; SendRemoteNumber(CONN,MAILBOX1,SIGNALON); //持ち上げる Off(OUT_ABC); Wait(3000); OnRev(OUT_AC,50); //バックで距離を取る Wait(1000); Off(OUT_AC); RotateMotorEx(OUT_AC, 75, 1860, 100, true, false); //振り返る Off(OUT_AC); n=0; while(n<=70) { //Gで止まる trase_L } Off(OUT_AC); RotateMotorEx(OUT_AC, 75, 400, -100, true, false ); Off(OUT_AC); SendRemoteNumber(CONN,MAILBOX1,SIGNALOFF); Off(OUT_ABC); Wait(3000); open; Off(OUT_ABC); Wait(3000); } *スレイブ [#l110beac] #define CONN 1 // スレーブの接続番号 #define SIGNALON 11 // ハサミで持ち上げるためのメッセージ #define SIGNALOFF 12 // 缶を落とすためのメッセージ #define llt OnFwd(OUT_A,50); OnRev(OUT_C,30); Wait(1);//大きく左に回る #define lrt OnRev(OUT_A,30); OnFwd(OUT_C,50); Wait(1);//大きく右に回る #define ternleft OnFwd(OUT_A,50); OnRev(OUT_C,10);//左に回る #define ternright OnRev(OUT_A,10); OnFwd(OUT_C,50);//右に回る #define go OnFwd(OUT_A,50); OnFwd(OUT_C,50);//直進する #define back OnRev(OUT_A,50); OnRev(OUT_C,50);//後退する #define trase_R {if(SENSOR_2<35){lrt; n++;} else if(SENSOR_2<50) {go; n=0;} else {llt; n=0;}} #define trase_L {if(SENSOR_2<35){llt; n++;} else if(SENSOR_2<50) {go; n=0;} else {lrt; n=0;}} #define open RotateMotor(OUT_B,25,85); Off(OUT_B);Wait(1000); #define close RotateMotor(OUT_B,25,-85); Off(OUT_B);Wait(1000); #define UP RotateMotor(OUT_C,40,90); Off(OUT_C); Wait(1000); #define DOWN RotateMotor(OUT_C,20,-90);Off(OUT_C); Wait(1000); task main () { int msg; // 受け取った値を格納する変数 while (true) { ReceiveRemoteNumber(MAILBOX1,true,msg); // if (msg == SIGNALON) { UP; } if (msg == SIGNALOFF) { DOWN; } } }