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.
Fork of UM6_IMU_AHRS_2012 by
Diff: main.cpp
- Revision:
- 6:43029c69b9ac
- Parent:
- 5:b3cd0bcf2968
--- a/main.cpp Thu May 02 11:38:25 2013 +0000 +++ b/main.cpp Sat May 04 09:34:15 2013 +0000 @@ -38,13 +38,14 @@ // SET SERIAL UART BAUD RATES ///////////////////////////////////////////////////////////////////////////////////////////////////// - // set UM6 serial uart baud 9600 - um6_uart.baud(115200); - pc.baud(115200); // pc baud for UM6 to pc interface + // set UM6 serial uart baud rate + um6_uart.baud(115200); // baud rate to um6 interface + pc.baud(115200); // baud rate to pc interface // attach interupt function to uart um6_uart.attach(&rxCallback, MODSERIAL::RxIrq); + // opens file for saving data to and sets up header row FILE *fp = fopen("/local/out3.csv", "w"); // Open "out.txt" on the local file system for writing fprintf(fp, "time (s),Yaw (deg),Roll (deg),Pitch (deg),GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,GPScourse(x100 deg),GPSspeed(x100 m/s)\r"); // sends header to file @@ -53,7 +54,7 @@ sync = 1; while (enable) { logLED = 1; // turns LED3 on when logging starts - wait(0.05); + wait(0.02); float time1=t.read(); float Yaw=data.Yaw; float Roll=data.Roll; @@ -64,25 +65,24 @@ float AccelX=data.Accel_Proc_X; float AccelY=data.Accel_Proc_Y; float AccelZ=data.Accel_Proc_Z; - // float MagX=data.Mag_Proc_X; - // float MagY=data.Mag_Proc_Y; - // float MagZ=data.Mag_Proc_Z; - // float GPSlong=data.GPS_long; - // float GPSlat=data.GPS_lat; + float GPSlong=data.GPS_long; // currently I can get GPS longitude to out data + float GPSlat=data.GPS_lat; // currently I can get GPS latitude to out data float GPScourse=data.GPS_course; float GPSspeed=data.GPS_speed; - // fprintf(fp, "%3.3f, %3.1f,%3.1f,%3.1f, %4.1f,%4.1f,%4.1f, %1.3f,%1.3f,%1.3f, %4.0f,%f\n",time1,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,MagX,MagY,MagZ,GPScourse,GPSspeed); - // pc.printf("time %3.3f, yaw %3.1f,%3.1f,%3.1f, gyro %4.1f,%4.1f,%4.1f,accel %1.3f,%1.3f,%1.3f,speed %4.0f, course %5.0f\n",time1,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,MagX,MagY,MagZ,GPScourse,GPSspeed); - pc.printf("time %3.3f, yaw %3.3f\n",time1,Yaw); - fprintf(fp, "%3.3f,%3.1f,%3.1f\n",time1,Yaw,GyroX); - pc_activity = !pc_activity; // Lights LED1 when uart RxBuff has > 40 bytes + // print to file every 20ms - this is what I would idealy do but it ends up freezing on a single value + fprintf(fp, "%3.3f, %3.1f,%3.1f,%3.1f, %4.1f,%4.1f,%4.1f, %1.3f,%1.3f,%1.3f, %4.0f,%f\n",time1,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,GPScourse,GPSspeed); + + // print to screen - I use this to check that data is outputting - works fine on its own, but also freezes when above line is used + pc.printf("time %3.3f, yaw %3.1e,%3.1e,%3.1e, gyro %4.1e,%4.1e,%4.1e,accel %1.3e,%1.3e,%1.3e,speed %4.0e, course %5.0e\n",time1,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,GPScourse,GPSspeed); + + pc_activity = !pc_activity; // Lights LED1 when uart RxBuff has > 40 bytes } // end while(1) loop - fprintf(fp,"%3.3f \n",t.read()); - sync = 0; + fprintf(fp,"%3.3f \n",t.read()); // records time at end of measurement + sync = 0; // zeros synchronization digital output wait(0.6); // debug - hold LED on for 0.6s, even when while loop not true logLED = 0; // turns LED3 off when logging ends - fclose(fp); + fclose(fp); // closes log file, otherwise cannot access mbed drive } // end main() \ No newline at end of file