How to incorporate de/acceleration in a vector system

I am interfacing over udp with a system (a robot) wherein I send a vector movement and get feedback on it's actual co-ordinates many times per second (hopefully nearing the target of 4ms)

Due to there being no in-built ramping of the speed (accelerating or braking) this creates a jerking motion when the vector direction changes (or attempts to go from 0 to full speed in 4milliseconds..)

Anyone have any ideas on how to code this, wherein we can only send a movement vector, only receive the current position, and have a dynamic queue of points to drive towards; and have it accelerate/decelerate in response to drastic movement vector changes and yet behave normally when there isn't drastic movement vector change.

If anyone has code, psuedo-code, advice, or alternate solutions to suggest I'm all open.



  • PVector target = new PVector(0,0);
    PVector queued = new PVector(0,0);
    float lerp_amt = 0;
    boolean new_target = false;
    void setup(){
    void draw(){
      // Update lerp_amt
      lerp_amt = constrain(lerp_amt,0,1);
      // Switch to new target at 0 movement.
      if(lerp_amt == 0){
        target.x = queued.x;
        target.y = queued.y;
        new_target = false;
      // Queued target in blue.  
      line(0,0,queued.x, queued.y);
      // Current target in red.
      // Actual velocity vector in white.  
    void mousePressed(){
      // Queue new target.
      queued.x = mouseX-150;
      queued.y = mouseY-150;
      new_target = true;
  • Hmm, but this basically has the actual point stopping to 0 velocity at every point , as opposed to the normal smooth movement I would prefer (unless there was a drastic vector change) sorry if I wasn't clear on that.

    Moreover, as there is no feedback loop, if I did make it smooth (having the velocity lerp directly to the new queued velocity), it'd probably overshoot and end up somewhere completely different as no course correction is being carried out.

    And while its pretty minor, by dynamic queue I meant an actual queue of subsequent points to reach (say in an ArrayList or similar) It's somewhat of a moot point though as if it can be done with a single queued point, it shouldn't be too hard to expand it to a list of queued points.

  • slowdown quick illustration to hopefully better convey my intention black points are queued co-ordinates (movement between points would be linear, ignore how curved I made the path >_<)

Sign In or Register to comment.