RP6 ROBOT SYSTEM - 4. Programming the RP6
LEDs turn off, although the Pin is set to input for a few instruction cycles. Of course
you should not call these functions frequently without a delay of a few ms in between.
The LED Portpins should be controlled with the predefined functions only! There are
resistors to protect the bumper ports, but if the pins are set to low level output AND a
bumper switch is closed at the same time, the port terminal will conduct a bit more
current. Such unecessary currents should be avoided of course (the AVRs have Tri-
state outputs – to turn the LED off, they are set to floating)
Example:
if(getBumperLeft() && getBumperRight()) // Both Bumpers...
escape(); // Define your own function here, e.g. drive back and rotate
else if(getBumperLeft()) // Left...
escapeLeft(); // drive back again and turn to the right.
else if(getBumperRight()) // Right...
escapeRight(); // drive back again and turn to the left.
mSleep(50); // Check bumpers at a rate of 20 times pro second (20Hz)...
Pressing the bumpers will illuminate the LEDs 6 and 3. This is intentionally and cannot
be avoided. However, the bumper switches are usually not activated to often, so this
does not bother us too much.
You can connect other sensors with digital output to the four remain-
ing LEDs. Switching loads like additional LEDs or Motors on and off
via Transistors is possible, too. The only thing missing are apropriate
functions that control the four ports, but you can take a look at the
existing functions for the LEDs and Bumpers...
Attention:
In order to protect the microcontroller's ports, always in-
sert at least 470 Ohm resistors between sensors/actors and ports for
current limiting!
The RP6 allows you to deactivate the LEDs during the boot phase.
This is useful to avoid port activity while booting is in progress and if
there are other devices connected to the LED portpins.
The first byte in the internal EEPROM (addressed by 0) is reserved to
control the LED modes, so please do not use this byte for your own
programs (overriding this byte will not disturb anything else, but you
may wonder why LEDs are no longer illuminated after turning on the
RP6...) !
There are a lot of things on the RP6 that have to be evaluated constantly in order to
make them work correctly. For instance, the ACS needs to transmit IR pulses in spe-
cific intervals and check for reception. We can not use automated interrupt functions
for this, as the interrrupt service routines need to be as fast as possible. Thus you
have to call several functions from the main program frequently. In a well designed
program, these tasks will act like if they are just running in background.
We will discuss all these functions for ACS and similar later in this chapter and provide
more details on this. However we had to anticipate a few details in order to make it
easier for you to understand how the bumper functions work and why they are imple-
mented like this!
- 87 -