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
main.cpp@1:20201cda90d0, 2013-05-01 (annotated)
- Committer:
- njewin
- Date:
- Wed May 01 19:06:43 2013 +0000
- Revision:
- 1:20201cda90d0
- Parent:
- 0:03c649c76388
- Child:
- 2:db3bbd57b075
working_logUM6data_toFile;
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:20201cda90d0 | 7 | LocalFileSystem local("local"); // Create the 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 |
lhiggs | 0:03c649c76388 | 20 | |
njewin | 1:20201cda90d0 | 21 | DigitalIn enable(p5); // enable signal for logging data to file |
njewin | 1:20201cda90d0 | 22 | |
njewin | 1:20201cda90d0 | 23 | Timer t; // sets up timer 't' |
njewin | 1:20201cda90d0 | 24 | Ticker tick; // sets up ticker |
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 | |
njewin | 1:20201cda90d0 | 33 | int doRead = 0; |
njewin | 1:20201cda90d0 | 34 | |
njewin | 1:20201cda90d0 | 35 | void print_um6() { |
njewin | 1:20201cda90d0 | 36 | doRead = 1; // interupt to read signals from UM6 |
njewin | 1:20201cda90d0 | 37 | |
njewin | 1:20201cda90d0 | 38 | } |
lhiggs | 0:03c649c76388 | 39 | |
lhiggs | 0:03c649c76388 | 40 | int main() { |
lhiggs | 0:03c649c76388 | 41 | |
lhiggs | 0:03c649c76388 | 42 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
lhiggs | 0:03c649c76388 | 43 | // SET SERIAL UART BAUD RATES |
lhiggs | 0:03c649c76388 | 44 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
lhiggs | 0:03c649c76388 | 45 | |
lhiggs | 0:03c649c76388 | 46 | // set UM6 serial uart baud 9600 |
njewin | 1:20201cda90d0 | 47 | um6_uart.baud(115200); |
njewin | 1:20201cda90d0 | 48 | pc.baud(115200); // pc baud for UM6 to pc interface |
njewin | 1:20201cda90d0 | 49 | t.start(); // starts timer |
njewin | 1:20201cda90d0 | 50 | |
lhiggs | 0:03c649c76388 | 51 | // attach interupt function to uart |
lhiggs | 0:03c649c76388 | 52 | um6_uart.attach(&rxCallback, MODSERIAL::RxIrq); |
lhiggs | 0:03c649c76388 | 53 | |
njewin | 1:20201cda90d0 | 54 | tick.attach(&print_um6, 0.50); |
njewin | 1:20201cda90d0 | 55 | |
njewin | 1:20201cda90d0 | 56 | FILE *fp = fopen("/local/out3.csv", "w"); // Open "out.txt" on the local file system for writing |
njewin | 1:20201cda90d0 | 57 | fprintf(fp, "time1 (s),Yaw (deg),Roll (deg),Pitch (deg),GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,MagX,MagY,MagZ \r"); // sends header to file |
lhiggs | 0:03c649c76388 | 58 | |
njewin | 1:20201cda90d0 | 59 | while (enable) { |
njewin | 1:20201cda90d0 | 60 | logLED = 1; // turns LED3 on when logging starts |
njewin | 1:20201cda90d0 | 61 | if (doRead) { |
njewin | 1:20201cda90d0 | 62 | float time1=t.read(); |
njewin | 1:20201cda90d0 | 63 | float Yaw=data.Yaw; |
njewin | 1:20201cda90d0 | 64 | float Roll=data.Roll; |
njewin | 1:20201cda90d0 | 65 | float Pitch=data.Pitch; |
njewin | 1:20201cda90d0 | 66 | float GyroX=data.Gyro_Proc_X; |
njewin | 1:20201cda90d0 | 67 | float GyroY=data.Gyro_Proc_Y; |
njewin | 1:20201cda90d0 | 68 | float GyroZ=data.Gyro_Proc_Z; |
njewin | 1:20201cda90d0 | 69 | float AccelX=data.Accel_Proc_X; |
njewin | 1:20201cda90d0 | 70 | float AccelY=data.Accel_Proc_Y; |
njewin | 1:20201cda90d0 | 71 | float AccelZ=data.Accel_Proc_Z; |
njewin | 1:20201cda90d0 | 72 | float MagX=data.Mag_Proc_X; |
njewin | 1:20201cda90d0 | 73 | float MagY=data.Mag_Proc_Y; |
njewin | 1:20201cda90d0 | 74 | float MagZ=data.Mag_Proc_Z; |
njewin | 1:20201cda90d0 | 75 | float GPSlong=data.GPS_long; |
njewin | 1:20201cda90d0 | 76 | |
njewin | 1:20201cda90d0 | 77 | pc.printf("time1 %3.3f s,Yaw %3.3f deg,Roll %3.3f deg,Pitch %3.3f deg\n",time1,Yaw,Roll,Pitch); |
njewin | 1:20201cda90d0 | 78 | //pc.printf("time1 %3.3f s,Yaw %3.3f deg,Roll %3.3f deg,Pitch %3.3f deg, Longitude %f deg\n",time1,Yaw,Roll,Pitch,GPSlong); |
njewin | 1:20201cda90d0 | 79 | fprintf(fp, "%3.3f,%3.3f,%3.3f,%3.3f\n",time1,Yaw,Roll,Pitch); |
njewin | 1:20201cda90d0 | 80 | //%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,MagX,MagY,MagZ); |
njewin | 1:20201cda90d0 | 81 | |
njewin | 1:20201cda90d0 | 82 | pc_activity = !pc_activity; // Lights LED1 when uart RxBuff has > 40 bytes |
njewin | 1:20201cda90d0 | 83 | doRead = 0; |
lhiggs | 0:03c649c76388 | 84 | } |
njewin | 1:20201cda90d0 | 85 | |
lhiggs | 0:03c649c76388 | 86 | } // end while(1) loop |
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() |