-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGesture.py
65 lines (49 loc) · 2.87 KB
/
Gesture.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
#-*- coding: utf-8 -*-
import logging
import qi
import time
class Gesture:
"""Class to control the Gestures with ALAnimationPlayer on the NAO robot"""
#%% CONSTRUCTOR ==========================================================================================================
def __init__(self, nao_ip):
self.__nao_ip = nao_ip
self.__session = qi.Session()
self.__session.connect("tcp://" + self.__nao_ip + ":9559")
self.__gesture_service = self.__session.service("ALAnimationPlayer")
self.__posture_service = self.__session.service("ALRobotPosture")
self.__add_tags()
self.__running = False
self.__future = None
#%% METHODS ==============================================================================================================
def __add_tags(self):
tagToAnims = dict()
tagToAnims["Toi"] = ["animations/Sit/Gestures/You_4"]
tagToAnims["Moi"] = ["animations/Sit/Gestures/Me_7"]
tagToAnims["Bonjour"] = ["animations/Sit/Gestures/Hey_3"]
tagToAnims["BodyTalk"] = ["animations/Sit/BodyTalk/BodyLanguage/BodyTalk_" + str(i) for i in range(1, 13)]
tagToAnims["Attente"] = ["animations/Sit/Waiting/PlayHands_1", "animations/Sit/Waiting/PlayHands_2", "animations/Sit/Waiting/PlayHands_3", "animations/Sit/Waiting/Relaxation_1", "animations/Sit/Waiting/Relaxation_2", "animations/Sit/Waiting/Relaxation_3", "animations/Sit/Waiting/ScratchBack_1", "animations/Sit/Waiting/ScratchHand_1", "animations/Sit/Waiting/ScratchHead_1", "animations/Sit/Waiting/ScratchLeg_1", "animations/Sit/Waiting/ScratchEye_1", "animations/Sit/Waiting/ScratchTorso_1", "animations/Sit/Waiting/Think_1", "animations/Sit/Waiting/Think_2", "animations/Sit/Waiting/Think_3", "animations/Sit/Waiting/Rest_1"]
self.__gesture_service.addTagForAnimations(tagToAnims)
#%% GETTERS AND SETTERS ==================================================================================================
def get_running(self):
return self.__running
#%% COMMANDS =============================================================================================================
def say_hi(self):
self.__gesture_service.runTag("Bonjour")
self.__gesture_service.runTag("Moi")
def say_bye(self):
self.__gesture_service.runTag("Bonjour")
self.__posture_service.goToPosture("Sit", 0.5)
def sit(self):
self.__posture_service.goToPosture("Sit", 0.3)
def start(self):
self.__running = True
while self.__running:
self.__future = self.__gesture_service.runTag("BodyTalk", _async=True)
self.__future.wait()
time.sleep(1)
self.__running = False
def stop(self):
self.__running = False
if self.__future:
self.__future.cancel()
logging.info("T11_Gesture: Finished.")