RangeFinder - fixed example sketch so it works again

This commit is contained in:
Randy Mackay 2011-12-10 16:32:34 +09:00
parent 1f53c25577
commit df1e54ec79

View File

@ -3,28 +3,36 @@
Code by DIYDrones.com
*/
// includes
#include <AP_RangeFinder.h> // Range finder library
#include <Arduino_Mega_ISR_Registry.h>
#include <AP_PeriodicProcess.h>
#include <AP_ADC.h> // ArduPilot Mega Analog to Digital Converter Library
#include <AP_AnalogSource.h>
#include <ModeFilter.h> // 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()