RP6 ROBOT SYSTEM - 4. Programming the RP6
and robot's expansion boards mounted on the top). You will be able to extend the
communication range by adding some more IR LEDs (for example controlled by anoth-
er MOSFET with a large capacitor and a small series resistor).
Synchronisation to the ACS operation is controlled by the task_ACS() function, which
must be called frequently from the main-loop in order to handle reception of IR-sig-
nals – and additionally for managing the IRCOMM transfers!
RC5-data packets consist of a device address, a key code and a toggle bit. The 5 Bit
device address tells which device is controlled by the remote control. Such as a televi-
sion, a video recorder, a Hi-Fi system, etc. For our application, the device address may
also be used to address several individual robots. The 6 Bit Key code corresponds to
the pressed key on the remote control, but may allow us to transfer any other data as
well. This provides only 6 bits per transfer, but you can transmit 8 Bit Data in two
seperate transfers or divert 2 bits of the device address and/or the toggle bit from
their intended use.
Standard remote controls use the toggle bit to identify a continously hold down or re-
peatedly pressed key. However we may use the toggle bit for any other functionality
for communication between robots.
RC5 data packets can be transmitted with the following function:
void IRCOMM_sendRC5(uint8_t adr, uint8_t data)
in which
adr
corresponds to the device address and
data
to the Key code respectively
the data value. The parameter
adr
allows you to set the Toggle Bit at the most signi-
ficant bit (MSB) by applying the constant
TOGGLEBIT
in the following way:
IRCOMM_sendRC5(12 | TOGGLEBIT, 40);
This command will transmit an RC5 data packet to the device with address 12, activ-
ated Toggle Bit and 40 as data value.
IRCOMM_sendRC5(12, 40);
This is what it looks like without activated Toggle Bit.
In analogy to the bumpers and ACS, reception of RC5 data can be managed by an
Event Handler. As soon as a new RC5 packet has been received, an Event Handler will
be called automatically by the task_ACS() function. For examle this allows you write a
program that lets the robot turn to the left if it receives the key code 4 and turn to the
right at a key code of 6...
One of the example programs provides this functionality: full motion control by using
an IR remote control.
The prescribed signature for the Event Handler must correspond to:
void receiveRC5Data(RC5data_t rc5data)
but of course you may freely name the function!
void IRCOMM_setRC5DataReadyHandler(void (*rc5Handler)(RC5data_t))
This function allows you to register a predefined Event Handler, e.g. by:
IRCOMM_setRC5DataReadyHandler(receiveRC5Data);
After this, the specified function will be called on every valid RC5 code reception.
- 96 -