BE@R lab / Mbed 2 deprecated dog_V3_3_testmotor

Dependencies:   Communication_Robot QEI iSerial mbed motion_control

Fork of dog_V3_2_testmotor by BE@R lab

Revision:
5:f07cbb5a86c3
Parent:
4:a35291005a30
Child:
6:8d80c84e0c09
--- a/main.cpp	Wed Jul 15 08:06:00 2015 +0000
+++ b/main.cpp	Thu Jul 16 08:19:18 2015 +0000
@@ -101,6 +101,68 @@
     */
 
     /*
+        while(1) {
+            if(sw_LU_U) {
+                pc.printf("sw_LU_U = 1");
+            } else {
+                pc.printf("sw_LU_U = 0");
+            }
+
+            if(sw_LU_D) {
+                pc.printf(" sw_LU_D = 1");
+            } else {
+                pc.printf(" sw_LU_D = 0");
+            }
+            pc.printf("\n");
+    ///////////////////////////////////
+            if(sw_LL_U) {
+                pc.printf("sw_LL_U = 1");
+            } else {
+                pc.printf("sw_LL_U = 0");
+            }
+
+            if(sw_LL_D) {
+                pc.printf(" sw_LL_D = 1");
+            } else {
+                pc.printf(" sw_LL_D = 0");
+            }
+            pc.printf("\n");
+            //////////////////////////////////////
+            ///////////////////////////////////
+
+            /////////////////////
+            if(sw_RU_U) {
+                pc.printf("sw_RU_U = 1");
+            } else {
+                pc.printf("sw_RU_U = 0");
+            }
+
+            if(sw_RU_D) {
+                pc.printf(" sw_RU_D = 1");
+            } else {
+                pc.printf(" sw_RU_D = 0");
+            }
+    pc.printf("\n");
+    ///////////////////////////////////
+            if(sw_RL_U) {
+                pc.printf("sw_RL_U = 1");
+            } else {
+                pc.printf("sw_RL_U = 0");
+            }
+
+            if(sw_RL_D) {
+                pc.printf(" sw_RL_D = 1");
+            } else {
+                pc.printf(" sw_RL_D = 0");
+            }
+            //////////////////////////////////////
+    pc.printf("\n");
+    pc.printf("\n");
+            wait(1);
+        }
+    */
+
+    /*
     while(1) {
         myled =1;
         wait_ms(200);
@@ -153,7 +215,7 @@
     }
     */
 
-    //  while(1) {
+      while(1) {
     //calibration
     pc.printf("Welcome to DOGWHEELSCHAIR\n");
     pc.printf("Calibration [START]\n");
@@ -163,7 +225,7 @@
     calibration(4);
     pc.printf("Calibration [FINISH]\n");
     pc.printf("RUN mode [START]\n");
-    //   }
+       }
 
 
     uint8_t count=0;
@@ -333,7 +395,7 @@
 {
     switch(id) {
         case 1://Left Upper
-            if(sw_LU_U && sw_LU_D) {
+            if(~sw_LU_U && ~sw_LU_D) {
                 motor_set(id,dirction);
             } else {
                 motor_stop(id);
@@ -342,7 +404,7 @@
             break;
 
         case 2://Left Lowwer
-            if(sw_LL_U && sw_LL_D) {
+            if(~sw_LL_U && ~sw_LL_D) {
                 motor_set(id,dirction);
             } else {
                 motor_stop(id);
@@ -351,7 +413,7 @@
             break;
 
         case 3://Right Upper
-            if(sw_RU_U && sw_RU_D) {
+            if(~sw_RU_U && ~sw_RU_D) {
                 motor_set(id,dirction);
             } else {
                 motor_stop(id);
@@ -360,7 +422,7 @@
             break;
 
         case 4://Right Lowwer
-            if(sw_RL_U && sw_RL_D) {
+            if(~sw_RL_U && ~sw_RL_D) {
                 motor_set(id,dirction);
             } else {
                 motor_stop(id);
@@ -412,14 +474,14 @@
     switch(id) {
         case 1:
             pc.printf("motor[1] run up\n");
-            while(sw_LU_U) {
+            do {
                 motor_set(id,1);
-            }
+            } while(sw_LU_U ==0);
             pc.printf("motor[1] stop up\n");
             //wait_ms(500);
             do {
                 motor_set(id,2);
-            } while(sw_LU_U ==0);
+            } while(sw_LU_U);
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[1] read position\n");
@@ -427,13 +489,13 @@
             pc.printf("max_pos_LU= %d\n",max_pos_LU);
 
             pc.printf("motor[1] run down\n");
-            while(sw_LU_D) {
+            do {
                 motor_set(id,2);
-            }
+            } while(sw_LU_D==0) ;
             pc.printf("motor[1] stop down\n");
             do {
                 motor_set(id,1);
-            } while(sw_LU_D ==0);
+            } while(sw_LU_D);
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[1] read position\n");
@@ -444,29 +506,29 @@
         case 2:
 
             pc.printf("motor[2] run up\n");
-            while(sw_LL_U) {
+            do{
                 motor_set(id,1);
-            }
+            }while(sw_LL_U==0) ;
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[2] stop up\n");
             do {
                 motor_set(id,2);
-            } while(sw_LL_U == 0);
+            } while(sw_LL_U );
             motor_stop(id);
             wait_ms(500);
             max_pos_LL = position_LL.read_u16();
             pc.printf("max_pos_LL= %d\n",max_pos_LL);
             pc.printf("motor[2] run down\n");
-            while(sw_LL_D) {
+            do{
                 motor_set(id,2);
-            }
+            }while(sw_LL_D==0) ;
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[2] stop down\n");
             do {
                 motor_set(id,1);
-            } while(sw_LL_D == 0);
+            } while(sw_LL_D);
             motor_stop(id);
             wait_ms(500);
             min_pos_LL = position_LL.read_u16();
@@ -474,11 +536,11 @@
             break;
 
         case 3:
-            uint8_t count=1000;
+            //    uint8_t count=1000;
             pc.printf("motor[3] run up\n");
-            while(sw_RU_U) {
+            do {
                 motor_set(id,1);
-            }
+            }while(sw_RU_U==0);
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[3] stop up\n");
@@ -486,7 +548,7 @@
             do {
                 motor_set(id,2);
 
-            } while(sw_RU_U ==0);
+            } while(sw_RU_U);
             motor_stop(id);
             wait_ms(500);
             max_pos_RU = position_RU.read_u16();
@@ -501,16 +563,16 @@
                     count--;
                 }
             }*/
-            while(sw_RU_D) {
+            do {
 
                 motor_set(id,2);
-            }
+            }while(sw_RU_D==0);
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[3] stop down\n");
             do {
                 motor_set(id,1);
-            } while(sw_RU_D == 0);
+            } while(sw_RU_D);
             motor_stop(id);
             wait_ms(500);
             min_pos_RU = position_RU.read_u16();
@@ -520,29 +582,29 @@
         case 4:
 
             pc.printf("motor[4] run up\n");
-            while(sw_RL_U) {
+            do {
                 motor_set(id,1);
-            }
+            }while(sw_RL_U==0);
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[4] stop up\n");
             do {
                 motor_set(id,2);
-            } while(sw_RL_U==0);
+            } while(sw_RL_U);
             motor_stop(id);
             wait_ms(500);
             max_pos_RL = position_RL.read_u16();
             pc.printf("max_pos_RL= %d\n",max_pos_RL);
             pc.printf("motor[4] run down\n");
-            while(sw_RL_D) {
+            do{
                 motor_set(id,2);
-            }
+            }while(sw_RL_D==0);
             motor_stop(id);
             wait_ms(500);
             pc.printf("motor[4] stop down\n");
             do {
                 motor_set(id,1);
-            } while(sw_RL_D == 0);
+            } while(sw_RL_D);
             motor_stop(id);
             wait_ms(500);
             min_pos_RL = position_RL.read_u16();
@@ -551,7 +613,7 @@
     }
 
 }
-
+/*
 uint16_t convert(uint16_t data)
 {
     uint16_t ans=0;
@@ -563,5 +625,6 @@
 
     uint16_t scale(uint16_t data)
 {
-    
-}
\ No newline at end of file
+
+}
+*/
\ No newline at end of file