2010-12-16 23:01:29 -04:00
|
|
|
#ifndef RangeFinder_h
|
|
|
|
#define RangeFinder_h
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#define AP_RANGEFINDER_NUM_AVERAGES 4
|
2010-12-16 23:01:29 -04:00
|
|
|
|
|
|
|
class RangeFinder
|
|
|
|
{
|
2010-12-21 08:34:24 -04:00
|
|
|
public:
|
2010-12-16 23:01:29 -04:00
|
|
|
int _analogPort; // the port to which the sensor is connected
|
2010-12-21 08:34:24 -04:00
|
|
|
int _history_ptr;
|
|
|
|
int _history[AP_RANGEFINDER_NUM_AVERAGES];
|
2010-12-16 23:01:29 -04:00
|
|
|
public:
|
|
|
|
int raw_value; // raw value from the sensor
|
|
|
|
int distance; // distance in cm
|
|
|
|
int max_distance; // maximum measurable distance (in cm)
|
|
|
|
int min_distance; // minimum measurable distance (in cm)
|
2010-12-21 08:34:24 -04:00
|
|
|
int orientation_x, orientation_y, orientation_z;
|
|
|
|
|
|
|
|
int filter(int latestValue); // returns the average of the last AP_RANGEFINDER_NUM_AVERAGES values
|
2010-12-16 23:01:29 -04:00
|
|
|
|
|
|
|
virtual void init(int analogPort);
|
2010-12-21 08:34:24 -04:00
|
|
|
virtual void set_orientation(int x, int y, int z);
|
2010-12-16 23:01:29 -04:00
|
|
|
virtual int read(); // read value from analog port and return distance in cm
|
|
|
|
};
|
|
|
|
#endif
|