forked from Cozomo-Laboratory/Cozmo-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09_cube_lights.py
53 lines (40 loc) · 1.82 KB
/
09_cube_lights.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
#!/usr/bin/env python3
# Copyright (c) 2017 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.
'''Control Cozmo's Cube lights
This script shows how you can control Cozmo's cube lights and set
them to different colors - to red, green and blue in this case.
'''
import time
import cozmo
from cozmo.objects import LightCube1Id, LightCube2Id, LightCube3Id
def cozmo_program(robot: cozmo.robot.Robot):
cube1 = robot.world.get_light_cube(LightCube1Id) # looks like a paperclip
cube2 = robot.world.get_light_cube(LightCube2Id) # looks like a lamp / heart
cube3 = robot.world.get_light_cube(LightCube3Id) # looks like the letters 'ab' over 'T'
if cube1 is not None:
cube1.set_lights(cozmo.lights.red_light)
else:
cozmo.logger.warning("Cozmo is not connected to a LightCube1Id cube - check the battery.")
if cube2 is not None:
cube2.set_lights(cozmo.lights.green_light)
else:
cozmo.logger.warning("Cozmo is not connected to a LightCube2Id cube - check the battery.")
if cube3 is not None:
cube3.set_lights(cozmo.lights.blue_light)
else:
cozmo.logger.warning("Cozmo is not connected to a LightCube3Id cube - check the battery.")
# Keep the lights on for 10 seconds until the program exits
time.sleep(10)
cozmo.run_program(cozmo_program)