-
Notifications
You must be signed in to change notification settings - Fork 90
Sphero SPRK controlled via Mac fills up queue and lags with executing commands #93
Description
Hello there,
I have a following issue and I hope someone can help me :/
Quick Description of the issue
I am trying to use this https://github.com/charliegerard/leap_sphero.git with my Sphero SPRK. But after I start sending commands to Sphero, the queue fills up and Sphero starts to lag in the real world responses to the commands.
My Question
1/ Did anyone encounter common issue and managed to fix that?
2/ Any tips on what to study to find out how does the queue or how to debug this?
3/ I was thinking of simply dumping the Sphero queue if it is longer than a few commands, any tips how can I do it please?
Fixes tried
1/ I tested on different versions of MacOS (not win and linux however)
2/ I found that the issue could be caused by noble version 1.8.0. I downgraded noble to 1.7.0 as suggested here #85
3/ Call ping() after connect() as suggested here #37
4/ @olcar here #37 said it works for him with Node 5.2.0 so I tried also downgrading to this version
Current Config
Mac OSX 10.12.6
Sphero model: S003, SPRK (not plus)
node -v 9.2.0
"express": "^4.16.2",
"leapjs": "^0.6.4",
"noble": "^1.7.0",
"serialport": "^3.1.2",
"sphero": "^0.9.2"
Detailed Description of the Issue
I only send roll commands to sphero, and I limit them to one command every 200ms.
Fist few commands execute instantly, but then after few seconds (or commands, either way it looks random), they suddenly start filling in the queue and execution starts lagging (up to few seconds long lags) and I was getting following message:
Unhandled rejection Error: Command sync response was lost.
at Sphero.handler (/Users/martin/Workspace/LEAP Sphero MJ/node_modules/sphero/lib/sphero.js:252:21)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
I tried sending commands more often and less often, it made no difference.
And I also tried waiting (for example 60 seconds) and then started sending commands. It looks like Sphero starts to lag after random seconds (or commands) after I start to send commands no matter how many commands I send and how much I waited before.
The error line is in this funcion:
/**
- Adds a promise to the queue, to be executed when a response
- gets back from the sphero.
- @Private
- @param {Array} cmdPacket the bytes array to be send through the wire
- @param {Function} resolve function to be triggered on success
- @param {Function} reject function to be triggered on failure
- @example
- sphero._execCommand(packet, resolve, reject);
- @return {void}
*/
Sphero.prototype._queuePromise = function(cmdPacket, resolve, reject) {
var seq = cmdPacket[4];
var handler = function(err, packet) {
clearTimeout(this.responseQueue[seq].timeoutId);
this.responseQueue[seq] = null;
this.busy = false;
if (typeof resolve === "function") {
if (!err && !!packet) {
resolve(packet);
} else {
var error = new Error("Command sync response was lost.");
reject(error);
}
}
this._execCommand();
};