Note
This chapter explains how use NAO with remote controls, not the use of the infrared communication between two NAO.
To use NAO as a remote control:
/\**
* Function sendRemoteKey is used as an IR remote control.
* @param pRemote : string containing the remote control name
* @param pKey : string containing the button name
\*/
void sendRemoteKey(const std::string& pRemote, const std::string& pKey );
Python example to switch ON your TV:
import naoqi
from naoqi import ALProxy
lirc=ALProxy("ALInfrared","127.0.0.1",9559)
lirc.sendRemoteKey("My_TV_name", "KEY_POWER")
After sending a remote key, the following data will be saved in ALMemory:
Event / Data | Type | ALMemory | Description |
---|---|---|---|
Data | string | “Device/SubDeviceList/IR/LIRC/Remote/Remote/Actuator/Value/” | Last remote name sent |
Data | string | “Device/SubDeviceList/IR/LIRC/Remote/Key/Actuator/Value/” | Last button name sent |
To be able to receive infrared data you should call the following bound method:
/\**
* Function initReception
* is called to initialyse receiving IR information from a remote control or a NAO
* @param pRepeatThreshold : number which set the repetition threshold of buttons
\*/
void initReception(const int& pRepeatThreshold);
Python example:
import naoqi
from naoqi import ALProxy
lirc=ALProxy("ALInfrared","127.0.0.1",9559)
lirc.initReception(10);
The parameter pRepeatThreshold is only useful with some remote controls. It avoids thousands of event receptions if the remote control sends the same button frame several times with only one tap! If you don’t care about it, just set it to -1 and the default value will be set or it will keep the previous value if you already called this method:
lirc.initReception(-1);
When ALInfrared receives a remote control button, it raises an event containing all information about it. The event name is InfraRedRemoteKeyReceived.
All information about the event are also kept in ALMemory.
The event array and the related data are described in the following table:
Event / Data | Type | ALMemory | Description |
---|---|---|---|
Event | array | “InfraRedRemoteKeyReceived” | Contains the 5 following data |
Data | string | “Device/SubDeviceList/IR/LIRC/Remote/LircCode/Sensor/Value/” | LIRC hexa code ( online LIRC documentation) |
Data | int | “Device/SubDeviceList/IR/LIRC/Remote/Repeat/Sensor/Value/” | Same frame of the button receive in one shot |
Data | string | “Device/SubDeviceList/IR/LIRC/Remote/Key/Sensor/Value/” | Name of the button |
Data | string | “Device/SubDeviceList/IR/LIRC/Remote/Remote/Sensor/Value/” | Name of the remote (device model) |
Data | int | “Device/SubDeviceList/IR/LIRC/Remote/IrSide/Sensor/Value/” | 0 means received on the left eye, 7 means on the right eye. |
Python example to receive and display remote buttons event:
alinfrared_receiveremotekey.py
"""
Receive and display remote buttons event:
"""
import naoqi
import time
# create python module
class myModule(naoqi.ALModule):
def pythondatachanged(self, strVarName, value, strMessage):
"""callback when data change"""
print "Data changed on", strVarName, ": ", value, " ", strMessage
# call method
try:
lircProxy = naoqi.ALProxy("ALInfrared")
lircProxy.initReception(repeatThreshold = 10)
pythonModule = myModule("pythonModule")
memProxy = naoqi.ALProxy("ALMemory")
memProxy.subscribeToEvent("InfraRedRemoteKeyReceived", "pythonModule",
"pythondatachanged")
except Exception, e:
print "error"
print e
exit(1)
time.sleep(10)
exit(0)
It is possible to send 3 kinds of data:
To do that use respectively the 3 following bound methods:
/\**
* Function sendIpAddress is called to send an IP address
* @param pIP: string containing an IP address (eg "127.0.15.129")
\*/
void sendIpAddress(const std::string& pIP);
/\**
* Function send8 is called to send 1 octet
* @param pOctet : Integer containing an octet
\*/
void send8(const int& pOctet);
/\**
* Function send32 is called to send 4 octets
* @param pData_IR: string containing a 4 octet value (be careful it's a string)
\*/
void send32(const std::string& pData_IR);
// OR
/\**
* Function send32 is called to send 4 octets
* @param pOctet1 : 1st octet of the 32 bits value
* @param pOctet2 : 2nd octet of the 32 bits value
* @param pOctet3 : 3rd octet of the 32 bits value
* @param pOctet4 : 4th octet of the 32 bits value
\*/
void send32(const int& pOctet1, const int& pOctet2, const int& pOctet3, const int& pOctet4);
Python example to send successively the 3 kinds of data:
"""
Send an element of each of the 3 supported data type to nao
"""
from naoqi import ALProxy
import time
lirc=ALProxy("ALInfrared","127.0.0.1",9559) # change IP with NAO IP
lirc.sendIpAddress("127.0.0.1") # Send IP address
time.sleep(0.5) # Delay necessary for a reliable transfer
lirc.send8(42) # Send the number 42
time.sleep(0.5)
lirc.send32(0x42, 0x2A, 0x13, 0x0D) # Send one 32 bits number
time.sleep(0.5)
lirc.send32("36757575") # Send one 32 bits number
Warning
It takes around 0.5 seconds to send an octet and around 2 seconds to send 4 octets or an IP address.
Warning
A delay (~0.5’‘) between every sending is necessary for a reliable transfer.
After having sent a value, the corresponding data will be saved in ALMemory:
Event / Data | Type | ALMemory | Description |
---|---|---|---|
Data | int | “Device/SubDeviceList/IR/LIRC/Data/IP/Actuator/Value/” | IP address |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt8/Byte/Actuator/Value/” | Unsigned 8 bits integer |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte1/Actuator/Value/” | 1st octet of the 32 bits unsigned integer |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte2/Actuator/Value/” | 2nd octet of the 32 bits unsigned integer |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte3/Actuator/Value/” | 3rd octet of the 32 bits unsigned integer |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte4/Actuator/Value/” | 4th octet of the 32 bits unsigned integer |
When ALInfrared receives data from an other NAO, it raises an event containing the data.
All information about the event are also kept in ALnemory.
The event array and the related data are described in the following table:
Event / Data | Type | ALMemory | Description |
---|---|---|---|
Event | string | “InfraRedIpAdressReceived” | IP address |
Data | string | “Device/SubDeviceList/IR/LIRC/Data/uInt8/Byte/Sensor/Value/” | IP address |
Event | int | “InfraRedOneByteReceived” | 8 bits value |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt8/Byte/Sensor/Value/” | 8 bits value |
Event | array | “InfraRedFourBytesReceived” | array containing the 4 octets |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte1/Sensor/Value/” | 1st octet |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte2/Sensor/Value/” | 2nd octet |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte3/Sensor/Value/” | 3rd octet |
Data | int | “Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte4/Sensor/Value/” | 4th octet |
Python example to receive an IP address:
"""Receive an IP address"""
import naoqi
import time
# create python module
class myModule(naoqi.ALModule):
def pythondatachanged(self, strVarName, value, strMessage):
"""callback when data change"""
print "IP address = ", value, " ", strMessage
# call method
try:
pythonModule = myModule("pythonModule")
prox = naoqi.ALProxy("ALMemory")
prox.subscribeToEvent("InfraRedIpAdressReceived", "pythonModule", "pythondatachanged")
except Exception, e:
print "error"
print e
exit(1)
time.sleep(10)
exit(0)