forked from Cozomo-Laboratory/Cozmo-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCube Learning.py
54 lines (41 loc) · 1.49 KB
/
Cube Learning.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
import asyncio
import sys
import cozmo
from cozmo.util import degrees, distance_mm
def go_to_object_test(robot):
'''The core of the go to object test program'''
# Move lift down and tilt the head up
robot.move_lift(-3)
robot.set_head_angle(degrees(0)).wait_for_completed()
# look around and try to find a cube
look_around = robot.start_behavior(cozmo.behavior.BehaviorTypes.LookAroundInPlace)
cube = 1
try:
cube = robot.world.wait_for_observed_light_cube(timeout=30)
print("Found cube: %s" % 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:
# Drive to 70mm away from the cube (much closer and Cozmo
# will likely hit the cube) and then stop.
action = robot.go_to_object(cube, distance_mm(70.0))
action.wait_for_completed()
print("Completed action: result = %s" % action)
print("Done.")
def run(sdk_conn):
'''The run method runs once Cozmo is connected.'''
robot = sdk_conn.wait_for_robot()
try:
go_to_object_test(robot)
except KeyboardInterrupt:
print("")
print("Exit requested by user")
if __name__ == '__main__':
cozmo.setup_basic_logging()
try:
cozmo.connect(run)
except cozmo.ConnectionError as e:
sys.exit("A connection error occurred: %s" % e)