Trying to log data from UM6 sensor with GPS receiver LS20031. I have two problems: - I can't log to file at a fast rate (<0.5s) without data values freezing to a fixed value. Print to pc screen it works fine. Ideally I would do this with an interrupt (e.g. ticker) so that the time of each reading is a fixed interval - I removed this as I thought this was causing the problem. - I want to record GPS lat and long. I have setup the GPS ground speed so I know the sensor are communicating. So I possibly havent set the config file to correctly interpet these two signals.

Dependencies:   MODSERIAL mbed

Fork of UM6_IMU_AHRS_2012 by lhiggs CSUM

Committer:
njewin
Date:
Thu May 02 08:52:53 2013 +0000
Revision:
4:aefc0f09fe1c
Parent:
3:0cfe2e18440d
Child:
5:b3cd0bcf2968
GPS speed and course printing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lhiggs 0:03c649c76388 1 #include "mbed.h" // MBED LIBRARY
lhiggs 0:03c649c76388 2 #include "MODSERIAL.h" // MBED BUFFERED SERIAL
lhiggs 0:03c649c76388 3
lhiggs 0:03c649c76388 4 #include "UM6_usart.h" // UM6 USART HEADER
lhiggs 0:03c649c76388 5 #include "UM6_config.h" // UM6 CONFIG HEADER
lhiggs 0:03c649c76388 6
njewin 4:aefc0f09fe1c 7 LocalFileSystem local("local"); // Create local filesystem under the name "local"
njewin 1:20201cda90d0 8
lhiggs 0:03c649c76388 9 /////////////////////////////////////////////////////////////////////////////////////////////
lhiggs 0:03c649c76388 10 // SETUP (ASSIGN) SERIAL COMMUNICATION PINS ON MBED
lhiggs 0:03c649c76388 11 /////////////////////////////////////////////////////////////////////////////////////////////
lhiggs 0:03c649c76388 12 MODSERIAL pc(USBTX, USBRX); // PC SERIAL OVER USB PORT ON MBED
lhiggs 0:03c649c76388 13
lhiggs 0:03c649c76388 14 ////////////////////////////////////////////////////////////////////////////////////////////////
lhiggs 0:03c649c76388 15 // SETUP (ASSIGN) MBED LED (1 thru 3) FOR VISUAL DEBUGGING ON MBED
lhiggs 0:03c649c76388 16 ////////////////////////////////////////////////////////////////////////////////////////////////
lhiggs 0:03c649c76388 17 DigitalOut pc_activity(LED1); // LED1 = PC SERIAL
lhiggs 0:03c649c76388 18 DigitalOut uart_activity(LED2); // LED2 = UM6 SERIAL
njewin 1:20201cda90d0 19 DigitalOut logLED(LED3); // LED3 = logging active
njewin 3:0cfe2e18440d 20 DigitalOut sync(p6);
njewin 1:20201cda90d0 21 DigitalIn enable(p5); // enable signal for logging data to file
njewin 1:20201cda90d0 22
njewin 3:0cfe2e18440d 23 Timer t; // sets up timer for measuring data time stamp
njewin 3:0cfe2e18440d 24 Timer t1;// sets up timer for measuring time to read/write data
lhiggs 0:03c649c76388 25
lhiggs 0:03c649c76388 26 void rxCallback(MODSERIAL_IRQ_INFO *q) {
lhiggs 0:03c649c76388 27 if (um6_uart.rxBufferGetCount() >= MAX_PACKET_DATA) {
lhiggs 0:03c649c76388 28 uart_activity = !uart_activity; // Lights LED when uart RxBuff has > 40 bytes
lhiggs 0:03c649c76388 29 Process_um6_packet();
lhiggs 0:03c649c76388 30 }
lhiggs 0:03c649c76388 31 }
njewin 1:20201cda90d0 32
lhiggs 0:03c649c76388 33
lhiggs 0:03c649c76388 34 int main() {
lhiggs 0:03c649c76388 35
njewin 2:db3bbd57b075 36
lhiggs 0:03c649c76388 37 /////////////////////////////////////////////////////////////////////////////////////////////////////
lhiggs 0:03c649c76388 38 // SET SERIAL UART BAUD RATES
lhiggs 0:03c649c76388 39 /////////////////////////////////////////////////////////////////////////////////////////////////////
lhiggs 0:03c649c76388 40
lhiggs 0:03c649c76388 41 // set UM6 serial uart baud 9600
njewin 1:20201cda90d0 42 um6_uart.baud(115200);
njewin 1:20201cda90d0 43 pc.baud(115200); // pc baud for UM6 to pc interface
njewin 1:20201cda90d0 44
lhiggs 0:03c649c76388 45 // attach interupt function to uart
lhiggs 0:03c649c76388 46 um6_uart.attach(&rxCallback, MODSERIAL::RxIrq);
lhiggs 0:03c649c76388 47
njewin 1:20201cda90d0 48
njewin 1:20201cda90d0 49 FILE *fp = fopen("/local/out3.csv", "w"); // Open "out.txt" on the local file system for writing
njewin 3:0cfe2e18440d 50 fprintf(fp, "time (s),Yaw (deg),Roll (deg),Pitch (deg),GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ\r"); // sends header to file
njewin 3:0cfe2e18440d 51
njewin 3:0cfe2e18440d 52 t.start(); // start data log time
njewin 3:0cfe2e18440d 53 sync = 1;
njewin 3:0cfe2e18440d 54 while (enable) {
njewin 2:db3bbd57b075 55 logLED = 1; // turns LED3 on when logging starts
njewin 3:0cfe2e18440d 56 wait(0.5);
njewin 1:20201cda90d0 57 float time1=t.read();
njewin 1:20201cda90d0 58 float Yaw=data.Yaw;
njewin 1:20201cda90d0 59 float Roll=data.Roll;
njewin 1:20201cda90d0 60 float Pitch=data.Pitch;
njewin 1:20201cda90d0 61 float GyroX=data.Gyro_Proc_X;
njewin 1:20201cda90d0 62 float GyroY=data.Gyro_Proc_Y;
njewin 1:20201cda90d0 63 float GyroZ=data.Gyro_Proc_Z;
njewin 1:20201cda90d0 64 float AccelX=data.Accel_Proc_X;
njewin 1:20201cda90d0 65 float AccelY=data.Accel_Proc_Y;
njewin 1:20201cda90d0 66 float AccelZ=data.Accel_Proc_Z;
njewin 2:db3bbd57b075 67 // float MagX=data.Mag_Proc_X;
njewin 2:db3bbd57b075 68 // float MagY=data.Mag_Proc_Y;
njewin 2:db3bbd57b075 69 // float MagZ=data.Mag_Proc_Z;
njewin 1:20201cda90d0 70 float GPSlong=data.GPS_long;
njewin 3:0cfe2e18440d 71 float GPSlat=data.GPS_lat;
njewin 3:0cfe2e18440d 72 float GPScourse=data.GPS_course;
njewin 3:0cfe2e18440d 73 float GPSspeed=data.GPS_speed;
njewin 1:20201cda90d0 74
njewin 3:0cfe2e18440d 75 // pc.printf("time1 %3.3f s,Yaw %3.3f deg,Roll %3.3f deg,Pitch %3.3f deg",time1,Yaw,Roll,Pitch);
njewin 3:0cfe2e18440d 76 pc.printf("time1 %3.3f s,Yaw %3.3f deg, Speed %f 0.01m/s,course %f 0.01m/s, long %f deg, lat %f deg\n",time1,Yaw,GPSspeed,GPScourse,GPSlong,GPSlat);
njewin 3:0cfe2e18440d 77 // fprintf(fp, "%3.3f,%3.3f,%3.3f,%3.3f \n",time1,Yaw,Roll,Pitch);
njewin 2:db3bbd57b075 78 // fprintf(fp, "%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f\n",time1,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ);
njewin 2:db3bbd57b075 79 // fprintf(fp, "%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f\n",time1,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ);
njewin 1:20201cda90d0 80
njewin 3:0cfe2e18440d 81 pc_activity = !pc_activity; // Lights LED1 when uart RxBuff has > 40 bytes
njewin 3:0cfe2e18440d 82
njewin 3:0cfe2e18440d 83 } // end while(1) loop
njewin 3:0cfe2e18440d 84 fprintf(fp,"%3.3f \n",t.read());
njewin 3:0cfe2e18440d 85 sync = 0;
njewin 2:db3bbd57b075 86 wait(0.6); // debug - hold LED on for 0.6s, even when while loop not true
njewin 1:20201cda90d0 87 logLED = 0; // turns LED3 off when logging ends
njewin 1:20201cda90d0 88 fclose(fp);
lhiggs 0:03c649c76388 89
lhiggs 0:03c649c76388 90 } // end main()