johnny-five
johnny-five copied to clipboard
Feature request: Callback/promise on accelStepperStop
If I try to give my stepper a second command after the first one, then it usually just stops moving and says complainy sounds. I found a way around that by calling board.io.accelStepperStop(id) and setting in a 100ms delay, but that adds a small delay, not a big deal, unless maybe once it takes more than 100ms to stop the servo, then it'll bugger up. I may be trying to solve the problem in the wrong way though, if that's the case, please let me know xD
There is already a way. When you call stop, after decelerating and stopping firmata will report back from the board with STEPPER_MOVE_COMPLETE and the stepper's position. The board instance will emit stepper-done-# where # is the stepper number. It will receive the stepper's current position as its only parameter.
Not tested, but here's the gist.
function stopThenDo(stepper, callback) {
board.io.once(`stepper-done-${stepper}`, position => {
callback(position);
});
board.io.accelStepperStop(stepper);
}
// Stop stepper 2 and report position after reaching a complete stop
stopThenDo(2, position => {
console.log(`Stopped at position ${position}`);
});