Sharp GP2 familly distance sensor library
Dependents: FRC_2018 0hackton_08_06_18 0hackton_08_06_18_publish Kenya_2019 ... more
GP2A.h@0:17de10d278c2, 2018-05-18 (annotated)
- Committer:
- haarkon
- Date:
- Fri May 18 16:47:44 2018 +0000
- Revision:
- 0:17de10d278c2
- Child:
- 1:956ee3b2eaa0
Untested first release of SHARP GP2 familly distance sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
haarkon | 0:17de10d278c2 | 1 | /** |
haarkon | 0:17de10d278c2 | 2 | * @author Hugues Angelis |
haarkon | 0:17de10d278c2 | 3 | * |
haarkon | 0:17de10d278c2 | 4 | * @section LICENSE |
haarkon | 0:17de10d278c2 | 5 | * |
haarkon | 0:17de10d278c2 | 6 | * Copyright (c) 2010 ARM Limited |
haarkon | 0:17de10d278c2 | 7 | * |
haarkon | 0:17de10d278c2 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
haarkon | 0:17de10d278c2 | 9 | * of this software and associated documentation files (the "Software"), to deal |
haarkon | 0:17de10d278c2 | 10 | * in the Software without restriction, including without limitation the rights |
haarkon | 0:17de10d278c2 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
haarkon | 0:17de10d278c2 | 12 | * copies of the Software, and to permit persons to whom the Software is |
haarkon | 0:17de10d278c2 | 13 | * furnished to do so, subject to the following conditions: |
haarkon | 0:17de10d278c2 | 14 | * |
haarkon | 0:17de10d278c2 | 15 | * The above copyright notice and this permission notice shall be included in |
haarkon | 0:17de10d278c2 | 16 | * all copies or substantial portions of the Software. |
haarkon | 0:17de10d278c2 | 17 | * |
haarkon | 0:17de10d278c2 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
haarkon | 0:17de10d278c2 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
haarkon | 0:17de10d278c2 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
haarkon | 0:17de10d278c2 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
haarkon | 0:17de10d278c2 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
haarkon | 0:17de10d278c2 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
haarkon | 0:17de10d278c2 | 24 | * THE SOFTWARE. |
haarkon | 0:17de10d278c2 | 25 | * |
haarkon | 0:17de10d278c2 | 26 | * @section DESCRIPTION |
haarkon | 0:17de10d278c2 | 27 | * |
haarkon | 0:17de10d278c2 | 28 | * SHARP GP2 Analog sensor familly library |
haarkon | 0:17de10d278c2 | 29 | * |
haarkon | 0:17de10d278c2 | 30 | * Any GP2 analog sensor may be added to this library using the constructor : |
haarkon | 0:17de10d278c2 | 31 | * minDistance : is the minimum distance for linear approximation (cm) |
haarkon | 0:17de10d278c2 | 32 | * maxDistance : is the maximum distance for linear approximation (cm) |
haarkon | 0:17de10d278c2 | 33 | * slope : is the slope of the linear part of the graph V = f(1/d) |
haarkon | 0:17de10d278c2 | 34 | * take special care that we use the 1/d instead of d for x |
haarkon | 0:17de10d278c2 | 35 | * axis. |
haarkon | 0:17de10d278c2 | 36 | * the slope parameter must be computed by user. You may |
haarkon | 0:17de10d278c2 | 37 | * also use the defined values (see below) |
haarkon | 0:17de10d278c2 | 38 | * |
haarkon | 0:17de10d278c2 | 39 | * One must be aware that under the minimum distance the sensor will output |
haarkon | 0:17de10d278c2 | 40 | * a false value of distance leading to strong errors. |
haarkon | 0:17de10d278c2 | 41 | * |
haarkon | 0:17de10d278c2 | 42 | */ |
haarkon | 0:17de10d278c2 | 43 | |
haarkon | 0:17de10d278c2 | 44 | #ifndef GP2A_H |
haarkon | 0:17de10d278c2 | 45 | #define GP2A_H |
haarkon | 0:17de10d278c2 | 46 | |
haarkon | 0:17de10d278c2 | 47 | /** |
haarkon | 0:17de10d278c2 | 48 | * Slope definitions for common GP2A sensors |
haarkon | 0:17de10d278c2 | 49 | */ |
haarkon | 0:17de10d278c2 | 50 | |
haarkon | 0:17de10d278c2 | 51 | #define GP2Y0A02YK0F 60.0 |
haarkon | 0:17de10d278c2 | 52 | #define GP2Y0A21YK0F 20.888 |
haarkon | 0:17de10d278c2 | 53 | |
haarkon | 0:17de10d278c2 | 54 | /** |
haarkon | 0:17de10d278c2 | 55 | * Includes |
haarkon | 0:17de10d278c2 | 56 | */ |
haarkon | 0:17de10d278c2 | 57 | #include "mbed.h" |
haarkon | 0:17de10d278c2 | 58 | |
haarkon | 0:17de10d278c2 | 59 | /** |
haarkon | 0:17de10d278c2 | 60 | * GP2A_Sensor |
haarkon | 0:17de10d278c2 | 61 | */ |
haarkon | 0:17de10d278c2 | 62 | class GP2A { |
haarkon | 0:17de10d278c2 | 63 | |
haarkon | 0:17de10d278c2 | 64 | public : |
haarkon | 0:17de10d278c2 | 65 | |
haarkon | 0:17de10d278c2 | 66 | /** |
haarkon | 0:17de10d278c2 | 67 | * Constructor. |
haarkon | 0:17de10d278c2 | 68 | * |
haarkon | 0:17de10d278c2 | 69 | * @param vmes is the Mbed pin used to connect with GP2A sensor |
haarkon | 0:17de10d278c2 | 70 | * @param dMin is the GP2A sensor min distance to mesure |
haarkon | 0:17de10d278c2 | 71 | * @param dMax is the GP2A sensor max distance to mesure |
haarkon | 0:17de10d278c2 | 72 | * @param slope is the slope of the linear part of the graph V = f(1/d) |
haarkon | 0:17de10d278c2 | 73 | */ |
haarkon | 0:17de10d278c2 | 74 | GP2A(PinName vmes, float dMin, float dMax, float slope); |
haarkon | 0:17de10d278c2 | 75 | |
haarkon | 0:17de10d278c2 | 76 | /** |
haarkon | 0:17de10d278c2 | 77 | * Return the distance to target in cm |
haarkon | 0:17de10d278c2 | 78 | * |
haarkon | 0:17de10d278c2 | 79 | * @return : the distance in cm |
haarkon | 0:17de10d278c2 | 80 | */ |
haarkon | 0:17de10d278c2 | 81 | float getDistance (void); |
haarkon | 0:17de10d278c2 | 82 | |
haarkon | 0:17de10d278c2 | 83 | /** |
haarkon | 0:17de10d278c2 | 84 | * Return the voltage on GP2A output |
haarkon | 0:17de10d278c2 | 85 | * |
haarkon | 0:17de10d278c2 | 86 | * @return : the voltage between 0 and 3.3V |
haarkon | 0:17de10d278c2 | 87 | */ |
haarkon | 0:17de10d278c2 | 88 | float getVoltage (void); |
haarkon | 0:17de10d278c2 | 89 | |
haarkon | 0:17de10d278c2 | 90 | private : |
haarkon | 0:17de10d278c2 | 91 | float m_dMin, m_dMax, m_slope; |
haarkon | 0:17de10d278c2 | 92 | |
haarkon | 0:17de10d278c2 | 93 | protected : |
haarkon | 0:17de10d278c2 | 94 | |
haarkon | 0:17de10d278c2 | 95 | AnalogIn _sensor ; |
haarkon | 0:17de10d278c2 | 96 | |
haarkon | 0:17de10d278c2 | 97 | }; |
haarkon | 0:17de10d278c2 | 98 | #endif //GP2A_H |