
RP6 ROBOT SYSTEM - 4. Programming the RP6
Let's explain the idea in a small example with two simple functions and the alerady
known main-function:
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void
someLittleFunction
(
void
)
{
writeString
(
"[Function 1]\n"
);
}
void
someOtherFunction
(
void
)
{
writeString
(
"[Function 2 – something different]\n"
);
}
int
main
(
void
)
{
// Always start an RP6-program by calling this function!
initRobotBase
();
// A few function calls:
someLittleFunction
();
someOtherFunction
();
someLittleFunction
();
someOtherFunction
();
someOtherFunction
();
return
0
;
}
The program would display the following text at the output device:
[Function 1]
[Function 2 – something different]
[Function 1]
[Function 2 – something different]
[Function 2 – something different]
The main-function serves as the entry point and any C program will start by calling
this function. Therefore each C program MUST provide a main-function.
In the previous example, the main-function starts by calling the initRobotBase-func-
tion from the RP6Library, which will initializes the microcontrollers hardware. Basically
the initRobotBase-function is structured similar to the two functions in this example.
In the main function, the two previously defined functions get called several times and
the program code of these functions is executed.
Apart from defining functions as described in the previous example, we may also use
parameters and return values. The above example is using “void” as parameter and
return value, which means we do not use any parameters or return values here. The
parameter “void” always indicates functions without a return values, respectively
without parameters.
You may define a great number of parameters for a function and parameters are sep-
arated by commas.
- 73 -