Rockwell-automation 2098-IPD-xxx Ultra5000 C Programming using the Mot Manual de usuario Pagina 20

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 114
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 19
Publication 2098-PM001E-EN-P — July 2002
1-8 Programming Motion Control in C
Example 2.2 - Varying the Program using Variables
There are many different ways to write a program for a particular task.
This program performs the same tasks as Example 2.1 - A Motion
Program Using Variables, but it uses slightly different software code.
#include <motion.h>
/* increment through the 10 index positions 1000, 2000,...,
until target > endpoint */
int main (void)
{
long target;
InitMotionLibrary();
AxisEnable();
MoveSetAcc(2000);
MoveSetVel(1000);
MoveSetDec(2000);
AxisDefinePos(0);
for (target = 1000; target <= 10000; target = target + 1000) {
MoveAbsolute(target);
while (MoveInProgress()) {/* loop */}
}
AxisDisable();
return 0;
}
Example 2.2 Explained
This program produces the same motion, but looks different than
Example 2.1. One major change is the elimination of most of the
variables; only target remains. The index and endpoint values appear
only as constants in the for statement.
The for statement is a loop. Compare the for loop to the previous
usage of the while command. Within the parentheses, there are three
parts, separated by semicolons. The first part, the initialization
target = 1000
is done once, before the loop proper is entered. The second part is
the test or condition that controls the loop:
target <= 10000
This condition is evaluated, and if it is true, the body of the loop is
executed. Then the increment step
target = target + 1000
Vista de pagina 19
1 2 ... 15 16 17 18 19 20 21 22 23 24 25 ... 113 114

Comentarios a estos manuales

Sin comentarios