2010-12-16 23:01:29 -04:00
|
|
|
#ifndef RangeFinder_h
|
|
|
|
#define RangeFinder_h
|
|
|
|
|
2011-01-03 00:17:43 -04:00
|
|
|
#include <stdlib.h>
|
2010-12-16 23:01:29 -04:00
|
|
|
#include <inttypes.h>
|
2011-01-03 00:17:43 -04:00
|
|
|
#include "../AP_ADC/AP_ADC.h"
|
2011-07-30 17:35:36 -03:00
|
|
|
#include "../ModeFilter/ModeFilter.h" // ArduPilot Mega RC Library
|
2010-12-16 23:01:29 -04:00
|
|
|
|
2011-07-30 17:35:36 -03:00
|
|
|
/*
|
2010-12-21 08:34:24 -04:00
|
|
|
#define AP_RANGEFINDER_ORIENTATION_FRONT 0, 10, 0
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_RIGHT -10, 0, 0
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_BACK 0,-10, 0
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_LEFT 10, 0, 0
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_UP 0, 0,-10
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_DOWN 0, 0, 10
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_FRONT_RIGHT -5, -5, 0
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_BACK_RIGHT -5, -5, 0
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_BACK_LEFT 5, -5, 0
|
|
|
|
#define AP_RANGEFINDER_ORIENTATION_FRONT_LEFT 5, 5, 0
|
2011-07-30 17:35:36 -03:00
|
|
|
*/
|
|
|
|
//#define AP_RANGEFINDER_PITOT_TUBE 1007
|
2011-01-03 00:17:43 -04:00
|
|
|
#define AP_RANGEFINDER_PITOT_TUBE_ADC_CHANNEL 7
|
|
|
|
|
2011-07-30 17:35:36 -03:00
|
|
|
//#define AP_RANGEFINDER_NUM_AVERAGES 4
|
2010-12-16 23:01:29 -04:00
|
|
|
|
|
|
|
class RangeFinder
|
|
|
|
{
|
2011-07-30 17:35:36 -03:00
|
|
|
protected:
|
|
|
|
//GPS(Stream *s) : _port(s) {};
|
|
|
|
RangeFinder(AP_ADC *adc, ModeFilter *filter) :
|
|
|
|
_ap_adc(adc),
|
|
|
|
_mode_filter(filter),
|
|
|
|
_analogPort(-1)
|
|
|
|
{}
|
2010-12-21 08:34:24 -04:00
|
|
|
public:
|
2011-07-30 17:35:36 -03:00
|
|
|
|
2011-01-03 00:17:43 -04:00
|
|
|
int raw_value; // raw value from the sensor
|
|
|
|
int distance; // distance in cm
|
|
|
|
int max_distance; // maximum measurable distance (in cm) - should be set in child's constructor
|
|
|
|
int min_distance; // minimum measurable distance (in cm) - should be set in child's constructor
|
2010-12-21 08:34:24 -04:00
|
|
|
int orientation_x, orientation_y, orientation_z;
|
2011-06-16 13:30:37 -03:00
|
|
|
|
2011-07-30 17:35:36 -03:00
|
|
|
virtual void set_analog_port(int analogPort);
|
2010-12-21 08:34:24 -04:00
|
|
|
virtual void set_orientation(int x, int y, int z);
|
2011-05-04 16:12:27 -03:00
|
|
|
virtual int convert_raw_to_distance(int _raw_value) { return _raw_value; } // function that each child class should override to convert voltage to distance
|
2011-01-03 00:17:43 -04:00
|
|
|
virtual int read(); // read value from sensor and return distance in cm
|
2011-07-30 17:35:36 -03:00
|
|
|
|
|
|
|
int _analogPort; // the port to which the sensor is connected
|
|
|
|
AP_ADC *_ap_adc; // pointer to AP_ADC used for pitot tube
|
|
|
|
ModeFilter *_mode_filter;
|
2010-12-16 23:01:29 -04:00
|
|
|
};
|
|
|
|
#endif
|