# -*- encoding: UTF-8 -*-
""" Say 'hello, you' each time a human face is detected
"""
import sys
import time
import thread
import math
from naoqi import ALProxy
from naoqi import ALBroker
from naoqi import ALModule
from optparse import OptionParser
NAO_IP = "192.168.1.102"
# Global variable to store the HumanGreeter module instance
HumanGreeter = None
memory = None
class HumanGreeterModule(ALModule):
""" A simple module able to react
to facedetection events
"""
def __init__(self, name):
ALModule.__init__(self, name)
self.tts = ALProxy("ALTextToSpeech")
global memory
memory = ALProxy("ALMemory")
global motion
motion= ALProxy("ALMotion")
global postureProxy
postureProxy = ALProxy("ALRobotPosture")
global proxyLed
proxyLed = ALProxy("ALLeds")
global FaceTracker
FaceTracker = ALProxy("ALFaceTracker")
global aup
aup = ALProxy("ALAudioPlayer")
global sonarProxy
sonarProxy = ALProxy("ALSonar")
memory.subscribeToEvent("FaceDetected",
"HumanGreeter",
"onFaceDetected")
def face( self,threadName, delay):
if threadName=="Thread-1":
#proxyLed.fadeRGB("FaceLeds",0x00CD6600,2)
motion.wakeUp()
names = "RArm"
angleLists = [0.216, 0.005, 2.086, 1.545, -0.955, 1]
times = 0.6
isAbsolute = True
motion.angleInterpolation(names, angleLists, times, isAbsolute)
#time.sleep(delay)
angleLists = [0.304, -0.002, 1.051, 1.525, -0.977,1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
angleLists = [0.216, 0.005, 2.086, 1.545, -0.955, 1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
time.sleep(delay)
names = "LArm"
motion.setStiffnesses("LArm", 1.0)
motion.setStiffnesses("RArm", 1.0)
angleLists =[ 0.969, -0.208, -0.75, -1.496, -0.813,0.8]
times = 1.0
isAbsolute = True
motion.angleInterpolation(names, angleLists, times, isAbsolute)
#time.sleep(delay)
angleLists= [0.977, -0.314, -1.639, -1.07, -0.815,1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
time.sleep(0.5)
names ="RArm"
angleLists =[1.031, -0.108, 0.688, 1.545, 0.269,0.93]
times = 1
isAbsolute = True
motion.angleInterpolation(names, angleLists, times, isAbsolute)
angleLists = [1.091, 0.147, 1.798, 1.122, 0.387,1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
time.sleep(0.5)
angleLists = [1.531, -0.082, 2.084, 0.164, 0.016,1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
names = "LArm"
angleLists = [1.051, -0.134, -1.627, -1.115, 0.133,1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
self.tts.say("握个手吧")
memory.subscribeToEvent("HandLeftRightTouched",
"HumanGreeter",
"onHandLeftRightTouched")
else:
self.tts.say("你好,很高興見到你")
time.sleep(delay)
self.tts.say("我的名字,叫闹")
time.sleep(0.2)
self.tts.say("我是一个机器人")
proxyLed.fadeRGB("FaceLeds",0x005CACEE,2)
memory.subscribeToEvent("FrontTactilTouched",
"HumanGreeter",
"onFrontTactilTouched")
def hand( self,threadName, delay):
if threadName=="Thread-3":
names = "LArm"
angleLists = [1.496, 0.103, -1.705, -0.264, -0.508,0.8]
times = 1
isAbsolute = True
motion.angleInterpolation(names, angleLists, times, isAbsolute)
time.sleep(0.5)
times = 0.7
for i in range(2):
angleLists =[-0.852, 0.201, -0.754, -1.33, -0.672,0.9]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
angleLists =[-0.785, 0.557, -0.855, -1.422, -0.614,0.9]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
names = "LArm"
motion.setStiffnesses("LArm", 1.0)
motion.setStiffnesses("RArm", 1.0)
angleLists =[ 0.969, -0.208, -0.75, -1.496, -0.813,0.8]
times = 1.0
isAbsolute = True
motion.angleInterpolation(names, angleLists, times, isAbsolute)
#time.sleep(delay)
angleLists= [0.977, -0.314, -1.639, -1.07, -0.815,1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
time.sleep(0.5)
angleLists = [1.496, 0.103, -1.705, -0.264, -0.508,0.8]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
else:
time.sleep(3)
self.tts.say("你摸摸我头")
time.sleep(0.5)
self.tts.say("我会跟你走")
def hand2( self,threadName, delay):
if threadName=="Thread-5":
names = "LArm"
motion.setStiffnesses("LArm", 1.0)
isAbsolute = True
time.sleep(0.5)
times = 0.7
for i in range(2):
angleLists =[-0.852, 0.201, -0.754, -1.33, -0.672,0.9]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
angleLists =[-0.785, 0.557, -0.855, -1.422, -0.614,0.9]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
angleLists =[ 0.969, -0.208, -0.75, -1.496, -0.813,0.8]
times = 1.0
isAbsolute = True
motion.angleInterpolation(names, angleLists, times, isAbsolute)
angleLists= [0.977, -0.314, -1.639, -1.07, -0.815,1]
motion.angleInterpolation(names, angleLists, times, isAbsolute)
time.sleep(0.5)
else:
time.sleep(1)
self.tts.say("你再摸摸我头")
time.sleep(1)
self.tts.say("我会跳舞")
memory.subscribeToEvent("MiddleTactilTouched",
"HumanGreeter",
"onMiddleTactilTouched")
def dance(self,threadName, delay):
if threadName=="Thread-7":
#fileId = aup.loadFile("/var/persistent/home/nao/1.mp3")
#aup.play(fileId)
pass
else:
motion.wakeUp()
postureProxy.goToPosture("StandInit", 0.7)
'''#titui
footStepsList = []
footStepsList.append([["LLeg"], [[0.06, 0.1, 0.0]]])
footStepsList.append([["LLeg"], [[0.00, 0.16, 0.0]]])
footStepsList.append([["RLeg"], [[0.00, -0.1, 0.0]]])
footStepsList.append([["LLeg"], [[0.00, 0.16, 0.0]]])
footStepsList.append([["RLeg"], [[-0.04, -0.1, 0.0]]])
footStepsList.append([["RLeg"], [[0.00, -0.16, 0.0]]])
footStepsList.append([["LLeg"], [[0.00, 0.1, 0.0]]])
footStepsList.append([["RLeg"], [[0.00, -0.16, 0.0]]])
stepFrequency = 0.4
clearExisting = False
nbStepDance = 3# defined the number of cycle to make
for j in range( nbStepDance ):
for i in range( len(footStepsList) ):
motion.setFootStepsWithSpeed(
footStepsList[i][0],
footStepsList[i][1],
[stepFrequency],
clearExisting)
isEnabled = True
motion.wbEnable(isEnabled)
#xiugaitou
names = "Head"
times = 0.5
isAbsolute = Tr