MMlab / Mbed 2 deprecated PING_ultrasonic

Dependencies:   USBDevice mbed

Revision:
8:59dd4860477f
Parent:
7:ed304ba2712a
Child:
12:36a6bae22fbf
diff -r ed304ba2712a -r 59dd4860477f main.cpp
--- a/main.cpp	Tue Sep 27 12:50:45 2016 +0000
+++ b/main.cpp	Tue Sep 27 13:42:03 2016 +0000
@@ -14,7 +14,7 @@
 int flag=0;
 float sum1=0,sum2=0,count1=0,count2=0,timecount1=0,timecount2=0,timesum1=0,timesum2=0,v,argv;
 float avg1,avg2,timeavg1,timeavg2,deltat,a,b;
-int16_t x=0,y=0,throttle = 0,rudder = 0,i=0,vmax,M_PI=3.14;
+int16_t x=0,y=0,throttle = 0,rudder = 0,i=0,vmax;
 int8_t button=0,hat = 0;
 long microsecondsToCentimeters(long microseconds);
 
@@ -27,22 +27,29 @@
 
 void output()
 {
+    timeouter1.detach();
     a=pow((avg2-avg1)/deltat*10,2);
     b=pow(0.1/deltat*1000,2);
     v=sqrt(a+b);    //|v|を求める
-    if(deltat==0){
+    if(deltat==0) {
         vmax=5;
-        }
+    }
     argv=atan(10/(avg2-avg1));  //θを求める
+
+    x = argv/3.141516*60.0;
+    y = v/5.0*240.0-120.0;
+    button=2;
     printf("\n|v|: %lf theta: %lf\n",v,argv); //最終的にだすやつ
-    x = (int)argv*M_PI/60;
-    y = (int)v/5*240-120;
-    i=2;
-    joystick.update(throttle, rudder, x, y, button, hat);
+    printf("\n x : %d y   : %d\n",x,y); //最終的にだすやつ
+    joystick.move(x, y);
+    wait_ms(10);
+    joystick.button(2);
     wait(1);
-    button = (0x0002) & 0x0F;
-
-    joystick.update(throttle, rudder, x, y, button, hat);
+    button = 0;
+    joystick.move(0, 0);
+    wait_ms(10);
+    joystick.button(0);
+    reset();
 }
 
 int main()
@@ -138,7 +145,7 @@
             deltat=timeavg2-timeavg1;   //Δtを求める
             printf("\ndeltat: %f\n",deltat);
 
-           
+
         }
         wait_ms(10);
     }