Skip to content
This repository was archived by the owner on Jun 10, 2023. It is now read-only.

Commit b9be06d

Browse files
committed
Added a simple distance events counter to reduce random triggering
1 parent b46e737 commit b9be06d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

hid_mbot.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
var HID = require('node-hid');
33
var device;
4+
const DISTANCE_THRESHOLD = 25;
5+
46

57
//TODO put inside green flag code inizialization for this and other vars
68
const defaultMotorsSpeed = 150;
@@ -55,7 +57,7 @@ function startRobotConnection() {
5557
}
5658

5759
function updateSensors() {
58-
getLineFollowSensor();
60+
//getLineFollowSensor();
5961
getDistanceSensor();
6062

6163
setTimeout(updateSensors, 10);
@@ -93,14 +95,19 @@ function readSensorsData(data) {
9395
lineFollower = num;
9496
}
9597
if (distance < 7) {
96-
//Trigger short distance event
97-
console.log("short");
98-
//TODO remove interpreter control from here
98+
distanceCounter++;
99+
} else {
100+
distanceCounter--;
101+
}
102+
if (distanceCounter > DISTANCE_THRESHOLD) {//Trigger short distance event
99103
stepCode(true);
104+
distanceCounter = DISTANCE_THRESHOLD;
105+
} else if (distanceCounter < 0) {
106+
distanceCounter = 0;
100107
}
101108

102109
}
103-
110+
var distanceCounter = 0;
104111

105112
function connectDongle(path) {
106113
try {

0 commit comments

Comments
 (0)