WasabiFan / ev3dev-lang-js

JavaScript language bindings for ev3dev
56 stars 8 forks source link

Infrared Sensor PROX #25

Open codeadamca opened 6 years ago

codeadamca commented 6 years ago

Hello, I am using the infrared sensor. I have NodeJS checking the proximity every 500 milliseconds. But the numbers seem very random. If I monitor the /sys/class/lego-sensor/sensor1/value0 file, it seems accurate. But the Infrared.getValue(0) does not.

Here my code that is being called every 500 milliseconds:

var ev3dev = require("ev3dev-lang");

var sensor = new ev3dev.InfraredSensor( ev3dev["INPUT_2"] );
sensor.mode = "IR-PROX";
console.log(sensor.getValue(0));
console.log(sensor.proximity);

Any help would be appreciated.

WasabiFan commented 6 years ago

I'm having trouble imagining a reason for the behavior you're seeing. Are you sure you're looking at the same sensor? And are pointing it in the same direction with the same expected result? Is it possible that the slowness of the EV3 (and, by extension, the inconsistency of any timers) is causing this?

If you can provide a sample of the readings from the two sources I might be able to spot a pattern.

codeadamca commented 6 years ago

I'm using a Pi3 and a BrickPi3. Would that make a difference? When I'm testing it's the only sensor I'm using. It's the same for the IR-SEEK. I'll send some data samples when I have a minute.