Example 1 explained, Example 1 explained -4 – Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual

Page 16

Advertising
background image

Publication 2098-PM001E-EN-P — July 2002

1-4

Programming Motion Control in C

Example 1 Explained

Any C program, whatever its size, consists of functions and variables.
A function contains statements that specify the operations to be done,
and variables that store the values used in those operations. Braces
(opening {, and closing }) enclose the statements in a function.

Example 1 uses a function named main. Normally you are free to give
functions whatever name you like, but main is special – C programs
begin executing at main. This means that every program must have

int main(void)

as its first function.

The main function calls other functions to help perform a task, some
that you write, and others from the motion library. The first line of the
program,

#include <motion.h>

tells the compiler to include information from the motion library. This
line must appear at the beginning of any program wishing to use
motion library functions. The chapter Referencing the Motion Library
describes the functions provided in the Ultraware Motion Library.

One method of communicating data between functions is for the
calling function to provide a list of values, called arguments, to a
function it is calling. Parentheses after a function name surround an
argument list. In our example, main is defined to be a function that
expects no arguments, which is indicated by the empty or void list
[written as (void) or often as a set of empty parentheses ( )].

In the first example, the function main contains several function calls
and a return statement, which are explained later. Each function is
called by naming it, followed by its arguments in parentheses, and is
terminated with a semicolon. The line

MoveSetDec(1000);

calls the function MoveSetDec with the argument 1000. MoveSetDec is
an Ultraware Motion Library function that sets the default move
deceleration value to 1000 encoder counts/sec².

Advertising