Example 2.3 explained – Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual
Page 22

Publication 2098-PM001E-EN-P — July 2002
1-10
Programming Motion Control in C
Example 2.3 - Another Variance of the Program using Variables
A third way to achieve the same result is to write the program as
follows:
#include <motion.h>
#define
ACCEL
2000
/* counts/second**2 */
#define
DECEL
2000
/* counts/second**2 */
#define
TARGETVEL
1000
/* counts/second */
#define
INDEX
1000
/* counts */
#define
ENDPOINT
10000
/* counts */
/* increment through the 10 index positions 1000, 2000,...,
until target > endpoint
*/
int main (void)
{
long target;
InitMotionLibrary();
AxisEnable();
MoveSetAcc(ACCEL);
MoveSetVel(TARGETVEL);
MoveSetDec(DECEL);
AxisDefinePos(0);
for (target = INDEX; target <= ENDPOINT; target = target +
INDEX) {
MoveAbsolute(target);
while (MoveInProgress()) {/* loop */}
}
AxisDisable();
return 0;
}
Example 2.3 Explained
The quantities ACCEL, DECEL, TARGETVEL, INDEX, and ENDPOINT
are symbolic constants, not variables, so they do not appear in
declarations. C programming conventions write constants in upper
case and variables in lower case, but this is not a requirement. Notice
that there is no semicolon at the end of a #define line.