User manual

RP6 ROBOT SYSTEM - 4. Programming the RP6
4.6. The RP6 function library (RP6Library)
The RP6 function library (abbr. RP6Library or RP6Lib) provides a great number of low-
level functions to control the RP6 hardware. With this library, you usually don't have
to care about all the hardware specific details of the Robot and the Microcontroller. Of
course, you do not need to read the 300 pages long datasheet of the ATMEGA32 Mi-
crocontroller in order to be able to write programs for the RP6. However, by reading
some important parts of the data sheet you may gain insight of how the RP6Library
works in detail.
In fact, we intentionally avoided perfect tuning for all RP6Library functions, in order to
leave some work for you! You are invited to add more functions and to optimize exist-
ing ones! Please consider the RP6Library as a good starting point, but not as an op-
timal solution.
This chapter discusses the most important functions and shows short examples. If you
are interested in further details, you can read the comments in the library files and
study the functions and the provided examples.
4.6.1. Initializing the microcontroller
void initRobotBase(void)
ALWAYS start the main function block by calling this function! It initialize the micro-
controller's hardware modules. The microcontroller may not be working properly if
your program does not start with this! Partially, the hardware modules are already ini-
tialized by the Bootloader, but not all.
Example:
1
2
3
4
5
6
7
8
9
10
11
#include "RP6RobotBaseLib.h"
int main(void)
{
initRobotBase(); // Initialization – ALWAYS CALL THIS FIRST!
// [...] Program code...
while(true); // Infinite loop
return 0;
}
Basically any RP6 Program should at least look like this. The infinite loop in
line 9 serves as a predefined end of the program. Skipping the infinite loop
may result in unexpected program behaviour!
Just to point out the idea of the infinite loop again: usually the infinite loop will be
used to execute your own program code. So you will delete the semicolon at line 9
and replace it with your own program block (surrounded by accolades). You can
define your own functions in the lines preceding the main function (at line 2 in this
case) and you may call your functions anywhere from the main loop.
- 79 -