[[2011a]]
 #define R OUT_A
 #define L OUT_C
*受け取る [#ae92cbfe]
 #define R OUT_C
 #define L OUT_A
 #define SLIDE OUT_B
 #define RL SENSOR_1
 #define LL SENSOR_3
 #define NINETY 10
 #define isWhite >40
 #define isBlack <40
 #define ANGLE 10
 #define GOAL 500 
 #define GOAL 350 
 
 void go_straight(){
 	OnFwd (R+L);
 }

 void go_straight_s(){
	OnFwd (R+L);
	Off (R+L);
	Wait (1);
 } 

 void go_back(){
	OnRev (R+L);
 }

 void go_back_s(){
        OnRev (R+L);
        Off(R+L);
        Wait(1);
 }

 void tr(){
	OnFwd (L);
	OnRev (R);
	Off (R+L);
	Wait (1);
 }

 void tl(){
	OnFwd (R);
	OnRev (L);
	Off (R+L);
	Wait (1);
 }

 void stop_moving(){
	Off (R+L);
	Wait (100);
 }

 void out(){
	OnFwd (SLIDE);
	Wait (50);
	Off (SLIDE);
 }

 void set_in(){
	OnRev (SLIDE);
	Wait (50);
	Off (SLIDE);
 }

 task main (){
	SetSensor (RL, SENSOR_LIGHT);
	SetSensor (LL, SENSOR_LIGHT);
	
	int blackline = 0;
	while (1){
		go_straight_s();
		if (blackline >= 2) break;
		if (RL isBlack && LL isBlack){
			PlaySound (SOUND_CLICK);
			blackline++;
			while (RL isBlack || LL isBlack) go_straight_s();
		}
	}
	
	stop_moving();
        PlaySound (SOUND_CLICK);
        OnRev(R+L);
        Wait(20);
	Off (R+L);
	OnFwd(R);
	OnRev(L);
        Wait(20);
	Off (R+L);
	while (1){
		if (RL isBlack && LL isBlack) break;
	        if (RL isWhite && LL isWhite) {
                        go_back();
		} else if (RL isBlack && LL isWhite) {
			tl();
		} else if (RL isWhite && LL isBlack) {
			tr();
		}
	}
        PlaySound(SOUND_UP);
	while (1){
		stop_moving();
		SendMessage (1);
		
		tl();
		Wait (NINETY);
		stop_moving();
		
		Wait (300);
		
		tr();
		Wait (70);
		SendMessage (1);

		go_straight();
                Wait(10);
		Off (R+L);
		OnRev(L);
        	Wait(50);
		Off (R+L);
		go_straight();
                Wait(15);
		Off (R+L);

		stop_moving();		
		Wait (500);				

		OnFwd(L);
		OnRev(R);
        	Wait(20);
		Off (R+L);

		go_straight();
		Wait (GOAL);
		
		stop_moving();
		out();
		
		set_in();
		go_back();
		Wait (GOAL);
		tl();
		Wait (ANGLE);
		Wait (ANGLE);
		stop_moving();
	}
 }

*押す方 [#rdb636b7]
 #define R OUT_C
 #define L OUT_A
 #define RL SENSOR_3
 #define LL SENSOR_1
 #define isBlack <40
 #define isWhite >=40
 #define NINETY 17
 #define BALL 20

 void go_straight(){
	OnFwd (R+L);
 }

 void go_straight_s(){
	OnFwd (R+L);
	Off (R+L);
	Wait (2);	
 }

 void tr(){
	OnFwd (L);
	OnRev (R);
 }

 void tr_s(){
	OnFwd (L);
	Off (R+L);
 } 

 void tl(){
	OnFwd (R);
	OnRev (L);
 }

 void tl_s(){
	OnFwd (R);
	Off (R+L);
 }

 void stop_moving(){
	Off (R+L);
	Wait (100);
 }

 task main (){
	SetSensor (RL, SENSOR_LIGHT);
	SetSensor (LL, SENSOR_LIGHT);
	
	int blackline = 0;
	while (1){
		go_straight();
		if (blackline >= 2) break;
		if (RL isBlack && LL isBlack){
			PlaySound (SOUND_CLICK);
			blackline++;
			while (RL isBlack || LL isBlack) go_straight();
		}
	}
	stop_moving();
	// turn left
	while (1){
		if (LL isBlack) break;
		tl_s();
	}
	stop_moving();
	// should be on the line, so trace it
	while (1){
		if (RL isBlack && LL isBlack) {
			while (RL isBlack && LL isBlack) go_straight();
			break;
		}
		else if (RL isWhite && LL isWhite) go_straight();
		else if (RL isBlack && LL isWhite) tr_s();
		else if (RL isWhite && LL isBlack) tl_s();
	}
	stop_moving();
	// should be at the end of the line
	/*while (1){
		if (LL isBlack) break;
		tl();
	}*/
	tl();
	Wait (NINETY);
	stop_moving();
	
	// ready
	while (1){
		if (Message() == 1){
			Wait (300);
			go_straight();
			Wait (BALL);
			Off(R+L);
		}
		ClearMessage();
	}
	go_straight();
	//Wait (300);
        Off(R+L);
 }

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