AIビジョン#

導入#

VEX AIMコーディングロボットのAIビジョンセンサーは、物体、色、およびAprilTag IDを検出して追跡します。これにより、ロボットは周囲の状況を分析し、物体を追跡し、検出された視覚データに基づいて反応することができます。

AIビジョンセンサーの解像度は320×240ピクセルです。原点(0, 0)は左上隅に位置し、センサーの中心は(160, 120)に配置されます。下の図を参照してください。

AIM AI Vision Sensorの解像度を示す図。図の左上が座標0, 0、右上が座標320, 0、左下が座標0, 240、中央が座標160, 120です。

以下に、すべてのメソッドとプロパティの一覧を示します。

操作 — AI Visionカメラの映像を表示または非表示にします。

  • show_aivision — ロボットの画面にAI Visionフィードを表示します。

  • hide_aivision — AI Vision フィードを画面から非表示にします。

  • tag_detection — AprilTag ID の検出をオンまたはオフにします。

ゲッター — ロボットが物体を保持しているかどうかを検出します。

  • get_data — 特定のシグネチャに対して検出されたオブジェクトのタプルを返します。

  • has_sports_ball — ロボットがスポーツボールを持っているかどうかを返します。

  • has_any_barrel — ロボットが何らかの種類の樽を持っているかどうかを返します。

  • has_blue_barrel — ロボットが青いバレルを持っているかどうかを返します。

  • has_orange_barrel — ロボットがオレンジ色の樽を持っているかどうかを返します。

プロパティ — get_data から返されるオブジェクトデータ。

  • exists — オブジェクトが現在の検出に存在するかどうかをブール値で表します。

  • width — 検出されたオブジェクトの幅。

  • height — 検出されたオブジェクトの高さ。

  • centerX — オブジェクトの中心の X 座標。

  • centerY — オブジェクトの中心の Y 座標。

  • bearing — ロボットの前面に対する水平角度。

  • rotation — オブジェクトの向き。

  • originX — オブジェクトの左上隅の X 座標。

  • originY — オブジェクトの左上隅の Y 座標。

  • id — オブジェクトの分類またはタグ ID。

  • score — AI 分類の信頼度スコア。

  • type — オブジェクトのタイプ (AI、タグ、カラー、またはコード) を返します。

コンストラクタ — 色のシグネチャとコードを定義します。

行動#

show_aivision#

show_aivision は、AIビジョンセンサーのリアルタイムデータフィードをロボットの画面に表示します。リアルタイムデータフィードは、画面上の他の画像やテキストを覆い隠します。

注: hide_aivision を使用してフィードを非表示にしない限り、画面には他の画像やテキストは表示されません。

Usage:
robot.screen.show_aivision()

パラメータ

説明

このメソッドにはパラメータがありません。

# Watch the AI Vision Sensor detect AI Classifications
# and AprilTag IDs as you move the robot
robot.screen.show_aivision()

hide_aivision#

hide_aivision は、ロボットの画面から AI ビジョンセンサーのライブデータフィードを削除します。

Usage:
robot.screen.hide_aivision()

パラメータ

説明

このメソッドにはパラメータがありません。

# View the AI Vision Sensor's feed for five seconds
robot.screen.show_aivision()
wait(5, SECONDS)
robot.screen.hide_aivision()

tag_detection#

tag_detection は AprilTag ID の検出を有効または無効にします。状態はブール値です。

このセンサーは、Circle21h7ファミリーのAprilTag ID 0~36を検出できます。

Usage:
robot.vision.tag_detection(state)

パラメータ

説明

state

値は、 True、AprilTag IDの検出を有効にする)、または False、AprilTag IDの検出を無効にする)です。

robot.screen.set_font(PROP30)

# Cut off AprilTag ID detection after 5 seconds
while True:
    if timer.time(SECONDS) > 5:
        robot.vision.tag_detection(False)

    robot.screen.clear_screen()
    robot.screen.set_cursor(3, 1)
    apriltags = robot.vision.get_data(ALL_TAGS)

    if apriltags[0].exists:
        robot.screen.print("AprilTag ID detected!")
    else:
        robot.screen.print("Nothing detected!")

    wait(0.1, SECONDS)

ゲッター#

get_data#

get_data は、AI Vision Sensor フレームからデータをフィルタリングして、単一のシグネチャ (センサーが認識できるものの保存された説明。事前学習済みのオブジェクト、AprilTag ID、構成済みのカラーシグネチャまたはカラーコードなど) を取得し、タプル を返します。

この方法で使用する前に、AI Vision Utilityでカラーシグネチャとカラーコードを最初に設定する必要があります。

タプルは、インデックス0から始まる幅の大きい順から小さい順にオブジェクトを格納します。各オブジェクトのプロパティには、そのインデックスを使用してアクセスできます。一致するオブジェクトが検出されない場合は、空のタプルが返されます。

Usage:
robot.vision.get_data(signature, count)

パラメータ

説明

signature

Filters the dataset to only include data of the given signature. Available signatures are:

  • ALL_VISION - Sports balls, barrels, VEX AIM Coding Robots, AprilTag IDs, colors, and color codes
  • ALL_CARGO - Sports balls and barrels
  • ALL_TAGS - All AprilTag IDs
  • ALL_COLORS - All configured color signatures and color codes
  • SPORTS_BALL - Only sports balls
  • BLUE_BARREL - Only blue barrels
  • ORANGE_BARREL - Only orange barrels
  • AIM_ROBOT - All VEX AIM Coding Robots
  • TAG0 through TAG37 - A single AprilTag ID from 0 to 37
  • NAME - Color signature or color code where NAME is the name configured in the AI Vision Utility.

count

オプション。返されるオブジェクトの最大数を1~24の間で設定します(デフォルト:8)。

注: AprilTag ID 5~37は、AIM Printablesから印刷されたAprilTag IDを使用することで取得できます。

# Move forward if a sports ball is detected
while True:
    ball = robot.vision.get_data(SPORTS_BALL)
    if ball[0].exists:
        robot.move_for(10, 0)
    wait(50, MSEC)

注: 返されたタプルは、Python の sorted を使用して、幅だけでなく任意の プロパティ でソートできます。たとえば、AprilTag ID でソートする場合:

# Print each detected AprilTag ID in ascending order by ID
while True:
    apriltags = sorted(robot.vision.get_data(ALL_TAGS), key=id)
    for tag in apriltags:
        print(tag.id)
    wait(1, SECONDS)

または、高さ順に並べ替えることもできます。

# Print each detected AprilTag ID in ascending order by height
while True:
    apriltags_by_height = sorted(robot.vision.get_data(ALL_TAGS), key=lambda tag: tag.height)
    for tag in apriltags_by_height:
        print(tag.height)
    wait(1, SECONDS)

データの表示#

get_data によって返されるタプルを出力すると、検出されたすべてのオブジェクトのすべてのプロパティのリストが表示されます。

# Display properties of all detected AprilTag IDs
while True:
    vision_data = robot.vision.get_data(ALL_TAGS)

    if vision_data[0].exists:
        break

    wait(0.25, SECONDS)

print(vision_data)

検出された AprilTag ID のデバッグ出力を表示するコンソール ウィンドウのスクリーンショット。テキストには、exists: True、type: AprilTag ID、id: 2、centerX: 223、centerY: 54、originX: 210、originY: 42、width: 27、height: 23、bearing: 14.1、rotation: 0.0 などのフィールドを持つ「オブジェクト #0」がリストされ、その後に区切り線と、exists: True、type: AprilTag ID、id: 4、centerX: 122 を持つ「オブジェクト #1」の開始が続きます。

AI分類#

AIM AIビジョンセンサーは、以下のAI分類を検出できます。

ID番号

AI分類

サイン

0

ボール

SPORTS_BALL

1

ブルーバレル

BLUE_BARREL

2

オレンジバレル

ORANGE_BARREL

3

AIMロボット

AIM_ROBOT

カラーシグネチャー#

カラーシグネチャとは、AIビジョンセンサーが認識できる固有の色のことです。これらのシグネチャにより、センサーは色に基づいて物体を検出および追跡できます。カラーシグネチャが設定されると、センサーは視野内のその特定の色を持つ物体を識別できます。カラーシグネチャは、get_data で使用され、色付き物体をリアルタイムで処理および検出します。

AI Vision Utility は、接続されたビジョンセンサーが 2 つの色の物体を検出している様子を示しています。左側にはライブカメラの映像が表示され、左側に青いボックス、右側に赤いボックスが表示され、それぞれ白い境界ボックスで囲まれています。黒いラベルには、それぞれの名前、座標、寸法が表示されます。右側には、赤と青のボックスの色相と彩度範囲のスライダーを備えたカラーシグネチャ設定があります。下部には、色の追加、ビデオのフリーズ、画像のコピー、画像の保存を行うボタンがあり、右下隅には閉じるボタンがあります。

# Display if any objects match the Red_Box signature
while True:
    robot.screen.set_cursor(1, 1)
    robot.screen.clear_row(1)
    # Change to any configured Color Signature
    ai_objects = robot.vision.get_data(Red_Box)
    if ai_objects[0].exists:
        robot.screen.print("Color signature detected!")

カラーコード#

カラーコードとは、2~4色の色を特定の順序で並べた構造化されたパターンです。これらのコードにより、AIビジョンセンサーはあらかじめ定義された色のパターンを認識できます。カラーコードは、複雑な物体を識別したり、自律航行のための固有のマーカーを作成したりするのに役立ちます。

AI Vision Utility インターフェースには、接続されたビジョンセンサーが隣接する 2 つのオブジェクト (左側の青いボックスと右側の赤いボックス) を検出し、それらを BlueRed というラベルの付いた単一の白い境界ボックスにまとめて表示しています。検出情報には、角度 (A:11°)、座標 (X:143、Y:103)、幅 (W:233)、高さ (H:108) が含まれます。右側のパネルには、調整可能な色相と彩度範囲を持つ Red_Box、Blue_Box、BlueRed の 3 つのカラーシグネチャが表示されます。BlueRed シグネチャは Blue_Box と Red_Box を組み合わせたものです。ビデオフィードの下には、Freeze Video、Copy Image、Save Image、Close というラベルの付いたボタンがあります。

# Display if any objects match the BlueRed code
while True:
    robot.screen.set_cursor(1, 1)
    robot.screen.clear_row(1)
    # Change to any configured Color Code
    ai_objects = robot.vision.get_data(BlueRed)
    if ai_objects[0].exists:
        robot.screen.print("Color code detected!")

has_sports_ball#

has_sports_ball は、ロボットが現在スポーツボールを持っているかどうかを示すブール値を返します。

  • True — ロボットはスポーツボールを持っています。

  • False — ロボットにはスポーツボールがありません。

Usage:
robot.has_sports_ball()

パラメータ

説明

このメソッドにはパラメータがありません。

# Kick when the robot has a sports ball
while True:
    if robot.has_sports_ball():
        robot.kicker.kick(MEDIUM)

    wait(50, MSEC)

has_any_barrel#

has_any_barrel 、ロボットが現在何らかの種類のバレルを持っているかどうかを示すブール値を返します。

  • True — ロボットには樽があります。

  • False — ロボットには樽がありません。

Usage:
robot.has_any_barrel()

パラメータ

説明

このメソッドにはパラメータがありません。

# Push a barrel away when detected
while True:
    if robot.has_any_barrel():
        robot.kicker.place()

    wait(50, MSEC)

has_blue_barrel#

has_blue_barrel 、ロボットが現在青いバレルを持っているかどうかを示すブール値を返します。

  • True — ロボットには青い樽が付いています。

  • False — ロボットには青い樽がありません。

Usage:
robot.has_blue_barrel()

パラメータ

説明

このメソッドにはパラメータがありません。

# Push a blue barrel away when detected
while True:
    if robot.has_blue_barrel():
        robot.kicker.place()

    wait(50, MSEC)

has_orange_barrel#

has_orange_barrel 、ロボットが現在オレンジ色のバレルを持っているかどうかを示すブール値を返します。

  • True — ロボットにはオレンジ色の樽が付いています。

  • False — ロボットにはオレンジ色の樽がありません。

Usage:
robot.has_orange_barrel()

パラメータ

説明

このメソッドにはパラメータがありません。

# Push an orange barrel away when detected
while True:
    if robot.has_orange_barrel():
        robot.kicker.place()

    wait(50, MSEC)

不動産#

robot.vision.get_data メソッドを使用した後にタプルに格納される各オブジェクトには、12 個のプロパティが含まれています。

.id.score 、および .type を除くすべてのプロパティ値は robot.vision.get_data 使用された時点での検出されたオブジェクトの位置、サイズ、向き、または方位を表します。これらの値は、センサーの 320 x 240 ピクセルの解像度に基づいて、ピクセルまたは度で測定されます。

青い樽にオレンジ色のストライプが入ったものがフレームの中央に配置され、黒い境界ボックスで囲まれています。x軸とy軸は、上部に左から右へ0から320、左側に上から下へ0から240とそれぞれラベル付けされています。

.exists#

.exists 、インデックスがタプル内に存在するかどうかを示すブール値を返します。

  • True — インデックスが存在します。

  • False — インデックスが存在しません。

# Check if at least two objects are detected
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    ai_objects = robot.vision.get_data(ALL_CARGO)

    if ai_objects[0].exists:
        if ai_objects[1].exists:
            robot.screen.print("At least 2")
        else:
            robot.screen.print("Less than 2")
    wait(0.1, SECONDS)

.width#

.width 、検出されたオブジェクトの幅をピクセル単位で返します。これは 1 から 320 までの整数です。

注: ピクセル値はセンサーの座標系に対する相対値です。はじめにの図を参照してください。

青い樽にオレンジ色のストライプが入ったものがフレームの中央に配置され、黒い境界ボックスで囲まれています。フレームの上部から境界ボックスの左右の端まで、2本の赤い破線が垂直に伸びています。これらの線の間にある両方向の黒い矢印は、幅の測定値を示しています。

# Move towards a Blue Barrel until its width is
# larger than 100 pixels
while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if barrel[0].width < 100:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.height#

.height 、検出されたオブジェクトの高さをピクセル単位で返します。これは 1 から 240 までの整数です。

注: ピクセル値はセンサーの座標系に対する相対値です。はじめにの図を参照してください。

オレンジ色のストライプが入った青い樽がフレームの中央に配置され、黒い境界ボックスで囲まれています。フレームの左側から境界ボックスの上端と下端まで、2本の赤い水平破線が伸びています。これらの線の間にある両方向の黒い矢印は、高さの測定値を示しています。

# Move towards a Blue Barrel until its height is
# larger than 100 pixels
while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if barrel[0].height < 100:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.centerX#

.centerX 、検出されたオブジェクトの中心の x 座標をピクセル単位で返します。これは 0 から 320 までの整数です。

注: ピクセル値はセンサーの座標系に対する相対値です。はじめにの図を参照してください。

青い樽にオレンジ色のストライプが入ったものがフレームの中央に配置され、黒い境界ボックスで囲まれています。フレームの上部から境界ボックスの中心まで垂直の赤い破線が伸びており、中心のX座標を示しています。

# Turn slowly until a Blue Barrel is centered in
# front of the robot
robot.set_turn_velocity(30)
robot.turn(RIGHT)

while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if 140 < barrel[0].centerX < 180:
            robot.stop_all_movement()

    wait(10,MSEC)

.centerY#

.centerY 、検出されたオブジェクトの中心の y 座標をピクセル単位で返します。これは 0 から 240 までの整数です。

注: ピクセル値はセンサーの座標系に対する相対値です。はじめにの図を参照してください。

オレンジ色のストライプが入った青い樽がフレームの中央に配置され、黒い境界ボックスで囲まれています。フレームの左側から境界ボックスの中心まで水平の赤い破線が伸びており、中心のY座標を示しています。

# Move towards a Blue Barrel until its
# center y-coordinate is more than 140 pixels
while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if barrel[0].centerY < 140:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.bearing#

.bearing 、AI Vision Sensor のビューの中心からオブジェクトが左右にどれだけ離れているかを度数で表した小数 (float) を返します。値が 0 の場合は中心に位置していることを意味し、正の値はオブジェクトが右にあることを意味し、負の値はオブジェクトが左にあることを意味します。

上から見た図。円形のベースの中央にVEX AIMコーディングロボットが配置され、垂直の基準線と、左側のスポーツボールに向かってマイナス30度の角度で伸びる赤い線が示されている。 上から見た図。円形のベースの中央にVEX AIMコーディングロボットが配置され、垂直の基準線と、右側のスポーツボールに向かって30度の角度で伸びる赤い線が示されている。
# Turn to keep the Blue Barrel directly in front
robot.set_turn_velocity(40)
while True:
    vision_data = robot.vision.get_data(BLUE_BARREL)

    if vision_data[0].exists:

        if vision_data[0].bearing > 5:
            robot.turn(RIGHT)
        elif vision_data[0].bearing < -5:
            robot.turn(LEFT)
        else:
            robot.stop_all_movement()

    else:
        robot.stop_all_movement()

    wait(0.1, SECONDS)

.rotation#

.rotation 、AI Vision Sensor の視野面におけるオブジェクトの向きを、0 度から 359 度の範囲で返します。カラーコードが水平に並んでいる場合 (例: 赤 - 青) は、0° になります。色が回転すると、角度が変わります (例: 青 - 赤 の並びは 180° になります)。

以下の例では、カラーコードは左側が赤、右側が青に設定されています。

この画像では、赤の上に青を重ねることは、元のカラーコードを右に270度回転させることに相当します。

カメラのインターフェースには、上半分が青、下半分が赤の垂直に積み重ねられたオブジェクトがフレームの中央に表示されます。オブジェクトの下のラベルには、Red_Blue A:270° CX:185 CY:81 W:93 H:150 と表示され、オブジェクトの名前、回転角度、中心の X および Y 座標、幅、高さを示しています。グリッド線と数値軸は画像の寸法を示しており、X は 0 ~ 320、Y は 0 ~ 240 の範囲です。

# Slide left or right depending on how a Color Code (BlueRed)
# is rotated on the vertical plane
while True:
    # Original Color Code is Red to the left, Blue to the right
    code = robot.vision.get_data(BlueRed)

    if code[0].exists:
        # Check if Color Code is now Red on top of Blue
        if 50 < code[0].rotation < 100 :
            robot.move_at(90)

        # Check if Color Code is now Blue on top of Red
        elif 270 < code[0].rotation < 330 :
            robot.move_at(270)

        else:
            robot.stop_all_movement()
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.originX#

.originX 、検出されたオブジェクトのバウンディングボックスの左上隅の x 座標をピクセル単位で返します。これは 0 から 320 までの整数です。

注: ピクセル値はセンサーの座標系に対する相対値です。はじめにの図を参照してください。

オレンジ色のストライプが入った青い樽がフレームの中央に配置され、黒い境界ボックスで囲まれています。フレームの上部から境界ボックスの左端まで垂直の赤い破線が伸びており、境界ボックスの原点のX座標を示しています。

# Display if an Orange Barrel is to the
# left or the right
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1,1)

    orange_barrel = robot.vision.get_data(ORANGE_BARREL)

    if orange_barrel[0].exists:
        if orange_barrel[0].originX < 160:
            robot.screen.print("To the left!")
        else:
            robot.screen.print("To the right!")

    wait(50, MSEC)

.originY#

.originY 、検出されたオブジェクトのバウンディングボックスの左上隅の y 座標をピクセル単位で返します。これは 0 から 240 までの整数です。

注: ピクセル値はセンサーの座標系に対する相対値です。はじめにの図を参照してください。

オレンジ色のストライプが入った青い樽がフレームの中央に配置され、黒い境界ボックスで囲まれています。フレームの左側から境界ボックスの上端まで水平の赤い破線が伸びており、境界ボックスの原点のY座標を示しています。

# Display if an Orange Barrel is close or far
# from the robot
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)

    orange_barrel = robot.vision.get_data(ORANGE_BARREL)

    if orange_barrel[0].exists:
        if orange_barrel[0].originY < 80:
            robot.screen.print("Far")
        else:
            robot.screen.print("Close")

    wait(50, MSEC)

.id#

.id 、検出された AI 分類の ID または AprilTag ID を整数として返します。

AprilTag ID の場合、 .id プロパティは、検出された AprilTag ID 番号を 0 ~ 37 の範囲で表します。AI 分類の場合、 .id プロパティは、AI 分類 セクションで定義済みの ID に対応します。

# Move forward when AprilTag ID 1 is detected
while True:
    apriltags = robot.vision.get_data(ALL_TAGS)

    if apriltags[0].exists:
        if apriltags[0].id == 1:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.score#

.score 、検出された AI 分類の信頼度スコアを 1 から 100 までの整数として返します。

スコアが低いほど、センサーは検出された物体に対する確信度が低いことを意味し、スコアが高いほど、センサーの確信度が高いことを意味します。

# Look confident if an Orange Barrel is detected
while True:
    barrel = robot.vision.get_data(ORANGE_BARREL)

    if barrel[0].exists:
        if barrel[0].score > 95:
            robot.screen.show_emoji(CONFIDENT)
        else:
            robot.screen.hide_emoji()

    wait(50, MSEC)

.type#

.type は、検出されたオブジェクトのタイプを示す整数を返します。この値は、タイプ番号または対応する名前付き定数のいずれかを使用して比較できます。

オブジェクトタイプ

含まれるオブジェクト

AiVision.AI_OBJECT

— スポーツボール
— 青い樽
— オレンジ色の樽

AiVision.TAG_OBJECT

— AprilTag IDs

AiVision.COLOR_OBJECT

— 色のシグネチャー

AiVision.CODE_OBJECT

— 色分け

# Display if an AprilTag ID or AI Classification
# is detected
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    vision_data = robot.vision.get_data(ALL_VISION)
    if vision_data[0].exists:
        if vision_data[0].type == AiVision.AI_OBJECT:
            robot.screen.print("AI Object!")
        elif vision_data[0].type == AiVision.TAG_OBJECT:
            robot.screen.print("AprilTag ID!")
    wait(0.1, SECONDS)

# Display a list of all detected objects
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    vision_data = robot.vision.get_data(ALL_VISION)

    if vision_data[0].exists:
        for obj in vision_data:
            if obj.type == AiVision.AI_OBJECT:
                robot.screen.print("- AI Object")
            elif obj.type == AiVision.TAG_OBJECT:
                robot.screen.print("- AprilTag ID")
            robot.screen.next_row()

    wait(0.1, SECONDS)

建設業者#

Creating a Color Signature#

新しいカラーシグネチャは、 Colordesc コンストラクタを使用して作成され、 color_description メソッドを使用して AI ビジョンセンサーに登録されます Colordesc オブジェクトは、センサーで検出可能な最大 7 つのカラーシグネチャのうち 1 つを定義しますが、有効にするには color_description を使用して明示的に設定する必要があります。

Colordesc の使用方法:
Colordesc(index, red, green, blue, hangle, hdsat)

パラメータ

説明

index

カラーシグネチャのインデックスを表す1~7の整数。2つのカラーシグネチャが同じインデックスを使用している場合、2番目のカラーシグネチャが最初のものを上書きします。

red

色の赤色成分を表す、0から255までの整数値。

green

色の緑色成分を表す、0から255までの整数値。

blue

色の青色成分を表す、0から255までの整数値。

hangle

色相範囲を度数で表した、1から40までの浮動小数点数。

hdsat

飽和範囲を表す0.10から1.00までの浮動小数点数。

color_description 使用例:
robot.vision.color_description(object)

パラメータ

説明

object

検出可能なカラーシグネチャとして設定する Colordesc オブジェクト。

# Detect a red object
red_box = Colordesc(1, 207, 19, 25, 10.00, 0.20)
robot.vision.color_description(red_box)

while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)

    red_boxes = robot.vision.get_data(red_box)

    if red_boxes[0].exists:
        robot.screen.print("Red detected!")
    else:
        robot.screen.print("No red detected.")

    wait(0.2, SECONDS)

Creating a Color Code#

新しいカラーコードは、 Codedesc コンストラクタを使用して作成され、 code_description メソッドを使用してアクティブ化されます。カラーコードは、2 ~ 4 つの既存の Colordesc オブジェクトを単一の識別子にグループ化し、AI ビジョンセンサーがシーケンスとして検出できるようにしますが、有効にするには code_description を使用して明示的に設定する必要があります。

Codedesc の使用法:
Codedesc(index, c1, c2, c3, c4, c5)

パラメータ

説明

index

カラーコードのインデックス(1~8)。注:同じインデックスを持つ Codedesc オブジェクトを 2 つ作成した場合、2 つ目のオブジェクトが最初のオブジェクトを上書きします。

c1

コード内の最初の Colordesc オブジェクト。

c2

コード内の 2 番目の Colordesc オブジェクト。

c3

オプション。3 番目の Colordesc オブジェクト。

c4

オプション。4番目の Colordesc オブジェクト。

code_description 使用例:
robot.vision.code_description(object)

パラメータ

説明

object

検出可能なカラーコードとして登録する、 Codedesc オブジェクト。

# Create Color Signatures
red_box = Colordesc(1, 207, 19, 25, 10.00, 0.20)
purple_box = Colordesc(2, 98, 18, 227, 10.00, 0.20)

robot.vision.color_description(red_box)
robot.vision.color_description(purple_box)

# Detect a red_purple Color Code
red_purple = Codedesc(1, red_box, purple_box)
robot.vision.code_description(red_purple)

while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)

    code_objects = robot.vision.get_data(red_purple)

    if code_objects[0].exists:
        robot.screen.print("Code detected!")
    else:
        robot.screen.print("No code detected.")

    wait(0.2, SECONDS)