forked from Lion-ly/HNIT-JXROBOT
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGolfModule.py
67 lines (55 loc) · 2 KB
/
GolfModule.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
# coding=utf-8
"""自定义模块"""
import sys
import time
from naoqi import ALProxy
from naoqi import ALBroker
from naoqi import ALModule
import threading
GolfGreeter = None
memory = None
class GolfGreeterModule(ALModule):
def __init__(self, name):
ALModule.__init__(self, name)
self.tts = ALProxy("ALTextToSpeech")
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("FrontTactilTouched", "GolfGreeter", "onFrontTactilTouched")
memory.subscribeToEvent("MiddleTactilTouched", "GolfGreeter", "onMiddleTactilTouched")
def onFrontTactilTouched(self, *_args):
memory.unsubscribeToEvent("FrontTactilTouched", "GolfGreeter")
# 触摸头前部 响应程序
self.tts.say("Hello, you touch me front head")
# end
memory.subscribeToEvent("FrontTactilTouched", "GolfGreeter", "onFrontTactilTouched")
def onMiddleTactilTouched(self, *_args):
memory.unsubscribeToEvent("MiddleTactilTouched", "GolfGreeter")
# 触摸头中部 响应程序
self.tts.say("Hello, you touch me middle head")
# end
memory.subscribeToEvent("MiddleTactilTouched", "GolfGreeter", "onMiddleTactilTouched")
def myMethod(self):
self.tts.say("hello")
def main(robotIp):
myBroker = ALBroker("GolfBroker", "0.0.0.0", 0, robotIp, 9559)
global GolfGreeter
GolfGreeter = GolfGreeterModule("GolfGreeter")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print "Interrupted by user, shutting down"
myBroker.shutdown()
sys.exit(0)
def MyClass(robotIp):
# example
mymodule = ALProxy("GolfGreeter", robotIp, 9559)
mymodule.myMethod()
if __name__ == '__main__':
# robotIp = "192.168.43.165"
Ip = "127.0.0.1"
t1 = threading.Thread(target=main(robotIp))
t1.start()
# t1.is_alive()
# t2 = threading.Thread(target=MyClass(robotIp))
# t2.start()