前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Cozmo人工智能机器人SDK使用笔记(1)

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

作者头像
zhangrelay
发布2019-01-23 15:38:38
1.4K0
发布2019-01-23 15:38:38
举报
文章被收录于专栏:机器人课程与技术

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!

代码语言:javascript
复制
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()

代码语言:javascript
复制
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):

代码语言:javascript
复制
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示例组合,走完成一个正方形!

代码语言:javascript
复制
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

移动头部,手臂和履带。

代码语言:javascript
复制
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示例扩展!学唱歌???

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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

手机播放声音:

代码语言:javascript
复制
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。

代码语言:javascript
复制
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

代码语言:javascript
复制
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


本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年01月08日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • APP和SDK有对应关系
  • 部分CSDN关于Czomo博文汇总:
  • SDK简要说明:
  • 01_hello_world.py
  • 02_drive_and_turn.py
  • 03_count.py
  • 04_drive_square.py
  • 05_motors.py
  • 06_sing_scales.py
  • 07_backpack_lights.py
  • 08_animation.py
  • 09_cube_lights.py
  • 10_play_sound.py
  • 11_play_song.py
  • 12_random_animation.py
相关产品与服务
腾讯云小微
腾讯云小微,是一套腾讯云的智能服务系统,也是一个智能服务开放平台,接入小微的硬件可以快速具备听觉和视觉感知能力,帮助智能硬件厂商实现语音人机互动和音视频服务能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档