/examples/tutorials/04_cubes_and_objects/07_lookaround.py
https://github.com/anki/cozmo-python-sdk · Python · 74 lines · 33 code · 21 blank · 20 comment · 4 complexity · ebd64d3f5e5caaea753517c0f5d625f5 MD5 · raw file
- #!/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)