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@2:db3bbd57b075, 2013-05-01 (annotated)
- Committer:
- njewin
- Date:
- Wed May 01 23:32:16 2013 +0000
- Revision:
- 2:db3bbd57b075
- Parent:
- 1:20201cda90d0
- Child:
- 3:0cfe2e18440d
before full change from 'attach interrupt' to using 'wait'
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 | 2:db3bbd57b075 | 23 | Timer t; // sets up timer for measuring data loggin time |
njewin | 2:db3bbd57b075 | 24 | Timer t1; // sets up timer for reading data at set intervals |
njewin | 2:db3bbd57b075 | 25 | //Ticker tick; // sets up ticker |
njewin | 2:db3bbd57b075 | 26 | |
njewin | 2:db3bbd57b075 | 27 | //int doRead = 0; // ticker interupt variable |
lhiggs | 0:03c649c76388 | 28 | |
lhiggs | 0:03c649c76388 | 29 | void rxCallback(MODSERIAL_IRQ_INFO *q) { |
lhiggs | 0:03c649c76388 | 30 | if (um6_uart.rxBufferGetCount() >= MAX_PACKET_DATA) { |
lhiggs | 0:03c649c76388 | 31 | uart_activity = !uart_activity; // Lights LED when uart RxBuff has > 40 bytes |
lhiggs | 0:03c649c76388 | 32 | Process_um6_packet(); |
lhiggs | 0:03c649c76388 | 33 | } |
lhiggs | 0:03c649c76388 | 34 | } |
njewin | 1:20201cda90d0 | 35 | |
njewin | 2:db3bbd57b075 | 36 | //void print_um6() { |
njewin | 2:db3bbd57b075 | 37 | // doRead = 1; // interupt to read signals from UM6 |
njewin | 2:db3bbd57b075 | 38 | // } |
lhiggs | 0:03c649c76388 | 39 | |
lhiggs | 0:03c649c76388 | 40 | int main() { |
lhiggs | 0:03c649c76388 | 41 | |
njewin | 2:db3bbd57b075 | 42 | |
lhiggs | 0:03c649c76388 | 43 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
lhiggs | 0:03c649c76388 | 44 | // SET SERIAL UART BAUD RATES |
lhiggs | 0:03c649c76388 | 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
lhiggs | 0:03c649c76388 | 46 | |
lhiggs | 0:03c649c76388 | 47 | // set UM6 serial uart baud 9600 |
njewin | 1:20201cda90d0 | 48 | um6_uart.baud(115200); |
njewin | 1:20201cda90d0 | 49 | pc.baud(115200); // pc baud for UM6 to pc interface |
njewin | 1:20201cda90d0 | 50 | t.start(); // starts timer |
njewin | 1:20201cda90d0 | 51 | |
lhiggs | 0:03c649c76388 | 52 | // attach interupt function to uart |
lhiggs | 0:03c649c76388 | 53 | um6_uart.attach(&rxCallback, MODSERIAL::RxIrq); |
lhiggs | 0:03c649c76388 | 54 | |
njewin | 2:db3bbd57b075 | 55 | // tick.attach(&print_um6, 0.20); // ticker interupt |
njewin | 1:20201cda90d0 | 56 | |
njewin | 1:20201cda90d0 | 57 | FILE *fp = fopen("/local/out3.csv", "w"); // Open "out.txt" on the local file system for writing |
njewin | 2:db3bbd57b075 | 58 | fprintf(fp, "time1 (s),Yaw (deg),Roll (deg),Pitch (deg),GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ\r"); // sends header to file |
njewin | 2:db3bbd57b075 | 59 | |
njewin | 2:db3bbd57b075 | 60 | int n = 0; // while loop counter |
lhiggs | 0:03c649c76388 | 61 | |
njewin | 2:db3bbd57b075 | 62 | while (n < 10) { |
njewin | 2:db3bbd57b075 | 63 | logLED = 1; // turns LED3 on when logging starts |
njewin | 2:db3bbd57b075 | 64 | t1.start(); |
njewin | 2:db3bbd57b075 | 65 | wait(0.5); |
njewin | 2:db3bbd57b075 | 66 | if (t1 > 0.5) { |
njewin | 1:20201cda90d0 | 67 | float time1=t.read(); |
njewin | 1:20201cda90d0 | 68 | float Yaw=data.Yaw; |
njewin | 1:20201cda90d0 | 69 | float Roll=data.Roll; |
njewin | 1:20201cda90d0 | 70 | float Pitch=data.Pitch; |
njewin | 1:20201cda90d0 | 71 | float GyroX=data.Gyro_Proc_X; |
njewin | 1:20201cda90d0 | 72 | float GyroY=data.Gyro_Proc_Y; |
njewin | 1:20201cda90d0 | 73 | float GyroZ=data.Gyro_Proc_Z; |
njewin | 1:20201cda90d0 | 74 | float AccelX=data.Accel_Proc_X; |
njewin | 1:20201cda90d0 | 75 | float AccelY=data.Accel_Proc_Y; |
njewin | 1:20201cda90d0 | 76 | float AccelZ=data.Accel_Proc_Z; |
njewin | 2:db3bbd57b075 | 77 | // float MagX=data.Mag_Proc_X; |
njewin | 2:db3bbd57b075 | 78 | // float MagY=data.Mag_Proc_Y; |
njewin | 2:db3bbd57b075 | 79 | // float MagZ=data.Mag_Proc_Z; |
njewin | 1:20201cda90d0 | 80 | float GPSlong=data.GPS_long; |
njewin | 1:20201cda90d0 | 81 | |
njewin | 1:20201cda90d0 | 82 | pc.printf("time1 %3.3f s,Yaw %3.3f deg,Roll %3.3f deg,Pitch %3.3f deg\n",time1,Yaw,Roll,Pitch); |
njewin | 2:db3bbd57b075 | 83 | //pc.printf("time1 %3.3f s,Yaw %3.3f deg,Rol l %3.3f deg,Pitch %3.3f deg, Longitude %f deg\n",time1,Yaw,Roll,Pitch,GPSlong); |
njewin | 1:20201cda90d0 | 84 | fprintf(fp, "%3.3f,%3.3f,%3.3f,%3.3f\n",time1,Yaw,Roll,Pitch); |
njewin | 2:db3bbd57b075 | 85 | // 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 | 86 | // 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 | 87 | |
njewin | 1:20201cda90d0 | 88 | pc_activity = !pc_activity; // Lights LED1 when uart RxBuff has > 40 bytes |
njewin | 2:db3bbd57b075 | 89 | // doRead = 0; // reset ticker interupt variable |
njewin | 2:db3bbd57b075 | 90 | t1.reset(); |
njewin | 2:db3bbd57b075 | 91 | n++; |
lhiggs | 0:03c649c76388 | 92 | } |
njewin | 2:db3bbd57b075 | 93 | } // end while(1) loopn |
njewin | 2:db3bbd57b075 | 94 | wait(0.6); // debug - hold LED on for 0.6s, even when while loop not true |
njewin | 1:20201cda90d0 | 95 | logLED = 0; // turns LED3 off when logging ends |
njewin | 1:20201cda90d0 | 96 | fclose(fp); |
lhiggs | 0:03c649c76388 | 97 | |
lhiggs | 0:03c649c76388 | 98 | } // end main() |