2012-11-27 21:39:15 -04:00
|
|
|
#ifndef __RANGEFINDER_H__
|
|
|
|
#define __RANGEFINDER_H__
|
2012-01-10 19:44:04 -04:00
|
|
|
|
2012-11-11 21:40:19 -04:00
|
|
|
#include <AP_Common.h>
|
2012-11-27 21:39:15 -04:00
|
|
|
#include <AP_HAL.h>
|
2012-11-11 21:40:19 -04:00
|
|
|
#include <Filter.h> // Filter library
|
2012-01-10 19:44:04 -04:00
|
|
|
|
|
|
|
/*
|
2012-08-17 03:21:04 -03: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
|
|
|
|
*/
|
2012-01-10 19:44:04 -04:00
|
|
|
|
|
|
|
class RangeFinder
|
|
|
|
{
|
2012-08-17 03:21:04 -03:00
|
|
|
protected:
|
2012-11-27 21:39:15 -04:00
|
|
|
RangeFinder(AP_HAL::AnalogSource * source, FilterInt16 *filter) :
|
2012-08-17 03:21:04 -03:00
|
|
|
_analog_source(source),
|
|
|
|
_mode_filter(filter) {
|
|
|
|
}
|
|
|
|
public:
|
2012-11-27 21:39:15 -04:00
|
|
|
// distance: in cm
|
2014-02-10 01:56:52 -04:00
|
|
|
int16_t distance;
|
2012-11-27 21:39:15 -04:00
|
|
|
// maximum measurable distance: in cm
|
2014-02-10 01:56:52 -04:00
|
|
|
int16_t max_distance;
|
2012-11-27 21:39:15 -04:00
|
|
|
// minimum measurable distance: in cm
|
2014-02-10 01:56:52 -04:00
|
|
|
int16_t min_distance;
|
2012-01-10 19:44:04 -04:00
|
|
|
|
2012-11-27 21:39:15 -04:00
|
|
|
/**
|
|
|
|
* convert_raw_to_distance:
|
|
|
|
* function that each child class should override to convert voltage
|
|
|
|
* to distance (in cm)
|
|
|
|
*/
|
2014-02-10 01:56:52 -04:00
|
|
|
virtual int16_t convert_raw_to_distance(int16_t raw_value) {
|
|
|
|
return raw_value;
|
2012-11-27 21:39:15 -04:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* read:
|
|
|
|
* read value from sensor and return distance in cm
|
|
|
|
*/
|
2014-02-10 01:56:52 -04:00
|
|
|
virtual int16_t read();
|
2012-01-10 19:44:04 -04:00
|
|
|
|
2014-02-10 01:56:52 -04:00
|
|
|
AP_HAL::AnalogSource* _analog_source;
|
2012-08-17 03:21:04 -03:00
|
|
|
FilterInt16 * _mode_filter;
|
2012-01-10 19:44:04 -04:00
|
|
|
};
|
2012-11-27 21:39:15 -04:00
|
|
|
#endif // __RANGEFINDER_H__
|