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.

Values – Access and use the captured data.

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.

The Get object data stack block.#
obtener [AIVision 1 v] datos de [SELECT_A_SIG v]

Parameter

Description

signature

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

  • AprilTags
  • AI Classifications – includes:
    • BlueBall
    • GreenBall
    • RedBall
    • BlueRing
    • GreenRing
    • RedRing
    • BlueCube
    • GreenCube
    • RedCube
    • NAME – A color or color code where NAME is the name configured in the AI Vision Utility

Note: For AprilTag or AI Classification options to appear, their detection must be enabled in the AI Vision Utility.

Example

cuando empezó :: hat events
[Drive forward if an AprilTag is detected.]
para siempre
obtener [AprilTags v] datos de [AIVision 1 v]
si <¿Existe [AIVIsion1 v] objeto?> entonces
unidad [adelante v] para [10] [mm 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.

The AI Vision Utility showing a connected vision sensor detecting two colored objects. The left side displays a live camera feed with a blue box on the left and a red box on the right, each outlined with white bounding boxes. Black labels display their respective names, coordinates, and dimensions. The right side contains color signature settings, with sliders for hue and saturation range for both the red and blue boxes. Buttons for adding colors, freezing video, copying, and saving the image are at the bottom, along with a close button in the lower right corner.

Example

cuando empezó :: hat events
[Display if any objects matching the RED_BOX signature is detected.]
para siempre
Coloque el cursor en la fila [1] columna [1] en la pantalla
Limpiar la fila [1] de la pantalla
[Change the signature to any configured Color Signature.]
obtener [RED_BOX v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
imprimir [Color detected!] en la pantalla ▶

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.

The AI Vision Utility interface shows a connected vision sensor detecting two adjacent objects, a blue box on the left and a red box on the right, grouped together in a single white bounding box labeled BlueRed. Detection information includes angle (A:11°), coordinates (X:143, Y:103), width (W:233), and height (H:108). On the right panel, three color signatures are listed: Red_Box, Blue_Box, and BlueRed, with adjustable hue and saturation ranges. The BlueRed signature combines the Blue_Box and Red_Box. Below the video feed are buttons labeled Freeze Video, Copy Image, Save Image, and Close.

Example

cuando empezó :: hat events
[Display if any objects matching the RED_BLUE code is detected.]
para siempre
Coloque el cursor en la fila [1] columna [1] en la pantalla
Limpiar la fila [1] de la pantalla
[Change the signature to any configured Color Code.]
obtener [RED_BLUE v] datos de [AIVision 1 v]
si <¿Existe [AIVIsion1 v] objeto?> entonces
imprimir [Code detected!] en la pantalla ▶

Settings#

set AI Vision object item#

The set AI Vision object item block sets which item in the dataset to use.

The Set AI Vision object item stack block.#
Establecer el elemento de objeto [AIVision 1 v] en (1)

Parameters

Description

item

The number of the item in the dataset to use.

Example

A stack of blocks that begins with a when started block, followed by a comment block reading Display the largest detected AprilTag ID. Inside a forever loop, a take a AI Vision snapshot block captures an image of AprilTags. An if block checks if an AI Vision object exists. If true, a set AI Vision object item block assigns the object count to a variable, and a print block displays the tag ID of the detected object on the screen.#
cuando empezó :: hat events
[Display the largest detected AprilTag ID.]
para siempre
obtener [AprilTags v] datos de [AIVision 1 v]
Limpiar la fila [1] de la pantalla
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <¿Existe [AIVision 1 v] objeto?> entonces
Establecer el elemento de objeto [AIVision 1 v] en ([AIVision1 v]object count)
imprimir ([AIVision 1 v] objeto [ID de etiqueta v]) en la pantalla ▶

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.

The AI Vision object exists Boolean block.#
<¿Existe [AIVision 1 v] objeto?>

Parameters

Description

This block has no parameters.

Example

cuando empezó :: hat events
[Drive forward if an object is detected.]
para siempre
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
unidad [adelante v] para [10] [mm v] ▶

AI Vision object count#

The AI Vision object count block returns the number of detected objects in the dataset as an integer.

The Set AI Vision object item stack block.#
([AIVision 1 v] recuento de objetos)

Parameters

Description

This block has no parameters.

Example

cuando empezó :: hat events
[Display the total amount of cubes, rings, and balls.]
para siempre
Limpiar la fila [1] de la pantalla
Coloque el cursor en la fila [1] columna [1] en la pantalla
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
imprimir ([AIVision 1 v] recuento de objetos) en la pantalla ▶
fin
esperar [0.5] segundos

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.

The AI Vision object property reporter block.#
([AIVision 1 v] objeto [amplitud 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.

The AI Vision object property stack block with its parameter set to width.#
([AIVision 1 v] objeto [amplitud v])

Example

cuando empezó :: hat events
[Drive towards an object until its width is larger than 100 pixels.]
para siempre
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <([AIVision 1 v] objeto [amplitud v]) [math_less_than v] [100]> entonces
unidad [adelante v]
fin
demás
deja de conducir

height#

height returns the height of the detected object in pixels as an integer from 1 to 240.

The AI Vision object property stack block with its parameter set to height.#
([AIVision 1 v] objeto [altura v])

Example

cuando empezó :: hat events
[Drive towards an object until its height is larger than 100 pixels.]
para siempre
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <([AIVision 1 v] objeto [altura v]) [math_less_than v] [100]> entonces
unidad [adelante v]
fin
demás
deja de conducir

centerX#

centerX returns the x-coordinate of the center of the detected object in pixels as an integer from 0 to 320.

The AI Vision object property stack block with its parameter set to centerX.#
([AIVision 1 v] objeto [centroX v])

Example

cuando empezó :: hat events
[Turn slowly until an object is centered in front of the robot.]
establecer la velocidad de giro a [30] %2
turno [derecha v]
para siempre
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <[140] [math_less_than v] ([AIVision 1 v] objeto [centroX v]) [math_less_than v] [180]> entonces
deja de conducir

centerY#

centerY returns the y-coordinate of the center of the detected object in pixels as an integer from 0 to 240.

The AI Vision object property stack block with its parameter set to centerY.#
([AIVision 1 v] objeto [centroY v])

Example

cuando empezó :: hat events
[Drive towards an object until its center y-coordinate is more than 140 pixels.]
para siempre
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <([AIVision 1 v] objeto [centroY v]) [math_less_than v] [140]> entonces
unidad [adelante v]
fin
demás
deja de conducir

angle#

angle returns the orientation of the detected Color Code or AprilTag as an integer in degrees from 0 to 359.

The AI Vision object property stack block with its parameter set to angle.#
([AIVision 1 v] objeto [ángulo v])

Example

cuando empezó :: hat events
[Slide left or right depending on how the Color Code is rotated.]
para siempre
obtener [RED_BLUE v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <[50] [math_less_than v] ([AIVision 1 v] objeto [ángulo v]) [math_less_than v] [100]> entonces
unidad [derecha v]
de lo contrario si <[270] [math_less_than v] ([AIVision 1 v] objeto [ángulo v]) [math_less_than v] [330]> entonces
unidad [izquierda v]
demás
deja de conducir
fin
demás
deja de conducir

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.

The AI Vision object property stack block with its parameter set to originX.#
([AIVision 1 v] objeto [origenX v])

Example

cuando empezó :: hat events
[Display if an object is to the left or the right.]
para siempre
Limpiar la fila [1] de la pantalla
Coloque el cursor en la fila [1] columna [1] en la pantalla
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <([AIVision 1 v] objeto [origenX v]) [math_less_than v] [160]> entonces
imprimir [To the left!] en la pantalla ▶
demás
imprimir [To the right!] en la pantalla ▶
fin
esperar [0.5] segundos

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.

The AI Vision object property stack block with its parameter set to originY.#
([AIVision 1 v] objeto [origenY v])

Example

cuando empezó :: hat events
[Display if an object is close or far from the robot.]
para siempre
Limpiar la fila [1] de la pantalla
Coloque el cursor en la fila [1] columna [1] en la pantalla
obtener [AI Classifications v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <([AIVision 1 v] objeto [origenY v]) [math_less_than v] [80]> entonces
imprimir [Far!] en la pantalla ▶
demás
imprimir [Close!] en la pantalla ▶
fin
esperar [0.5] segundos

tagID#

tagID returns the identification number of the detected AprilTag as an integer.

The AI Vision object property stack block with its parameter set to tagID.#
([AIVision 1 v] objeto [ID de etiqueta v])

Example

cuando empezó :: hat events
[Drive forward when AprilTag ID 0 is detected.]
para siempre
obtener [AprilTags v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <([AIVision 1 v] objeto [ID de etiqueta v]) [math_equal v] [0]> entonces
unidad [adelante v]
demás
deja de conducir
fin
esperar [0.5] segundos

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.

The AI Vision AI Classification is object Boolean block.#
<[AIVision1 v] object is [BlueBall v] ?>

Parameter

Description

object

Which object to compare the item to:

  • BlueBall
  • GreenBall
  • RedBall
  • BlueRing
  • GreenRing
  • RedRing
  • BlueCube
  • GreenCube
  • RedCube

Example

cuando empezó :: hat events
[Display if a Blue Cube is detected.]
para siempre
obtener [AI Classifications v] datos de [AIVision 1 v]
Limpiar la fila [1] de la pantalla
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <¿Existe [AIVision 1 v] objeto?> entonces
si <[AIVision1 v] object is [BlueCube v] ?> entonces
imprimir [Cube detected!] en la pantalla ▶
esperar [0.5] segundos

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.

The AI Vision detected AprilTag is Boolean block.#
<[AIVision1 v] object is AprilTag [1] ?>

Parameters

Description

AprilTag number

The number to compare against the detected AprilTag’s ID number.

Example:

cuando empezó :: hat events
[Report if AprilTag ID 3 is detected.]
para siempre
pantalla clara
Coloque el cursor en la fila [1] columna [1] en la pantalla
obtener [AprilTags v] datos de [AIVision 1 v]
si <¿Existe [AIVision 1 v] objeto?> entonces
si <[AIVision1 v] object is AprilTag [3] ?> entonces
imprimir [That is 3!] en la pantalla ▶
demás
imprimir [That isn't 3!] en la pantalla ▶
fin
fin
esperar [0.1] segundos