The basic idea is the same:
To generate the movement profile, you typically want to store the "start position," "start time," "target position," and "last sent position" for each servo.Code:int main() { setup(); while (true) { loop(); } } long lastTime = 0; void loop() { long time = millis(); if (time - lastTime >= 10) { calculateNewPosition(time); lastTime = time; } }
When you update, calculate "how long after the start time am I now? where do I want to be based on that? That's my new send-position."
So would calculateNewPosition function include something like sin? How would I create a function that maps time passed to a sinusoidal velocity profile? Also, would it work best to apply this individually to only the start/stop acceleration and (With a constant velocity in between stop/start positions) or map the whole motion to a sinusoidal velocity profile?
Last edited by memmerich; 12-16-2016 at 07:27 PM.
It could, although usually, it will just be a trapezoidal value. (The closer you are to each end point, the slower you go, with some clamp to the maximum velocity allowed.)
Note that you can map either time, or position, to the desired velocity. Mapping current-position to desired-velocity requires almost no math, but the exact behavior will then depend on the time step size. (The math reason for this is that it ends up being a discrete simulation of a differential equation.)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks