Skip to content

Commit

Permalink
Proximity: add resolution of MB1003 device
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlup authored and rwaldron committed Feb 20, 2018
1 parent 998b353 commit b2ebba8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/proximity.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ var Controllers = {
toCm: {
value: function(raw) {
// http://www.maxbotix.com/articles/032.htm
return raw / 2;
//
// Datasheet available at https://www.maxbotix.com/documents/HRLV-MaxSonar-EZ_Datasheet.pdf
//
// From intro in page 1
// 'This sensor line features 1-mm resolution, .....'
return toFixed(raw / 2, 1);
}
}
},
Expand Down
13 changes: 7 additions & 6 deletions test/proximity.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,15 +656,16 @@ exports["Proximity: MB1003"] = {
MB1003: function(test) {
var callback = this.analogRead.args[0][1];

test.expect(4);
test.expect(5);

// 500 is an actual reading at ~250cm
callback(500);
callback(507);

test.equals(Math.round(this.proximity.centimeters), 250);
test.equals(Math.round(this.proximity.cm), 250);
test.equals(Math.round(this.proximity.inches), 98);
test.equals(Math.round(this.proximity.in), 98);
test.equals(Math.round(this.proximity.centimeters), 254);
test.equals(Math.round(this.proximity.cm), 254);
test.equals(Math.round(this.proximity.inches), 99);
test.equals(Math.round(this.proximity.in), 99);
test.equals(digits.fractional(this.proximity.centimeters), 1);

test.done();
},
Expand Down

0 comments on commit b2ebba8

Please sign in to comment.