Skip to content

Commit 2b86f8d

Browse files
authored
Merge pull request #6 from DrGFreeman/GP2Y0A710K0F
Add GPY0A710K0F sensor model
2 parents 82a489e + 95553e9 commit 2b86f8d

6 files changed

Lines changed: 21 additions & 8 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SharpDistSensor
22
A library for the Arduino IDE that helps interface with Sharp analog distance sensors.
33

4-
Version 1.1.1
4+
Version 1.2.0
55
[![Build Status](https://travis-ci.org/DrGFreeman/SharpDistSensor.svg?branch=master)](https://travis-ci.org/DrGFreeman/SharpDistSensor)
66
By Julien de la Bruère-Terreault (drgfreeman@tuta.io)
77

@@ -38,7 +38,7 @@ Constructor: `pin` is the analog pin to which the sensor is connected, `size` is
3838
Returns the measured distance. Distance units are in millimeters (mm) if using the library default settings or pre-defined sensor models. If using custom calibration, units depend on the calibration used.
3939

4040
* `void setModel(const byte model)`
41-
Sets the calibration based on pre-defined sensor model fit functions.
41+
Sets the calibration based on pre-defined sensor model fit functions. Note that the model argument must be preceded by the SharpDistSensor namespace, i.e.: `setModel(SharpDistSensor::Model_Name)`
4242

4343
* `void setPolyFitCoeffs(const byte nbCoeffs, const float* coeffs, const uint16_t valMin, const uint16_t valMax)`
4444
Sets the polynomial fit function coefficients _C0_ to _C5_ in the relation:
@@ -54,17 +54,20 @@ where _A_ is the analog value read from the sensor. `valMin` and `valMax` define
5454
Sets the range of analog values for which the polynomial or power fit is valid (`valMin` and `valMax`). Analog values outside this range will be set to the respective min or max values.
5555

5656
## Pre-defined sensor models
57-
* `GP2Y0A60SZLF_5V` - GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V
57+
* `GP2Y0A60SZLF_5V` - GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V
58+
* `GP2Y0A710K0F_5V_DS` - GP2Y0A710K0F Analog Distance Sensor 100-500cm, 5V (data sheet)
5859

5960
Model | Units | C0 | C1 | C2 | C3 | C4 | C5 | valMin | valMax
6061
------|-------|----|----|----|----|----|----|--------|--------
6162
**GP2Y0A60SZLF_5V** | mm | 1734 | -9.005 | 2.032E-2 | -2.251E-5 | 1.167E-8 | -2.037E-12 | 30 | 875
63+
**GP2Y0A710K0F_5V_DS** | mm | 178506 | -1607.72 | 5.5239 | -8.47601E-3 | 4.87819E-6 | | 284 | 507
6264

6365
**Important Note:** The analog voltage returned by the sensor is largely dependent of the reflected object size and reflectivity. The distance returned by these pre-defined calibration functions can therefore vary significantly from the real distance depending on the object detected. Where accuracy is required by the application, it is recommended to perform calibration with the object to be detected and use custom calibration fit functions instead.
6466

6567
This library has been designed so that it is easy to add sensor models. Contributions are therefore welcome. Adding models to the library can be done by either submitting a pull request or providing me the proposed fit function and associated calibration data by email so I can add it myself. Thank you for contributing!
6668

6769
## Version history
70+
* 1.2.0 (2017-05-10): Added GP2Y0A710K0F_5V_DS model.
6871
* 1.1.1 (2017-05-01): Clarified comments and fixed typos in examples, improved README.
6972
* 1.1.0 (2017-04-05): Added support of power fit functions.
7073
* 1.0.0 (2017-03-29): Initial major release for Arduino Library Manager (no change rel. to 0.3.2)

SharpDistSensor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,18 @@ void SharpDistSensor::setModel(const models model)
8787
{
8888
case GP2Y0A60SZLF_5V:
8989
{
90-
// Set default coefficients and range for Sharp GP2Y0A60SZLF 5V
90+
// Set coefficients and range for Sharp GP2Y0A60SZLF 5V
9191
float coeffs[] = {1734, -9.005, 2.023E-2, -2.251E-5, 1.167E-8, -2.037E-12};
9292
setPolyFitCoeffs(6, coeffs, 30, 875);
9393
break;
9494
}
95+
case GP2Y0A710K0F_5V_DS:
96+
{
97+
// Set coefficients and range for Sharp GP2Y0A710K0F 5V
98+
float coeffs[] = {178506, -1607.72, 5.5239, -8.47601E-3, 4.87819E-6};
99+
setPolyFitCoeffs(5, coeffs, 284, 507);
100+
break;
101+
}
95102
}
96103
}
97104

SharpDistSensor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ coefficients may be required.
4343
Use the setModel method to change the sensor model calibration. The following
4444
models are currently supported:
4545
-GP2Y0A60SZLF_5V (GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V)
46+
-GP2Y0A710K0F_5V_DS (GP2Y0A710K0F Analog Distance Sensor 100-500cm, 5V)
4647
4748
Use the setPolyFitCoeffs method to define custom polynomial coefficients.
4849
@@ -67,7 +68,9 @@ class SharpDistSensor
6768
enum models
6869
{
6970
// Constant for GP2Y0A60SZLF 5V model
70-
GP2Y0A60SZLF_5V
71+
GP2Y0A60SZLF_5V,
72+
// Constant for GP2Y0A710K0F 5V model
73+
GP2Y0A710K0F_5V_DS
7174
};
7275

7376
/** Constructor

examples/SharpDistSensorByModel/SharpDistSensorByModel.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void setup() {
4747
Serial.begin(9600);
4848

4949
// Set sensor model
50-
sensor.setModel(SharpDistSensor::GP2Y0A60SZLF_5V);
50+
sensor.setModel(SharpDistSensor::GP2Y0A710K0F_5V_DS);
5151
}
5252

5353
void loop() {

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ setPolyFitCoeffs KEYWORD2
55
setPowerFitCoeffs KEYWORD2
66
setValMinMax KEYWORD2
77
GP2Y0A60SZLF_5V LITERAL1
8-
GP2Y0A60SZLF_3V LITERAL1
8+
GP2Y0A710K0F_5V_DS LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SharpDistSensor
2-
version=1.1.1
2+
version=1.2.0
33
author=Julien de la Bruere-Terreault (drgfreeman@tuta.io)
44
maintainer=Julien de la Bruere-Terreault (drgfreeman@tuta.io)
55
sentence=Sharp analog distance sensor library

0 commit comments

Comments
 (0)