-
Notifications
You must be signed in to change notification settings - Fork 0
/
face_turn.py
89 lines (67 loc) · 2.69 KB
/
face_turn.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
import threading
import anki_vector
from anki_vector import behavior
from anki_vector.events import Events
from anki_vector.util import degrees
from anki_vector.util import distance_mm, speed_mmps, degrees
import time
from turn_right_at_wall import right_at_wall
from victory_emote import victory_emote
said_text = False
def turn_left_at_obstacle():
with anki_vector.Robot() as robot:
def left_turn():
robot.behavior.turn_in_place(degrees(90))
def say_hi():
args = anki_vector.util.parse_command_args()
with anki_vector.Robot(args.serial) as robot:
print('Vector says hello to the minotaur')
robot.behavior.say_text('I turned left')
say_hi()
left_turn()
def main():
def on_robot_observed_face(robot, event_type, event, done):
print("Vector sees a face")
global said_text
if not said_text:
said_text = True
robot.behavior.say_text("I see a face!")
done.set()
# victory_face = False
def on_robot_observed_face(robot, event_type, event, done):
name_data_list = robot.faces.request_enrolled_names()
global said_text
if not said_text:
if event.face_id == name_data_list.faces[3].face_id:
robot.behavior.say_text("I see a Merry!")
turn_left_at_obstacle()
said_text = True
done.set()
if event.face_id == name_data_list.faces[0].face_id:
# nonlocal victory_face
victory_emote()
# victory_face = True
said_text = True
done.set()
args = anki_vector.util.parse_command_args()
with anki_vector.Robot(args.serial, enable_face_detection=True) as robot:
# If necessary, move Vector's Head and Lift to make it easy to see his face
robot.behavior.set_head_angle(degrees(15.0))
robot.behavior.set_lift_height(0.0)
done = threading.Event()
robot.events.subscribe(on_robot_observed_face, Events.robot_observed_face, done)
print("------ waiting for face events, press ctrl+c to exit early ------")
try:
if not done.wait(timeout=5):
print("------ Vector never saw your face! ------")
except KeyboardInterrupt:
pass
robot.events.unsubscribe(on_robot_observed_face, Events.robot_observed_face)
if __name__ == '__main__':
count = 0
# nonlocal victory_face
# while not victory_face:
while count < 3:
count += 1
main()
# time.sleep(20)