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
Revision 29:cfcf08d8ac79, committed 2014-03-04
- Comitter:
- DavidEGrayson
- Date:
- Tue Mar 04 00:46:18 2014 +0000
- Parent:
- 28:4374035df5e0
- Child:
- 30:84be2d602dc0
- Commit message:
- trying to figure out the analog problem;
Changed in this revision
--- a/line_sensors.cpp Sat Mar 01 03:13:57 2014 +0000 +++ b/line_sensors.cpp Tue Mar 04 00:46:18 2014 +0000 @@ -4,4 +4,25 @@ AnalogIn(p20), // brown wire, left-most sensor AnalogIn(p19), // orange wire, middle sensor AnalogIn(p17), // blue wire, right-most sensor -}; \ No newline at end of file +}; + +/** +uint16_t analogReadWithFilter(AnalogIn * input) +{ + uint16_t readings[3]; + for(uint8_t i = 0; i < 3; i++) + { + readings[i] = input->read_u16(); + } + + if (readings[0] <= readings[1] && readings[0] >= readings[2]) + { + return readings[0]; + } + if (readings[1] <= readings[0] && readings[1] >= readings[2]) + { + return readings[1]; + } + return readings[2]; +} +**/ \ No newline at end of file
--- a/line_sensors.h Sat Mar 01 03:13:57 2014 +0000 +++ b/line_sensors.h Tue Mar 04 00:46:18 2014 +0000 @@ -4,4 +4,6 @@ #define LINE_SENSOR_COUNT 3 -extern AnalogIn lineSensorsAnalog[LINE_SENSOR_COUNT]; \ No newline at end of file +extern AnalogIn lineSensorsAnalog[LINE_SENSOR_COUNT]; + +uint16_t analogReadWithFilter(AnalogIn * input); \ No newline at end of file
--- a/main.cpp Sat Mar 01 03:13:57 2014 +0000 +++ b/main.cpp Tue Mar 04 00:46:18 2014 +0000 @@ -45,7 +45,8 @@ //testFinalSettleIn(); //testCalibrate(); //testLineFollowing(); - testAnalog(); + //testAnalog(); + testAnalogReadWithFilter(); // Real routines for the contest. loadCalibration();
--- a/test.cpp Sat Mar 01 03:13:57 2014 +0000 +++ b/test.cpp Tue Mar 04 00:46:18 2014 +0000 @@ -16,10 +16,49 @@ void __attribute__((noreturn)) infiniteReckonerReportLoop(); void printBar(const char * name, uint16_t adcResult); +void testAnalogReadWithFilter() +{ + AnalogIn testInput(p18); + Pacer reportPacer(1000000); + uint32_t badCount = 0, goodCount = 0; + while(1) + { + uint16_t reading = analogReadWithFilter(&testInput); + if(reading > 100) + { + badCount += 1; + pc.printf("f %5d %11d %11d\r\n", reading, badCount, goodCount); + } + else + { + goodCount += 1; + } + + if (reportPacer.pace()) + { + pc.printf("Hello\r\n"); + } + } +} + void testAnalog() { AnalogIn testInput(p18); + DigitalOut pin20(p20); + DigitalOut pin19(p19); + //DigitalOut pin18(p18); + DigitalOut pin17(p17); + DigitalOut pin16(p16); + DigitalOut pin15(p15); + + pin20 = 0; + pin19 = 0; + //pin18 = 0; + pin17 = 0; + pin16 = 0; + pin15 = 0; + uint32_t badCount = 0, goodCount = 0; Pacer reportPacer(1000000);
--- a/test.h Sat Mar 01 03:13:57 2014 +0000 +++ b/test.h Tue Mar 04 00:46:18 2014 +0000 @@ -9,4 +9,5 @@ void __attribute__((noreturn)) testFinalSettleIn(); void __attribute__((noreturn)) testCalibrate(); void __attribute__((noreturn)) testLineFollowing(); -void __attribute__((noreturn)) testAnalog(); \ No newline at end of file +void __attribute__((noreturn)) testAnalog(); +void __attribute__((noreturn)) testAnalogReadWithFilter();