A project similar to http://mbed.org/users/lhiggs/code/UM6_IMU_AHRS_2012/, where I'm trying to log data from a UM6 (CH Robotics orientation sensor) and a GPS transceiver to an sd card. I've adapted LHiggs code to include ModGPS. For sum reason a soon as I pick up a gps signal the UM6 data freezes i.e. the time and gps signals continue to print out but the UM6 signals fixes on a single value.

Dependencies:   MODGPS MODSERIAL SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
njewin
Date:
Fri Jun 07 08:49:59 2013 +0000
Parent:
9:7dcfa24d5e7a
Child:
11:2b2537dcf504
Commit message:
GPS working! printing lat/long/alt/speed/course to pc

Changed in this revision

MODGPS.lib Show annotated file Show diff for this revision Revisions of this file
UM6_config/UM6_config.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODGPS.lib	Fri Jun 07 08:49:59 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mprinke/code/MODGPS/#34a9030f27a4
--- a/UM6_config/UM6_config.h	Thu May 30 13:32:54 2013 +0000
+++ b/UM6_config/UM6_config.h	Fri Jun 07 08:49:59 2013 +0000
@@ -35,7 +35,7 @@
 // This setup makes it easy to make more data immediately available when needed - simply increase the array size, add code in
 // the firmware that writes data to the new array location, and then make updates to the firmware definition on the PC side.
 #define    CONFIG_ARRAY_SIZE        44
-#define    DATA_ARRAY_SIZE          36
+#define    DATA_ARRAY_SIZE          37
 #define    COMMAND_COUNT             9
 
 // original data array size 32
@@ -93,6 +93,7 @@
 #define    UM6_ERROR_COV_33        (DATA_REG_START_ADDRESS + 32)
 #define    UM6_GPS_LONGITUDE       (DATA_REG_START_ADDRESS + 34)
 #define    UM6_GPS_LATITUDE        (DATA_REG_START_ADDRESS + 35)
+#define    UM6_GPS_ALTITUDE        (DATA_REG_START_ADDRESS + 36)
 #define    UM6_GPS_COURSE_SPEED    (DATA_REG_START_ADDRESS + 40)
 
 
@@ -144,9 +145,9 @@
 float Yaw;
 float GPS_long;
 float GPS_lat;
+float GPS_alt;
 float GPS_course;
 float GPS_speed;
-int32_t GPS_lat_raw;
 
 };
 UM6 data;
@@ -176,6 +177,10 @@
 int32_t MY_DATA_GPS_LAT0;
 int32_t MY_DATA_GPS_LAT1;
 int32_t MY_DATA_GPS_LAT2;
+int32_t MY_DATA_GPS_ALT;
+int32_t MY_DATA_GPS_ALT0;
+int32_t MY_DATA_GPS_ALT1;
+int32_t MY_DATA_GPS_ALT2;
 int16_t MY_DATA_GPS_COURSE;
 int16_t MY_DATA_GPS_SPEED;
 
@@ -493,16 +498,29 @@
                                 //------------------------------------------------------------
                                //-------------------------------------------------------------------
                                 // GPS lat
-                               if (new_packet.address == UM6_GPS_LATITUDE) {
+                         /*      if (new_packet.address == UM6_GPS_LATITUDE) {
                                     // Latitude                                 
-                                   MY_DATA_GPS_LAT0 = (int32_t)new_packet.packet_data[0]<<24;
-                                   MY_DATA_GPS_LAT1 = (int32_t)new_packet.packet_data[1]<<16;                                 
-                                   MY_DATA_GPS_LAT2 = (int32_t)new_packet.packet_data[2]<<8;
-                                   MY_DATA_GPS_LAT = MY_DATA_GPS_LAT0|MY_DATA_GPS_LAT1|MY_DATA_GPS_LAT2|new_packet.packet_data[3];                                                                                                                                                                                                          
-                                   memcpy(&data.GPS_lat,&MY_DATA_GPS_LAT,sizeof(int));
-                                   data.GPS_lat_raw = MY_DATA_GPS_LAT;
+                                   //MY_DATA_GPS_LAT0 = (int32_t)new_packet.packet_data[0]<<24;
+                                   //MY_DATA_GPS_LAT1 = (int32_t)new_packet.packet_data[1]<<16;                                 
+                                   //MY_DATA_GPS_LAT2 = (int32_t)new_packet.packet_data[2]<<8;
+                                   //MY_DATA_GPS_LAT = MY_DATA_GPS_LAT0|MY_DATA_GPS_LAT1|MY_DATA_GPS_LAT2|new_packet.packet_data[3];                                                                                                                                                                                                          
+                                   //memcpy(&data.GPS_lat,&MY_DATA_GPS_LAT,sizeof(int));
+                                  // data.GPS_lat_raw = new_packet.packet_data[0];
                                }  
                                 //------------------------------------------------------------ 
+                                 //-------------------------------------------------------------------
+                                // GPS altitude
+                               if (new_packet.address == UM6_GPS_ALTITUDE) {
+                                    // Longitude
+                                   MY_DATA_GPS_ALT0 = (int32_t)new_packet.packet_data[0]<<24;
+                                   MY_DATA_GPS_ALT1 = (int32_t)new_packet.packet_data[1]<<16;
+                                   MY_DATA_GPS_ALT2 = (int32_t)new_packet.packet_data[2]<<8;
+                                   MY_DATA_GPS_ALT = MY_DATA_GPS_ALT0|MY_DATA_GPS_ALT1|MY_DATA_GPS_ALT2|new_packet.packet_data[3];                                                                                                                                      
+                                   memcpy(&data.GPS_alt,&MY_DATA_GPS_ALT,sizeof(int)); 
+                                 //  data.GPS_alt_raw = MY_DATA_GPS_ALT0;
+
+                               }  
+                          */      //------------------------------------------------------------
                             }    // end if(ADDRESS_TYPE_DATA)
 
 
--- a/main.cpp	Thu May 30 13:32:54 2013 +0000
+++ b/main.cpp	Fri Jun 07 08:49:59 2013 +0000
@@ -3,7 +3,7 @@
 #include "MODSERIAL.h"   
 #include "UM6_usart.h"     // UM6 USART HEADER
 #include "UM6_config.h"    // UM6 CONFIG HEADER
-
+#include "GPS.h"
 
 //------------ system and interface setup ----------------------------//
 MODSERIAL pc(USBTX, USBRX);  // sets up serial connection to pc terminal
@@ -16,6 +16,7 @@
 DigitalIn enable(p10);                 // enable logging pin
 DigitalOut sync(p11);                  // sychronization (with CAN logger) pin  
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+GPS gps(NC,p27); 
 
 // interupt function for processing uart messages --------------------//
 void rxCallback(MODSERIAL_IRQ_INFO *q) {
@@ -33,14 +34,19 @@
 
 //============= Main Program =========================================//
 int main() {
+    Ticker tick;         
+    Timer t;  
+    GPS_Time q1;
+    GPS_VTG  v1;
+    
     pc.baud(115200);       // baud rate to pc interface
     um6_uart.baud(115200); // baud rate to um6 interface
-    Ticker tick;         
-    Timer t;  
+    gps.baud(57600);
+    gps.format(8, GPS::None, 1);
     
     //---- call interrupt functions --------------------------//
     um6_uart.attach(&rxCallback, MODSERIAL::RxIrq); // attach interupt function to uart
-    tick.attach(&LogData, 0.5); // attaches LogData function to 'tick' ticker interrupt every 0.5s
+    tick.attach(&LogData, 2); // attaches LogData function to 'tick' ticker interrupt every 0.5s
     t.start(); // start logging time        
 
     //---------- setup sd card directory------------------------------// 
@@ -81,20 +87,25 @@
                         float AccelX=data.Accel_Proc_X;
                         float AccelY=data.Accel_Proc_Y;
                         float AccelZ=data.Accel_Proc_Z;
-                        float GPSlong=data.GPS_long;        // currently not reading GPS longitude correctly
-                        float GPSlat=data.GPS_lat;                   // currently not reading GPS latitude correctly
+                        double GPSlong=gps.longitude();        // currently not reading GPS longitude correctly
+                        double GPSlat=gps.latitude();                   // currently not reading GPS latitude correctly
+                        double GPSalt=gps.altitude(); 
                         float GPScourse=data.GPS_course;
                         float GPSspeed=data.GPS_speed;
-                        int32_t GPSlatR=data.GPS_lat_raw;
-                        
+                    
                         //----- print TEST signals----------------------------//
                        // fprintf(fp,"%.3f,%.2f,%.4f,%.2f \r",time,Yaw,AccelX,GPSspeed); 
-                        pc.printf("time %.3f,Yaw %f,Accel %f, Speed %f, Lat %f, Long %f, LatR %d \n",time,Yaw,AccelX,GPSspeed,GPSlat,GPSlong,GPSlatR);
+                        pc.printf("time %.3f,Yaw %f, Lat %f, Long %f, Alt %f \n",time,Yaw,GPSlat,GPSlong,GPSalt);                       
+                        gps.timeNow(&q1);
+                        pc.printf("%c %02d:%02d:%02d %02d/%02d/%04d\r\n",q1.status, q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year);                               
+                        gps.vtg(&v1);
+                        pc.printf("Speed(kph):%lf,Track(true):%lf\r\n", v1.velocity_kph(), v1.track_true());
+                        
                         //pc.printf("time %.3f,Yaw %f,Accel %f, Speed %f \n",time,Yaw,AccelX,GPSspeed);
                        // pc.printf("time %f,LongIn 0x%08X, LongOut %f\n",time,GPSlong,*(int *)&GPSlong);
         
                         //----- print ALL signals to file --------------------//  
-                        fprintf(fp, "%3.3f, %3.1f,%3.1f,%3.1f, %3.2f,%3.2f,%3.2f, %3.4f,%3.4f,%3.4f, %3.1f,%3.2f,%d,%f\r",time,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,GPScourse,GPSspeed,GPSlat,GPSlong);                             
+                 //       fprintf(fp, "%3.3f, %3.1f,%3.1f,%3.1f, %3.2f,%3.2f,%3.2f, %3.4f,%3.4f,%3.4f, %3.1f,%3.2f,%d,%f\r",time,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,GPScourse,GPSspeed,GPSlat,GPSlong);                             
                         flag=0; // reset LogData interrupt flag
                         pc_led = !pc_led;  // Lights LED1 when transmitting to PC screen   
                     }    // end if(flag=1) loop