#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# How to incorporate de/acceleration in a vector system

edited July 2016

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.

Thanks.

Tagged:

• ``````PVector target = new PVector(0,0);
PVector queued = new PVector(0,0);
float lerp_amt = 0;
boolean new_target = false;

void setup(){
size(300,300);
}

void draw(){
background(0);
translate(150,150);
stroke(255);

// Update lerp_amt
lerp_amt+=0.01;
if(new_target){
lerp_amt-=0.02;
}
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.
strokeWeight(1);
stroke(0,0,255);
line(0,0,queued.x, queued.y);

// Current target in red.
strokeWeight(3);
stroke(255,0,0);
line(0,0,target.x,target.y);

// Actual velocity vector in white.
strokeWeight(1);
stroke(255);
line(0,0,lerp(0,target.x,lerp_amt),lerp(0,target.y,lerp_amt));
}

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.

• 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 >_<)