2015/05/13

Dependencies:   ADXL345 AigamozuControlPackets HMC5843 ITG3200 MBed_Adafruit-GPS-Library XBee agzIDLIST mbed

Files at this revision

API Documentation at this revision

Comitter:
kityann
Date:
Wed May 13 04:09:16 2015 +0000
Parent:
0:daab5accfd83
Commit message:
2015/05/13

Changed in this revision

AigamozuControlPackets.lib Show annotated file Show diff for this revision Revisions of this file
agz_common.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r daab5accfd83 -r b2b950b916ce AigamozuControlPackets.lib
--- a/AigamozuControlPackets.lib	Tue May 12 11:49:24 2015 +0000
+++ b/AigamozuControlPackets.lib	Wed May 13 04:09:16 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/aigamozu/code/AigamozuControlPackets/#01882120e6cf
+http://mbed.org/teams/aigamozu/code/AigamozuControlPackets/#13b24b50800e
diff -r daab5accfd83 -r b2b950b916ce agz_common.lib
--- a/agz_common.lib	Tue May 12 11:49:24 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/teams/aigamozu/code/agz_common/#14e469b0c33e
diff -r daab5accfd83 -r b2b950b916ce main.cpp
--- a/main.cpp	Tue May 12 11:49:24 2015 +0000
+++ b/main.cpp	Wed May 13 04:09:16 2015 +0000
@@ -23,7 +23,6 @@
 #include "AigamozuControlPackets.h"
 #include "agzIDLIST.h"
 #include "aigamozuSetting.h"
-#include "agz_common.h"
 #include "Kalman.h"
 
 //************ID Number*****************
@@ -31,7 +30,7 @@
 //Base    ID: 'a' ~ 'a'
 //manager ID: '0'(数字のゼロ)
 //
-const char MyID = 'D';
+const char MyID = 'd';
 //************ID Number*****************
 
 /////////////////////////////////////////
@@ -159,6 +158,53 @@
     else agz.nowStatus = GPS_UNAVAIL;
     
 } 
+  
+/////////////////////////////////////////
+//
+//Get Status
+//
+/////////////////////////////////////////
+void Get_Status(char SenderIDc,uint8_t *packetdata){
+    
+    //マネージャからデータが来たとき
+    if(SenderIDc == '0'){
+        printf("get manager Status\n");
+    }
+    //他のロボットからデータが来たとき
+    if(SenderIDc >= 'A' && SenderIDc <= 'Z'){
+        printf("get other robots Status\n");
+    }
+    //基地局からデータが来たとき
+    if(SenderIDc >= 'a' && SenderIDc <= 'z'){
+        printf("Get Base data\n");
+        int id = SenderIDc - 'a';
+        agz.reNewBasePoint(id,&packetdata[13],&packetdata[21]);
+        agz.reNewBasePointKalman(id,&packetdata[29],&packetdata[37]);
+        
+        //debug
+        for(int i = 0;i < 4;i++){
+        printf("BASE:%d\n",i);
+        printf("latitude:%f,longitude:%f\nlatitudeK:%f,longitudeK:%f\n",
+            agz.get_basePoint_lati(i),agz.get_basePoint_longi(i),
+            agz.get_basePointKalman_lati(i),agz.get_basePointKalman_longi(i)
+            );
+        }
+    }
+}
+
+/////////////////////////////////////////
+//
+//Send_Request_to_base
+//
+/////////////////////////////////////////
+void Send_Request_Base(int basenumber){
+    printf("send\n");
+    agz.createRequestCommand(MyID, basenumber);
+    //Select Destination
+    ZBTxRequest tx64request(base_Address[basenumber],agz.packetData,agz.getPacketLength());
+    //Send -> Base
+    xbee.send(tx64request);
+}
 
 
 /////////////////////////////////////////
@@ -248,9 +294,12 @@
     Adafruit_GPS myGPS(gps_Serial); 
     Timer refresh_Timer;
     const int refresh_Time = 2000; //refresh time in ms
+    Timer collect_Timer;
+    const int collect_Time = 2000; //refresh time in ms
     myGPS.begin(GPS_BAUD_RATE); 
     
     char SenderIDc;
+    int basenumber=0;
     //GPS Send Command
     myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); 
     myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
@@ -260,7 +309,8 @@
        
     //interrupt start
     refresh_Timer.start();
-
+    collect_Timer.start();
+    
     printf("start\n");
     
     while (true) {
@@ -286,6 +336,10 @@
                         Send_Status(SenderIDc);                     
                         break;          
                     }
+                    case RECEIVE_STATUS:{
+                        Get_Status(SenderIDc,buf1);
+                        break;
+                    }
                     default:{
                         break;
                     }
@@ -301,12 +355,19 @@
                 continue;   
             }       
         }
-        
-        
+        //一定時間ごとに自分のGPSデータを取得し、AigamozuControlPacketsないのagzPointとagzPointKalmanに格納する
         if (refresh_Timer.read_ms() >= refresh_Time) {
             refresh_Timer.reset();
             Get_GPS(&myGPS);
 
         }
+        
+        //一定時間ごとに基地局のGPSデータを取得し、AigamozuControlPacketsないのagzBasePointとagzBasePointKalmanに格納する
+        if (collect_Timer.read_ms() >= collect_Time) {
+            collect_Timer.reset();
+            Send_Request_Base(basenumber);
+            basenumber++;
+            if(basenumber > 4)basenumber=0;
+        }
     }
 }
\ No newline at end of file