Sharp GP2 familly distance sensor library
Dependents: FRC_2018 0hackton_08_06_18 0hackton_08_06_18_publish Kenya_2019 ... more
GP2A.h
- Committer:
- haarkon
- Date:
- 2018-05-21
- Revision:
- 2:5e591a5b8edd
- Parent:
- 1:956ee3b2eaa0
- Child:
- 3:dcd04d9d0eb7
File content as of revision 2:5e591a5b8edd:
/** * @author Hugues Angelis * * @section LICENSE * * 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 unless the GP2 reference is * listed in the list below : * - GP2Y0A02YK0F (Min = 30cm, Max = 150cm, Slope = 60) * - GP2Y0A21YK0F (Min = 7cm, Max = 80cm, Slope = 20.88) * * You may add others sensors if you wish it * * One must be aware that under the minimum distance the sensor will output * a false value of distance leading to strong errors. * @endsection */ #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 */ double getDistance (void); /** * Return the voltage on GP2A output * * @return the voltage between 0 and 3.3V */ double getVoltage (void); /** * A short hand of getDistance */ operator double(); private : float m_dMin, m_dMax, m_slope; protected : AnalogIn _sensor ; }; #endif //GP2A_H