cozmo玩耍記錄1

我也不知道這算什麼,姑且稱之爲——走個T臺?


看了cozmo sdk裏面01_basics的例子後,可以按頭讓cozmo做點什麼了。

想具體瞭解01_basics例子的朋友可以移步zhangrelay老師博客,他有整理過。https://zhangrelay.blog.csdn.net/article/details/86096163

我這個走t臺就是,小方塊閃爍,cozmo自我介紹,走兩步招招手,再扭兩下轉轉圈這麼個過程,還挺無聊的。

#!/usr/bin/env python3

#edited by jiali zhang, 20190807
#cozmo's runway show

import time
import cozmo
from cozmo.util import degrees, distance_mm, speed_mmps
from cozmo.objects import LightCube1Id, LightCube2Id, LightCube3Id

def cozmo_cube(robot: cozmo.robot.Robot):
    cube1 = robot.world.get_light_cube(LightCube1Id)
    cube2 = robot.world.get_light_cube(LightCube2Id)
    cube3 = robot.world.get_light_cube(LightCube3Id)
    for _ in range(2):
        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.")
        time.sleep(0.5)

        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.")
        time.sleep(0.5)

        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.")
        time.sleep(0.5)

        if cube1 is not None:
            cube1.set_lights(cozmo.lights.white_light)
        else:
            cozmo.logger.warning("Cozmo is not connected to a LightCube1Id cube - check the battery.")
        time.sleep(0.5)

        if cube2 is not None:
            cube2.set_lights(cozmo.lights.red_light)
        else:
            cozmo.logger.warning("Cozmo is not connected to a LightCube2Id cube - check the battery.")
        time.sleep(0.5)

        if cube3 is not None:
            cube3.set_lights(cozmo.lights.green_light)
        else:
            cozmo.logger.warning("Cozmo is not connected to a LightCube3Id cube - check the battery.")
        time.sleep(0.5)


def cozmo_walk(robot: cozmo.robot.Robot):
    robot.move_head(5)
    robot.move_lift(-5)
    robot.say_text("HEY!!! I am cozmo!").wait_for_completed()

    for _ in range(2):
        robot.set_all_backpack_lights(cozmo.lights.red_light)
        time.sleep(0.1)
        # set all of Cozmo's backpack lights to green, and wait for 2 seconds
        robot.set_all_backpack_lights(cozmo.lights.green_light)
        time.sleep(0.1)
        # set all of Cozmo's backpack lights to blue, and wait for 2 seconds
        robot.set_all_backpack_lights(cozmo.lights.blue_light)
        time.sleep(0.1)
        # set just Cozmo's center backpack lights to white, and wait for 2 seconds
        robot.set_center_backpack_lights(cozmo.lights.white_light)
        time.sleep(0.1)
        # turn off Cozmo's backpack lights and wait for 2 seconds
        robot.set_all_backpack_lights(cozmo.lights.off_light)
        time.sleep(0.1)
    

    robot.drive_wheels(25, 25)
    time.sleep(2)
    robot.move_lift(5)
    time.sleep(2)
    robot.move_lift(-5)
    time.sleep(2)
    robot.drive_wheels(25,50)
    time.sleep(1)
    robot.drive_wheels(50,25)
    time.sleep(3)
    robot.drive_wheels(25,50)
    time.sleep(2)
    robot.drive_wheels(100, -100)
    time.sleep(5)


cozmo.run_program(cozmo_cube)
cozmo.run_program(cozmo_walk)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章