• 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:

    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
    
    
About

Avatar for Gordon @Gordon started