Unko buriburi

Dependencies:   mbed PS_PAD

Revision:
1:aec7284f51de
Parent:
0:dfd7b420339f
Child:
2:61693469fd81
diff -r dfd7b420339f -r aec7284f51de main.cpp
--- a/main.cpp	Wed Aug 26 08:22:16 2020 +0000
+++ b/main.cpp	Sat Sep 05 09:16:52 2020 +0000
@@ -27,10 +27,16 @@
             b = 0;
         }else {
             a = 0;
-            b = duty > -1 ? -duty : -1;
+            b = duty > -1 ? -duty : 1;
         }
         return *this;
     }
+      operator double() {
+        if(a > 0)
+            return (double)a;
+        else
+            return -(double)b;
+    }
 };
 
 
@@ -46,72 +52,59 @@
 
 int main() {
     vsc3.init();
-    double movey = 0, turn = 0;
+    double movery = 0, movely = 0 , speed = 1 ;
     printf("START\n");
     
     while(1) {
         vsc3.poll();
-        if (vsc3.read(PS_PAD::PAD_TOP)){
-            movey = -1;
-        }else if(vsc3.read(PS_PAD::PAD_BOTTOM)){
-            movey = 1;
-        }else if(abs(vsc3.read(PS_PAD::ANALOG_LY)) > 10){
-            movey = (vsc3.read(PS_PAD::ANALOG_LY)) / 128.0;
+        
+        if(abs(vsc3.read(PS_PAD::ANALOG_RY)) > 10){
+            movery = (vsc3.read(PS_PAD::ANALOG_RY)) / 284.4 ;
+        }else{
+            movery = 0;
+        }
+         if(abs(vsc3.read(PS_PAD::ANALOG_LY)) > 10){
+            movely = (vsc3.read(PS_PAD::ANALOG_LY)) / 284.4 ;
         }else{
-            movey = 0;
+            movely = 0;
+        }
+        rmotor = movery;      //move
+        lmotor = movely;
+        
+        /* paper makiage*/
+        
+        if (vsc3.read(PS_PAD::PAD_SQUARE)/* && lim[2] == 0*/){
+            sxmotor = speed;
+        }else if (vsc3.read(PS_PAD::PAD_X) /*&& lim[3] == 0*/){
+                  sxmotor = -speed;
+        }else{
+            sxmotor = 0;
+        }        
+        
+        /* fan right */
+        if (vsc3.read(PS_PAD::PAD_L1) /*&& lim[4] == 0*/){
+            tsmotor = speed;
+        }else{
+            tsmotor = 0;
         }
                
-        if (vsc3.read(PS_PAD::PAD_RIGHT)){
-            turn = -1;
-        }else if(PS_PAD::PAD_LEFT){
-            turn = 1;
-        }else if(abs(vsc3.read(PS_PAD::ANALOG_LX)) > 10){
-            turn = (vsc3.read(PS_PAD::ANALOG_LX)) / 128.0;
-        }else{
-            turn = 0;
-        }
-        
-        rmotor = -movey+turn;      //move
-        lmotor = -movey-turn;
-        
-        if (vsc3.read(PS_PAD::PAD_CIRCLE) && lim[0] == 0){        //limitswitch
-            sxmotor = 1;
-        }else if(vsc3.read(PS_PAD::PAD_X) && lim[1] == 0){
-            sxmotor = -1;
-        }else if(vsc3.read(PS_PAD::PAD_CIRCLE) && vsc3.read(PS_PAD::PAD_X)){
-            sxmotor = 0;
-        }else{
-            sxmotor = 0;
-        }
-        
-        if (vsc3.read(PS_PAD::PAD_TRIANGLE) && lim[2] == 0){
-            tsmotor = 1;
-        }else if(vsc3.read(PS_PAD::PAD_SQUARE) && lim[3] == 0){
-            tsmotor = -1;
-        }else if(vsc3.read(PS_PAD::PAD_TRIANGLE) && vsc3.read(PS_PAD::PAD_SQUARE)){
-            tsmotor = 0;
-        }else{
-            tsmotor = 0;
-        }        
-        
-        if (vsc3.read(PS_PAD::PAD_R1) && lim[4] == 0){
-            trmotor = 1;
-        }else if(vsc3.read(PS_PAD::PAD_R2) && lim[5] == 0){
-            trmotor = -1;
-        }else if(vsc3.read(PS_PAD::PAD_R1) && vsc3.read(PS_PAD::PAD_R2)){
-            trmotor = 0;
+        /* fan left */ 
+        if (vsc3.read(PS_PAD::PAD_R1) /*&& lim[6] == 0*/){
+            trmotor = speed;
         }else{
             trmotor = 0;
         }
-                
-        if (vsc3.read(PS_PAD::PAD_L1) && lim[6] == 0){
-            tlmotor = 1;
-        }else if(vsc3.read(PS_PAD::PAD_L2) && lim[7] == 0){
-            tlmotor = -1;
-        }else if(vsc3.read(PS_PAD::PAD_L1) && vsc3.read(PS_PAD::PAD_L2)){
-            tlmotor = 0;
-        }else{
-            tlmotor = 0;
+        
+        /*fan makiage double*/
+         if (vsc3.read(PS_PAD::PAD_L1)&& vsc3.read(PS_PAD::PAD_R1)&& vsc3.read(PS_PAD::PAD_SQUARE)/*&& lim[4] == 0*/){
+            tsmotor = 0.5;
+            trmotor = 0.5;
+            sxmotor = speed;
+        }
+         if (vsc3.read(PS_PAD::PAD_L1)&& vsc3.read(PS_PAD::PAD_R1)&& vsc3.read(PS_PAD::PAD_X)/*&& lim[4] == 0*/){
+            tsmotor = 0.5;
+            trmotor = 0.5;
+            sxmotor = -speed;
         }
         
         wait(0.05);