-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path07_lookaround.py
More file actions
74 lines (52 loc) · 2.09 KB
/
07_lookaround.py
File metadata and controls
74 lines (52 loc) · 2.09 KB
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
#!/usr/bin/env python3
# Copyright (c) 2016 Anki, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the file LICENSE.txt or at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''Make Cozmo look around for a cube.
Cozmo looks around, reacts, and picks up and puts down a cube if found.
'''
import asyncio
import cozmo
from cozmo.util import degrees
def cozmo_program(robot: cozmo.robot.Robot):
look_around = robot.start_behavior(cozmo.behavior.BehaviorTypes.LookAroundInPlace)
# try to find a block
cube = None
try:
cube = robot.world.wait_for_observed_light_cube(timeout=30)
print("Found cube", cube)
except asyncio.TimeoutError:
print("Didn't find a cube :-(")
finally:
# whether we find it or not, we want to stop the behavior
look_around.stop()
if cube is None:
robot.play_anim_trigger(cozmo.anim.Triggers.MajorFail)
return
print("Yay, found cube")
cube.set_lights(cozmo.lights.green_light.flash())
anim = robot.play_anim_trigger(cozmo.anim.Triggers.BlockReact)
anim.wait_for_completed()
action = robot.pickup_object(cube)
print("got action", action)
result = action.wait_for_completed(timeout=30)
print("got action result", result)
robot.turn_in_place(degrees(90)).wait_for_completed()
action = robot.place_object_on_ground_here(cube)
print("got action", action)
result = action.wait_for_completed(timeout=30)
print("got action result", result)
anim = robot.play_anim_trigger(cozmo.anim.Triggers.MajorWin)
cube.set_light_corners(None, None, None, None)
anim.wait_for_completed()
cozmo.run_program(cozmo_program)