Variables, loops, and constants, Example 2.1 - a motion program using variables, Variables, loops, and constants -5 – Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual

Page 17: Example 2.1 - a motion program using variables -5

Advertising
background image

Publication 2098-PM001E-EN-P — July 2002

Programming Motion Control in C

1-5

Variables, Loops, and Constants

The next example is a motion program that makes a series of 10 index
moves of 1000 counts each. This program introduces you to:

• Comments
• Declarations
• Variables
• Arithmetic expressions
• Loops

Example 2.1 - A Motion Program Using Variables

Enter the following program into a source file using the same process
as Example 1.

#include <motion.h>

/* increment through the 10 index positions

1000, 2000,..., until target > endpoint

*/

int main (void)

{

long target, index, endpoint;

InitMotionLibrary();

AxisEnable();

MoveSetAcc(1000);

MoveSetVel(1000);

MoveSetDec(1000);

AxisDefinePos(0);

/* define current position as

index = 1000;

0 */

target = index;

/* initialize target to first

index position (1000) */

endpoint = index * 10;

/* initialize endpoint to

10000 (1000 * 10) */

while (target <= endpoint) {

MoveAbsolute(target);

while (MoveInProgress()) {/* loop */}

target = target+index;

}

AxisDisable();

return 0;

}

Advertising