[[戻る>2005/A6/ガイダンス]]

製作者&size(30){AI};さんです (>д<)&size(10){疲れた〜};
製作者&size(30){AI};さんです &color(green){(>д<)};&size(10){ちかれた〜};

*1つ目のRCXのプログラミング [#b6ef349c]
 #define line 47        //ライントレース用の閾値
 #define turn_time 200  //90度回る時間
 #define go_time 100
 #define box_time 50
 int move_time;
 int Mes;  //メッセージ
 int t;
 
 void turn_left(){//左折
 	OnFwd(OUT_C); OnRev(OUT_A);
 	Wait(t);
 }
 
 void turn_right(){//右折
 	OnFwd(OUT_A); OnRev(OUT_C);
 	Wait(t);
 }
 
 sub line_go(){//ライントレース(前進)
 	SetSensor(SENSOR_1,SENSOR_LIGHT);//left
 	SetSensor(SENSOR_3,SENSOR_LIGHT);//right 
 	OnFwd(OUT_A+OUT_C);
 	while(true){
 	if((SENSOR_1 <  line) && (SENSOR_3 > line)){
 		OnFwd(OUT_C);
 		Off(OUT_A);
 		until(SENSOR_1 > line);
 		}
 	if((SENSOR_1 > line) && (SENSOR_3 < line)){
 		OnFwd(OUT_A);
 		Off(OUT_C);
 		until(SENSOR_3 > line);
 		}
 	if((SENSOR_1 < line) && (SENSOR_3 < line)){
 		break;
 		}      	
 	else{
 		OnFwd(OUT_A+OUT_C);
 		}
 	}
 }
 sub line_back(){//ライントレース(後進)
 	SetSensor(SENSOR_1,SENSOR_LIGHT);//left
 	SetSensor(SENSOR_3,SENSOR_LIGHT);//right        
 	OnRev(OUT_A+OUT_C);
 	while(true){
 		if((SENSOR_1 <  line) && (SENSOR_3 > line)){
 			OnRev(OUT_C);
 			Off(OUT_A);
 			until(SENSOR_1 > line);
 		}
 	
 		if((SENSOR_1 > line) && (SENSOR_3 < line)){
 			OnRev(OUT_A);
 			Off(OUT_C);
 			until(SENSOR_3 > line);
 		}
 		
 		if((SENSOR_1 < line) && (SENSOR_3 < line)){
 			break;
 		}
 	
 		else{
 			OnRev(OUT_A+OUT_C);
 		}
 	}
 }
 sub GetMessage(){//メッセージ受信
 	while(true){
 		ClearMessage();
 		until (Message() != 0);	
 		if(Message() == 1)Mes=1;//toriawatta
 		if(Message() == 2)Mes=2;//green dayo
 		if(Message() == 3)Mes=3;//white dayo
 		if(Message() == 4)Mes=4;//brack dayo
 		}
 }
 sub bunbetu(){//箱を分別
 	repeat(3){
 		while(true){
 		ClearMessage();
 		until (Message() != 0);
 		if(Message() == 1)Mes=1;//toriawatta
 		if(Message() == 2)Mes=2;//green dayo
 		if(Message() == 3)Mes=3;//white dayo
 		if(Message() == 4)Mes=4;//brack dayo
 		}
 		if(Mes == 2){//緑     	    	
 	SetSensor(SENSOR_1,SENSOR_LIGHT);//left
 	SetSensor(SENSOR_3,SENSOR_LIGHT);//right 
 	OnFwd(OUT_A+OUT_C);
 	while(true){
 		if((SENSOR_1 <  line) && (SENSOR_3 > line)){
 			OnFwd(OUT_C);
 			Off(OUT_A);
 			until(SENSOR_1 > line);
 		}
 		if((SENSOR_1 > line) && (SENSOR_3 < line)){
 			OnFwd(OUT_A);
 			Off(OUT_C);
 			until(SENSOR_3 > line);
 		}      		
 		if((SENSOR_1 < line) && (SENSOR_3 < line)){
 			break;
 		}      	
 		else{
 			OnFwd(OUT_A+OUT_C);
 		}
 	}
 			OnFwd(OUT_A);OnRev(OUT_C);Wait(turn_time);
 			OnFwd(OUT_A+OUT_C);Wait(go_time);
 			SendMessage(5); Wait(500);//落とし終わった
 		 	OnRev(OUT_A+OUT_C);Wait(go_time);
 			OnFwd(OUT_C);  OnRev(OUT_A);Wait(turn_time);
 			
 			
 			  SetSensor(SENSOR_1,SENSOR_LIGHT);//left
 	SetSensor(SENSOR_3,SENSOR_LIGHT);//right        	
 	OnRev(OUT_A+OUT_C);      	
 	while(true){
 	if((SENSOR_1 <  line) && (SENSOR_3 > line)){
 		OnRev(OUT_C);
 		Off(OUT_A);
 		until(SENSOR_1 > line);
 		}      	
 	if((SENSOR_1 > line) && (SENSOR_3 < line)){
 		OnRev(OUT_A);
 		Off(OUT_C);
 		until(SENSOR_3 > line);
 		}     		
 	if((SENSOR_1 < line) && (SENSOR_3 < line)){
 		break;
 		}
 	else{
 		OnRev(OUT_A+OUT_C);
 		}
 		}      			
 			OnFwd(OUT_B);Wait(box_time);
 		}
 		else if(Mes == 3){//白
 			line_go();
 			line_go();
 			turn_right(turn_time);
 			OnFwd(OUT_A+OUT_C);Wait(go_time);
 			SendMessage(5); Wait(500);//落とし終わった
 			OnRev(OUT_A+OUT_C);Wait(go_time);
 			turn_left(turn_time);
 			line_back();
 			line_back();
 			OnFwd(OUT_B);Wait(box_time);
 		}
 		else if(Mes == 4){//黒
 			line_go();
 			line_go();
 			line_go();
 			turn_right(turn_time);
 			OnFwd(OUT_A+OUT_C);Wait(go_time);
 			SendMessage(5); Wait(500);//落とし終わった
 			OnRev(OUT_A+OUT_C);Wait(go_time);
 			turn_left(turn_time);
 			line_back();
 			line_back();
 			line_back();
 			OnFwd(OUT_B);Wait(box_time);
 		}
 	}
 }
 task main(){
 	SetSensor(SENSOR_1,SENSOR_LIGHT);
 	SetSensor(SENSOR_3,SENSOR_LIGHT);
 	GetMessage();
 	if(Mes==1){//箱を取り込み終わったかどうか
 		OnFwd(OUT_A+OUT_C);
 		until((SENSOR_1 < line) && (SENSOR_3 < line));
 		OnFwd(OUT_A); OnRev(OUT_C);
 		until((SENSOR_1 > line) && (SENSOR_3 > line));
 		repeat(3){
 			line_go();
 		}
 		OnFwd(OUT_A); OnRev(OUT_C);
 		Wait(turn_time);
 		OnFwd(OUT_A+OUT_C);
 		until(SENSOR_1 < line);
 		OnFwd(OUT_C); OnRev(OUT_A);
 		Wait(turn_time);
 		line_go();
 	}
 	bunbetu();
 	line_back();//go home
 	turn_left(turn_time);
 	SendMessage(6); Wait(500);//totte
 	GetMessage();
 	if(Mes==1){
 		OnFwd(OUT_A+OUT_C);
 		until((SENSOR_1 < line) && (SENSOR_3 < line));
 		OnFwd(OUT_A); OnRev(OUT_C);
 		until((SENSOR_1 > line) && (SENSOR_3 > line)); 
 		line_go();	
 		OnFwd(OUT_A); OnRev(OUT_C);
 		Wait(turn_time);
 		OnFwd(OUT_A+OUT_C);
 		until(SENSOR_1 < line);
 		OnFwd(OUT_C); OnRev(OUT_A);
 		Wait(turn_time);
 		line_go();
 	}
 	bunbetu();
 	line_back();//go home
 	turn_left(turn_time);
 }

   &color(purple){(−ο−;)};&size(10){やっと1つだよ〜};
* 2つ目のRCX [#ia97c4b6]
 #define getta_time 200//箱を取り込むまでの時間
 #define otosu_time1 200//箱を落とす時間
 #define otosu_time2 100//箱を落とす時間
 #define green_white 48//緑と白の間の値
 #define brack_green 38//黒と緑の間の値
 
 int Mes;
 
 sub Getta(){//箱の取り込み
 
 	OnFwd(OUT_A);
 	Wait(getta_time);
 	Off(OUT_A);
 	SendMessage(1);
 	}
 sub otosu(){//箱を落とす
 
 	OnRev(OUT_A);
 	Wait(otosu_time1);
 	Off(OUT_A);
 	OnFwd(OUT_C);
 	Wait(otosu_time2);
 	Off(OUT_C);
 	}
 task main(){
 
 	Getta();
 	
 	
 	while(true){
 	while(true){
 		ClearMessage();
 		until (Message() != 0);
 		
 		if(Message() == 5)Mes=5; break;//落として
 		if(Message() == 6)Mes=6; break;//取って
 		if(Message() == 7)Mes=7; break;//取って
 		}
 		
 		if(Mes==5){
 			otosu();
 			
 			}
 		if(Mes==6){
 			Getta();
 			
 			
 			}
 		if(Mes==7){
 			SetSensor(SENSOR_1,SENSOR_LIGHT);
 			
 			if((SENSOR_1 <= green_white) && (SENSOR_1 >= brack_green)){
 				SendMessage(2);Wait(500);//緑だよ
 				}
 			if(SENSOR_1 > green_white){
 				SendMessage(3);Wait(500);//白だよ
 				}
 			if(SENSOR_1 < brack_green) {
 				SendMessage(4);Wait(500);//黒だよ
 				}
 			
 			}
 		}
 }
   &color(blue){(TοT)};&size(10){ながかったよ〜};

 よろしければ感想、顔文字、暗号、何でもお書きください &size(20){&color(gray){↓(. .)↓};};
#comment

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS