Robot-Specific Blocks#

Introduction#

The Hero Bot, Dex, includes two motor options, an AI Vision Sensor, an Optical Sensor, and a Game Positioning System (GPS) Sensor.

All standard VEXcode VR Blocks are available for use in the V5RC 25-26 Push Back Playground.

Below is a list of all available Robot-specific Blocks:

Drivetrain – Move and turn the robot.

  • Actions

    • drive — Moves the robot forward or reverse forever.

    • drive for — Moves the robot forward or reverse for a specific distance.

    • turn — Turns the robot left or right forever.

    • turn for — Turns the robot left or right for a specific number of degrees.

    • turn to heading — Turns the robot to face a specific heading.

    • turn to rotation — Turns the robot to a specific rotation.

    • stop driving — Stops the robot’s movement.

  • Settings

  • Values

Motion – Move and track the robot’s motors.

AI Vision – Capture and analyze objects using the AI Vision Sensor.

Sensing – Utilize the robot’s various sensors.

  • Optical

    • Optical found an object – Reports whether the sensor is detecting an object within range.

    • Optical detects color – Reports whether the Optical Sensor detects a specified color.

    • Optical brightness – Reports the brightness detected by the Optical Sensor.

    • Optical hue – Reports the hue detected by the Optical Sensor.

    • when Optical – Runs the attached stack of blocks when the Optical Sensor detects or loses an object.

  • GPS

    • GPS position – Returns the X or Y position from the GPS Sensor.

    • GPS heading – Returns the heading the robot is currently facing.

The examples on this page use the default Playground start position.

Drivetrain#

The drivetrain controls how the VR Robot drives and turns. The drivetrain can move forward or reverse, turn left or right, turn to headings, and track its rotation.

Actions#

drive#

The drive stack block moves the robot forward or reverse forever. The robot will continue to move until it is given another action, like turning or stopping.

  drive [forward v]

Parameters

Description

direction

The direction the robot moves: forward or reverse.

Example

  when started :: hat events
  [Drive forward, then stop.]
  drive [forward v]
  wait (2) seconds
  stop driving

drive for#

The drive for stack block moves the robot forward or reverse for a specific distance. The project will wait until the robot is done moving before the next block in the stack runs.

  drive [forward v] for (200) [mm v] ▶

Parameters

Description

direction

The direction the robot moves: forward or reverse.

distance

The distance the robot drives. This can be an integer or a decimal.

unit

The distance unit: mm (millimeters) or inches

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

  when started :: hat events
  [Drive forward.]
  drive [forward v] for (500) [mm v] ▶

turn#

The turn stack block turns the robot left or right forever. The robot will continue to turn until it is given another action, like driving or stopping.

  turn [right v]

Parameters

Description

direction

The direction the robot turns: left or right.

Example

  when started :: hat events
  [Turn right, then stop.]
  turn [right v]
  wait (2) seconds
  stop driving

turn for#

The turn for stack block turns the robot left or right for a specific number of degrees. The turn is relative to the current position of the robot. The project will wait until the robot is done turning before the next block in the stack runs.

  turn [right v] for (90) degrees ▶

Parameters

Description

direction

The direction the robot turns: left or right.

angle

The number of degrees the robot turns. This can be an integer or a decimal.

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

  when started :: hat events
  [Turn left, then turn around to the right.]
  turn [left v] for (90) degrees ▶
  turn [right v] for (180) degrees ▶

turn to heading#

A heading is the direction the robot is facing, measured in degrees. The turn to heading stack block turns the robot to face a specific heading from -359 to 359 degrees. The robot will turn the shortest direction to reach the target heading.

The starting heading is 0 degrees.

The project will wait until the robot is done turning before the next block in the stack runs.

  turn to heading (90) degrees ▶

Parameters

Description

heading

The heading the robot should face, from -359 to 359 degrees.

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

  when started :: hat events
  [Turn to face the cardinal directions.]
  turn to heading (90) degrees ▶
  wait (2) seconds
  turn to heading (180) degrees ▶
  wait (2) seconds
  turn to heading (270) degrees ▶
  wait (2) seconds
  turn to heading (0) degrees ▶
  wait (2) seconds

turn to rotation#

The turn to rotation stack block turns the robot to a specific rotation.

Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. Rotation can also be set using the set drive rotation block.

Rotation values are absolute. This means the direction of the turn depends on the robot’s current rotation. Turning right increases the rotation, and turning left decreases the rotation.

For example, if the robot starts at 0 degrees and you turn to a rotation of 720 degrees, it will turn right twice. If you then turn to a rotation of 360 degrees, it will turn left once, because 360 is less than 720.

The project will wait until the robot is done turning before the next block in the stack runs.

  turn to rotation (90) degrees ▶

Parameters

Description

rotation

The rotation value, in degrees, that the robot will turn to. This can be an integer or a decimal.

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

  when started :: hat events
  [Turn left, then spin in a circle clockwise and face right.]
  turn to rotation (-90) degrees ▶
  wait (2) seconds
  turn to rotation (450) degrees ▶

stop driving#

The stop driving stack block stops the robot’s movement.

  stop driving

Parameters

Description

This block has no parameters.

Example

  when started :: hat events
  [Drive forward, then stop.]
  drive [forward v]
  wait [4] seconds
  stop driving

Settings#

set drive velocity#

The set drive velocity stack block tells the robot how fast to drive. A higher percentage makes the robot drive faster and a lower percentage makes the robot drive slower.

Every project begins with the robot driving at 50% velocity by default.

Note: A higher velocity makes the robot drive faster, but it may be less precise. A lower velocity makes the robot drive slower, but it can be more precise.

  set drive velocity to (50) [% v]

Parameters

Description

velocity

The velocity to drive with from 0% to 100%.

unit

The velocity unit: %

Example

  when started :: hat events
  [Drive forward at the default velocity.]
  drive [forward v] for (100) [mm v] ▶
  wait (1) seconds
  [Move slower.]
  set drive velocity to (20) [% v]
  drive [forward v] for (100) [mm v] ▶
  wait (1) seconds
  [Move faster.]
  set drive velocity to (100) [% v]
  drive [forward v] for (100) [mm v] ▶
  wait (1) seconds

set turn velocity#

The set turn velocity stack block tells the robot how fast to turn. A higher percentage makes the robot turn faster and a lower percentage makes the robot turn slower.

Every project begins with the robot turning at 50% velocity by default.

Note: A higher velocity makes the robot turn faster, but it may be less precise. A lower velocity makes the robot turn slower, but it can be more precise.

  set turn velocity to (50) [% v]

Parameters

Description

velocity

The velocity to turn with from 0% to 100%.

unit

The velocity unit: %

Example

  when started :: hat events
  [Turn at default velocity.]
  turn [right v] for (100) degrees ▶
  wait (1) seconds
  [Turn slower.]
  set turn velocity to (20)%
  turn [right v] for (100) degrees ▶
  wait (1) seconds
  [Turn faster.]
  set turn velocity to (100)%
  turn [right v] for (100) degrees ▶
  wait (1) seconds

set drive heading#

A heading is the direction the robot is facing, measured in degrees. The set drive heading stack block changes the robot’s current heading to a new heading value.

For example, if the robot has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the robot can turn to other positions based on that new heading.

  set drive heading to (0) degrees

Parameters

Description

heading

The heading value, in degrees, to set for the robot.

Example

  when started :: hat events
  [Turn to the left.]
  set drive heading to (90) degrees
  turn to heading (0) degrees ▶

set drive rotation#

Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. The set drive rotation stack block changes the robot’s current rotation to a new value.

For example, if the robot has made two full turns to the right, its rotation value will be 720 degrees. Setting the rotation to 0 degrees will reset that rotation from 720 to 0 degrees. Then the robot can turn to rotations based on that new value.

  set drive rotation to (0) degrees

Parameters

Description

rotation

The rotation value, in degrees, to set for the robot. This can be an integer or a decimal.

Example

  when started :: hat events
  [Spin counterclockwise two times.]
  set drive rotation to (720) degrees
  turn to rotation (0) degrees ▶

set drive timeout#

The set drive timeout stack block sets how many seconds the robot will try to finish a movement. If the robot cannot finish in that time it will stop trying and move on to the next block in the stack. This keeps the robot from getting stuck on a movement.

  set drive timeout to (1) seconds

Parameters

Description

time

The number of seconds the robot can try to finish a movement. This can be a whole number or a decimal.

Example

When started, limits drive time to 1 second and then turns 90 degrees.#
  when started :: hat events
  [Drive forward for 1 second, then turn.]
  set drive timeout to (1) seconds
  drive [forward v] for (25) [inches v] ▶
  turn [right v] for (90) degrees ▶

Values#

drive is done#

The drive is done Boolean block reports whether the robot is finished moving. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is finished moving.

  • False — The robot is still moving.

This block works together with drivetrain blocks that have the and don’t wait parameter.

    <drive is done?>

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Start spinning when the drive is complete.]
    drive [forward v] for (200) [mm v] ◀ and don't wait
    wait until <drive is done?>
    turn [right v] for (360) degrees ▶

drive is moving#

The drive is moving Boolean block reports whether the robot is moving. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is moving.

  • False — The robot is not moving.

This block works together with drivetrain blocks that have the and don’t wait parameter.

    <drive is moving?>

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Print that the robot is moving while it is still driving.]
    drive [forward v] for (200) [mm v] ◀ and don't wait
    while <drive is moving?>
    print [Still Moving...] ▶
    wait (0.1) seconds
    clear screen
    end
    print [Done!] ▶

drive heading#

A heading is the direction the robot is facing, measured in degrees. The drive heading reporter block reports that heading from 0 to 359.99 degrees.

The robot’s starting heading is 0 degrees.

    (drive heading in degrees)

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Display the heading after turning.]
    turn [right v] for (450) degrees ▶
    print (drive heading in degrees) on screen ◀ and set cursor to next row

drive rotation#

Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. The drive rotation reporter block reports the robot’s current rotation.

Turning right increases the rotation, and turning left decreases the rotation. For example, making two full turns to the right will report a rotation of 720 degrees.

    (drive rotation in degrees)

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Display the rotation after turning.]
    turn [right v] for (450) degrees ▶
    print (drive rotation in degrees) on screen ◀ and set cursor to next row

drive velocity#

The drive velocity reporter block reports how fast the robot is driving.

    (drive velocity in [% v])

Parameters

Description

unit

The velocity unit: %

Example

    when started :: hat events
    [Display the velocity after driving.]
    drive [forward v] for (200) [mm v] ▶
    print (drive velocity in [% v]) on screen ◀ and set cursor to next row

Motion#

Dex uses the intake motor to pull Blocks into the robot. The conveyor motor moves Blocks from the intake to the top of the robot so they can be pushed into a goal.

Each motor has its own direction options. The direction names describe how that motor moves on Dex.

Actions#

spin motor#

The spin motor stack block spins a motor in one of two directions forever. The motor will continue to spin until it is given another action, like spinning in a different direction or stopping.

    spin [ConveyorMotor v] [up v]

Parameters

Description

motor

The motor to spin: ConveyorMotor or IntakeMotor.

direction

The direction the motor spins:

  • ConveyorMotorup or down
  • IntakeMotorintake or outtake

Example

    when started
    [Pick up a second Block.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [350] [mm v] ▶

spin motor for#

The spin motor for stack block spins a motor for a specific distance. The spin is relative to the current position of the motor. The project will wait until the motor is done spinning before the next block in the stack runs.

    spin [ConveyorMotor v] [up v] for (90) [degrees v] ▶

Parameters

Description

motor

The motor to spin: ConveyorMotor or IntakeMotor.

direction

The direction the motor spins:

  • ConveyorMotorup or down
  • IntakeMotorintake or outtake

distance

The distance the motor spins. Degrees use integers. Turns can use integers or decimals.

unit

The distance unit: degrees or turns.

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

    when started
    [Pick up a second Block.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [350] [mm v] ▶

spin motor to position#

The spin motor to position stack block spins a motor to a specific position.

A motor’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. At the beginning of a project, the motor position is set to 0 degrees. The motor position can also be set using the set motor position block.

Position values are absolute. This means the direction of the spin depends on the motor’s current position.

For example, if the motor starts at 0 degrees and spins to a position of 720 degrees, it will spin forward two turns. If it then spins to a position of 360 degrees, it will spin reverse one turn, because 360 is less than 720.

    spin [ConveyorMotor v] to position (90) [degrees v] ▶

Parameters

Description

motor

The motor to spin: ConveyorMotor or IntakeMotor.

position

The position value the motor will spin to. Degrees use integers. Turns can use integers or decimals.

unit

The position unit: degrees or turns.

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

    when started
    [Pick up a second Block.]
    spin [ConveyorMotor v] to position [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [350] [mm v] ▶

stop motor#

The stop motor stack block stops the selected motor.

    stop [ConveyorMotor v]

Parameters

Description

motor

The motor to stop: ConveyorMotor or IntakeMotor.

Example

    when started
    [Pick up a second Block.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [350] [mm v] ▶
    stop [IntakeMotor v]

Settings#

set motor velocity#

The set motor velocity stack block tells a motor how fast to spin. A higher percentage makes the motor spin faster and a lower percentage makes the motor spin slower.

Every project begins with each motor spinning at 50% velocity by default.

Note: A higher velocity makes the motor spin faster, but it may be less precise. A lower velocity makes the motor spin slower, but it can be more precise.

    set [ConveyorMotor v] velocity to [50] [% v]

Parameters

Description

motor

The motor to set the velocity of: ConveyorMotor or IntakeMotor.

velocity

The speed the motor will spin at. Percent uses whole numbers from 0% to 100%.

unit

The velocity unit: %.

Example

    when started
    [Pick up a second Block.]
    set [ConveyorMotor v] velocity to [100] [% v]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [400] [mm v] ▶

set motor timeout#

The set motor timeout stack block sets how much time a motor will try to finish a movement. If the motor cannot finish in that time, it will stop trying and move on to the next block in the stack. This keeps the motor from getting stuck on a movement.

    set [ConveyorMotor v] timeout to [1] seconds

Parameters

Description

motor

The motor to set the timeout of: ConveyorMotor or IntakeMotor.

time

The number of seconds the motor can try to finish a movement. This can be a whole number or decimal.

Example

    when started
    [Pick up a second Block.]
    set [ConveyorMotor v] timeout to [0.5] seconds
    spin [ConveyorMotor v] to position [1000] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [400] [mm v] ▶

Position#

motor position#

A motor’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. The motor position reporter block reports the motor’s current position.

At the beginning of a project, the motor position is set to 0 degrees. If the motor spins one full turn forward, the position will be 360 degrees or 1 turn. If the motor spins the other direction, the position will be negative.

    ([ConveyorMotor v] position in [degrees v])

Parameters

Description

motor

The motor to report the position of: ConveyorMotor or IntakeMotor.

unit

The unit to report the motor position in: degrees or turns.

Example

    when started
    [Pick up a second Block.]
    while <([ConveyorMotor v] position in [degrees v]) [math_less_than v] [200]>
    spin [ConveyorMotor v] [up v]
    end
    stop [ConveyorMotor v]
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [400] [mm v] ▶

set motor position#

A motor’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. The set motor position stack block changes the motor’s current position to a new value.

For example, if a motor has spun to 180 degrees, setting the position to 0 degrees will reset that position from 180 to 0 degrees. Then the motor can spin to positions based on that new value.

    set [ConveyorMotor v] position to (0) [degrees v]

Parameters

Description

motor

The motor to set the position of: ConveyorMotor or IntakeMotor.

position

The position value the motor will spin to. Degrees use integers. Turns can use integers or decimals.

unit

The position unit: degrees or turns.

Example

    when started
    [Pick up a second Block.]
    set [ConveyorMotor v] position to [-200] [degrees v]
    spin [ConveyorMotor v] to position [0] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [400] [mm v] ▶

Values#

motor is done#

The motor is done Boolean block reports whether the motor is finished moving. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor is finished moving.

  • False — The motor is still moving.

This block works together with the following Motion blocks that have the and don’t wait parameter: spin motor for and spin motor to position.

    <[ConveyorMotor v] is done?>

Parameters

Description

motor

The motor to report whether it is finished moving: ConveyorMotor or IntakeMotor.

Example

    when started
    [Pick up a second Block.]
    spin [ConveyorMotor v] to position [300] [degrees v] ◀ and don't wait
    drive [forward v]
    spin [IntakeMotor v] [intake v]
    wait until <[ConveyorMotor v] is done?>
    stop driving
    stop [IntakeMotor v]

motor is spinning#

The motor is spinning Boolean block reports whether the motor is spinning. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor is spinning.

  • False — The motor is not spinning.

This block works together with the following Motion blocks that have the and don’t wait parameter: spin motor for and spin motor to position.

    <[ConveyorMotor v] is spinning?>

Parameters

Description

motor

The motor to report whether it is spinning: ConveyorMotor or IntakeMotor.

Example

    when started
    [Pick up a second Block.]
    spin [ConveyorMotor v] to position [300] [degrees v] ◀ and don't wait
    wait [0.1] seconds
    while <[ConveyorMotor v] is spinning?>
    drive [forward v] for [200] [mm v] ▶
    spin [IntakeMotor v] [intake v]

motor velocity#

The motor velocity reporter block reports how fast the motor is spinning, as a percentage from -100% to 100%.

    ([ConveyorMotor v] velocity in [% v] :: custom-motion)

Parameters

Description

motor

The motor to report the velocity of: ConveyorMotor or IntakeMotor.

unit

The unit to report the motor velocity in: %.

Example

    when started
    [Pick up a second Block.]
    set [ConveyorMotor v] velocity to [100] [% v]
    spin [ConveyorMotor v] to position [300] [degrees v] ◀ and don't wait
    wait [0.2] seconds
    print ([ConveyorMotor v] velocity in [% v] :: custom-motion) ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [400] [mm v] ▶

AI Vision#

Actions#

get object data#

The get object data block filters data from the AI Vision Sensor frame. The AI Vision Sensor can detect Game Elements on the field.

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.#
  get [AI Classifications v] data from AI Vision

Parameter

Description

signature

Filters the dataset to only include data of the given signature. The only available signature is:

  • AI Classifications – Detects Red and Blue Blocks.

Example

    when started
    [If an object is detected, pick it up.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    spin [IntakeMotor v] [intake v]
    drive [forward v]
    wait until <[Bumper v] pressed?>
    stop driving
    break

Settings#

set object item#

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

The Set AI Vision object item stack block.#
  set [AIVision v] object item to [1]

Parameters

Description

item

The number of the item in the dataset to use.

Example

    when started
    [Display what object is farthest away.]
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    set [AIVision v] object item to ([AIVision v] object count)
    clear all rows
    if <[AIVision v] object is [BlueBlock v]?> then
    print [Blue Block farthest away.] ▶
    else
    print [Red Block farthest away.] ▶

Values#

object exists#

The 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.#
  <[AIVision v] object exists?>

Parameters

Description

This block has no parameters.

Example

    when started
    [If an an object is detected, pick it up.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    spin [IntakeMotor v] [intake v]
    drive [forward v]
    wait until <[Bumper v] pressed?>
    stop driving
    break

AI Classification 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.#
  <[AIVision v] object is [BlueBlock v]?>

Parameter

Description

object

Which object to compare the item to:

  • BlueBlock
  • RedBlock

Example

    when started
    [Display what object is farthest away.]
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    set [AIVision v] object item to ([AIVision v] object count)
    clear all rows
    if <[AIVision v] object is [BlueBlock v]?> then
    print [Blue Block farthest away.] ▶
    else
    print [Red Block farthest away.] ▶

object count#

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

The Set AI Vision object item stack block.#
  ([AIVision] object count)

Parameters

Description

This block has no parameters.

Example

    when started
    [Display what object is farthest away.]
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    set [AIVision v] object item to ([AIVision v] object count)
    clear all rows
    if <[AIVision v] object is [BlueBlock v]?> then
    print [Blue Block farthest away.] ▶
    else
    print [Red Block farthest away.] ▶

object property#

There are six 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 v] object [width 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 v] object [width v])

Example

    when started
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <([AIVision v] object [width v]) [math_greater_than v] [65]> then
    stop driving
    break
    else
    spin [IntakeMotor v] [intake v]
    drive [forward v]
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 v] object [height v])

Example

    when started
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <([AIVision v] object [height v]) [math_greater_than v] [55]> then
    stop driving
    break
    else
    spin [IntakeMotor v] [intake v]
    drive [forward v]
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 v] object [centerX v])

Example

  when started
  [Pick up a Block from the top left group.]
  spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
  turn [left v] for [80] degrees ▶
  drive [forward v] for [100] [mm v] ▶
  set turn velocity to [20] [% v]
  turn [left v]
  forever
  get [AI Classifications v] data from [AIVision v]
  if <[AIVision v] object exists?> then
  if <<[140] [math_less_than v] ([AIVision v] object [centerX v])> and <([AIVision v] object [centerX v]) [math_less_than v] [180]>> then
  spin [IntakeMotor v] [intake v]
  drive [forward v]
  wait until <[Bumper v] pressed?>
  stop driving
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 v] object [centerY v])

Example

    when started
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <([AIVision v] object [centerY v]) [math_greater_than v] [140]> then
    stop driving
    break
    else
    spin [IntakeMotor v] [intake v]
    drive [forward 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.

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

Example

  when started
  [Pick up a Block from the top left group.]
  spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
  turn [left v] for [80] degrees ▶
  drive [forward v] for [100] [mm v] ▶
  set turn velocity to [20] [% v]
  turn [left v]
  forever
  get [AI Classifications v] data from [AIVision v]
  if <[AIVision v] object exists?> then
  if <<[100] [math_less_than v] ([AIVision v] object [originX v])> and <([AIVision v] object [originX v]) [math_less_than v] [140]>> then
  spin [IntakeMotor v] [intake v]
  drive [forward v]
  wait until <[Bumper v] pressed?>
  stop driving
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 v] object [originY v])

Example

    when started
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <[120] [math_less_than v] ([AIVision v] object [originY v])> then
    stop driving
    break
    else
    spin [IntakeMotor v] [intake v]
    drive [forward v]
    end
    end

Sensing#

Optical#

Optical found an object#

The Optical found an object Boolean block reports whether or not the Optical Sensor detects an object within range.

  • True — The Optical Sensor detects an object.

  • False — The Optical Sensor does not detect an object.

    <[Optical v] found an object?>

Parameters

Description

This block has no parameters.

Example

    when started
    [Move the preloaded Block to the top of the Conveyor.]
    spin [ConveyorMotor v] [up v]
    wait until <[Optical v] found an object?>
    stop [ConveyorMotor v]

Optical detects color#

The Optical detects color Boolean block reports whether the Optical Sensor detects a specified color, based on the detected hue value.

  • True – The sensor detects the specified color.

  • False – The sensor does not detect the specified color.

    <[Optical v] detects [red v]?>

Parameters

Description

color

Which color to look for:

  • red – A detected hue value between 340° - 20°.
  • green – A detected hue value between 80° - 140°.
  • blue – A detected hue value between 200° - 240°.
  • yellow – A detected hue value between 40° - 60°.
  • orange – A detected hue value between 20° - 40°.
  • purple – A detected hue value between 240° - 280°.
  • cyan – A detected hue value between 140° - 200°.

Example

    when started
    [Pick up and move a Blue Block to the top of the Conveyor.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [360] [mm v] ▶
    spin [ConveyorMotor v] [up v]
    wait until <[Optical v] detects [blue v]?>
    stop [ConveyorMotor v]

Optical brightness#

The Optical brightness reporter block reports how much light is reflected back to the Optical Sensor, as a percentage from 0% to 100%.

    ([Optical v] brightness in %)

Parameters

Description

This block has no parameters.

Example

    when started
    [Move the preloaded Block to the top of the Conveyor.]
    spin [ConveyorMotor v] [up v]
    wait until <[0] [math_less_than v] ([Optical v] brightness in %)>
    stop [ConveyorMotor v]

Optical hue#

The Optical hue reporter block reports the hue detected by the Optical Sensor as a number from 0 to 359 degrees.

Hue is a way to describe color using numbers around a color wheel.

A circular color wheel displaying a full spectrum of hues labeled with degree values around the perimeter, increasing in 30-degree increments from 0° at the top to 360°.

    ([Optical v] hue in degrees)

Parameters

Description

This block has no parameters.

Example

    when started
    [Pick up and move a Blue Block to the top of the Conveyor.]
    spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [360] [mm v] ▶
    spin [ConveyorMotor v] [up v]
    wait until <[240] [math_equal v] ([Optical v] hue in degrees)>
    stop [ConveyorMotor v]

when Optical#

The when Optical hat block runs the attached stack of blocks whenever the Optical Sensor detects or loses an object.

    when [Optical v] [detects v] an object

Parameters

Description

state

When the attached stack of blocks will run: detects runs when an undetected object is detected, while loses runs when a detected object is now no longer detected.

GPS#

GPS position#

The GPS position block returns the positional offset of the robot’s turning reference point from the center of a field with the GPS (Game Positioning System™) Sensor.

    ([GPS v] position [X v] in [mm v])

Parameters

Description

axis

Which axis to report:

  • X
  • Y

units

The unit to represent the position: mm or inches

Example

    when started
    [Pick up a second Block.]
    spin [ConveyorMotor v] to position [200] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v]
    wait until <[-450] [math_greater_than v] ([GPS v] position [Y v] in [mm v])>
    stop driving

GPS heading#

The GPS heading block returns the heading that the robot is currently facing based on the GPS (Game Positioning System™) Sensor’s readings from the VEX GPS Field Code from 0.00 to 359.99 degrees.

    ([GPS v] heading in degrees)

Parameters

Description

This block has no parameters.

Example

    when started
    [Score the preloaded Block into a Center Goal.]
    turn [left v]
    wait until <[40] [math_greater_than v] ([GPS v] heading in degrees)>
    drive [forward v] for [1000] [mm v] ▶
    turn [right v]
    wait until <([GPS v] heading in degrees) [math_greater_than v] [310]>
    drive [reverse v] for [200] [mm v] ▶
    spin [ConveyorMotor v] [up v]