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

main.cpp

Committer:
njewin
Date:
2013-05-02
Revision:
3:0cfe2e18440d
Parent:
2:db3bbd57b075
Child:
4:aefc0f09fe1c

File content as of revision 3:0cfe2e18440d:

#include "mbed.h"          // MBED LIBRARY
#include "MODSERIAL.h"     // MBED BUFFERED SERIAL

#include "UM6_usart.h"     // UM6 USART HEADER
#include "UM6_config.h"    // UM6 CONFIG HEADER

LocalFileSystem local("local");               // Create the local filesystem under the name "local"

/////////////////////////////////////////////////////////////////////////////////////////////
// SETUP (ASSIGN) SERIAL COMMUNICATION PINS ON MBED
/////////////////////////////////////////////////////////////////////////////////////////////
MODSERIAL pc(USBTX, USBRX);  // PC SERIAL OVER USB PORT ON MBED

////////////////////////////////////////////////////////////////////////////////////////////////
// SETUP (ASSIGN) MBED LED (1 thru 3) FOR VISUAL DEBUGGING ON MBED
////////////////////////////////////////////////////////////////////////////////////////////////
DigitalOut pc_activity(LED1);    // LED1 = PC SERIAL
DigitalOut uart_activity(LED2);  // LED2 = UM6 SERIAL
DigitalOut logLED(LED3);  // LED3 = logging active
DigitalOut sync(p6);
DigitalIn enable(p5);    // enable signal for logging data to file

Timer t; // sets up timer for measuring data time stamp
Timer t1;// sets up timer for measuring time to read/write data

void rxCallback(MODSERIAL_IRQ_INFO *q) {
    if (um6_uart.rxBufferGetCount() >=  MAX_PACKET_DATA) {
        uart_activity = !uart_activity;  // Lights LED when uart RxBuff has > 40 bytes
        Process_um6_packet();
    }
}


int main() {


/////////////////////////////////////////////////////////////////////////////////////////////////////
//          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
    
    // attach interupt function to uart
    um6_uart.attach(&rxCallback, MODSERIAL::RxIrq);


    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\r");   // sends header to file
 
    t.start(); // start data log time
    sync = 1;
    while (enable) {
         logLED = 1; // turns LED3 on when logging starts
         wait(0.5);                
           float time1=t.read();
           float Yaw=data.Yaw;
           float Roll=data.Roll;
           float Pitch=data.Pitch;
           float GyroX=data.Gyro_Proc_X;
           float GyroY=data.Gyro_Proc_Y;
           float GyroZ=data.Gyro_Proc_Z;
           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 GPScourse=data.GPS_course;
           float GPSspeed=data.GPS_speed;
           
        //   pc.printf("time1 %3.3f s,Yaw %3.3f deg,Roll %3.3f deg,Pitch %3.3f deg",time1,Yaw,Roll,Pitch);  
           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);  
          // fprintf(fp, "%3.3f,%3.3f,%3.3f,%3.3f \n",time1,Yaw,Roll,Pitch);
          // fprintf(fp, "%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f,%3.3f\n",time1,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ);
          // 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);
           
           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;
   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);

}  // end main()