It was for steppers, not servos - but the same should apply for more than one servo:
function moveTo(p, speed, callback) {
var dx = x.pos - p[0];
var dy = y.pos - p[1];
var d = Math.sqrt(dx*dx+dy*dy);
var time = d*speed;
x.move(p[0],time, undefined);
y.move(p[1],time, callback);
}
You can just call move on multiple servo instances, having the same time period for all of them - and then callback when one has finished (they will all finish at the same time). Note the code above is trying to keep a constant speed, not movement time.
Getting that to work as a promise, with a set time perios should be something like:
function moveTo(p, time) {
return new Promise(function(resolve){
x.move(p[0],time, undefined);
y.move(p[1],time, resolve);
}
}
moveTo([0,0],1000).then(x=>{
moveTo([1,1],1000)
})...etc
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I guess you might find what I did for the laser cutter helpful: http://forum.espruino.com/conversations/821/#26363
It was for steppers, not servos - but the same should apply for more than one servo:
You can just call
move
on multiple servo instances, having the same time period for all of them - and then callback when one has finished (they will all finish at the same time). Note the code above is trying to keep a constant speed, not movement time.Getting that to work as a promise, with a set time perios should be something like: