通过一个远程控制来控制NAO
当ALInfrared接收到一个远程控制按钮时,它会引发一个事件,包含所有有关信息。事件名称为InfraRedRemoteKeyReceived。
该事件的所有信息也都会保存在内存中。
下表介绍了该事件数组及被分开的数据:
事件/数据 | 类型 | ALMemory | 说明 |
---|---|---|---|
事件 | 数组 | "InfraRedRemoteKeyReceived" | 包含5个以下数据 |
数据 | 字符串 | "Device/SubDeviceList/IR/LIRC/Remote/LircCode/Sensor/Value/" | LIRC hexa code (LIRC在线程序说明书) |
数据 | 整型(int) | "Device/SubDeviceList/IR/LIRC/Remote/Repeat/Sensor/Value/" | 一次接收的按钮的同一帧 |
数据 | 字符串 | "Device/SubDeviceList/IR/LIRC/Remote/Key/Sensor/Value/" | 按钮名称 |
数据 | 字符串 | "Device/SubDeviceList/IR/LIRC/Remote/Remote/Sensor/Value/" | 远程(器件模型)的名称 |
数据 | 整型(int) | "Device/SubDeviceList/IR/LIRC/Remote/IrSide/Sensor/Value/" | 0意为在左眼上接收,7意为在右眼上接收。 |
Python范例:接收和显示远程按钮事件
from naoqi import * import time # create python module class myModule(ALModule): """python class myModule test auto documentation""" def pythondatachanged(self, strVarName, value, strMessage): """callback when data change""" print "----------------------------------------------------------" print "Data changed on", strVarName, ": ", value, " ", strMessage print "----------------------------------------------------------" broker = ALBroker("pythonBroker","127.0.0.1",9999,"127.0.0.1",9559) # call method try: lirc=ALProxy("ALInfrared") repeatThreshold = 10 eventName = "InfraRedRemoteKeyReceived" lirc.initReception(repeatThreshold) pythonModule = myModule("pythonModule") prox = ALProxy("ALMemory") prox.subscribeToEvent(eventName,"pythonModule", "pythondatachanged") except Exception,e: print "error" print e exit(1) time.sleep(10) exit(0)