2012-11-27 21:39:15 -04:00
|
|
|
#ifndef __AP_RangeFinder_SharpGP2Y_H__
|
|
|
|
#define __AP_RangeFinder_SharpGP2Y_H__
|
2012-01-10 19:44:04 -04:00
|
|
|
|
|
|
|
#include "RangeFinder.h"
|
|
|
|
|
|
|
|
#define AP_RANGEFINDER_SHARPEGP2Y_MIN_DISTANCE 20
|
|
|
|
#define AP_RANGEFINDER_SHARPEGP2Y_MAX_DISTANCE 150
|
|
|
|
|
|
|
|
class AP_RangeFinder_SharpGP2Y : public RangeFinder
|
|
|
|
{
|
2012-08-17 03:21:05 -03:00
|
|
|
public:
|
2012-11-27 21:39:15 -04:00
|
|
|
AP_RangeFinder_SharpGP2Y(AP_HAL::AnalogSource *source, FilterInt16 *filter);
|
2014-02-10 01:57:17 -04:00
|
|
|
int16_t convert_raw_to_distance(int16_t raw_value) {
|
|
|
|
if (raw_value == 0) {
|
2012-08-17 03:21:05 -03:00
|
|
|
return max_distance;
|
2012-11-27 21:39:15 -04:00
|
|
|
} else {
|
2014-02-10 01:57:17 -04:00
|
|
|
return 14500/raw_value;
|
2012-11-27 21:39:15 -04:00
|
|
|
}
|
2012-08-17 03:21:05 -03:00
|
|
|
} // read value from analog port and return distance in cm
|
2012-01-10 19:44:04 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
#endif
|