Do you mean you have an analog linear positioning drive of some sort, and you want to control its position as a function of time as

Code:

x(t) = x_{0} + L sin (2 π t / t_{0})

where x_{0} is the center point, L is half the total travel, and t_{0} is the duration of each full cycle of movement?

Or do you mean you want to find out how to calculate the required velocity to move the drive to a new position using a sine acceleration curve? In other words, for each stroke from x_{0} to x_{1} in time t = 0 .. t_{1}:

Code:

x(t) = x_{0} + (x_{1} - x_{0}) (1 - cos( π t / t_{1} ) ) / 2

which has a velocity curve

Code:

v(t) = π (x_{1} - x_{0}) / t_{1}) sin( π t / t_{1} )

(a single "hump" of a sine wave, a half wave from zero to max velocity back to zero).

Since you have an analog linear positioning drive, the latter also gives you the PWM duty cycle you need to drive the analog motor:

Code:

duty(t) = duty_{max} / v_{max} |v(t)|

and the sign of v(t) tells you the direction.

_____________________________________

In real life you cannot control the duty cycle continously, so you need to discretize the algorithm (which replaces a short interval of the curve with a fixed value of the same duration, that has the same effect). Instead of v(t) or duty(t), you need duty_{i} for i = 0 .. N-1 steps, N = round(t_{1}·rate).

The simplest option is to first do the calculations like I showed above to make sure the curve yields the desired velocity or acceleration profile, then set the duty cycle for each sampling period to the value that yields the desired movement. Assuming for a smooth movement from point x_{0} to x_{1} in N steps (t_{1} time duration), with initial and final velocities zero, you get

Code:

t_{i} = i / N t_{1}
Δx_{i} = x(t_{i+1}) - x(t_{i}) = (x_{1} - x_{0}) ( cos(π i / N + π / N) - cos(π i / N) ) / 2
duty_{i} = duty_{max} / v_{max} Δx_{i}

i.e.

Code:

duty_{i} = duty_{max} / v_{max} (x_{1} - x_{0}) ( cos(π i / N + π / N) - cos(π i / N) ) / 2, i = 0 .. N-1

To compute the sine and cosine, use the CORDIC algorithm. If computation speed becomes an issue, you can try replacing cos(π i / N + π / N) - cos(π i / N) with the mathematically equivalent, but simpler

Code:

const_{1} cos(π i / N) - const_{2} sin(π i / N)

where
Code:

const_{1} = cos(π / N) - 1
const_{2} = sin(π / N)