- #1

Joan M

Gold Member

- 13

- 0

Hello all,

First of all let me say this is my first post here and I don't know if I'm placing it into the right forum/place. If I'm doing something wrong or similar, please let me know and I'll try to solve it asap.

This is not homework, but it is for sure introductory level so I've thought it was right to write it here.

Again, if it is not the right place just let me know.

I'm creating a small program to move a motor. That movement will have to be performed using the trapezoid profile in order to keep it soft at the beginning and at the end.

In my case I'm trying to create a trajectory from point x0 to x1 given a maximum acceleration and a speed (which is entered by the user and therefore it can be much higher than what is allowed by the system).

The available data is:

See in the attempt at a solution where I've pasted a piece of code and all the comments to make it easier to follow.

~~The solution works with two big flaws:~~

I've been looking at formulas for two days and now I'm obfuscated and I've decided to search for help.

I've seen this forum and I've thought to write this here and see what happens.

Usually in the forums I participate I try to help and so, but I'm afraid here I won't be able to help a lot, but I'll try to snoop around and see if I can give something to the community.

Well, thank you for your time and for helping.

Joan.

First of all let me say this is my first post here and I don't know if I'm placing it into the right forum/place. If I'm doing something wrong or similar, please let me know and I'll try to solve it asap.

This is not homework, but it is for sure introductory level so I've thought it was right to write it here.

Again, if it is not the right place just let me know.

1. Homework Statement1. Homework Statement

I'm creating a small program to move a motor. That movement will have to be performed using the trapezoid profile in order to keep it soft at the beginning and at the end.

In my case I'm trying to create a trajectory from point x0 to x1 given a maximum acceleration and a speed (which is entered by the user and therefore it can be much higher than what is allowed by the system).

The available data is:

- vmax = desired maximum speed (it can be impossible to reach).
- v0 = initial speed.
- vf = final speed (usually it will be 0).
- a = acceleration (to accelerate and brake, we will use the same).
- x0 = initial position.
- xf = destination position.

## Homework Equations

See in the attempt at a solution where I've pasted a piece of code and all the comments to make it easier to follow.

## The Attempt at a Solution

Code:

```
ta = Abs((vmax - v0) / a) ' Acceleration time
da = (v0 * ta) + (0.5 * a * ta * ta) ' Distance while accelerating
tf = Abs((vmax - vf) / a) ' Braking time.
df = (vf * tf) + (0.5 * a * tf * tf) ' Distance while braking.
If (da + df > dist) Then ' If the acceleration and braking distances are bigger than the complete travel we have problems...
If (v0 = vf) Then ' If initial and final speeds are the same...
taux = (Sqr((a * dist) + (v0 * v0)) - v0) / a ' then I can calculate the time it will take to reach the real maximum speed
vmax = v0 + a * taux ' and at the end I can calculate the maximum speed
Else ' but... if both speeds are not coincident...
DistTotal = xf - x0 - da - df ' Here I'm getting the total distance that is traveled.
RelAccDec = da / (da + df) ' The relationship between the acceleration and deceleration stages.
dist_corr_acc = DistTotal * RelAccDec ' The correction factor for the acceleration stage.
da = da + dist_corr_acc ' The real distance traveled during acceleration.
dist_corr_dec = DistTotal * (1 - RelAccDec) ' the correction factor for braking.
df = df + dist_corr_dec ' the real distance traveled during braking.
taux = (Sqr((a * dist) + (v0 * v0)) - v0) / a ' This should give me the time the acceleration stage takes.
vmax = v0 + (a * taux) ' and this the maximum speed reached during the acceleration (which will be the maximum speed used to move the motor).
End If
End If
```

~~We can not find the real vmax (just something close to it as we are drecreasing always by 1).~~

~~It will take ages to calculate the vmax if the user enters a very big value for vmax initially.~~

I've been looking at formulas for two days and now I'm obfuscated and I've decided to search for help.

I've seen this forum and I've thought to write this here and see what happens.

Usually in the forums I participate I try to help and so, but I'm afraid here I won't be able to help a lot, but I'll try to snoop around and see if I can give something to the community.

Well, thank you for your time and for helping.

Joan.

Last edited: