This is some awesome robot code
Dependencies: mbed-rtos mbed QEI
Fork of ICRSEurobot13 by
Diff: Communication/coprocserial.cpp
- Revision:
- 20:70d651156779
- Child:
- 26:7cb3a21d9a2e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Communication/coprocserial.cpp Tue Apr 09 15:33:36 2013 +0000 @@ -0,0 +1,71 @@ +#include "Kalman.h" +#include "mbed.h" +#include "globals.h" + +Serial coprocserial(NC, P_SERIAL_RX); + +//DigitalOut OLED1(LED1); +DigitalOut OLED2(LED2); + +// bytes packing +typedef union { + + struct _data{ + unsigned char sync[3]; + unsigned char ID; + float value; + float variance; + } data; + + unsigned char type_char[12]; +} bytepack_t; + +bytepack_t incbuff; + +volatile int buffprintflag = 0; +void printbuff(){ + while(!buffprintflag); + buffprintflag = 0; + for(int i = 0; i < 9; i++){ + printf("%x ", incbuff.type_char[i]); + } + printf("\r\n"); +} + +void procserial(){ + + //Fetch the byte in a "clear interrupt" sense + unsigned char c = LPC_UART1->RBR; + + //OLED1 = !OLED1; + + static int ctr = 0; + + + if (ctr < 3){ + if (c == 0xFF) + ctr++; + else + ctr = 0; + } else { + incbuff.type_char[ctr] = c; + if (++ctr == 12){ + ctr = 0; + + OLED2 = !OLED2; + buffprintflag = 1; + + //runupdate + Kalman::runupdate((Kalman::measurement_t)incbuff.data.ID, incbuff.data.value, incbuff.data.variance); + } + } + +} + +void InitSerial(){ + + coprocserial.baud(115200); + + printf("attachserial\r\n"); + coprocserial.attach(procserial); +} \ No newline at end of file