User manual

RP6 ROBOT SYSTEM - 4. Programming the RP6
The program will react on alterations of the bumper status once-only by outputting
the current status of both bumpers. For example, if you press down the right bumper,
the output would be:
Bumper Status has changed:
- Left bumper has not been activated.
- Right bumper has been activated!
Pressing down both bumper sensors will result in:
Bumper Status has changed:
- Left bumper has been activated!
- Right bumper has been activated!
You will hardly ever manage to activate both bumpers simultaneously and you might
see an additional message in which only one of the bumpers is pressed down. If you
press them down fast enough, it should show only one message. This is because of
the 50ms interval...
You may notice that the example program never directly calls the bumpersStateChanged
function! The RP6Library manages this automatically at each bumper status alteration
from the task_Bumpers function. In fact, task_Bumpers first does not know our
bumpersStateChanged function and must be calling this function by using a pointer,
which will be set up properly in line 24.
Of course the Event Handler may be extended beyond text outputs e.g. think of
stopping the robot and driving back / rotating. However, such things should not be
peformed in the Event Handler itself, but elsewhere in the program. You might set a
command variable(s) in the Event Handler, which is then checked in the main pro-
gram to identify which movement should be performed! Always keep Event Handlers
as short as possible!
You can use all RP6Library functions in Event Handlers, but you must be careful with
the “rotate” and “move” functions, which are to be discussed in later chapters! Do
NEVER use the blocking mode of these functions in event handlers (repeatedly activ-
ating the bumpers will not quite work as expected ;-) )!
The basic idea of Event Handlers is used by a number of other functions, too. For ex-
ample the ACS which is very similar to use by calling an Event Handler for each
status alteration of the object sensors.
We also use an Event Handler for receiving RC5 Codes from remote controls. Any re-
ception of RC5 Coded signals initiates a call to a corresponding Event Handler func-
tion.
There is no need to use Event Handlers for these jobsof course you may simply use
if-conditions to check for changes, but the Event Handlers simplify program design.
Consider it a matter of of taste.
By the way: the CD provides you with a number of detailed sample programs on this
topic!
- 90 -