Sharp GP2 familly distance sensor library

Dependents:   FRC_2018 0hackton_08_06_18 0hackton_08_06_18_publish Kenya_2019 ... more

Embed: (wiki syntax)

« Back to documentation index

GP2A Class Reference

GP2A Class Reference

Includes : Mbed library. More...

#include <GP2A.h>

Public Member Functions

 GP2A (PinName vmes, float dMin, float dMax, float slope, float origin=0)
 Constructor of a Sharp GP2 Familly object.
double getDistance (void)
 Return the distance to target mesured by sensor in cm.
double getVoltage (void)
 Return the current voltage on GP2A output.
 operator double ()
 A short hand of getDistance.

Detailed Description

Includes : Mbed library.

GP2A Sensor : See sharp website for more informations http://www.sharp-world.com/products/device/lineup/selection/opto/haca/diagram.html

Parameters:
slope= 60 for a GP2Y0A02 and 0.236 for a GP2Y0A21
origin= 0 for a GP2Y0A02 and -0.297 for a GP2Y0A21

Definition at line 71 of file GP2A.h.


Constructor & Destructor Documentation

GP2A ( PinName  vmes,
float  dMin,
float  dMax,
float  slope,
float  origin = 0 
)

Constructor of a Sharp GP2 Familly object.

Parameters:
vmes(PinName) : the Mbed pin used to connect with GP2A sensor
dMin(double) : the GP2A sensor min distance to mesure
dMax(double) : the GP2A sensor max distance to mesure
slope(double) : the slope of the linear part of the graph V = f(1/d)
origin(double) : the origin (Y for X=0) of the linear pat of the graph V = f(1/d)
Note:
you better use slope and origin value that I've put above as sybolic constants

Definition at line 3 of file GP2A.cpp.


Member Function Documentation

double getDistance ( void   )

Return the distance to target mesured by sensor in cm.

Returns:
Distance in cm
Note:
Distance is (very) approximative, to have a better mesurment I recommand an averaging of at least 5 measures
you may get a new mesurment every 50ms

Definition at line 11 of file GP2A.cpp.

double getVoltage ( void   )

Return the current voltage on GP2A output.

Returns:
Voltage between 0 and 3.3V

Definition at line 20 of file GP2A.cpp.

operator double (  )

A short hand of getDistance.

Definition at line 25 of file GP2A.cpp.