View Full Version : Trapezoidal Motion Profile Using Discrete Method
martinrand
09-03-2015, 11:44
Hi,
I'm trying to program an arduino to generate a Trapezoidal Motion Profile to control a DC motor with a quadrature encoder.
Essentially, the user will input the desired Target Position, Max Velocity and Acceleration (decel = -accel) and the code will calculate the target position versus time which will then be compared with the actual position. The result will then be subject to a PID calculation
My initial assumption was that I could use basic Newtonian physics to determine position (i.e. PT = P0 + V0T + 1/2AT2, VT = V0 + AT). However, after reading through documentation for pre-existing motion controllers, I discovered that the prevalent method was to use a discrete time method, which is as follows:
VK = VK-1 + A (A = Acceleration)
PK = PK-1 + VK-1 + A/2
I'm having a hard time understanding quite how this equation would generate the target position versus time. In the case of Velocity, it seems to just add the acceleration to the current velocity. But what about everything in between?
Could anybody take a shot at explaining to me how this method is used? I've spent ages searching for answers online but have had no such luck.
Thanks,
Martin
While you're waiting for answers, take a look at this paper (http://www.chiefdelphi.com/media/papers/download/4313). It's pretty straightforward.
martinrand
09-03-2015, 13:48
Thanks for your reply!
I'm trying to stay away from S-Curve profiles for the time being. I think I should probably understand the trapezoidal method before I start jumping into some more complicated.
I'm trying to stay away from S-Curve profiles for the time being.
If you use a trapezoidal velocity profile, you will get an S-curve for x(t) (http://www.chiefdelphi.com/media/papers/download/4285).
I think I should probably understand the trapezoidal method before I start jumping into some more complicated.
Sinusoidal is actually less complicated in many ways. No need to break the functions into regions.
FWIW, I just updated the paper to revA (http://www.chiefdelphi.com/media/papers/download/4319) to include a plot of accel vs velocity so you can check to make sure the profile does not run afoul of motor saturation.
martinrand
09-03-2015, 16:38
Thanks, I'll certainly take another look.
Potentially, I could generate an sigmoid function to represent position, using parameters from a trapezoidal profile.
I suppose calculating position at a given time would then be as simple as plugging t into the equation. This would then do away with the need to have 3 section for accel, max velocity and decel.
Does that sound feasible?
This was how I originally assumed things were done.
The a(t), v(t), and x(t) functions in the paper are stand-alone.
If you are not going to use velocity or acceleration in your control algorithm, you don't need to compute a(t) or v(t). Just use x(t).
martinrand
09-03-2015, 17:16
Any idea how I would take 3 variables for a trapezoidal profile (Accel, Max Velocity and Target Position, *decel=-accel*) and convert that into x(t)?
Any idea how I would take 3 variables for a trapezoidal profile (Accel, Max Velocity and Target Position, *decel=-accel*) and convert that into x(t)?
http://www.chiefdelphi.com/media/papers/download/4284
http://www.chiefdelphi.com/media/papers/download/4287
http://www.chiefdelphi.com/media/papers/download/4288
Knock yourself out.
martinrand
09-03-2015, 17:38
Thanks for that!
Afraid I can't open the .exe as I'm using a mac. Any chance you have a mac version or source code available?
Thanks
Afraid I can't open the .exe as I'm using a mac. Any chance you have a mac version or source code available?
You have the equations. Just put them into a spreadsheet or LabVIEW. Or install Maxima on your Mac and run the script I gave you.
Potentially, I could generate an sigmoid function to represent position
Which particular sigmoid function did you have in mind?
Assuming you meant the Logistic Function:
x(t) = L/(1+exp(-k*(t-tm))),
where:
tm = the t-value of the sigmoid's midpoint
L = the curve's maximum value
k = the steepness of the curve
...that would be a poor choice.
To see why, suppose you want to go from x=0 and v=0 and a=0 at t=0 to x=5ft and v=0 and a=0 at t=3seconds.
Then L and tm would be L=5 tm=3/2.
The only free parameter left is k; try k=2, k=3, k=4, k=5.
As can be seen from the graphs, there is no acceptable value for k.
k=2: a, v, and x are non-zero at beginning and end points, and x has not reached 5 at t=3.
k=3: better, but a and v are still nonzero at endpoints
k=4: a is still not quite zero at endpoints. max accel has grown to 7.7
k=5: endpoints look good, but max accel is now 12, and max jerk is 77
Compare those graphs to the Figure on page 1 of this paper (http://www.chiefdelphi.com/media/papers/download/4319), which uses a sinusoidal function for x(t), resulting in
x=0, v=0, and a=0 at t=0, and
x=5, v=0, a=0 at t=3, and
max accel=3.5, max speed=3.3, max jerk=7.3
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.