embedded system library for e-puck  1.0.1
A redesigned API library for the e-puck robot platform
 All Data Structures Files Functions Variables Enumerations Enumerator Modules Pages
Files
Infrared Receiver

interface of the IR receiver on top of the e-puck More...

Files

file  el_ir_receiver.h
 

Detailed Description

interface of the IR receiver on top of the e-puck

Introduction

The e-puck has a IR receiver module — TSOP36236. It is able to receive transmissions based on RC5 protocol which is a protocol used by domestic appliances (e.g. a TV remote). For example, Philip and Toshiba are known to use the protocol.

Example Usage

Display the Data Received

To utilize a TV remote to command one or a group of e-pucks, the first thing to do it to study what exactly the data received are. In this example, any valid transmission is received and the data obtained are displayed via serial communication.

// assume that the following process is launched properly in somewhere
void IrReceiver_Process(void*unused){
int check;
int address;
int key_value;
while(1){
// ir receiver requires a reset before a potential receiving
// wait for a new income ('check' becoming either 0 or 1)
do{
}while( (check != 0)&&(check != 1) );
// grab the data
key_value = el_ir_receiver_get_data();
// display the contents in the received transmission
elu_println("[IRRC]");
elu_println("%d\t%d\t%d",check,address,key_value);
}
}

Note: the code to enable the ir receiver (el_enable_ir_receiver) and launching of the process is not shown in the code section above.

Use As Trigger

In Display the Data Received, the IR receiver is used in an infinite loop within a process. A disadvantage of doing so is that it constantly occupies a process. The maximum number of processes is limited, which may run out if all components occupy a process of their own. Using a trigger to handle the IR receiver is a better design choice.

In this example, a trigger is written to make a LED on the robot controlled by a key on the remote.

Related global variables and function prototypes:

#define THE_ADDRESS_WE_WANT 5
#define THE_VALUE_WE_WANT 1
el_handle trg_remote_control;
void Trigger_RemoteControl_Setup();
void Trigger_RemoteControl_Clear();
bool Trigger_RemoteControl_Condition(el_handle this_trigger);
void Trigger_RemoteControl_Process(el_handle this_trigger);

Code to setup/clear the trigger:

void Trigger_RemoteControl_Setup(){
trg_remote_control = el_create_trigger();
// specify the event of triggering
// this trigger is a typical case where a condition callback may be used
el_trigger_set_condition( trg_remote_control, Trigger_RemoteControl_Condition );
// specify the process to launch when the event occurs
el_trigger_set_process( trg_remote_control, Trigger_RemoteControl_Process );
}
void Trigger_RemoteControl_Clear(){
el_delete_trigger( trg_remote_control );
}

Code of the trigger's condition callback and process:

/*
* Note:
* In real world, the IR receiver will receive a lot of noise. So the event
* EL_EVENT_IR_RECEIVER_INCOME will typically occur more frequently than true signals.
* As a result, most of times, the packet received contains corrupted data.
* To save the effort to launch a process in such a case, a condition callback
* is used for this trigger to filter unwanted events.
*/
bool Trigger_RemoteControl_Condition(el_handle this_trigger){
if( el_ir_receiver_get_address() != THE_ADDRESS_WE_WANT ){
return false;// do not launch the process
}
return true;// proceed to launch the process
}
/*
* Note:
* For a trigger-launched process, the argument given to the entry function
* is the handle of the trigger.
*/
void Trigger_RemoteControl_Process(el_handle this_trigger){
int key_value;
key_value = el_ir_receiver_get_data();
if( key_value == THE_VALUE_WE_WANT ){
el_led_set( EL_LED_BODY, EL_TOGGLE );
}
el_trigger_enable( this_trigger );
el_ir_receiver_reset();// get ready for next incoming transmission
}

For the above trigger, it is also valid to move the code in the process function to the condition function because the program does not require any timing (e.g. el_process_wait). If that's the case, a process is no longer required and no el_trigger_enable is needed at the end.

Appendix

The address and key values from the universal remote (emulating a Philip VCR remote) used in Sheffield Robotics:

#define IR_REMOTE_ADDRESS 5
#define IR_REMOTE_KEY_PLAY 53
#define IR_REMOTE_KEY_STOP 54
#define IR_REMOTE_KEY_PAUSE 41
#define IR_REMOTE_KEY_REW 37
#define IR_REMOTE_KEY_FF 38
#define IR_REMOTE_KEY_REC 55
#define IR_REMOTE_KEY_POWER 12
#define IR_REMOTE_KEY_MUTE 13
#define IR_REMOTE_KEY_PRESET 14
#define IR_REMOTE_KEY_PLUS 16
#define IR_REMOTE_KEY_MINUS 17
#define IR_REMOTE_KEY_INFO 18
#define IR_REMOTE_KEY_NUM_0 0
#define IR_REMOTE_KEY_NUM_1 1
#define IR_REMOTE_KEY_NUM_2 2
#define IR_REMOTE_KEY_NUM_3 3
#define IR_REMOTE_KEY_NUM_4 4
#define IR_REMOTE_KEY_NUM_5 5
#define IR_REMOTE_KEY_NUM_6 6
#define IR_REMOTE_KEY_NUM_7 7
#define IR_REMOTE_KEY_NUM_8 8
#define IR_REMOTE_KEY_NUM_9 9