Skip to content

Commit f190df9

Browse files
authored
Merge pull request #10 from DrGFreeman/GP2Y0A51SK0F
Adding GP2Y0A51SK0F sensor model
2 parents e078f81 + 13e1054 commit f190df9

File tree

4 files changed

+173
-151
lines changed

4 files changed

+173
-151
lines changed

README.md

Lines changed: 21 additions & 7 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.3.0
4+
Version 1.4.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

@@ -58,19 +58,33 @@ where _A_ is the analog value read from the sensor. `valMin` and `valMax` define
5858
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.
5959

6060
## Pre-defined sensor models
61-
* `GP2Y0A60SZLF_5V` - GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V
62-
* `GP2Y0A710K0F_5V_DS` - GP2Y0A710K0F Analog Distance Sensor 100-500cm, 5V (data sheet)
61+
* `GP2Y0A60SZLF_5V`: GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V, polynomial fit.
62+
* `GP2Y0A710K0F_5V_DS`: GP2Y0A710K0F Analog Distance Sensor 100-500cm, 5V (data sheet), polynomial fit.
63+
* `GP2Y0A51SK0F_5V_DS`: GP2Y0A51SK0F Analog Distance Sensor 2-15cm, 5V (data sheet), power fit.
64+
65+
#### Polynomial / Power fit coefficients:
66+
67+
Model | Units | C0/C | C1/P | C2 | C3 | C4 | C5
68+
------|-------|----|----|----|----|----|----
69+
**GP2Y0A60SZLF_5V** | mm | 1734 | -9.005 | 2.032E-2 | -2.251E-5 | 1.167E-8 | -2.037E-12
70+
**GP2Y0A710K0F_5V_DS** | mm | 178506 | -1607.72 | 5.5239 | -8.47601E-3 | 4.87819E-6 |
71+
**GP2Y0A51SK0F_5V_DS** | mm | 4.03576E+4 | -1.26093 | | | |
72+
73+
#### Analog values range:
74+
75+
Model | valMin | valMax
76+
------|--------|--------
77+
**GP2Y0A60SZLF_5V** | 30 | 875
78+
**GP2Y0A710K0F_5V_DS** | 284 | 507
79+
**GP2Y0A51SK0F_5V_DS** | 70 | 500
6380

64-
Model | Units | C0 | C1 | C2 | C3 | C4 | C5 | valMin | valMax
65-
------|-------|----|----|----|----|----|----|--------|--------
66-
**GP2Y0A60SZLF_5V** | mm | 1734 | -9.005 | 2.032E-2 | -2.251E-5 | 1.167E-8 | -2.037E-12 | 30 | 875
67-
**GP2Y0A710K0F_5V_DS** | mm | 178506 | -1607.72 | 5.5239 | -8.47601E-3 | 4.87819E-6 | | 284 | 507
6881

6982
**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.
7083

7184
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!
7285

7386
## Version history
87+
* 1.4.0 (2018-05-21): Added GP2Y0A51SK0F_5V_DS model.
7488
* 1.3.0 (2018-05-20): Added SharpDistSensorArray example.
7589
* 1.2.0 (2017-05-10): Added GP2Y0A710K0F_5V_DS model.
7690
* 1.1.1 (2017-05-01): Clarified comments and fixed typos in examples, improved README.

SharpDistSensor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Source: https://github.com/DrGFreeman/SharpDistSensor
44
55
MIT License
66
7-
Copyright (c) 2017 Julien de la Bruere-Terreault <drgfreeman@tuta.io>
7+
Copyright (c) 2018 Julien de la Bruere-Terreault <drgfreeman@tuta.io>
88
99
Permission is hereby granted, free of charge, to any person obtaining a copy
1010
of this software and associated documentation files (the "Software"), to deal
@@ -99,6 +99,12 @@ void SharpDistSensor::setModel(const models model)
9999
setPolyFitCoeffs(5, coeffs, 284, 507);
100100
break;
101101
}
102+
case GP2Y0A51SK0F_5V_DS:
103+
{
104+
// Set coefficients and range for Sharp GP2Y0A51SK0F 5V
105+
setPowerFitCoeffs(4.03576E+4, -1.26093, 70, 500);
106+
break;
107+
}
102108
}
103109
}
104110

SharpDistSensor.h

Lines changed: 144 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,144 @@
1-
/*
2-
SharpDistSensor.h
3-
Source: https://github.com/DrGFreeman/SharpDistSensor
4-
5-
MIT License
6-
7-
Copyright (c) 2017 Julien de la Bruere-Terreault <drgfreeman@tuta.io>
8-
9-
Permission is hereby granted, free of charge, to any person obtaining a copy
10-
of this software and associated documentation files (the "Software"), to deal
11-
in the Software without restriction, including without limitation the rights
12-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
copies of the Software, and to permit persons to whom the Software is
14-
furnished to do so, subject to the following conditions:
15-
16-
The above copyright notice and this permission notice shall be included in all
17-
copies or substantial portions of the Software.
18-
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25-
SOFTWARE.
26-
*/
27-
28-
/*
29-
SharpDistSensor; Sharp analog distance sensor library
30-
31-
This is a library for the Arduino IDE that helps interface with Sharp IR analog
32-
distance sensors.
33-
34-
The analog value from the sensor is converted to distance using either a fifth
35-
order polynomial fit function or a power fit function.
36-
37-
By default, this library is set to use polynomial coefficients calibrated for
38-
the Sharp GP2Y0A60SZLF Analog Distance Sensor 10-150cm 5V, over a range of
39-
50-1500 mm (analog values 30-875). The returned distance is in millimeters (mm)
40-
units. For different accuracy, range, sensor model or units, different
41-
coefficients may be required.
42-
43-
Use the setModel method to change the sensor model calibration. The following
44-
models are currently supported:
45-
-GP2Y0A60SZLF_5V (GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V)
46-
-GP2Y0A710K0F_5V_DS (GP2Y0A710K0F Analog Distance Sensor 100-500cm, 5V)
47-
48-
Use the setPolyFitCoeffs method to define custom polynomial coefficients.
49-
50-
Use the setPowerFitCoeffs method to define custom power coefficients.
51-
52-
Use the setValMinMax method to define different analog values range.
53-
54-
The distance output is filtered using median filtering. MedianFilter class from
55-
the following library is used: https://github.com/daPhoosa/MedianFilter.
56-
*/
57-
58-
#ifndef SharpDistSensor_h
59-
#define SharpDistSensor_h
60-
61-
#include <Arduino.h>
62-
#include <MedianFilter.h>
63-
64-
class SharpDistSensor
65-
{
66-
public:
67-
// List of pre-defined sensor models
68-
enum models
69-
{
70-
// Constant for GP2Y0A60SZLF 5V model
71-
GP2Y0A60SZLF_5V,
72-
// Constant for GP2Y0A710K0F 5V model
73-
GP2Y0A710K0F_5V_DS
74-
};
75-
76-
/** Constructor
77-
pin: Arduino analog pin the sensor is connected to
78-
size: Window size of the median filter (1 = no filtering)
79-
**/
80-
SharpDistSensor(const byte pin, const byte size = 1);
81-
82-
// Return the measured distance
83-
uint16_t getDist();
84-
85-
// Set the sensor model
86-
void setModel(const models model);
87-
88-
/* Set the polynomial fit function coefficients and range
89-
nbCoeffs: Number of coefficients (1 min, 6 max)
90-
coeffs: Coefficients (x^0 to x^5)
91-
valMin: Minimal analog value for which to return a distance
92-
valMax: Maximal analog value for which to return a distance
93-
*/
94-
void setPolyFitCoeffs(const byte nbCoeffs, const float* coeffs,
95-
const uint16_t valMin, const uint16_t valMax);
96-
97-
/* Set the power fit function coefficients and range
98-
C and P: Coefficients in Distance = C*x^P relation
99-
valMin: Minimal analog value for which to return a distance
100-
valMax: Maximal analog value for which to return a distance
101-
*/
102-
void setPowerFitCoeffs(const float C, const float P,
103-
const uint16_t valMin, const uint16_t valMax);
104-
105-
// Set the analog value range for which to return a distance
106-
void setValMinMax(const uint16_t valMin, const uint16_t valMax);
107-
108-
private:
109-
// Arduino analog pin the sensor is connected to
110-
byte _pin;
111-
112-
// Window size of the median filter (1 = no filtering)
113-
byte _mfSize;
114-
115-
// Minimal analog value for which to return a distance
116-
uint16_t _valMin;
117-
118-
// Maximal analog value for which to return a distance
119-
uint16_t _valMax;
120-
121-
// Polynomial function coefficients to convert analog signal to distance
122-
float _polyCoeffs[6];
123-
124-
// Power function coefficients to convert analog signal to distance
125-
float _powerCoeffC;
126-
float _powerCoeffP;
127-
128-
// Possible types of fit functions
129-
enum fitTypes
130-
{
131-
FIT_POLY,
132-
FIT_POWER
133-
};
134-
135-
// Fit function type used
136-
fitTypes _fitType;
137-
138-
// Median filter object instance
139-
MedianFilter medFilt;
140-
};
141-
142-
#endif
1+
/*
2+
SharpDistSensor.h
3+
Source: https://github.com/DrGFreeman/SharpDistSensor
4+
5+
MIT License
6+
7+
Copyright (c) 2018 Julien de la Bruere-Terreault <drgfreeman@tuta.io>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
/*
29+
SharpDistSensor; Sharp analog distance sensor library
30+
31+
This is a library for the Arduino IDE that helps interface with Sharp IR analog
32+
distance sensors.
33+
34+
The analog value from the sensor is converted to distance using either a fifth
35+
order polynomial fit function or a power fit function.
36+
37+
By default, this library is set to use polynomial coefficients calibrated for
38+
the Sharp GP2Y0A60SZLF Analog Distance Sensor 10-150cm 5V, over a range of
39+
50-1500 mm (analog values 30-875). The returned distance is in millimeters (mm)
40+
units. For different accuracy, range, sensor model or units, different
41+
coefficients may be required.
42+
43+
Use the setModel method to change the sensor model calibration. The following
44+
models are currently supported:
45+
-GP2Y0A60SZLF_5V (GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V)
46+
-GP2Y0A710K0F_5V_DS (GP2Y0A710K0F Analog Distance Sensor 100-500cm, 5V)
47+
48+
Use the setPolyFitCoeffs method to define custom polynomial coefficients.
49+
50+
Use the setPowerFitCoeffs method to define custom power coefficients.
51+
52+
Use the setValMinMax method to define different analog values range.
53+
54+
The distance output is filtered using median filtering. MedianFilter class from
55+
the following library is used: https://github.com/daPhoosa/MedianFilter.
56+
*/
57+
58+
#ifndef SharpDistSensor_h
59+
#define SharpDistSensor_h
60+
61+
#include <Arduino.h>
62+
#include <MedianFilter.h>
63+
64+
class SharpDistSensor
65+
{
66+
public:
67+
// List of pre-defined sensor models
68+
enum models
69+
{
70+
// Constant for GP2Y0A60SZLF 5V model
71+
GP2Y0A60SZLF_5V,
72+
// Constant for GP2Y0A710K0F 5V model
73+
GP2Y0A710K0F_5V_DS,
74+
// Constant for GP2Y0A51SK0F 5V model
75+
GP2Y0A51SK0F_5V_DS,
76+
};
77+
78+
/** Constructor
79+
pin: Arduino analog pin the sensor is connected to
80+
size: Window size of the median filter (1 = no filtering)
81+
**/
82+
SharpDistSensor(const byte pin, const byte size = 1);
83+
84+
// Return the measured distance
85+
uint16_t getDist();
86+
87+
// Set the sensor model
88+
void setModel(const models model);
89+
90+
/* Set the polynomial fit function coefficients and range
91+
nbCoeffs: Number of coefficients (1 min, 6 max)
92+
coeffs: Coefficients (x^0 to x^5)
93+
valMin: Minimal analog value for which to return a distance
94+
valMax: Maximal analog value for which to return a distance
95+
*/
96+
void setPolyFitCoeffs(const byte nbCoeffs, const float* coeffs,
97+
const uint16_t valMin, const uint16_t valMax);
98+
99+
/* Set the power fit function coefficients and range
100+
C and P: Coefficients in Distance = C*x^P relation
101+
valMin: Minimal analog value for which to return a distance
102+
valMax: Maximal analog value for which to return a distance
103+
*/
104+
void setPowerFitCoeffs(const float C, const float P,
105+
const uint16_t valMin, const uint16_t valMax);
106+
107+
// Set the analog value range for which to return a distance
108+
void setValMinMax(const uint16_t valMin, const uint16_t valMax);
109+
110+
private:
111+
// Arduino analog pin the sensor is connected to
112+
byte _pin;
113+
114+
// Window size of the median filter (1 = no filtering)
115+
byte _mfSize;
116+
117+
// Minimal analog value for which to return a distance
118+
uint16_t _valMin;
119+
120+
// Maximal analog value for which to return a distance
121+
uint16_t _valMax;
122+
123+
// Polynomial function coefficients to convert analog signal to distance
124+
float _polyCoeffs[6];
125+
126+
// Power function coefficients to convert analog signal to distance
127+
float _powerCoeffC;
128+
float _powerCoeffP;
129+
130+
// Possible types of fit functions
131+
enum fitTypes
132+
{
133+
FIT_POLY,
134+
FIT_POWER
135+
};
136+
137+
// Fit function type used
138+
fitTypes _fitType;
139+
140+
// Median filter object instance
141+
MedianFilter medFilt;
142+
};
143+
144+
#endif

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.3.0
2+
version=1.4.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)