-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_listener.py
119 lines (105 loc) · 4.24 KB
/
event_listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- coding: utf-8 -*
from naoqi import ALProxy, ALBroker, ALModule
import time
import sys
from multiprocessing import Process
import interactive_demo2 as interat
ip_robot = "10.0.7.63"
port_robot = 9559
# Global variable to store the humanEventWatcher module instance
humanEventWatcher = None
memory = None
#人脸追踪拍照测试
class HumanTrackedEventWatcher(ALModule):
""" A module to react to HumanTracked and PeopleLeft events """
def __init__(self):
ALModule.__init__(self, "humanEventWatcher")
global memory
memory = ALProxy("ALMemory", ip_robot, port_robot)
memory.subscribeToEvent("ALBasicAwareness/HumanTracked",
"humanEventWatcher",
"onHumanTracked")
memory.subscribeToEvent("ALBasicAwareness/PeopleLeft",
"humanEventWatcher",
"onPeopleLeft")
#memory.subscribeToEvent('WordRecognized', ip_robot, 'wordRecognized')
self.speech_reco = ALProxy("ALSpeechRecognition", ip_robot, port_robot)
self.text_to_speech=ALProxy("ALTextToSpeech", ip_robot, port_robot)
self.is_speech_reco_started = False
self.photo_apture=ALProxy("ALPhotoCapture", ip_robot, port_robot)
self.cameraMap = {
'Top': 0,
'Bottom': 1
}
self.camera_id=0
self.recordFolder = "/home/nao/recordings/cameras/"
self.p = Process(target=interat)
def onHumanTracked(self, key, value, msg):
""" callback for event HumanTracked """
print "got HumanTracked: detected person with ID:", str(value)
if value >= 0: # found a new person
self.start_speech_reco()
position_human = self.get_people_perception_data(value)
[x, y, z] = position_human
print "The tracked person with ID", value, "is at the position:", \
"x=", x, "/ y=", y, "/ z=", z
print "Aha, I saw a human!"
self.p.is_alive()
if (
self.p.is_alive()):
pass
else:
self.p = Process(target=interat)
self.p.start()
else:
pass
def onPeopleLeft(self, key, value, msg):
""" callback for event PeopleLeft """
print "got PeopleLeft: lost person", str(value)
self.p.terminate()
self.stop_speech_reco()
def start_speech_reco(self):
""" start asr when someone's detected in event handler class """
if not self.is_speech_reco_started:
try:
data = memory.getData("WordRecognized")
print(data)
except RuntimeError:
print "ASR already started"
self.speech_reco.setVisualExpression(True)
self.speech_reco.subscribe("BasicAwareness_Test")
self.is_speech_reco_started = True
print "start ASR"
def stop_speech_reco(self):
""" stop asr when someone's detected in event handler class """
if self.is_speech_reco_started:
self.speech_reco.unsubscribe("BasicAwareness_Test")
self.is_speech_reco_started = False
print "stop ASR"
def get_people_perception_data(self, id_person_tracked):
memory = ALProxy("ALMemory", ip_robot, port_robot)
memory_key = "PeoplePerception/Person/" + str(id_person_tracked) + \
"/PositionInWorldFrame"
return memory.getData(memory_key)
if __name__ == "__main__":
event_broker = ALBroker("event_broker", "0.0.0.0", 0,
ip_robot, port_robot)
global humanEventWatcher
humanEventWatcher = HumanTrackedEventWatcher()
basic_awareness = ALProxy("ALBasicAwareness", ip_robot, port_robot)
motion = ALProxy("ALMotion", ip_robot, port_robot)
#start
motion.wakeUp()
basic_awareness.setEngagementMode("FullyEngaged")
basic_awareness.startAwareness()
#loop on, wait for events until interruption
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print "Interrupted by user, shutting down"
#stop
basic_awareness.stopAwareness()
motion.rest()
event_broker.shutdown()
sys.exit(0)