From df1e54ec7915144e2b730148af0071f218f8e15c Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Sat, 10 Dec 2011 16:32:34 +0900 Subject: [PATCH] RangeFinder - fixed example sketch so it works again --- .../AP_RangeFinder_test.pde | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libraries/AP_RangeFinder/examples/AP_RangeFinder_test/AP_RangeFinder_test.pde b/libraries/AP_RangeFinder/examples/AP_RangeFinder_test/AP_RangeFinder_test.pde index 0a41bddbd8..8b287b0c73 100644 --- a/libraries/AP_RangeFinder/examples/AP_RangeFinder_test/AP_RangeFinder_test.pde +++ b/libraries/AP_RangeFinder/examples/AP_RangeFinder_test/AP_RangeFinder_test.pde @@ -3,28 +3,36 @@ Code by DIYDrones.com */ +// includes #include // Range finder library +#include +#include #include // ArduPilot Mega Analog to Digital Converter Library #include #include // mode filter -#define RF_PIN AP_RANGEFINDER_PITOT_TUBE // the pitot tube on the front of the oilpan -//#define RF_PIN A5 // A5 is the far back-right pin on the oilpan (near the CLI switch) - -// declare global instances for reading pitot tube +// declare global instances +Arduino_Mega_ISR_Registry isr_registry; +AP_TimerProcess adc_scheduler; AP_ADC_ADS7844 adc; -AP_AnalogSource_ADC adc_source(&adc, AP_RANGEFINDER_PITOT_TYPE_ADC_CHANNEL, 0.25); ModeFilter mode_filter; +// uncomment the appropriate line corresponding to where sonar is connected +AP_AnalogSource_ADC adc_source(&adc, AP_RANGEFINDER_PITOT_TYPE_ADC_CHANNEL, 0.25); // uncomment this line to use Pitot tube +//AP_AnalogSource_Arduino adc_source(A5); // uncomment this line to use A5 analog pin (far back-right pin on the oilpan near the CLI switch + // create the range finder object //AP_RangeFinder_SharpGP2Y aRF(&adc_source, &mode_filter); AP_RangeFinder_MaxsonarXL aRF(&adc_source, &mode_filter); void setup() { - Serial.begin(115200); - Serial.println("Range Finder Test v1.0"); - adc.Init(); // APM ADC library initialization + Serial.begin(115200); + Serial.println("Range Finder Test v1.1"); + isr_registry.init(); + adc_scheduler.init(&isr_registry); + adc.filter_result = true; + adc.Init(&adc_scheduler); // APM ADC initialization } void loop()