# Fixed time positioning trajectory calculation

#### Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

•  Subject
• Author
• Posted on
For an application, I need to position a motor over a given distance
in a given time, within limitations of maximum speed, max ramp. As
long as ramp-up and ramp-down are equal and maximum speed is not
reached, the speed profile is a triangle and calculation is simple
(max speed is 2 x average, ramp-up half the time, ramp down for the
rest of the time).

But if I end up with needing a trapezoid, things get more complicated
and I have not found a nice solution yet. Searching for positioning, I
only found calculations that use distance, ramp and max-speed with
the actual time it takes as a result, not as an input.

Can anyone give me a pointer or link?

I would like to avoid iterative methods and look-up tables if
possible.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

"Most people would like to be delivered from
We've slightly trimmed the long signature. Click to see the full one.
Re: Fixed time positioning trajectory calculation

That's because as soon as the v(t) has to become trapezoidal, you
don't *have* two variables to control any more --- in other words,
you'll be driving the motor at the fastest speed it can possibly go,
with no options left.  I.e. the time you get as the result from those
formulae is not the time you wish for this move to take, but the
minimum amount of time the machine needs to get that far.

Assuming you're in the trapezoid regime,

a_max := max ramp (acceleration and deceleration limit assumed equal)
v_max := max speed
t_max := v_max / a_max = time from rest to v_max, at a_max

Max_distance(t) = 2 * a_max / 2 * t_max^2 + v_max * (t - 2 * t_max)
= v_max^2 / a_max         + v_max * (t - 2 * v_max / amax)
= v_max * t - v_max^2 / a_max
= v_max * (t - t_max)

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

You are now talking about a position that is not reachable in the
given time. But between these two extremes there is trapezoidal
solution that takes excactly the required time. There are 3 areas:

1) Short distance, ramps not at max, max speed not reached,
triangle, target reached in time.
2) Medium distance, ramps not at max, max speed not reached,
trapezoid, target reached in time.
3) Long distance, ramps at max, max speed reached,
trapezoid, target not reached in time.

1) is an easy solution (if ramps are equal)
3) can not be remedied, we'll have to live with that.

Yes, this gives the maximum distance possible in the given time and marks
the boundary between 2) and 3).

The problem:

Inputs:
- MaxRampUp
- MaxRampDown
- MaxSpeed
- MoveDistance
- MoveTime

Outputs:
- RampUp
- RampDown
- TopSpeed
- BrakingPoint

The resulting move should complete in exactly MoveTime if possible and
use the slowest possible ramps.

To complicate things, the max ramps are not equal and there is a starting
velocity. But I'll handle those if I can handle the simple case. :-)

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

Re: Fixed time positioning trajectory calculation

[...]

[...]

Look up to your own quoted text: you yourself started speaking of
"needing" a trapezoid.  You only "need" a trapezoid if a triangular
speed profile isn't workable, i.e. if the distance is larger than the
maximum triangle-type move can give you.  Once you're beyond that
point, you do indeed lose one degree of freedom.

Ah! That requirement is new, isn't it?  And do you want to keep
ramp-up and ramp-down equally fast, or both the same ratio of their
maximum allowed value. Or something else?

The formula still applies --- just drop the _max from a_max, and solve
it for a.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

[Helpfull info that I need to study in more detail]

I indeed did not mention it earlier, sorry. But even if I drop that
requirement and, for instance, use fixed time ramps I still have
trouble calculating the required topspeed to get to the target
position in time.

But which a? That remains my problem: a? topspeed? I'll keep on it, but
if anyone can come up with a clue I would be thankfull. I think I'm

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

PLUG IT IN!!!

Re: Fixed time positioning trajectory calculation

Repeat after me:

v = u+at
s = ut + a*sqr(t)
sqr(v) = (sqr(u) + 2*a*s
s = (v+u)/2 * t

GCE physics 1967.

Paul Burke

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

x(t) = x(0) + v(0)*t + 0.5*a*t^2

Highschool physics 1982 (?)

I already know my distance and the time it should take, now work out
ramp-up, steady and ramp-down. This was not in my physics exam I'm
affraid. Also notice the random sig below (Maybe fortune is not
that random after all :-)

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

Education is what survives when what has been learnt has been forgotten.
We've slightly trimmed the long signature. Click to see the full one.
Re: Fixed time positioning trajectory calculation

Sorry, my typo. Look, it's all quite easy. You have max speed Vm, and
acceleration a. So time to accelerate (= time to decelerate) = Vm/a.
Distance covered in acceleration and deceleration  = Vm*Vm/a.

The run distance is the remaining distance after acc/dec = S-Vm^2/a.
The time taken = distance/speed = S/Vm - Vm/a.

So total time = 2*Vm/a + S/Vm - Vm/a = S/Vm+Vm/a.

So Vm^2 -Vm*a*t +a*S = 0. Al Khwarismi will get your Vm for you (as well
as tell you if it's possible)

Paul Burke

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

Yes, if 'a' is known... So I'll have to estimate the a's (they are not
equal) and from there get Vm. Probably not optimal, but usable if
the sqrts don't take too long.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

One good reason why computers can do more work than people is that they
We've slightly trimmed the long signature. Click to see the full one.
Re: Fixed time positioning trajectory calculation

mail)

Can you adjust the ramp up and ramp down rates, in other words the
acceleration? If you can then there is no need to worry about the flat top
as you can get any timing within the limits of the machine by reducing the
acceleration. If you need to hit your maximum speed and the graph has a flat
top out then you don't have a solution, the machine can't possibly get there
in time.

http://www.crocodile-clips.com/absorb/AP5/sample/010104.html

Peter

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

Yes, I can adjust the ramps. And is some cases there is a solution with
a flat top at max speed, as long as acceleration is not over max. Or
even a flat top at less then max speed is possible.

All very basic highschool physics that I do know (or at least should :-)
but I'll study it to make sure. Thanks for that link.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

GIVE:    Support the helpless victims of computer error.

Re: Fixed time positioning trajectory calculation

Indeed.  And in those cases, *you* have to make a decision which kind
of profile you prefer.  You have 3 parameters in a trapezoidal
pattern: the actual ramp rates, and the flat top speed.  You have only
2 parametric requirements: total time (--> base width of the
trapezoid), and total distance (area of the trapezoid).

Which means your system is under-constrained, and will usually have an
infinitude of possible solutions.  You have to impose one more
restriction to get a well-defined solution.

I still think that if you "need" a trapezoidal pattern, that
automatically means you don't have any choice but to max out both the
the ramps and the top speed, and the problem doesn't actually arise.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

This restriction would ideally be "the lowest possible acceleration"
but that again needs to be found. So upto now I have not found an
easy solution.

No: Maxing out both can lead to reaching the destination before the
required time.

I think I'll work on an acceleration aproximation and from there,
using a modified version of paul's equation, get Vmax etc. This
might not give an 'optimum' but will probably work OK.

One more constraint: The calcualtions should not take more than a
few ms on a 30MHz 16-bit dsp. I thought I covered this in my first
post by asking for "no iterations" but it now looks like I'll
be needing square-roots, i'll see how long those take.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

"By the time they had diminished from 50 to 8, the other dwarves began
We've slightly trimmed the long signature. Click to see the full one.
Re: Fixed time positioning trajectory calculation
[snip]

mail)

Let S be the distance to go.
Let T be the time you want to get there in.
Let A be the maximum acceleration permitted.
Let V be the maximum speed permitted.
Let a be the actual acceleration required and t be the time for acceleration
(= time to slow too).

(1) Then try a triangle
a = 4S/T^2 and v = a*(T/2) = 2S/T. If a <= A and v <= V then we are done.

(2) If a>A then we just can't get there in time.

(3) so now we have a<= A and v > V, which means we try a trapezium with v =
V and up the a at the two ends to compensate.
We have S = 2(1/2)at^2 + V(T-2t) = at^2 + V(T-2t). But note that we must
accelerate from 0 to V in time t, so at = V. This leads to S = Vt + V(T-2t)
= V(T-t). So t = T - (S/V) and (taddah!)

a = V/(T-(S/V))

if a > A then we still can't get there in time, otherwise we're done.

So lets double check how far we go:

S' = at^2 + V(T-2t)
= V/(T-(S/V)*(T-(S/V))^2 +VT - 2V(T-(S/V))
= V*(T-(S/V)) + VT - 2V(T-(S/V)) = VT - V(T-(S/V))
= VT - VT + S
= S.

There are no square roots, no complications, just a few divides, and one of
them is by a constant (V).

Peter

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

Not completely done yet. The solution can still be triangular but requiring
more time then asked for. So we need some means to calculate the topspeed
reached in the trajectory. I've now made a quick hack that assumes only
accelerating for half of the _requested_ time. Which is far from optimal
as the move will take longer if shorter time is requested. I'll solve
this later.

[snip excellent formulas]

I've implemented your solution in my simple simulator and it works
perfectly, thanks.

All that is now left to do is take unequal accellleration and decelleration
into account. Which may not be that trivial as most simplifications in the
formulas are because they are equal. And there is also the matter of the
initial speed step that is now in there to prevent the motor from stalling.
But I'll try to get this working now.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

Re: Fixed time positioning trajectory calculation

acceleration
requiring

Eh? If a>A for a triangle then you can't get to where you want to be by
accelerating as hard as you can for half the time then decelerating just as
hard for the the other half. In that case you just can't get there on time
even if you don't get anywhere near the max speed.

You can't have more time than asked for, thats a given.

Eh?

Thanks, but I wrote formulae :)

decelleration
stalling.

It depends on the constraints between the acceleration and deceleration. It
can be simple, difficult or haev a family of solutions.

If you are moving at the start and want to arrive at the same speed then the
extension is also trivial - just replace S but S-v0*t, V by V-v0 and use the
initial moving frame as your new rest frame.

mail)

Peter

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

You are being a bit too strict here. :-)

The given time is a request, the distance is a must, not the other way
around. But that may not have been completely clear from my question.
So you can accelerate for for more than half the requested time and
decelerate for more than half the requested time, thereby completing
the required move in more than the requested time, using a triangular
profile.

If the move can not be completed in the requested time but stil uses
a triangular profile, you'll need to calculate the top of the actual
triangle, not the 'preferred' one. I've made a very crude calculation
topspeed = (required_time / 2) * max_accel. The result is not a triangle
but a trapezoid that gets lower if you request shorter (impossible) times.
I only did this to get the simulation up and running and see if the
other solutions give the wanted results. (and they did). I will now
punish myself for this foul and lazy hack and do it properly.

Goed, maar eigenlijk lees ik formules. ;-)

I'm not actually moving at the start, but the motor control loop gets an
initial 'minimal' speed to prevent sticking. This may not be the ideal
solution but this was already in the software. I am just rewriting the
profile generation as the original was rather flakey and did not meet
the targets even when possible. (It just calculated the required average
speed and set that as max_speed. Which ofcourse always results in a move
that takes longer than requested).

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

Novinson's Revolutionary Discovery:
We've slightly trimmed the long signature. Click to see the full one.
Re: Fixed time positioning trajectory calculation

[...]

Not only that: you have two accelerations, which you appear to want to
control separately.  So what does "lowest possible" actually mean,
then?  How do you plan to control two competing parameters by a single
minimization criterion?

Lacking that information, I'll assume the two accelerations to be
always the same (but of different sign), i.e. a symmetrical situation.

Let's go back to the v(t) diagram.  You want to construct a trapezoid
(or a triangle, which is included as a degenerate trapezoid with
zero-length upper parallel edge), with given base line (time to go)
and area (distance to cover).  Contraints are on the angles in the two
bottom corners (--> max acceleration and deceleration), and on the
height of the trapezoid.

If you think about it for a while, and make some sketches, I hope you
can agree find that for minimal angles, only two cases can happen:

1) triagonal pattern (because if you lower the accelerations any more,
you'll still have a triangular, but of smaller area).

2) a trapezoid of maxed-out height (because if there's still room
above the upper edge, you could always rotate the diagonals down a
bit, and compensate to keep the area fixed, by moving the upper edge
up a bit).

In a nutshell: if your movement needs an average velocity (v) of less
than v_max / 2, use a triangular pattern that only goes up to 2*v, and
immediately down again.  If you need v > v_max/2, use a trapezoidal
pattern going all the way up to v_max.  Use the equation poster
earlier, solved for the acceleration, to find out what acceleration
you need.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: Fixed time positioning trajectory calculation
In comp.arch.embedded,

"lowest possible" means as low as possible while still completing the
move in time. If you decrease the accelleration too much, the move can
not be completed in time.

are not equal.

Yes you are right on this. There is in some cases the posibility of
a trapeziod that not has the maxed out height. But, as you write
above, this can always be changed to a maxed out one. That does
make the problem a little easier. And this does in fact result
in the "lowest possible acceleration" solution. :-)

Yes I'll try this using equal accelerations and zero startspeed for
now. I already wrote a small C program to test the equations and show
me the resulting move. If this works OK, I'll try to move on to
non-zero start speed and asymetrical acceleration.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

The chief cause of problems is solutions.
We've slightly trimmed the long signature. Click to see the full one.
Re: Fixed time positioning trajectory calculation

You still speak about decreasing _the_ acceleration.  But you have
_two_ accelerations to choose from.  For the second time: as stated,
that optimization goal doesn't make sense.  You have to be more
specific in how you want to apply this single goal to two independent
parameters.

In the trapezoidal case, it's actually quite simple to resolve this,
since the area of the trapezoid has only one remaining parameter
(after we agreed that the height must be v_max, and the baseline is
given by the travel time): the length of the "roof".  In particular,
you can shift around the upper horizontal part arbitrarily, without
changing the effective result.  Keeping it centered will give lowest
maximum acceleration (because if you move it away from the center, the
two angles will be different, and one of them will be larger than in
the symmetric case).  If that violates the smaller of the two
acceleration limits, pin that side of the trapezoid to the allowed
angle and shift the roof accordingly.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.