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@5:b3cd0bcf2968, 2013-05-02 (annotated)
- Committer:
- njewin
- Date:
- Thu May 02 11:38:25 2013 +0000
- Revision:
- 5:b3cd0bcf2968
- Parent:
- 4:aefc0f09fe1c
- Child:
- 6:43029c69b9ac
before removing floats
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 | 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 | 5:b3cd0bcf2968 | 50 | 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 |
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 | 5:b3cd0bcf2968 | 56 | wait(0.05); |
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 | 5:b3cd0bcf2968 | 70 | // float GPSlong=data.GPS_long; |
njewin | 5:b3cd0bcf2968 | 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 | 5:b3cd0bcf2968 | 75 | // 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); |
njewin | 5:b3cd0bcf2968 | 76 | // 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); |
njewin | 5:b3cd0bcf2968 | 77 | pc.printf("time %3.3f, yaw %3.3f\n",time1,Yaw); |
njewin | 5:b3cd0bcf2968 | 78 | fprintf(fp, "%3.3f,%3.1f,%3.1f\n",time1,Yaw,GyroX); |
njewin | 3:0cfe2e18440d | 79 | pc_activity = !pc_activity; // Lights LED1 when uart RxBuff has > 40 bytes |
njewin | 3:0cfe2e18440d | 80 | |
njewin | 3:0cfe2e18440d | 81 | } // end while(1) loop |
njewin | 3:0cfe2e18440d | 82 | fprintf(fp,"%3.3f \n",t.read()); |
njewin | 3:0cfe2e18440d | 83 | sync = 0; |
njewin | 2:db3bbd57b075 | 84 | wait(0.6); // debug - hold LED on for 0.6s, even when while loop not true |
njewin | 1:20201cda90d0 | 85 | logLED = 0; // turns LED3 off when logging ends |
njewin | 1:20201cda90d0 | 86 | fclose(fp); |
lhiggs | 0:03c649c76388 | 87 | |
lhiggs | 0:03c649c76388 | 88 | } // end main() |