cansat_B 2019 / Mbed 2 deprecated GPSと走行の統合 1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
saeichi
Date:
Thu Dec 05 00:17:03 2019 +0000
Parent:
5:f3b266c917a6
Commit message:
GPSGO;

Changed in this revision

TB6612.cpp Show annotated file Show diff for this revision Revisions of this file
TB6612.h Show annotated file Show diff for this revision Revisions of this file
gps.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TB6612.cpp	Thu Dec 05 00:17:03 2019 +0000
@@ -0,0 +1,57 @@
+/**
+ * Motor Driver TB6612 Control Library
+ *
+ * -- TB6612 is a device of the TOSHIBA. 
+ *
+ * Copyright (C) 2012 Junichi Katsu (JKSOFT) 
+ */
+ 
+ 
+#include "TB6612.h"
+ 
+// TB6612 Class Constructor
+TB6612::TB6612(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+ 
+    _fwd = 0;
+    _rev = 0;
+    _pwm = 0.0;
+    _pwm.period(0.001);
+}
+ 
+// Speed Control
+//  arg
+//   int speed -100 -- 0 -- 100
+void TB6612::speed(int speed) {
+        
+    if( speed > 0 )
+    {
+        _pwm = ((float)speed) / 100.0;
+        _fwd = 1;
+        _rev = 0;
+    }
+    else if( speed < 0 )
+    {
+        _pwm = -((float)speed) / 100.0;
+        _fwd = 0;
+        _rev = 1;
+    }
+    else
+    {
+        _fwd = 1;
+        _rev = 1;
+    }
+}
+ 
+ 
+// Speed Control with time-out
+//  arg
+//   int speed -100 -- 0 -- 100
+//   int time  0
+void TB6612::move(int sspeed , int time)
+{
+    speed(sspeed);
+    wait_ms(time);
+}
+ 
+            
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TB6612.h	Thu Dec 05 00:17:03 2019 +0000
@@ -0,0 +1,30 @@
+/**
+ * Motor Driver TB6612 Control Library
+ *
+ * -- TB6612 is a device of the rohm. 
+ *
+ * Copyright (C) 2012 Junichi Katsu (JKSOFT) 
+ */
+ 
+#ifndef MBED_TB6612_H
+#define MBED_TB6612_H
+ 
+#include "mbed.h"
+ 
+class TB6612 {
+public:
+    TB6612(PinName pwm, PinName fwd, PinName rev);
+    void speed(int speed);
+    void move(int speed , int time);
+    void operator= ( int value )
+    {
+        speed(value);
+    }
+    
+protected:
+    PwmOut _pwm;
+    DigitalOut _fwd;
+    DigitalOut _rev;
+};
+ 
+#endif
\ No newline at end of file
--- a/gps.cpp	Wed Nov 13 12:14:34 2019 +0000
+++ b/gps.cpp	Thu Dec 05 00:17:03 2019 +0000
@@ -1,32 +1,49 @@
 #include "mbed.h"
 #include "getGPS.h"
 #include "math.h"
+#include "TB6612.h"
 
 Serial pc(USBTX,USBRX);
 GPS gps (p28,p27);
 Serial xbee(p13,p14);
+TB6612 left(p25,p17,p16);
+TB6612 right(p26,p19,p18);
 
 
 int main() {
      double a;
      double b;
      double distance;
-    
-    pc.printf("GPS Start\n");
-    xbee.printf("s\n");
+     int i = 0;
+     
+     pc.printf("GPS Start\n");
+     xbee.printf("s\n");
      while(1) {
          if(gps.getgps()){
+           
+          pc.printf("(%lf,%lf)\r\n",gps.latitude,gps.longitude);//緯度と経度を表示   
+          i ++;
+          if(i<29){
+           }else if(i == 30){
            a = gps.latitude;
            b = gps.longitude;
            
-          pc.printf("(%lf,%lf)\r\n",gps.latitude,gps.longitude);//緯度と経度を表示   
+           }else{
            break;
-           
+           }
          }else{
           pc.printf("NO DATA\r\n");//データ取得失敗
           wait(1);
             }
        }
+       
+        left = 100; //左モーター100%
+        right = 100;//右モーター100%
+        wait(30);
+        left = 0; //左モーター10%
+        right = 0;//右モーター10%(左折)
+        wait(15);
+        
       while(1){
          if(gps.getgps()) {
            
@@ -70,6 +87,14 @@
      }
      
      
+ 
+
+ 
+
+
+
+
+