Trapezoidal Motion Profile Using Discrete Method


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.



*While you’re waiting for answers, take a look at this paper. It’s pretty straightforward.

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.

If you use a trapezoidal velocity profile, you will get an S-curve for x(t).

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 to include a plot of accel vs velocity so you can check to make sure the profile does not run afoul of motor saturation.

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).

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)?

Knock yourself out.

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?

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.

Which particular sigmoid function did you have in mind?

Assuming you meant the Logistic Function:

x(t) = L/(1+exp(-k*(t-t[sub]m[/sub]))),


t[sub]m[/sub] = 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 t[sub]m[/sub] would be L=5 t[sub]m[/sub]=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, 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


sigmoid.pdf (811 KB)

sigmoid.pdf (811 KB)