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);
|
|
|
|
int convert_raw_to_distance(int _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 {
|
2012-08-17 03:21:05 -03: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
|