Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Sphero SPRK controlled via Mac fills up queue and lags with executing commands #93

Open
jasherone opened this issue Nov 25, 2017 · 2 comments

Comments

@jasherone
Copy link

jasherone commented Nov 25, 2017

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();
    };
@jasherone
Copy link
Author

jasherone commented Nov 25, 2017

I just noticed that after the queue is full and it starts to throw errors, it empties the queue approximately every half second (I attached the log below). Then after fully emptying the queue it starts to lag immediately.

`
Commands sent: 177 = = = = = = Time Running: 39.39800000190735 = = = = = = = Queue length: 10
Unhandled rejection Error: Command sync response was lost.
at Sphero.handler (/Users/martin/Workspace/LEAP Sphero MJ/node_modules/sphero/lib/sphero.js:257:21)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)

Commands sent: 177 = = = = = = Time Running: 39.431999921798706 = = = = = = = Queue length: 9
...//I cut this part, it was same logs just iterating Time Running variable ...
Commands sent: 177 = = = = = = Time Running: 39.883999824523926 = = = = = = = Queue length: 9

Unhandled rejection Error: Command sync response was lost.
at Sphero.handler (/Users/martin/Workspace/LEAP Sphero MJ/node_modules/sphero/lib/sphero.js:257:21)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)

Commands sent: 177 = = = = = = Time Running: 39.918999910354614 = = = = = = = Queue length: 8
...//I cut this part, it was same logs just iterating Time Running variable ...
Commands sent: 177 = = = = = = Time Running: 40.407999992370605 = = = = = = = Queue length: 8

Unhandled rejection Error: Command sync response was lost.
at Sphero.handler (/Users/martin/Workspace/LEAP Sphero MJ/node_modules/sphero/lib/sphero.js:257:21)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)

Commands sent: 177 = = = = = = Time Running: 40.43999981880188 = = = = = = = Queue length: 7
...//I cut this part, it was same logs just iterating Time Running variable ...
Commands sent: 177 = = = = = = Time Running: 40.89199995994568 = = = = = = = Queue length: 7

Unhandled rejection Error: Command sync response was lost.
at Sphero.handler (/Users/martin/Workspace/LEAP Sphero MJ/node_modules/sphero/lib/sphero.js:257:21)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)

Commands sent: 177 = = = = = = Time Running: 40.92799997329712 = = = = = = = Queue length: 6
`

@xocialize
Copy link

Could it be related to this bit of code in sphero/lib/sphero.js?

/**

  • Adds a sphero command to the queue
  • @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
  • this._queueCommand(cmdPacket, resolve, reject);
  • @return {void}
    */
    Sphero.prototype._queueCommand = function(cmdPacket, resolve, reject) {
    if (this.commandQueue.length === 20) { //I lowered this from 256
    this.commandQueue.shift();
    }

this.commandQueue.push({ packet: cmdPacket, resolver: resolve, rejecter: reject });
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants