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
Diff: main.cpp
- Revision:
- 10:d96e068f3595
- Parent:
- 9:7dcfa24d5e7a
- Child:
- 11:2b2537dcf504
diff -r 7dcfa24d5e7a -r d96e068f3595 main.cpp --- 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