Prints signals from UM6 orientation sensor (CH Robotics) and GPS receiver, using MODSerial and MODgps. GPS causes UM6 signals to freeze on a fixed value, which timer and gps continue to print out.
Dependencies: MODGPS MODSERIAL mbed
main.cpp@0:b9c0180d446f, 2013-07-08 (annotated)
- Committer:
- njewin
- Date:
- Mon Jul 08 18:22:43 2013 +0000
- Revision:
- 0:b9c0180d446f
prints um6 and gps signals to pc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
njewin | 0:b9c0180d446f | 1 | #include "mbed.h" |
njewin | 0:b9c0180d446f | 2 | #include "MODSERIAL.h" |
njewin | 0:b9c0180d446f | 3 | #include "UM6_usart.h" // UM6 USART HEADER |
njewin | 0:b9c0180d446f | 4 | #include "UM6_config.h" // UM6 CONFIG HEADER |
njewin | 0:b9c0180d446f | 5 | #include "GPS.h" |
njewin | 0:b9c0180d446f | 6 | |
njewin | 0:b9c0180d446f | 7 | //------------ system and interface setup ----------------------------// |
njewin | 0:b9c0180d446f | 8 | Serial pc(USBTX, USBRX); // sets up serial connection to pc terminal |
njewin | 0:b9c0180d446f | 9 | |
njewin | 0:b9c0180d446f | 10 | //------------ Hardware setup ----------------------------------------// |
njewin | 0:b9c0180d446f | 11 | DigitalOut pc_led(LED1); // LED1 = PC SERIAL |
njewin | 0:b9c0180d446f | 12 | DigitalOut uart_led(LED2); // LED2 = UM6 SERIAL |
njewin | 0:b9c0180d446f | 13 | GPS gps(NC,p27); |
njewin | 0:b9c0180d446f | 14 | |
njewin | 0:b9c0180d446f | 15 | |
njewin | 0:b9c0180d446f | 16 | // interupt function for processing uart messages --------------------// |
njewin | 0:b9c0180d446f | 17 | void rxCallback(MODSERIAL_IRQ_INFO *q) { |
njewin | 0:b9c0180d446f | 18 | if (um6_uart.rxBufferGetCount() >= MAX_PACKET_DATA) { |
njewin | 0:b9c0180d446f | 19 | uart_led = !uart_led; // Lights LED when uart RxBuff has > 40 bytes |
njewin | 0:b9c0180d446f | 20 | Process_um6_packet(); |
njewin | 0:b9c0180d446f | 21 | } |
njewin | 0:b9c0180d446f | 22 | } |
njewin | 0:b9c0180d446f | 23 | |
njewin | 0:b9c0180d446f | 24 | |
njewin | 0:b9c0180d446f | 25 | //============= Main Program =========================================// |
njewin | 0:b9c0180d446f | 26 | int main() { |
njewin | 0:b9c0180d446f | 27 | Timer t; |
njewin | 0:b9c0180d446f | 28 | GPS_Time q1; |
njewin | 0:b9c0180d446f | 29 | GPS_VTG v1; |
njewin | 0:b9c0180d446f | 30 | int Roll_Counter=0; |
njewin | 0:b9c0180d446f | 31 | |
njewin | 0:b9c0180d446f | 32 | pc.baud(115200); // baud rate to pc interface |
njewin | 0:b9c0180d446f | 33 | um6_uart.baud(115200); // baud rate to um6 interface |
njewin | 0:b9c0180d446f | 34 | gps.baud(115200); |
njewin | 0:b9c0180d446f | 35 | gps.format(8, GPS::None, 1); |
njewin | 0:b9c0180d446f | 36 | |
njewin | 0:b9c0180d446f | 37 | //---- call interrupt functions --------------------------// |
njewin | 0:b9c0180d446f | 38 | um6_uart.attach(&rxCallback, MODSERIAL::RxIrq); // attach interupt function to uart |
njewin | 0:b9c0180d446f | 39 | t.start(); // start logging timer |
njewin | 0:b9c0180d446f | 40 | |
njewin | 0:b9c0180d446f | 41 | //---- main while loop -------------------------------------------// |
njewin | 0:b9c0180d446f | 42 | while(1) { |
njewin | 0:b9c0180d446f | 43 | Roll_Counter++; |
njewin | 0:b9c0180d446f | 44 | if (Roll_Counter > 10000000) { |
njewin | 0:b9c0180d446f | 45 | |
njewin | 0:b9c0180d446f | 46 | gps.vtg(&v1); |
njewin | 0:b9c0180d446f | 47 | |
njewin | 0:b9c0180d446f | 48 | pc.printf("time %f s, Yaw %f deg, speed %f, longitude %f \n ",t.read(),data.Yaw,v1.velocity_kph(),gps.longitude()); |
njewin | 0:b9c0180d446f | 49 | pc_led = !pc_led; |
njewin | 0:b9c0180d446f | 50 | Roll_Counter = 0; |
njewin | 0:b9c0180d446f | 51 | } |
njewin | 0:b9c0180d446f | 52 | |
njewin | 0:b9c0180d446f | 53 | } // end while(1) loop |
njewin | 0:b9c0180d446f | 54 | |
njewin | 0:b9c0180d446f | 55 | } // end main() program |