forked from jesnk/pepper_demo_bilab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_yjsong.py
499 lines (409 loc) · 21.3 KB
/
main_yjsong.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# -*- encoding: UTF-8 -*-
import qi
import argparse
import sys
import math
import subprocess
import time
import touch
from naoqi import ALProxy
from threading import Thread
sys.path.insert(0, './motion')
import entertain
import saju
FRAME_WIDTH = 1280
FRAME_HEIGHT = 800
DEFAULT_VOLUME = 60
# jesnk touch
TOUCH_LIST = {}
TOUCH_LIST['RIGHT_SIDE'] = {"x": [FRAME_WIDTH / 2, FRAME_WIDTH], "y": [0, FRAME_HEIGHT], 'name': "RIGHT_SIDE"}
TOUCH_LIST['LEFT_SIDE'] = {"x": [0, FRAME_WIDTH], "y": [0, FRAME_HEIGHT], 'name': "LEFT_SIDE"}
TOUCH_LIST['JESNK_SIDE'] = {"x": [0, 200], "y": [0, 200], 'name': "JESNK_SIDE"}
TOUCH_LIST['BUTTON_LEFT'] = {"x": [75, 600], "y": [233, 593], 'name': "BUTTON_LEFT"}
TOUCH_LIST['BUTTON_RIGHT'] = {"x": [669, 1192], "y": [227, 598], 'name': "BUTTON_RIGHT"}
TOUCH_LIST['BUTTON_MIDDLE_DOWN'] = {"x": [485, 800], "y": [632, 705], 'name': "BUTTON_MIDDLE_DOWN"}
TOUCH_LIST['BUTTON_RIGHT_DOWN'] = {"x": [930, 1156], "y": [641, 707], 'name': "BUTTON_RIGHT_DOWN"}
TOUCH_LIST['BUTTON_LEFT_DOWN'] = {"x": [150, 390], "y": [621, 707], 'name': "BUTTON_LEFT_DOWN"}
scene_data = {}
scene_data['init'] = ['init', ['RIGHT_SIDE', 'LEFT_SIDE'], ['잘가', '다음', '처음']]
scene_data['1'] = ['1', ['RIGHT_SIDE', 'LEFT_SIDE'], ['잘가', '다음', '처음']]
scene_data['exit'] = ['exit', [], []]
scene_data['home'] = ['home', ['BUTTON_MIDDLE_DOWN', 'JESNK_SIDE'], ['시작', '다음', '페퍼']]
scene_data['first_menu'] = ['first_menu', \
['JESNK_SIDE', 'BUTTON_RIGHT', 'BUTTON_LEFT', \
'BUTTON_MIDDLE_DOWN', 'BUTTON_RIGHT_DOWN'], ['잘가', '다음', '처음']]
scene_data['tour'] = ['tour', \
['JESNK_SIDE', 'BUTTON_RIGHT', 'BUTTON_LEFT', \
'BUTTON_LEFT_DOWN', 'BUTTON_MIDDLE_DOWN', 'BUTTON_RIGHT_DOWN'], \
['잘가', '다음', '처음']]
scene_data['entertain'] = ['entertain', \
['JESNK_SIDE', 'BUTTON_RIGHT', 'BUTTON_LEFT', \
'BUTTON_LEFT_DOWN', 'BUTTON_MIDDLE_DOWN', 'BUTTON_RIGHT_DOWN'], \
['잘가', '다음', '처음']]
scene_data['entertain2'] = ['entertain2', \
['JESNK_SIDE', 'BUTTON_RIGHT', 'BUTTON_LEFT', \
'BUTTON_LEFT_DOWN', 'BUTTON_MIDDLE_DOWN', 'BUTTON_RIGHT_DOWN'], \
['잘가', '다음', '처음']]
scene_data['tour_hsr1'] = ['tour_hsr1', \
['JESNK_SIDE', 'BUTTON_RIGHT', 'BUTTON_LEFT', \
'BUTTON_LEFT_DOWN', 'BUTTON_MIDDLE_DOWN', 'BUTTON_RIGHT_DOWN'], \
['잘가', '다음', '처음']]
scene_data['tour_hsr2'] = ['tour_hsr2', \
['JESNK_SIDE', 'BUTTON_RIGHT', 'BUTTON_LEFT', \
'BUTTON_LEFT_DOWN', 'BUTTON_MIDDLE_DOWN', 'BUTTON_RIGHT_DOWN'], \
['잘가', '다음', '처음']]
signalID = 0
def touch_callback(x, y):
print(" coordinate x : ", x, " y : ", y)
print(signalID)
class Monitor_input:
def __init__(self, srv, touch_list=[], word_list=[]):
self.target_touch_list = touch_list
self.target_word_list = word_list
self.srv = srv
self.tabletService = srv['tablet']
self.signalID = srv['tablet'].onTouchDown.connect(self.touch_callback)
self.touched_position = None
self.exit_flag = False
self.ret = {}
self.memory = srv['memory']
self.asr = srv['asr']
self.asr.pause(True)
self.asr.setLanguage("Korean")
# self.asr.setLanguage("English")
self.debug_mode = False
self.debug_touch_count = 0
self.debug_touch_coordinate = []
try:
self.asr.unsubscribe("asr")
except:
pass
self.asr.pause(True)
def check_valid_touch(self):
for i in self.target_touch_list:
if self.touch_x > TOUCH_LIST[i]['x'][0] and self.touch_x < TOUCH_LIST[i]['x'][1]:
if self.touch_y > TOUCH_LIST[i]['y'][0] and self.touch_y < TOUCH_LIST[i]['y'][1]:
self.ret['touch_position'] = i
return True
return False
def touch_callback(self, x, y):
print(self.debug_mode)
if self.debug_mode:
self.debug_touch_count += 1
self.debug_touch_coordinate.append([x, y])
print("x : ", x, " y : ", y)
if self.debug_touch_count == 4:
self.debug_mode = False
self.debug_touch_count = 0
print("test")
xs = [x[0] for x in self.debug_touch_coordinate]
xs.sort()
ys = [x[1] for x in self.debug_touch_coordinate]
ys.sort()
print("X range : ", xs[0], "-", xs[-1])
print("Y range : ", ys[0], "-", ys[-1])
print("Touch_debug_mode Finished")
self.debug_touch_coordinate = []
return
return
self.touch_x = x
self.touch_y = y
if (self.check_valid_touch()):
self.ret['type'] = 'touch'
self.ret['x'] = x
self.ret['y'] = y
self.exit_flag = True
print("class_ x ", x, " y ", y)
def asr_callback(self, msg):
# Threshold
print(msg[0], ' is recognized. ', msg[1])
if msg[1] > 0.5:
print(msg[0], msg[1], " is returned")
self.ret['type'] = 'speech'
self.ret['word'] = msg[0]
self.exit_flag = True
def wait_for_get_input(self):
self.asr.setVocabulary(self.target_word_list, False)
print("Staring wait")
self.srv['audio_device'].setOutputVolume(3)
self.asr.subscribe('asr')
asr_mem_sub = self.memory.subscriber("WordRecognized")
asr_mem_sub.signal.connect(self.asr_callback)
while not self.exit_flag:
time.sleep(0.01)
self.asr.unsubscribe('asr')
self.srv['audio_device'].setOutputVolume(10)
self.exit_flag = False
return self.ret
def set_target_touch_list(self, touch_list):
self.target_touch_list = touch_list
def set_target_word_list(self, word_list):
self.target_word_list = word_list
def __del__(self):
self.tabletService.onTouchDown.disconnect(self.touch_callback)
self.asr.unsubscribe("ASR")
def get_html_address(file_name):
name = file_name
if len(name) > 5 and name[-5:] == '.html':
name = name[:-5]
return "http://198.18.0.1/apps/bi-html/" + name + '.html'
def transition(srv, scene, input_ret):
global monitor_input
# return value : scene name, available touch, avail word
print("Trainsition mode")
print(scene, input_ret)
if scene == 'home':
if input_ret['type'] == 'touch':
if input_ret['touch_position'] == 'BUTTON_MIDDLE_DOWN':
next_scene = 'first_menu'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("다음")
return scene_data[next_scene]
# jesnk : test
if input_ret['touch_position'] == 'JESNK_SIDE':
file_path = "/opt/aldebaran/www/apps/bi-sound/background.mp3"
# srv['tts'].post.say('yes')
player = ALProxy("ALAudioPlayer")
player.post.playFileFromPosition(file_path, 120)
# file_id = srv['audio_player'].loadFile("/opt/aldebaran/www/apps/bi-sound/background.mp3")
# srv['audio_player'].playFileFromPosition(file_path,120)
# srv['audio_player'].setVolume(file_id,0.3)
elif input_ret['type'] == 'speech':
if input_ret['word'] == '시작':
next_scene = 'first_menu'
srv['aas'].say("안녕하세요! 반갑습니다", aas_configuration)
srv['tablet'].showWebview(get_html_address(next_scene))
return scene_data[next_scene]
if input_ret['word'] == '안녕':
next_scene = 'home'
srv['aas'].say("안녕하세요!", aas_configuration)
return scene_data[next_scene]
if input_ret['word'] == '페퍼':
next_scene = 'home'
srv['aas'].say("네! 안녕하세요!", aas_configuration)
return scene_data[next_scene]
if scene == 'first_menu':
if input_ret['type'] == 'touch':
if input_ret['touch_position'] == 'JESNK_SIDE':
next_scene = 'first_menu'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("디버그")
monitor_input.debug_mode = True
while monitor_input.debug_mode:
time.sleep(0.01)
srv['tts'].say("디버그 끝")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_LEFT':
next_scene = 'tour'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("다음")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_RIGHT':
next_scene = 'entertain'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("다음")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_MIDDLE_DOWN':
next_scene = 'home'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say("다음")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_RIGHT_DOWN':
next_scene = scene
srv['tts'].setParameter("defaultVoiceSpeed", 100)
srv['aas'].say(
"제가 궁금하신가요? 저는 페퍼입니다. 소프트뱅크사에서 만들어진 휴머노이드 로봇으로, 인공지능을 사용할 수 있습니다. 귀여운 외모가 특징이며, 우리나라에선 금융, 서점, 의료, 유통 등 다양한 분야에 도입되어 있습니다.")
srv['tts'].setParameter("defaultVoiceSpeed", 70)
return scene_data[next_scene]
elif input_ret['type'] == 'speech':
if input_ret['word'] == '잘가':
return scene_data['exit']
if input_ret['word'] == '처음':
next_scene = 'home'
srv['tablet'].showWebview(get_html_address(next_scene))
return scene_data[next_scene]
if input_ret['word'] == '누구야':
next_scene = 'first_menu'
srv['tablet'].showWebview(get_html_address(next_scene))
return scene_data[next_scene]
if scene == 'tour':
if input_ret['type'] == 'touch':
if input_ret['touch_position'] == 'BUTTON_RIGHT':
next_scene = 'tour_hsr1'
srv['tts'].setParameter("defaultVoiceSpeed", 100)
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say("저희 연구실에 있는 로봇을 설명드리겠습니다. 먼저, 인간 도우미 로봇인 에이치에스알은, 이동형 조작 로봇입니다.", aas_configuration)
next_scene = 'tour_hsr2'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say("키는 약 1미터 이며, 다양한 카메라를 통해 물체를 인식하고, 그리퍼로 집는 것이 가능한, 만능 로봇입니다. 하지만 저보단 못생겼죠?",
aas_configuration)
next_scene = 'tour_blitz'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say(
"다음 로봇은, 블리츠 입니다. 물체를 옮기는데 특화된, 베이스 로봇과, 물체를 집는, 유알 파이브 로봇을 합쳐 만들어진 로봇입니다. 그외에 소리, 카메라 센서들을 탑재하여, 물체를 인식해 그리퍼로 집는 것이 가능한, 이동형 조작 로봇입니다.",
aas_configuration)
next_scene = 'tour_pepper1'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say(
"마지막으로 소개할 로봇은 저, 페퍼 입니다. 저는 소프트뱅크사에서 만들어진 휴머노이드 로봇으로, 인공지능을 사용할 수 있습니다.", aas_configuration)
next_scene = 'tour_pepper2'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say(
"귀여운 외모가 특징이며, 우리나라에선 금융, 서점, 의료, 유통 등 다양한 분야에 도입되어 있습니다. 뿐만 아니라 세계 로봇 대회인 로보컵 리그 중, 에스,에스,피,엘에서, 표준로봇으로 사용되고 있습니다.",
aas_configuration)
srv['tts'].setParameter("defaultVoiceSpeed", 70)
next_scene = 'tour'
srv['tablet'].showWebview(get_html_address(next_scene))
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_LEFT':
next_scene = 'tour_ourlab1'
srv['tts'].setParameter("defaultVoiceSpeed", 100)
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say(
"저희 연구실을 소개하겠습니다. 저희 바이오지능 연구실은 다음과 같은 연구들을 하고 있습니다. 먼저 베이비마인드, 브이티티 등, 인간 수준의 인공지능 개발을 위해, 인공지능, 심리학, 인지과학 등 다양한 분야와의 학제적 연구를 진행하고 있습니다. 또한 인간과 함께 활동하는 홈 로봇, 세계 로봇 대회인 로보컵 등, 다양한 플랫폼의 로봇 연구 또한 활발히 진행하고 있습니다.",
aas_configuration)
next_scene = 'tour_ourlab2'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say("그 밖에 궁금하신 부분 혹은, 문의사항이 있으시면, 다음의 홈페이지를 참고해 주시거나, 연락처로 문의해주시길 바랍니다.", aas_configuration)
srv['tts'].setParameter("defaultVoiceSpeed", 70)
next_scene = 'tour'
srv['tablet'].showWebview(get_html_address(next_scene))
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_MIDDLE_DOWN':
next_scene = 'home'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['aas'].say("처음으로", aas_configuration)
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_LEFT_DOWN':
next_scene = 'first_menu'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("이전")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_RIGHT_DOWN':
next_scene = scene
srv['tts'].setParameter("defaultVoiceSpeed", 110)
srv['aas'].say(
"제가 궁금하신가요? 저는 페퍼입니다. 소프트뱅크사에서 만들어진 휴머노이드 로봇으로, 인공지능을 사용할 수 있습니다. 귀여운 외모가 특징이며, 우리나라에선 금융, 서점, 의료, 유통 등 다양한 분야에 도입되어 있습니다.",
aas_configuration)
srv['tts'].setParameter("defaultVoiceSpeed", 70)
return scene_data[next_scene]
if scene == 'entertain':
if input_ret['type'] == 'touch':
if input_ret['touch_position'] == 'BUTTON_MIDDLE_DOWN':
next_scene = 'home'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("처음으로")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_LEFT_DOWN':
next_scene = 'first_menu'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("이전")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_LEFT':
file_path = "/opt/aldebaran/www/apps/bi-sound/elephant.ogg"
# srv['tts'].post.say('yes')
player = ALProxy("ALAudioPlayer", PEPPER_IP, 9559)
player.post.playFileFromPosition(file_path, 0)
entertain.elephant(srv)
player.post.stopAll()
pass
if input_ret['touch_position'] == 'BUTTON_RIGHT':
file_path = "/opt/aldebaran/www/apps/bi-sound/UrbanStreet.mp3"
player = ALProxy("ALAudioPlayer", PEPPER_IP, 9559)
player.post.playFileFromPosition(file_path, 0)
entertain.disco(srv)
player.post.stopAll()
pass
if input_ret['touch_position'] == 'BUTTON_RIGHT_DOWN':
next_scene = 'entertain2'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("다음")
return scene_data[next_scene]
if scene == 'entertain2':
if input_ret['type'] == 'touch':
if input_ret['touch_position'] == 'BUTTON_MIDDLE_DOWN':
next_scene = 'home'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("처음으로")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_LEFT_DOWN':
next_scene = 'first_menu'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("이전")
return scene_data[next_scene]
if input_ret['touch_position'] == 'BUTTON_LEFT':
srv['aas'].say("생년월일을 영어로 말씀해주세요.", aas_configuration)
text = saju.main(srv)
srv['ass'].say(text, aas_configuration)
if input_ret['touch_position'] == 'BUTTON_RIGHT':
pass
if input_ret['touch_position'] == 'BUTTON_RIGHT_DOWN':
next_scene = 'entertain'
srv['tablet'].showWebview(get_html_address(next_scene))
srv['tts'].say("다음")
return scene_data[next_scene]
# jesnk 1
monitor_input = None
aas_configuration = {"bodyLanguageMode": "contextual"}
def main(session):
# jesnk main
print("Hello")
srv = {}
srv['tablet'] = session.service("ALTabletService")
srv['memory'] = session.service("ALMemory")
srv['motion'] = session.service("ALMotion")
srv['asr'] = session.service("ALSpeechRecognition")
srv['tts'] = session.service("ALTextToSpeech")
srv['aas'] = session.service("ALAnimatedSpeech")
srv['audio_device'] = session.service("ALAudioDevice")
# srv['tts'].setVolume(0.1)
# srv['tts'].setParameter("defaultVoiceSpeed", 70)
srv['audio_player'] = session.service("ALAudioPlayer")
# Present Inital Page
srv['tablet'].enableWifi()
srv['tablet'].setOnTouchWebviewScaleFactor(1)
srv['tablet'].showWebview('http://198.18.0.1/apps/bi-html/home.html')
# Valid Input condition setting
global monitor_input
monitor_input = Monitor_input(srv)
init_scene = 'home'
scene_name, valid_touch_list, valid_word_list = \
scene_data[init_scene][0], scene_data[init_scene][1], scene_data[init_scene][2]
print(scene_name, valid_touch_list, valid_word_list)
monitor_input.set_target_touch_list(valid_touch_list)
monitor_input.set_target_word_list(valid_word_list)
while (True):
input_ret = monitor_input.wait_for_get_input()
ret = transition(srv, scene_name, input_ret)
if ret == None:
continue
print(ret)
scene_name, valid_touch_list, valid_word_list = ret[0], ret[1], ret[2]
monitor_input.set_target_touch_list(valid_touch_list)
monitor_input.set_target_word_list(valid_word_list)
if scene_name == 'exit':
break
print("passed 2")
# global signalID
# signalID = tabletService.onTouchDown.connect(touch_callback)
srv['tablet'].hideWebview()
print("Finished")
PEPPER_IP = '192.168.1.123'
if __name__ == "__main__":
print("Hello")
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str, default=PEPPER_IP,
help="Robot IP address. On robot or Local Naoqi: use '192.168.1.123'.")
parser.add_argument("--port", type=int, default=9559,
help="Naoqi port number")
print("Hello")
args = parser.parse_args()
session = qi.Session()
print("Hello")
try:
session.connect("tcp://" + PEPPER_IP + ":" + str(args.port))
except RuntimeError:
print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) + ".\n"
"Please check your script arguments. Run with -h option for help.")
sys.exit(1)
main(session)