SSブログ

COZMO に物を覚えさせる [科学、数学]

昨年のクリスマスに、COZMOにペットへクリスマスプレゼントを届けるプログラムを作ろうとしたけど、ペットの位置がわからなくて、挫折してましたが、COZMOのSDKのサンプルの中に、カスタム・オブジェクトを定義する方法が書かれていました。

https://github.com/anki/cozmo-python-sdk/blob/master/examples/tutorials/04_cubes_and_objects/09_custom_objects.py

COZMO and custom objects



COZMO Python SDKの中に、オブジェクトを認識させるためのマーカーの画像イメージファイルがあるので、

https://github.com/anki/cozmo-python-sdk/tree/master/docs/source/images/custom_markers

これをダウンロードして、印刷し、適当な物(オブジェクト)に貼り付けます。

cozmo_markers.JPG

今回は、100円ショップで売っている積み木にマーカを貼り付けてオブジェクトを作りました。

積み木の大きさが、横 90mm, 縦 30mm, 厚さ 15mm なので、マーカーのサイズを、30mm X 30mm にして、積み木の表と裏に貼り、define_custom_wall というメソッドを使って、オブジェクトを壁としてCOZMOに覚えさせます。

define_custom_wall メソッドは、定義するオブジェクトとマーカーの大きさを引数で指定するので、COZMOは、カメラに映るオブジェクトの見かけの大きさや傾き具合(斜めからみているか、正面から見ているか)から、オブジェクトの位置や向きを認知できるようになるようです。

cozmo_walls.png




#!/usr/bin/env python3

import time
import cozmo
from cozmo.objects import CustomObject, CustomObjectMarkers, CustomObjectTypes


def handle_object_appeared(evt, **kw):
    # This will be called whenever an EvtObjectAppeared is dispatched -
    # whenever an Object comes into view.
    if isinstance(evt.obj, CustomObject):
        print("Cozmo started seeing a %s" % str(evt.obj.object_type))


def handle_object_disappeared(evt, **kw):
    # This will be called whenever an EvtObjectDisappeared is dispatched -
    # whenever an Object goes out of view.
    if isinstance(evt.obj, CustomObject):
        print("Cozmo stopped seeing a %s" % str(evt.obj.object_type))


def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared, handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared, handle_object_disappeared)

    robot.world.delete_all_custom_objects()

    # define a unique wall (90mm x 30mm (x10mm thick for all walls)
    # with 30mm x 30mm Circles images on front and back
    wall_obj_1 = robot.world.define_custom_wall(CustomObjectTypes.CustomType01,
                                              CustomObjectMarkers.Circles2,
                                              90, 30,
                                              30, 30, True)
    wall_obj_2 = robot.world.define_custom_wall(CustomObjectTypes.CustomType02,
                                              CustomObjectMarkers.Circles3,
                                              90, 30,
                                              30, 30, True)
    wall_obj_3 = robot.world.define_custom_wall(CustomObjectTypes.CustomType03,
                                              CustomObjectMarkers.Circles4,
                                              90, 30,
                                              30, 30, True)
    wall_obj_4 = robot.world.define_custom_wall(CustomObjectTypes.CustomType04,
                                              CustomObjectMarkers.Circles5,
                                              90, 30,
                                              30, 30, True)
    print(wall_obj_1)
    print(wall_obj_2)
    print(wall_obj_3)
    print(wall_obj_4)

    print("Press CTRL-C to quit")
    while True:
        time.sleep(0.1)


cozmo.run_program(custom_objects, use_3d_viewer=True, use_viewer=True)






今回は、写真が少くなくて、さびしいので
日産 グローバル本社ギャラリーで展示中の
R382 GRX-III (V12・DOHC・4バルブ) 5,954cc







nice!(13)  コメント(0) 
共通テーマ:趣味・カルチャー

nice! 13

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。