Time is good

Dependencies:   RoboClaw mbed

Fork of Robot2016_2-0 by ARES

Revision:
100:7c7174048302
Parent:
99:1fcb088f8f36
--- a/main.cpp	Sat May 07 02:15:23 2016 +0000
+++ b/main.cpp	Tue May 31 14:24:48 2016 +0000
@@ -37,18 +37,18 @@
 DigitalIn EnL(PB_13);
 
 ControlleurPince controlleurPince(RMot, ZMot, LMot, EnR, EnZ, EnL,left_hand,right_hand);
+int SIMON_state = 's';
+Serial logger(PA_2, PA_3);
+
+void JPO(void);
 
 /* Debut du programme */
 int main(void)
 {
-    Ticker ticker;
-    Timeout end;
-    
-    ticker.attach(&Sharps, 0.01);
-    
+   
     init_globals();
     
-    if (SCouleur == VERT) {
+   /* if (SCouleur == VERT) {
         // Chateau
         end.attach(&endFonc, 90);
         GotoDist(9.0,2000,2000,2000);
@@ -98,79 +98,12 @@
         GotoThet(PI/2.f);
         GotoDist(1.75);
         controlleurPince.angle(50);
-        GotoArr(1);
-        
-    }
-    else// if (SCouleur == VIOLET)
-    {  
-    
-        // Chateau
-        end.attach(&endFonc, 90);
-        GotoDist(9.0,2000,2000,2000);
-        
-        // Callage
-        GotoArr(5);
-        R_SEUIL_SHARP = 0.25;
-        
-        // Cabane 1
-        GotoDist(1.25);
-        GotoThet(PI/2.f);
-        R_SEUIL_SHARP = 0.35;
-        GotoDist(2.75);
-        R_SEUIL_SHARP = 1;
-        controlleurPince.setPos(-1,150);
-        GotoDist(2.25);
-        
-        // Cabane 2
-        GotoArr(2);
-        R_SEUIL_SHARP = 0.35;
-        GotoThet(-PI/2.f);
-        GotoDist(1.75);
-        GotoThet(-PI/2.f);
-        GotoArr(3);
-        
-        // Coquillage 1
-        R_SEUIL_SHARP = 0.35;
-        GotoDist(3.5);
-        controlleurPince.setPos(0);
-        controlleurPince.angle(50);
-        
-        GotoThet(0.3f);
-        
-        GotoDist(2);
-        
-        controlleurPince.close();
-        controlleurPince.setPos(-1,70);
-        
-        // Coquillage 2
-        GotoThet(-PI/2.f+0.3f);
-        R_SEUIL_SHARP = 1;
-        controlleurPince.angle(50);
-        GotoDist(2);
-        controlleurPince.close();
-        
-        // Fin !!!
-        GotoThet(-PI/2.f);
-        GotoDist(1.75);
-        controlleurPince.angle(50);
-        GotoArr(1);
-    }
-   /* else {
-        GotoDistPos(200);
-        GotoThet(PI/2.f);
-        GotoDistPos(400);
-        
-        GotoThet(PI/2.f);
-        GotoThet(PI/2.f);
-        
-        GotoDistPos(400);
-        
-        GotoThet(-PI/2.f);
-        
-        GotoDistPos(200);
-        GotoThet(PI/2.f);
-        GotoThet(PI/2.f);
-    }*/
+        GotoArr(1);*/
+
+    R_SEUIL_SHARP = 0.35;
+    drapeau = 3;
+    while (1)
+       JPO();   
 
     while(1);
 }
@@ -246,3 +179,68 @@
     LEDV = 1;
     depart();
 }
+
+
+void JPO(void)
+{
+    char c = logger.getc();
+    printf("Coucou :)\n\r");
+    if(c=='z') {
+        if (SIMON_state != 1) {
+            SIMON_state = 1;
+            logger.printf("Avant (Z) \r\n");
+            roboclaw.SpeedAccelM1(accel_angle, vitesse_angle);
+            roboclaw.SpeedAccelM2(accel_angle, vitesse_angle);
+        }
+    } else if(c == 's') {
+        if (SIMON_state != 2) {
+            SIMON_state = 2;
+            logger.printf("Stop (S) \r\n");
+            roboclaw.SpeedAccelM1(accel_angle, 0);
+            roboclaw.SpeedAccelM2(accel_angle, 0);
+        }
+    } else if(c == 'd') {
+        if (SIMON_state != 3) {
+            SIMON_state = 3;
+            logger.printf("Droite (D) \r\n");
+            roboclaw.SpeedAccelM1(accel_angle, -vitesse_angle);
+            roboclaw.SpeedAccelM2(accel_angle, vitesse_angle);
+        }
+    } else if(c == 'q') {
+        if (SIMON_state != 4) {
+            SIMON_state = 4;
+            logger.printf("Gauche (Q)\r\n");
+            roboclaw.SpeedAccelM1(accel_angle, vitesse_angle);
+            roboclaw.SpeedAccelM2(accel_angle, -vitesse_angle);
+        }
+    } else if(c == 'x') {
+        if (SIMON_state != 5) {
+            SIMON_state = 5;
+            roboclaw.SpeedAccelM1(accel_angle, -vitesse_angle);
+            roboclaw.SpeedAccelM2(accel_angle, -vitesse_angle);
+        }
+    } else if (c == 'c') {
+        if (SIMON_state != 6) {
+            SIMON_state = 6;
+            
+        }
+    } else if (c == 'o') {
+        if (SIMON_state != 7) {
+            SIMON_state = 7;
+        }
+    } else if (c == 'h') {
+        if (SIMON_state != 8) {
+            SIMON_state = 8;
+        }
+    } else if (c == 'b') {
+        if (SIMON_state != 9) {
+            SIMON_state = 9;
+        }
+    }
+    else {
+        if (SIMON_state != 0) {
+            roboclaw.SpeedAccelM1M2(accel_angle, 0, 0);
+            SIMON_state = 0;
+        }
+    }
+}