2012-01-10 19:44:04 -04:00
|
|
|
#ifndef RangeFinder_h
|
|
|
|
#define RangeFinder_h
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <inttypes.h>
|
2011-11-12 23:16:31 -04:00
|
|
|
#include "../AP_AnalogSource/AP_AnalogSource.h"
|
2012-02-26 02:34:50 -04:00
|
|
|
#include "../Filter/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:
|
|
|
|
RangeFinder(AP_AnalogSource * source, FilterInt16 *filter) :
|
|
|
|
_analog_source(source),
|
|
|
|
_mode_filter(filter) {
|
|
|
|
}
|
|
|
|
public:
|
2012-01-10 19:44:04 -04:00
|
|
|
|
2012-08-17 03:21:04 -03: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
|
|
|
|
int orientation_x, orientation_y, orientation_z;
|
2012-01-10 19:44:04 -04:00
|
|
|
|
2012-08-17 03:21:04 -03:00
|
|
|
virtual void set_orientation(int x, int y, int z);
|
|
|
|
virtual int convert_raw_to_distance(int _raw_value) {
|
|
|
|
return _raw_value;
|
|
|
|
} // function that each child class should override to convert voltage to distance
|
|
|
|
virtual int read(); // read value from sensor and return distance in cm
|
2012-01-10 19:44:04 -04:00
|
|
|
|
2012-08-17 03:21:04 -03:00
|
|
|
AP_AnalogSource * _analog_source;
|
|
|
|
FilterInt16 * _mode_filter;
|
2012-01-10 19:44:04 -04:00
|
|
|
};
|
|
|
|
#endif
|