2013-05-29 20:51:11 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2013-08-29 02:34:34 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-01-10 19:44:04 -04:00
|
|
|
/*
|
2012-08-17 03:21:04 -03:00
|
|
|
* AP_RangeFinder_MaxsonarXL.cpp - Arduino Library for Sharpe GP2Y0A02YK0F
|
|
|
|
* infrared proximity sensor
|
|
|
|
* Code by Jose Julio and Randy Mackay. DIYDrones.com
|
|
|
|
*
|
|
|
|
* Sparkfun URL: http://www.sparkfun.com/products/9491
|
|
|
|
* datasheet: http://www.sparkfun.com/datasheets/Sensors/Proximity/XL-EZ0-Datasheet.pdf
|
|
|
|
*
|
|
|
|
* Sensor should be connected to one of the analog ports
|
|
|
|
*
|
|
|
|
* Variables:
|
|
|
|
* 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)
|
|
|
|
*
|
|
|
|
* Methods:
|
|
|
|
* read() : read value from analog port and returns the distance (in cm)
|
|
|
|
*
|
|
|
|
*/
|
2012-01-10 19:44:04 -04:00
|
|
|
|
|
|
|
#include "AP_RangeFinder_MaxsonarXL.h"
|
|
|
|
|
|
|
|
// Constructor //////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-27 21:39:15 -04:00
|
|
|
AP_RangeFinder_MaxsonarXL::AP_RangeFinder_MaxsonarXL(AP_HAL::AnalogSource *source, FilterInt16 *filter) :
|
2012-08-17 03:21:04 -03:00
|
|
|
RangeFinder(source, filter),
|
|
|
|
_scaler(AP_RANGEFINDER_MAXSONARXL_SCALER)
|
|
|
|
{
|
|
|
|
max_distance = AP_RANGEFINDER_MAXSONARXL_MAX_DISTANCE;
|
|
|
|
min_distance = AP_RANGEFINDER_MAXSONARXL_MIN_DISTANCE;
|
|
|
|
}
|
2012-01-10 19:44:04 -04:00
|
|
|
|
|
|
|
// Public Methods //////////////////////////////////////////////////////////////
|
|
|
|
float AP_RangeFinder_MaxsonarXL::calculate_scaler(int sonar_type, float adc_refence_voltage)
|
|
|
|
{
|
2013-01-10 14:42:24 -04:00
|
|
|
float type_scaler = 1.0f;
|
2012-08-17 03:21:04 -03:00
|
|
|
switch(sonar_type) {
|
|
|
|
case AP_RANGEFINDER_MAXSONARXL:
|
|
|
|
type_scaler = AP_RANGEFINDER_MAXSONARXL_SCALER;
|
|
|
|
min_distance = AP_RANGEFINDER_MAXSONARXL_MIN_DISTANCE;
|
|
|
|
max_distance = AP_RANGEFINDER_MAXSONARXL_MAX_DISTANCE;
|
|
|
|
break;
|
|
|
|
case AP_RANGEFINDER_MAXSONARLV:
|
|
|
|
type_scaler = AP_RANGEFINDER_MAXSONARLV_SCALER;
|
|
|
|
min_distance = AP_RANGEFINDER_MAXSONARLV_MIN_DISTANCE;
|
|
|
|
max_distance = AP_RANGEFINDER_MAXSONARLV_MAX_DISTANCE;
|
|
|
|
break;
|
|
|
|
case AP_RANGEFINDER_MAXSONARXLL:
|
|
|
|
type_scaler = AP_RANGEFINDER_MAXSONARXLL_SCALER;
|
|
|
|
min_distance = AP_RANGEFINDER_MAXSONARXLL_MIN_DISTANCE;
|
|
|
|
max_distance = AP_RANGEFINDER_MAXSONARXLL_MAX_DISTANCE;
|
|
|
|
break;
|
|
|
|
case AP_RANGEFINDER_MAXSONARHRLV:
|
|
|
|
type_scaler = AP_RANGEFINDER_MAXSONARHRLV_SCALER;
|
|
|
|
min_distance = AP_RANGEFINDER_MAXSONARHRLV_MIN_DISTANCE;
|
|
|
|
max_distance = AP_RANGEFINDER_MAXSONARHRLV_MAX_DISTANCE;
|
|
|
|
break;
|
2012-01-10 19:44:04 -04:00
|
|
|
}
|
2013-01-10 14:42:24 -04:00
|
|
|
_scaler = type_scaler * adc_refence_voltage / 5.0f;
|
2012-08-17 03:21:04 -03:00
|
|
|
return _scaler;
|
2012-07-11 22:46:47 -03:00
|
|
|
}
|