AI Vision Sensor#
Introduction#
The AI Vision Sensor can detect and track objects, colors, and AprilTags. This allows the robot to analyze its surroundings, follow objects, and react based on detected visual data.
The AI Vision examples are designed for use with a Basebot equipped with an AI Vision Sensor. In these examples, the sensor is configured with the name AIVision1, which appears in the blocks.
Below is a list of available blocks:
Actions – Capture data from the AI Vision Sensor for a selected signature.
get object data – Captures data for a specific object type, such as colors, pre-trained objects, or AprilTags.
Settings – Choose which object to interact with.
set AI Vision object item – Selects a specific object from the detected object list.
Values – Access and use the captured data.
AI Vision object exists? – Returns whether an object is detected.
AI Vision object count – Returns the number of detected objects.
AI Vision object property – Returns details such as:
AI Vision object is? – Checks if a detected object matches a specific classification.
AI Vision object is AprilTag ID? – Checks if a detected AprilTag matches a specific ID.
Actions#
get object data#
The get object data block filters data from the AI Vision Sensor frame. The AI Vision Sensor can detect signatures that include pre-trained objects, AprilTags, or configured colors and color codes.
Colors and color codes must be configured first in the AI Vision Utility before they can be used with this block.
The dataset stores objects ordered from largest to smallest by width, starting at index 0. Each object’s properties can be accessed using AI Vision object property block. An empty dataset is returned if no matching objects are detected.
从 [AIVision 1 v]获取 [SELECT_A_SIG v] 数据
Parameter |
Description |
---|---|
signature |
Filters the dataset to only include data of the given signature. Available signatures are:
|
Note: For AprilTag or AI Classification options to appear, their detection must be enabled in the AI Vision Utility.
Example
当开始 :: hat events
[Drive forward if an AprilTag is detected.]
永久循环
从 [AprilTags v]获取 [AIVision 1 v] 数据
如果 <[AIVIsion1 v] 对象存在?> 那么
驱动 [向前 v] [10] [毫米 v] ▶
Color Signatures#
A Color Signature is a unique color that the AI Vision Sensor can recognize. These signatures allow the sensor to detect and track objects based on their color. Once a Color Signature is configured, the sensor can identify objects with that specific color in its field of view.
Color Signatures are used in the Get object data block to process and detect colored objects in real-time. Up to 7 Color Signatures can be configured at a time.
Example
当开始 :: hat events
[Display if any objects matching the RED_BOX signature is detected.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[Change the signature to any configured Color Signature.]
从 [RED_BOX v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
在屏幕上打印 [Color detected!]▶
Color Codes#
A Color Code is a structured pattern made up of 2 to 4 Color Signatures arranged in a specific order. These codes allow the AI Vision Sensor to recognize predefined patterns of colors.
Color Codes are particularly useful for identifying complex objects, aligning with game elements, or creating unique markers for autonomous navigation. Up to 8 Color Codes can be configured at a time.
Example
当开始 :: hat events
[Display if any objects matching the RED_BLUE code is detected.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[Change the signature to any configured Color Code.]
从 [RED_BLUE v]获取 [AIVision 1 v] 数据
如果 <[AIVIsion1 v] 对象存在?> 那么
在屏幕上打印 [Code detected!]▶
Settings#
set AI Vision object item#
The set AI Vision object item block sets which item in the dataset to use.
设定 [AIVision 1 v] 对象标号为 (1)
Parameters |
Description |
---|---|
item |
The number of the item in the dataset to use. |
Example
当开始 :: hat events
[Display the largest detected AprilTag ID.]
永久循环
从 [AprilTags v]获取 [AIVision 1 v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[AIVision 1 v] 对象存在?> 那么
设定 [AIVision 1 v] 对象标号为 ([AIVision1 v]object count)
在屏幕上打印 ([AIVision 1 v] 对象 [tagID v])▶
Values#
AI Vision object exists?#
The AI Vision object exists block returns a Boolean indicating whether any object is detected in the dataset.
True – The dataset includes a detected object.
False – The dataset does not include any detected objects.
<[AIVision 1 v] 对象存在?>
Parameters |
Description |
---|---|
This block has no parameters. |
Example
当开始 :: hat events
[Drive forward if an object is detected.]
永久循环
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
驱动 [向前 v] [10] [毫米 v] ▶
AI Vision object count#
The AI Vision object count block returns the number of detected objects in the dataset as an integer.
([AIVision 1 v] 对象数目)
Parameters |
Description |
---|---|
This block has no parameters. |
Example
当开始 :: hat events
[Display the total amount of cubes, rings, and balls.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
在屏幕上打印 ([AIVision 1 v] 对象数目)▶
结束
等待 [0.5] 秒
AI Vision object property#
There are nine properties that are included with each object (shown below) stored after the Get object data block is used.
([AIVision 1 v] 对象 [宽 v])
Some property values are based off of the detected object’s position in the AI Vision Sensor’s view at the time that the Get object data block was used. The AI Vision Sensor has a resolution of 320 by 240 pixels.
Parameter |
Description |
---|---|
property |
Which property of the detected object to use: |
width#
width returns the width of the detected object in pixels as an integer from 1 to 320.
([AIVision 1 v] 对象 [宽 v])
Example
当开始 :: hat events
[Drive towards an object until its width is larger than 100 pixels.]
永久循环
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [宽 v]) [math_less_than v] [100]> 那么
驱动 [向前 v]
结束
否则
驱动停止
height#
height returns the height of the detected object in pixels as an integer from 1 to 240.
([AIVision 1 v] 对象 [高 v])
Example
当开始 :: hat events
[Drive towards an object until its height is larger than 100 pixels.]
永久循环
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [高 v]) [math_less_than v] [100]> 那么
驱动 [向前 v]
结束
否则
驱动停止
centerX#
centerX returns the x-coordinate of the center of the detected object in pixels as an integer from 0 to 320.
([AIVision 1 v] 对象 [中心X坐标 v])
Example
当开始 :: hat events
[Turn slowly until an object is centered in front of the robot.]
设定转向速度为 [30] %2
[右 v] 转
永久循环
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[140] [math_less_than v] ([AIVision 1 v] 对象 [中心X坐标 v]) [math_less_than v] [180]> 那么
驱动停止
centerY#
centerY returns the y-coordinate of the center of the detected object in pixels as an integer from 0 to 240.
([AIVision 1 v] 对象 [中心Y坐标 v])
Example
当开始 :: hat events
[Drive towards an object until its center y-coordinate is more than 140 pixels.]
永久循环
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [中心Y坐标 v]) [math_less_than v] [140]> 那么
驱动 [向前 v]
结束
否则
驱动停止
angle#
angle returns the orientation of the detected Color Code or AprilTag as an integer in degrees from 0 to 359.
([AIVision 1 v] 对象 [夹角 v])
Example
当开始 :: hat events
[Slide left or right depending on how the Color Code is rotated.]
永久循环
从 [RED_BLUE v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[50] [math_less_than v] ([AIVision 1 v] 对象 [夹角 v]) [math_less_than v] [100]> 那么
驱动 [右 v]
否则如果 <[270] [math_less_than v] ([AIVision 1 v] 对象 [夹角 v]) [math_less_than v] [330]> 那么
驱动 [左 v]
否则
驱动停止
结束
否则
驱动停止
originX#
originX returns the x-coordinate of the top-left corner of the detected object’s bounding box in pixels as an integer from 0 to 320.
([AIVision 1 v] 对象 [原点X v])
Example
当开始 :: hat events
[Display if an object is to the left or the right.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [原点X v]) [math_less_than v] [160]> 那么
在屏幕上打印 [To the left!]▶
否则
在屏幕上打印 [To the right!]▶
结束
等待 [0.5] 秒
originY#
originY returns the y-coordinate of the top-left corner of the detected object’s bounding box in pixels as an integer from 0 to 240.
([AIVision 1 v] 对象 [原点Y v])
Example
当开始 :: hat events
[Display if an object is close or far from the robot.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 [AI Classifications v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [原点Y v]) [math_less_than v] [80]> 那么
在屏幕上打印 [Far!]▶
否则
在屏幕上打印 [Close!]▶
结束
等待 [0.5] 秒
tagID#
tagID returns the identification number of the detected AprilTag as an integer.
([AIVision 1 v] 对象 [tagID v])
Example
当开始 :: hat events
[Drive forward when AprilTag ID 0 is detected.]
永久循环
从 [AprilTags v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [tagID v]) [math_equal v] [0]> 那么
驱动 [向前 v]
否则
驱动停止
结束
等待 [0.5] 秒
AI Vision object is?#
The AI Vision object is? block returns a Boolean indicating whether a detected object matches a specific classification.
True – The item in the dataset is the specific object.
False – The item in the dataset is not the specific object.
<[AIVision1 v] object is [BlueBall v] ?>
Parameter |
Description |
---|---|
object |
Which object to compare the item to:
|
Example
当开始 :: hat events
[Display if a Blue Cube is detected.]
永久循环
从 [AI Classifications v]获取 [AIVision 1 v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[AIVision1 v] object is [BlueCube v] ?> 那么
在屏幕上打印 [Cube detected!]▶
等待 [0.5] 秒
AI Vision object is AprilTag ID?#
The AI Vision object is AprilTag ID? block returns a Boolean indicating whether a detected AprilTag matches a specific ID.
True – The AprilTag ID is the number.
False – The AprilTag ID is not the number.
<[AIVision1 v] object is AprilTag [1] ?>
Parameters |
Description |
---|---|
AprilTag number |
The number to compare against the detected AprilTag’s ID number. |
Example:
当开始 :: hat events
[Report if AprilTag ID 3 is detected.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
从 [AprilTags v]获取 [AIVision 1 v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[AIVision1 v] object is AprilTag [3] ?> 那么
在屏幕上打印 [That is 3!]▶
否则
在屏幕上打印 [That isn't 3!]▶
结束
结束
等待 [0.1] 秒