Akihiro Nakabayashi / Mbed 2 deprecated MainBoard2018_Auto_Master_A_awasetekudsai

Dependencies:   QEI mbed

Fork of MainBoard2018_Auto_Master_A_neww by Taiki Maruyama

Revision:
13:ddd605700e8a
Parent:
10:ce0421ec431d
diff -r ce0421ec431d -r ddd605700e8a System/Process/Process.cpp
--- a/System/Process/Process.cpp	Sat Oct 06 17:05:33 2018 +0000
+++ b/System/Process/Process.cpp	Mon Oct 08 14:25:57 2018 +0000
@@ -121,7 +121,9 @@
 ////////////////
 
 //**********ライントレース変数*********
-int Point[3] = {234, 466, 590};//赤,緑,青
+int PointA[3] = {400, 700, 1000};//赤,緑,青
+int PointB[3] = {400, 700, 1000};//赤,緑,青
+int PointC[3] = {1000, 1700, 2400};//赤,緑,青
 	
 int startP = 35;
 int downP = 5;
@@ -498,7 +500,7 @@
 	if(traceon)
 	{
 		Color_changeflag();
-		if(!invationA && !invationB && !invationC && !invationD)
+		if(!invationA && !invationB && !invationC)
 		{
 		motor[TIRE_FR].dir = FOR;
 		motor[TIRE_FL].dir = FOR;
@@ -715,13 +717,14 @@
     
 	if(controller->Button.B && !color_flag)
 	{
-		traceon ^= 1;
+		traceon = true;
 		color_flag = true;
 	}
 	else if(!controller->Button.B)color_flag = false;
 	
 	if(traceon)
 	{
+		Color_changeflag();
 		if(!invationA && !compA && !invationB && !compB)
 		{
 		motor[TIRE_FR].dir = FOR;
@@ -733,9 +736,12 @@
 		motor[TIRE_FL].pwm = startP;
 		motor[TIRE_BR].pwm = startP;
 		motor[TIRE_BL].pwm = startP;
+		
+		Color_changeflag();
 		}
-	    else if(invationA && compA && !invationB && !compB)
+	    else if(invationC && compC && !invationB && !compB)
 	    {
+	    for(int i = 0; i<1000; i++){
 	    motor[TIRE_FR].dir = BRAKE;
 		motor[TIRE_FL].dir = BRAKE;
 		motor[TIRE_BR].dir = BRAKE;
@@ -745,38 +751,13 @@
 		motor[TIRE_FL].pwm = 255;
 		motor[TIRE_BR].pwm = 255;
 		motor[TIRE_BL].pwm = 255;
-		
-		wait(2);
+		}
 		
 		yokofla = true;
 		traceon = false;
 		}
-		else if(!invationA && !compA && !invationB && !compB)
-	    {
-	    motor[TIRE_FR].dir = BRAKE;
-		motor[TIRE_FL].dir = BRAKE;
-		motor[TIRE_BR].dir = BRAKE;
-		motor[TIRE_BL].dir = BRAKE;
-		
-		motor[TIRE_FR].pwm = 255;
-		motor[TIRE_FL].pwm = 255;
-		motor[TIRE_BR].pwm = 255;
-		motor[TIRE_BL].pwm = 255;
-		
-		wait(2);
-		
-		yokofla = true;
-		traceon = false;
-		}
-		else{
-		motor[TIRE_FR].dir = BRAKE;
-		motor[TIRE_FL].dir = BRAKE;
-		motor[TIRE_BR].dir = BRAKE;
-		motor[TIRE_BL].dir = BRAKE;
-		}
 	}
 	
-	pointcalculation();
 	
 	if(yokofla && !traceon)
 	{
@@ -799,7 +780,7 @@
 		boxslip = true;
 		yokofla = false;
 	}
-	else if(compA && compB)
+	else if(compA && compB && compC)
 	{
 	    motor[TIRE_FR].dir = FOR;
 		motor[TIRE_FL].dir = BACK;
@@ -813,72 +794,86 @@
 		
 		Color_changeflag();
 	}
-	else if(compA && !compB)
+	else if(invationA && invationB && invationC)
 	{
-	    motor[TIRE_FR].dir = FREE;
-		motor[TIRE_FL].dir = FOR;
-		motor[TIRE_BR].dir = BACK;
+		motor[TIRE_FR].dir = FREE;
+		motor[TIRE_FL].dir = BACK;
+		motor[TIRE_BR].dir = FOR;
 		motor[TIRE_BL].dir = FREE;
 		
+		//motor[TIRE_FR].pwm = startP;
 		motor[TIRE_FL].pwm = startP;
 		motor[TIRE_BR].pwm = startP;
-		
-		Color_changeflag();
+		//motor[TIRE_BL].pwm = startP;
 	}
-	else if(!compA && compB)
+	else if(!invationA && !invationB && !invationC)
 	{
-	    motor[TIRE_FR].dir = BACK;
+		motor[TIRE_FR].dir = FOR;
 		motor[TIRE_FL].dir = FREE;
 		motor[TIRE_BR].dir = FREE;
-		motor[TIRE_BL].dir = FOR;
+		motor[TIRE_BL].dir = BACK;
 		
 		motor[TIRE_FR].pwm = startP;
-		motor[TIRE_FL].pwm = startP;
-		motor[TIRE_BR].pwm = startP;
+		//motor[TIRE_FL].pwm = startP;
+		//motor[TIRE_BR].pwm = startP;
+		motor[TIRE_BL].pwm = startP;
+	}
+	else if(!invationA && compC && invationC)//C固定A下
+		{
+		motor[TIRE_FR].dir = BRAKE;
+		motor[TIRE_FL].dir = BRAKE;
+		motor[TIRE_BR].dir = BACK;
+		motor[TIRE_BL].dir = BACK;
+		
+		motor[TIRE_FR].pwm = 255;
+		motor[TIRE_FL].pwm = 100;
+		motor[TIRE_BR].pwm = 55;
 		motor[TIRE_BL].pwm = startP;
 		
 		Color_changeflag();
-	}
-	else if(compB && compC && (!compA || !compD))
-	{
-	    motor[TIRE_FR].dir = FOR;
+		}
+	else if(compA && compB && !invationC)//AB固定C下
+		{
+		motor[TIRE_FR].dir = FOR;
 		motor[TIRE_FL].dir = FOR;
+		motor[TIRE_BR].dir = BRAKE;
+		motor[TIRE_BL].dir = BRAKE;
+		
+		motor[TIRE_FR].pwm = 55;
+		motor[TIRE_FL].pwm = startP;
+		motor[TIRE_BR].pwm = 255;
+		motor[TIRE_BL].pwm = 100;
+		
+		Color_changeflag();
+		}
+		else if(compA && compB && !compC && invationC)//AB固定C上
+		{
+		motor[TIRE_FR].dir = BACK;
+		motor[TIRE_FL].dir = BACK;
+		motor[TIRE_BR].dir = BRAKE;
+		motor[TIRE_BL].dir = BRAKE;
+		
+		motor[TIRE_FR].pwm = startP;
+		motor[TIRE_FL].pwm = 55;
+		motor[TIRE_BR].pwm = 255;
+		motor[TIRE_BL].pwm = 100;
+		
+		Color_changeflag();
+		}
+		else if(!compA && invationA && compC)//C固定A上
+		{
+		motor[TIRE_FR].dir = BRAKE;
+		motor[TIRE_FL].dir = BRAKE;
 		motor[TIRE_BR].dir = FOR;
 		motor[TIRE_BL].dir = FOR;
 		
-		motor[TIRE_FR].pwm = startP;
-		motor[TIRE_FL].pwm = startP;
+		motor[TIRE_FR].pwm = 255;
+		motor[TIRE_FL].pwm = 100;
 		motor[TIRE_BR].pwm = startP;
-		motor[TIRE_BL].pwm = startP;
+		motor[TIRE_BL].pwm = 55;
 		
 		Color_changeflag();
-	}
-	else if(compA && compD && (!compB || !compC))
-	{
-	    motor[TIRE_FR].dir = BACK;
-		motor[TIRE_FL].dir = BACK;
-		motor[TIRE_BR].dir = BACK;
-		motor[TIRE_BL].dir = BACK;
-		
-		motor[TIRE_FR].pwm = startP;
-		motor[TIRE_FL].pwm = startP;
-		motor[TIRE_BR].pwm = startP;
-		motor[TIRE_BL].pwm = startP;
-		
-		Color_changeflag();
-	}
-	else
-	{
-		motor[TIRE_FR].dir = BRAKE;
-		motor[TIRE_FL].dir = BRAKE;
-		motor[TIRE_BR].dir = BRAKE;
-		motor[TIRE_BL].dir = BRAKE;
-		
-		motor[TIRE_FR].pwm = 255;
-		motor[TIRE_FL].pwm = 255;
-		motor[TIRE_BR].pwm = 255;
-		motor[TIRE_BL].pwm = 255;
-	}
+		}
   }
   
    if(boxslip)
@@ -1165,48 +1160,37 @@
 void Color_changeflag(){
     ColorDetection();
     
-    if(Color_A[0] > Point[0] && Color_A[1] > Point[1] && Color_A[2] > Point[2] && !compA)//白
+    if(Color_A[0] > PointA[0] && Color_A[1] > PointA[1] && Color_A[2] > PointA[2] && !compA)//白
 	{
 	invationA ^= 1;//start false,over true
 	compA = true;//on true,noon false
 	}	
-	else if(!(Color_A[0] > Point[0] && Color_A[1] > Point[1] && Color_A[2] > Point[2]))compA = false;//茶
+	else if(!(Color_A[0] > PointA[0] && Color_A[1] > PointA[1] && Color_A[2] > PointA[2]))compA = false;//茶
 	
-	if(Color_B[0] > Point[0] && Color_B[1] > Point[1] && Color_B[2] > Point[2] && !compB)//白
+	if(Color_B[0] > PointB[0] && Color_B[1] > PointB[1] && Color_B[2] > PointB[2] && !compB)//白
 	{
 	invationB ^= 1;//start false,over true
 	compB = true;//on true,noon false
 	}	
-	else if(!(Color_B[0] > Point[0] && Color_B[1] > Point[1] && Color_B[2] > Point[2]))compB = false;//茶
+	else if(!(Color_B[0] > PointB[0] && Color_B[1] > PointB[1] && Color_B[2] > PointB[2]))compB = false;//茶
 	
-	if(Color_C[0] > Point[0] && Color_C[1] > Point[1] && Color_C[2] > Point[2] && !compC)//白
+	if(Color_C[0] > PointC[0] && Color_C[1] > PointC[1] && Color_C[2] > PointC[2] && !compC)//白
 	{
 	invationC ^= 1;//start false,over true
 	compC = true;//on true,noon false
 	}	
-	else if(!(Color_C[0] > Point[0] && Color_C[1] > Point[1] && Color_C[2] > Point[2]))compC = false;//茶
-	
+	else if(!(Color_C[0] > PointC[0] && Color_C[1] > PointC[1] && Color_C[2] > PointC[2]))compC = false;//茶
+	/*
 	if(Color_D[0] > Point[0] && Color_D[1] > Point[1] && Color_D[2] > Point[2] && !compD)//白
 	{
 	invationD ^= 1;//start false,over true
 	compD = true;//on true,noon false
 	}	
 	else if(!(Color_D[0] > Point[0] && Color_D[1] > Point[1] && Color_D[2] > Point[2]))compD = false;//茶
+    */
 }
 
-void pointcalculation(){
-	ColorDetection();
-	/*if(Color_A[0] > Point[0] && Color_A[1] > Point[1] && Color_A[2] > Point[2] && !compA)//白
-	{
-	invationA ^= 1;//start false,over true
-	compA = true;//on true,noon false
-	}	
-	else if(!(Color_A[0] > Point[0] && Color_A[1] > Point[1] && Color_A[2] > Point[2]))compA = false;//茶*/
-	for(int i=0;i<3;i++){Asasult += Color_A[i]-Point[i];}
-	for(int i=0;i<3;i++){Bsasult += Color_B[i]-Point[i];}
-	for(int i=0;i<3;i++){Csasult += Color_A[i]-Point[i];}
-	for(int i=0;i<3;i++){Dsasult += Color_B[i]-Point[i];}
-}
+
 
 void BuzzerTimer_func() {
 	buzzer = !buzzer;