我在使用 naoqi python sdk 时遇到了一些问题。我有以下 Caresse Detector 代码。我的类继承自 ALModule 并注册到头部触觉传感器上的事件。
# -*- encoding: UTF-8 -*-
import sys
from naoqi import ALProxy
from naoqi import ALModule
from naoqi import ALBroker
import time
class caresseDetector(ALModule):
def __init__(self,name="caresseDetectorModule"):
ALModule.__init__(self,name)
self.tts = ALProxy("ALTextToSpeech")
self.memory = ALProxy("ALMemory")
self.memory.subscribeToEvent("FrontTactilTouched",name,"onFrontTouched")
self.memory.subscribeToEvent("RearTactilTouched",name,"onRearTouched")
self.memory.subscribeToEvent("MiddleTactilTouched",name,"onMiddleTouched")
self.touchFlags = [False,False,False]
self.t0 = 0
self.gestureDuration = 0.5
def onFrontTouched(self):
print self.touchFlags
if time.time()-self.t0 < self.gestureDuration:
if self.touchFlags == [False,True,True]:
self.greet()
else:
self.touchFlags = [False,False,False]
if self.touchFlags == [True,False,False]:
self.t0 = time.time()
elif self.touchFlags == [False,False,False]:
self.t0 = time.time()
self.touchFlags[0] = True
# else:
# self.touchFlags = [False,False,False]
# self.t0 = 0
def onRearTouched(self):
# print self.touchFlags
exec('print ' + str(self.touchFlags))
if time.time() - self.t0 < self.gestureDuration:
if self.touchFlags == [True,True,False]:
self.greet()
else:
self.touchFlags = [False,False,False]
if self.touchFlags == [False,False,True]:
self.t0 = time.time()
elif self.touchFlags == [False,False,False]:
self.t0 = time.time()
self.touchFlags[2] = True
# else:
# self.touchFlags = [False, False, False]
# self.t0 = 0
def onMiddleTouched(self):
# print self.touchFlags
exec ('print ' + str(self.touchFlags))
self.touchFlags[1] = True
if self.touchFlags == [True,True,True]:
self.greet()
# else:
# self.touchFlags = [False,False,False]
# self.t0 = 0
def greet(self):
# print "-------"
exec ('print ' + str(self.touchFlags))
self.t0 = 0
id = self.tts.post.say("Grazie!")
self.touchFlags = [False,False,False]
self.tts.wait(id,0)
def detect(self,broker):
# myBroker = ALBroker("myBroker", "0.0.0.0", 0, self.robotIP, self.port)
try:
while True:
time.sleep(1)
except:
# print
# print "Interrupted, shutting down"
exec ('print')
exec ('print "Interrupted, shutting down"')
broker.shutdown()
def __del__(self):
self.memory = None
self.tts = None
# robotIP = "194.119.214.185"
#
# myBroker = ALBroker("myBroker","0.0.0.0",0,robotIP,9559)
# goofy = caresseDetector("detector")
# goofy.detect(myBroker)
如果我运行代码末尾注释的最后一条指令,则模块运行良好,而如果我在导入我的类的外部文件中运行相同的代码,则在发生事件时会收到以下错误:
[E] 4099 qitype.dynamicobject: ALPythonTools::eval
python object not found detector
要测试的外部文件如下所示:
from naoqi import ALBroker
from caresseDetector import caresseDetector
robotIP = "194.119.214.185"
myBroker = ALBroker("myBroker","0.0.0.0",0,robotIP,9559)
goofy = caresseDetector("detector")
goofy.detect(myBroker)
我在网上没有找到任何东西,有人可以帮助我吗?
提前致谢