6.3.7 C code framework

You can code the velocity profile logic anyway you want. However, from the organization point of view, I suggest you use a structure to include all the properties:


\begin{lstlisting}{}
struct MotionProfile
{
struct FreqDiv vel; // velocity con...
...n; // sign of velocity
int a_sign; // sign of acceleration
};
\end{lstlisting}

Given that pmp is of type struct MotionProfile *, you should initialize it as follows:


\begin{lstlisting}{}
pmp->vel.freq = 0; // initially stationary
pmp->vel.sum = 0...
...initially nowhere to go
pmp->vset = 0; // initially stationary
\end{lstlisting}

In this example, the function step_func must handle positive and negative velocities. While pmp->vel.freq represents the magnitude of velocity, pmp->v_sign represents the direction. Similarly, the function accel_func must take into account the sign of acceleration, stored in pmp->a_sign.

step_func has to handle the sign crossover of pmp->D. This is easy because pmp->D is a signed number. accel_func has to handle the sign crossover of velocity magnitude pmp->vel.freq and velocity direction pmp->v_sign.



Copyright © 2006-02-15 by Tak Auyeung