-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01_cozmo_face_image.py
More file actions
82 lines (62 loc) · 3.04 KB
/
01_cozmo_face_image.py
File metadata and controls
82 lines (62 loc) · 3.04 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
75
76
77
78
79
80
81
#!/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.
'''Display images on Cozmo's face (oled screen)
'''
import sys
import time
try:
from PIL import Image
except ImportError:
sys.exit("Cannot import from PIL: Do `pip3 install --user Pillow` to install")
import cozmo
def get_in_position(robot: cozmo.robot.Robot):
'''If necessary, Move Cozmo's Head and Lift to make it easy to see Cozmo's face'''
if (robot.lift_height.distance_mm > 45) or (robot.head_angle.degrees < 40):
with robot.perform_off_charger():
lift_action = robot.set_lift_height(0.0, in_parallel=True)
head_action = robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE,
in_parallel=True)
lift_action.wait_for_completed()
head_action.wait_for_completed()
def cozmo_program(robot: cozmo.robot.Robot):
get_in_position(robot)
# load some images and convert them for display cozmo's face
image_settings = [("../../face_images/cozmosdk.png", Image.BICUBIC),
("../../face_images/hello_world.png", Image.NEAREST)]
face_images = []
for image_name, resampling_mode in image_settings:
image = Image.open(image_name)
# resize to fit on Cozmo's face screen
resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
# convert the image to the format used by the oled screen
face_image = cozmo.oled_face.convert_image_to_screen_data(resized_image,
invert_image=True)
face_images.append(face_image)
# display each image on Cozmo's face for duration_s seconds (Note: this
# is clamped at 30 seconds max within the engine to prevent burn-in)
# repeat this num_loops times
num_loops = 10
duration_s = 2.0
print("Press CTRL-C to quit (or wait %s seconds to complete)" % int(num_loops*duration_s) )
for _ in range(num_loops):
for image in face_images:
robot.display_oled_face_image(image, duration_s * 1000.0)
time.sleep(duration_s)
# Cozmo is moved off his charger contacts by default at the start of any program.
# This is because not all motor movement is possible whilst drawing current from
# the charger. In cases where motor movement is not required, such as this example
# we can specify that Cozmo can stay on his charger at the start:
cozmo.robot.Robot.drive_off_charger_on_connect = False
cozmo.run_program(cozmo_program)