Sharp GP2 familly distance sensor library
Dependents: FRC_2018 0hackton_08_06_18 0hackton_08_06_18_publish Kenya_2019 ... more
Diff: GP2A.h
- Revision:
- 0:17de10d278c2
- Child:
- 1:956ee3b2eaa0
diff -r 000000000000 -r 17de10d278c2 GP2A.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GP2A.h Fri May 18 16:47:44 2018 +0000 @@ -0,0 +1,98 @@ +/** + * @author Hugues Angelis + * + * @section LICENSE + * + * Copyright (c) 2010 ARM Limited + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * SHARP GP2 Analog sensor familly library + * + * Any GP2 analog sensor may be added to this library using the constructor : + * minDistance : is the minimum distance for linear approximation (cm) + * maxDistance : is the maximum distance for linear approximation (cm) + * slope : is the slope of the linear part of the graph V = f(1/d) + * take special care that we use the 1/d instead of d for x + * axis. + * the slope parameter must be computed by user. You may + * also use the defined values (see below) + * + * One must be aware that under the minimum distance the sensor will output + * a false value of distance leading to strong errors. + * + */ + +#ifndef GP2A_H +#define GP2A_H + +/** + * Slope definitions for common GP2A sensors + */ + +#define GP2Y0A02YK0F 60.0 +#define GP2Y0A21YK0F 20.888 + +/** + * Includes + */ +#include "mbed.h" + +/** + * GP2A_Sensor + */ +class GP2A { + +public : + + /** + * Constructor. + * + * @param vmes is the Mbed pin used to connect with GP2A sensor + * @param dMin is the GP2A sensor min distance to mesure + * @param dMax is the GP2A sensor max distance to mesure + * @param slope is the slope of the linear part of the graph V = f(1/d) + */ + GP2A(PinName vmes, float dMin, float dMax, float slope); + + /** + * Return the distance to target in cm + * + * @return : the distance in cm + */ + float getDistance (void); + + /** + * Return the voltage on GP2A output + * + * @return : the voltage between 0 and 3.3V + */ + float getVoltage (void); + +private : + float m_dMin, m_dMax, m_slope; + +protected : + + AnalogIn _sensor ; + +}; +#endif //GP2A_H \ No newline at end of file