added serial up, down, left and right control

Dependencies:   mbed

Fork of Robot_a_cables_v3_5 by RaC2018

Files at this revision

API Documentation at this revision

Comitter:
unslaad
Date:
Tue Jun 05 07:24:15 2018 +0000
Parent:
10:fb3542f3c5e6
Commit message:
added serial up, down, left and right control

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r fb3542f3c5e6 -r 0fa23c2dab76 main.cpp
--- a/main.cpp	Mon May 28 14:18:32 2018 +0000
+++ b/main.cpp	Tue Jun 05 07:24:15 2018 +0000
@@ -141,6 +141,11 @@
     BPO.mode(PullUp);
     
     initialisation();   // Mise en mode opérationnel des moteurs
+    
+    char Xtraj[] = "0.500";
+    char Ytraj[] = "0.500";
+    char lectpc='i';
+    bool contrTraj=false;
                 
     while(1)
     {
@@ -149,10 +154,10 @@
             pc.printf("L1 = %d", l1);
             pc.printf("\t L2 = %d", l2);*/
             if(mode == DEGRAD){
-            pc.printf("mode = D");    
+            pc.printf("mode = d");    
                 }
             else if(mode == NORMAL){
-            pc.printf("mode = N");    
+            pc.printf("mode = n");    
                 }
             pc.printf(" x = %f", dx);
             pc.printf(" y = %f", dy);
@@ -165,7 +170,36 @@
         
         CYCLE_TIME = 0;  
         robot.readPosition(&dx, &dy, &mode); //read motors encoders and calculate coordinates position (x,y)
-        robot.setVelocity(joystick_x.read(),joystick_y.read(),joystick_ctr.read(), mode);   //Motors control with the joystick and with the mode we use
+        if(pc.readable()||contrTraj){
+            lectpc=pc.getc();
+            if(lectpc!='f'){
+                contrTraj=true;
+                lectpc=pc.getc();
+                if(lectpc=='h'){
+                    /*for(int i=0;i!=5;i++){
+                        Xtraj[i]=pc.getc();   
+                    }
+                    for(int i=0;i!=5;i++){
+                        Ytraj[i]=pc.getc();   
+                    }*/
+                    robot.setVelocity(0.50,0.60,0.5, mode);   //Motors control with the joystick and with the mode we use
+                };
+                if(lectpc=='b'){
+                    robot.setVelocity(0.50,0.40,0.5, mode);   //Motors control with the joystick and with the mode we use
+                };
+                if(lectpc=='g'){
+                    robot.setVelocity(0.60,0.50,0.5, mode);   //Motors control with the joystick and with the mode we use
+                };
+                if(lectpc=='d'){
+                    robot.setVelocity(0.40,0.50,0.5, mode);   //Motors control with the joystick and with the mode we use
+                };
+            }else{
+                robot.setVelocity(0.50,0.50,0.5,mode);
+                contrTraj=false;
+            }
+        }else{
+            robot.setVelocity(joystick_x.read(),joystick_y.read(),joystick_ctr.read(), mode);   //Motors control with the joystick and with the mode we use
+        }
         robot.readVelocity(&pVx, &pVy);//read velocities applied on the robot
         display_mode();     // Controle des led affichant le mode