专栏首页机器人课程与技术Cozmo人工智能机器人SDK使用笔记(1)

Cozmo人工智能机器人SDK使用笔记(1)

APP和SDK有对应关系

如(3.0.0和1.4.6)或(3.1.0和1.4.7)。不严格对应,无法正常使用SDK。

cozmosdk.anki.com/docs/

Cozmo SDK经常更新,以便提供最佳的用户体验。SDK和Cozmo应用程序并不总是以相同的频率更新。检查此列表以查看要使用的SDK版本是否与正在使用的应用程序版本匹配。

应用版本#

SDK版本#

1.0.1

0.7.0

1.0.2

0.8.0

1.0.3

0.8.1

1.1.0

0.9.0

1.1.0

0.10.0

1.2.0

0.11.0

1.3.0

0.12.0

1.4.1

0.13.0

1.5.0

0.14.0

1.6.0

0.15.0

1.7.1

0.15.1

1.7.1

0.16.0

2.0.0

1.0.0

2.0.1

1.0.1

2.0.1

1.1.0

2.1.0

1.2.0

2.1.0

1.2.1

2.2.0

1.3.0

2.3.0

1.3.1

2.4.0

1.3.2

2.5.0

1.4.0

2.6.0

1.4.1

2.7.0

1.4.2

2.8.0

1.4.3

2.9.0

1.4.4

2.10.0

1.4.5

3.0.1

1.4.6

3.1.0

1.4.7

如果有不兼容的应用版本和SDK,请同步更新应用和SDK。


部分CSDN关于Czomo博文汇总:

手机连接Cozmo人工智能机器人玩具:

Cozmo机器人脱离智能手机使用的不完全攻略:

人工智能基础(高中版)教材补充和资源分享之番外篇 Cozmo+Python+ROS+AI:


SDK简要说明:

本文简要介绍一下教程tutorials中,基础部分01_basics:

使用前链接正确:


01_hello_world.py

Cozmo说出对应句子。

核心代码:robot.say_text("Hello World.").wait_for_completed()

可以替换如Hi Cozmo!

import cozmo


def cozmo_program(robot: cozmo.robot.Robot):
    robot.say_text("Hi Cozmo!").wait_for_completed()


cozmo.run_program(cozmo_program)

执行结果,听到cozmo说出hi cozmo:


02_drive_and_turn.py

基本运动指令。

核心代码:

直线运动:

robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()

转弯运动:

robot.turn_in_place(degrees(90)).wait_for_completed()

import cozmo
from cozmo.util import degrees, distance_mm, speed_mmps


def cozmo_program(robot: cozmo.robot.Robot):
    # Drive forwards for 150 millimeters at 50 millimeters-per-second.
    robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()

    # Turn 90 degrees to the left.
    # Note: To turn to the right, just use a negative number.
    robot.turn_in_place(degrees(90)).wait_for_completed()

前行150mm+转向90。


03_count.py

数数字,从1到10。

核心代码:循环使用for i in range(10):

import cozmo


def cozmo_program(robot: cozmo.robot.Robot):
    # A "for loop" runs for each value i in the given range - in this example
    # starting from 0, while i is less than 5 (so 0,1,2,3,4).
    for i in range(10):
        # Add 1 to the number (so that we count from 1 to 5, not 0 to 4),
        # then convert the number to a string and make Cozmo say it.
        robot.say_text(str(i+1)).wait_for_completed()


cozmo.run_program(cozmo_program)

cozmo开始数数字。


04_drive_square.py

02和03示例组合,走完成一个正方形!

import cozmo
from cozmo.util import degrees, distance_mm, speed_mmps


def cozmo_program(robot: cozmo.robot.Robot):
    # Use a "for loop" to repeat the indented code 4 times
    # Note: the _ variable name can be used when you don't need the value
    for _ in range(4):
        robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
        robot.turn_in_place(degrees(90)).wait_for_completed()


cozmo.run_program(cozmo_program)

运动指令和循环指令结合,当然也可以让他同时大声数数字。

加入???


05_motors.py

移动头部,手臂和履带。

import time

import cozmo


def cozmo_program(robot: cozmo.robot.Robot):
    # Tell the head motor to start lowering the head (at 5 radians per second)
    robot.move_head(-5)
    # Tell the lift motor to start lowering the lift (at 5 radians per second)
    robot.move_lift(-5)
    # Tell Cozmo to drive the left wheel at 25 mmps (millimeters per second),
    # and the right wheel at 50 mmps (so Cozmo will drive Forwards while also
    # turning to the left
    robot.drive_wheels(25, 50)

    # wait for 3 seconds (the head, lift and wheels will move while we wait)
    time.sleep(3)

    # Tell the head motor to start raising the head (at 5 radians per second)
    robot.move_head(5)
    # Tell the lift motor to start raising the lift (at 5 radians per second)
    robot.move_lift(5)
    # Tell Cozmo to drive the left wheel at 50 mmps (millimeters per second),
    # and the right wheel at -50 mmps (so Cozmo will turn in-place to the right)
    robot.drive_wheels(50, -50)

    # wait for 3 seconds (the head, lift and wheels will move while we wait)
    time.sleep(3)


cozmo.run_program(cozmo_program)

06_sing_scales.py

03示例扩展!学唱歌???

import cozmo
from cozmo.util import degrees


def cozmo_program(robot: cozmo.robot.Robot):
    # scales is a list of the words for Cozmo to sing
    scales = ["Doe", "Ray", "Mi", "Fa", "So", "La", "Ti", "Doe"]

    # Find voice_pitch_delta value that will range the pitch from -1 to 1 over all of the scales
    voice_pitch = -1.0
    voice_pitch_delta = 2.0 / (len(scales) - 1)

    # Move head and lift down to the bottom, and wait until that's achieved
    robot.move_head(-5) # start moving head down so it mostly happens in parallel with lift
    robot.set_lift_height(0.0).wait_for_completed()
    robot.set_head_angle(degrees(-25.0)).wait_for_completed()

    # Start slowly raising lift and head
    robot.move_lift(0.15)
    robot.move_head(0.15)

    # "Sing" each note of the scale at increasingly high pitch
    for note in scales:
        robot.say_text(note, voice_pitch=voice_pitch, duration_scalar=0.3).wait_for_completed()
        voice_pitch += voice_pitch_delta


cozmo.run_program(cozmo_program)

07_backpack_lights.py

灯光设置:红色--绿色--蓝色--白色--关闭

import time

import cozmo


def cozmo_program(robot: cozmo.robot.Robot):
    # set all of Cozmo's backpack lights to red, and wait for 2 seconds
    robot.set_all_backpack_lights(cozmo.lights.red_light)
    time.sleep(2)
    # 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(2)
    # 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(2)
    # 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(2)
    # turn off Cozmo's backpack lights and wait for 2 seconds
    robot.set_all_backpack_lights(cozmo.lights.off_light)
    time.sleep(2)

08_animation.py

播放动画动作(表情系列)

import cozmo


def cozmo_program(robot: cozmo.robot.Robot):
    # Play an animation via a Trigger - see:
    # http://cozmosdk.anki.com/docs/generated/cozmo.anim.html#cozmo.anim.Triggers
    # for a list of available triggers.
    # A trigger can pick from several appropriate animations for variety.
    print("Playing Animation Trigger 1:")
    robot.play_anim_trigger(cozmo.anim.Triggers.CubePounceLoseSession).wait_for_completed()

    # Play the same trigger, but this time ignore the track that plays on the
    # body (i.e. don't move the wheels). See the play_anim_trigger documentation
    # for other available settings.
    print("Playing Animation Trigger 2: (Ignoring the body track)")
    robot.play_anim_trigger(cozmo.anim.Triggers.CubePounceLoseSession, ignore_body_track=True).wait_for_completed()

    # Play an animation via its Name.
    # Warning: Future versions of the app might change these, so for future-proofing
    # we recommend using play_anim_trigger above instead.
    # See the remote_control_cozmo.py example in apps for an easy way to see
    # the available animations.
    print("Playing Animation 3:")
    robot.play_anim(name="anim_poked_giggle").wait_for_completed()


cozmo.run_program(cozmo_program)

09_cube_lights.py

三个能量方块分别为:红色/绿色/蓝色

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)

10_play_sound.py

手机播放声音:

import time

import cozmo

def cozmo_program(robot: cozmo.robot.Robot):
    # Play a sound that ends on its own
    robot.play_audio(cozmo.audio.AudioEvents.SfxGameWin)
    time.sleep(1.0)

    # Play a sound for us to interrupt after two seconds
    # This sound "MusicStyle80S1159BpmLoop" is:
    #   - "80S" style music #"1", at "159Bpm" (beats per minute)
    #   - if the song is played repeatedly, the beginning and end
    #     line up making it possible to play in a "Loop"
    robot.play_audio(cozmo.audio.AudioEvents.MusicStyle80S1159BpmLoop)

    # Most sounds have an accompanying (name + "Stop") event to cancel it
    # before it finishes.
    time.sleep(2.0)
    robot.play_audio(cozmo.audio.AudioEvents.MusicStyle80S1159BpmLoopStop)

    # Start the tiny orchestra system.
    # By itself, the tiny orchestra system will not make any sound, but
    # allows us to turn synchronized audio channels on and off until
    # we tell it to stop.
    robot.play_audio(cozmo.audio.AudioEvents.MusicTinyOrchestraInit)

    # Turn on the bass_mode_1 channel in the tiny orchestra system.
    robot.play_audio(cozmo.audio.AudioEvents.MusicTinyOrchestraBassMode1)

    # After 5 seconds...
    time.sleep(5.0)

    # Turn on the strings_mode_3 channel.
    robot.play_audio(cozmo.audio.AudioEvents.MusicTinyOrchestraStringsMode3)

    # After 5 seconds...
    time.sleep(5.0)

    # Stop the tiny orchestra system.
    # This will cause all tinyOrchestra music to stop playing.
    robot.play_audio(cozmo.audio.AudioEvents.MusicTinyOrchestraStop)

11_play_song.py

cozmo播放音乐:比手机音效zha。

import asyncio
import time

import cozmo

def cozmo_program(robot: cozmo.robot.Robot):

    # Create an array of SongNote objects, consisting of all notes from C2 to C3_Sharp
    notes = [
        cozmo.song.SongNote(cozmo.song.NoteTypes.C2, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.C2_Sharp, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.D2, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.D2_Sharp, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.E2, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.F2, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.F2_Sharp, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.G2, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.G2_Sharp, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.A2, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.A2_Sharp, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.B2, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.C3, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.C3_Sharp, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.Rest, cozmo.song.NoteDurations.Quarter) ]

    # Play the ascending notes
    robot.play_song(notes, loop_count=1).wait_for_completed()

    # Create an array of SongNote objects, consisting of the C3 pitch with varying durations
    notes = [
        cozmo.song.SongNote(cozmo.song.NoteTypes.C3, cozmo.song.NoteDurations.Half),
        cozmo.song.SongNote(cozmo.song.NoteTypes.C3, cozmo.song.NoteDurations.ThreeQuarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.Rest, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.C3, cozmo.song.NoteDurations.Quarter),
        cozmo.song.SongNote(cozmo.song.NoteTypes.C3, cozmo.song.NoteDurations.Whole) ]

    # Play the notes with varying durations
    robot.play_song(notes, loop_count=1).wait_for_completed()

cozmo.run_program(cozmo_program)

12_random_animation.py

import cozmo
import random

def cozmo_program(robot: cozmo.robot.Robot):
    # grab a list of animation triggers
    all_animation_triggers = robot.anim_triggers

    # randomly shuffle the animations
    random.shuffle(all_animation_triggers)

    # select the first three animations from the shuffled list
    triggers = 3
    chosen_triggers = all_animation_triggers[:triggers]
    print('Playing {} random animations:'.format(triggers))

    # play the three random animations one after the other, waiting for each to complete
    for trigger in chosen_triggers:
        print('Playing {}'.format(trigger.name))
        robot.play_anim_trigger(trigger).wait_for_completed()


    # grab animation triggers that have 'WinGame' in their name
    chosen_triggers = [trigger for trigger in robot.anim_triggers if 'WinGame' in trigger.name]

    # play the three random animations one after the other, waiting for each to complete
    for trigger in chosen_triggers:
        print('Playing {}'.format(trigger.name))
        robot.play_anim_trigger(trigger).wait_for_completed()

cozmo.run_program(cozmo_program)

Fin


本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Cozmo人工智能机器人SDK使用笔记(4)-任务部分cubes_and_objects

    接着,就自然过渡到第四部分----立方体和物体任务部分,共有13个项目专题,非常有趣。

    zhangrelay
  • Cozmo人工智能机器人SDK使用笔记(3)-视觉部分vision

    关于机器人感知-视觉部分,有过一次公开分享,讲稿全文和视屏实录,参考如下CSDN链接:

    zhangrelay
  • 机器人体验营笔记(二)基础

    版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons)

    zhangrelay
  • 答「测试从业者」经常问的10个问题

    1. 选Offer,如果犹豫了,就别去,说明某些条件,没达到期望,待不久(给面试官同样的建议,如果一个求职者,你在纠结要不要给Offer,就别给,再找找更适合的...

    IDO老徐
  • 京东“技术公司”算盘在企业业务这里能打响吗?

    “To B”浪潮如火如荼,几乎人人都在谈自己如何服务企业、服务产业,而事实上,在某些垂直领域,To B的企业业务早已激战多时,最近也在频频异动。

    曾响铃
  • git 通过 SublimeMerge 处理冲突

    在使用 Git 的时候,如果是多个小伙伴开发,那么如果同时修改一个文件将出现冲突。也就是在自动合并的时候不知道使用哪个代码才对,此时就需要合并工具的协助。我找了...

    林德熙
  • 迪士尼又出黑科技,可将自然语言脚本转化为VR视频 | 黑科技

    镁客网
  • 4 月排行:Python 最流行,Java 还行不行?

    PYPL 发布了 4 月份的编程语言排行榜。PYPL 是非常流行的参考指标,其榜单数据的排名均是根据榜单对象在 Google 上相关的搜索频率进行统计排名

    一墨编程学习
  • orion的简单测试 (r8笔记第75天)

    orion是一个做IO测试的小巧工具,可以测试随机读写,模拟混合负载等。 在oracle 11g已经自带包含了这一工具,无须额外的安装了,为IO方面的测试带来了...

    jeanron100
  • 神经机器翻译的无监督质量估计(CS CL)

    质量估计(QE)是使机器翻译(MT)在实际应用中有用的重要组成部分,因为它旨在在测试时告知用户MT输出的质量。现有方法需要大量的专家注释数据,计算和训练时间。作...

    刘子蔚

扫码关注云+社区

领取腾讯云代金券