David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.
Dependencies: PololuEncoder Pacer mbed GeneralDebouncer
Diff: test.cpp
- Revision:
- 31:739b91331f31
- Parent:
- 30:84be2d602dc0
- Child:
- 32:83a13b06093c
--- a/test.cpp Tue Mar 04 02:09:54 2014 +0000 +++ b/test.cpp Tue Mar 04 03:04:00 2014 +0000 @@ -48,14 +48,15 @@ uint16_t readP10() { DigitalInOut pin(p10); + pin.mode(PullNone); pin.output(); pin = 1; wait_us(20); - uint16_t value = 0x8000; + uint16_t value = 1000; Timer timer; timer.start(); pin.input(); - while(timer.read_us() < 0x8000) + while(timer.read_us() < 1000) { if(pin.read() == 0) { @@ -265,25 +266,51 @@ { led1 = 1; Pacer reportPacer(100000); + Pacer clearStatsPacer(2000000); + + uint16_t min[LINE_SENSOR_COUNT]; + uint16_t max[LINE_SENSOR_COUNT]; + bool const printBarGraph = true; while (1) { + if (clearStatsPacer.pace()) + { + for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++) + { + min[i] = 0xFFFF; + max[i] = 0; + } + } + + //values[0] = lineSensorsAnalog[0].read_u16(); + //values[1] = lineSensorsAnalog[1].read_u16(); + //values[2] = lineSensorsAnalog[2].read_u16(); + + uint16_t values[3]; + readSensors(values); + + for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++) + { + if (values[i] > max[i]){ max[i] = values[i]; } + if (values[i] < min[i]){ min[i] = values[i]; } + } + if (reportPacer.pace()) { - uint16_t left = lineSensorsAnalog[0].read_u16(); - uint16_t middle = lineSensorsAnalog[1].read_u16(); - uint16_t right = lineSensorsAnalog[2].read_u16(); - if (printBarGraph) { pc.printf("\x1B[0;0H"); // VT100 command for "go to 0,0" - printBar("L", left); - printBar("M", middle); - printBar("R", right); + printBar("L", values[0]); + printBar("M", values[1]); + printBar("R", values[2]); + pc.printf("%4d %4d \r\n", min[0], max[0]); + pc.printf("%4d %4d \r\n", min[1], max[1]); + pc.printf("%4d %4d \r\n", min[2], max[2]); } else { - pc.printf("%8d %8d %8d\n", left, middle, right); + pc.printf("%8d %8d %8d\r\n", values[0], values[1], values[2]); } } } @@ -356,7 +383,7 @@ if(reportPacer.pace()) { led2 = 1; - pc.printf("%8d %8d\n", encoderLeft.getCount(), encoderRight.getCount()); + pc.printf("%8d %8d\r\n", encoderLeft.getCount(), encoderRight.getCount()); led2 = 0; } } @@ -413,13 +440,16 @@ } -void printBar(const char * name, uint16_t adcResult) +// with should be between 0 and 63 +void printBar(const char * name, uint16_t result) { - pc.printf("%-2s %5d |", name, adcResult); - uint8_t width = adcResult >> 10; + pc.printf("%-2s %5d |", name, result); + uint16_t width = result >> 4; + if (width > 63) { width = 63; } uint8_t i; for(i = 0; i < width; i++){ pc.putc('#'); } for(; i < 63; i++){ pc.putc(' '); } pc.putc('|'); + pc.putc('\r'); pc.putc('\n'); } \ No newline at end of file