Robot Specific Blocks#

Introduction#

The V5RC 25-26 Push Back Playground features blocks exclusive to the build designed for this Playground, including two motor options, AI Vision Sensor, Optical Sensor, and Game Positioning System (GPS).

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

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

Motion – Move and track the robot’s motors.

  • Actions

    • spin – Spins the selected motor or motor group indefinitely.

    • spin for – Spins a motor or group for a specific distance in degrees or turns.

    • spin to position – Spins a motor or motor group to a set position.

    • stop motor – Stops a specific motor or motor group from spinning.

  • Settings

    • set motor velocity – Sets the speed of a motor or motor group as a percentage.

    • set motor timeout – Limits how long a motor block waits before giving up if movement is blocked.

  • Position

    • motor position – Returns the motor’s current rotational position in degrees or turns.

    • set motor position – Sets the encoder value of a motor or motor group.

  • Values

    • motor is done? – Returns a Boolean indicating whether the motor is no longer spinning.

    • motor is spinning? – Returns a Boolean indicating whether the motor is currently spinning.

    • motor velocity – Returns the motor’s current velocity in %.

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

Sensing – Utilize the robot’s various sensors.

The examples in this project use the default Playground start position.

Motion#

Actions#

spin#

The spin block spins a selected motor or motor group in a specified direction using the current motor velocity.

    spin [ConveyorMotor v] [up v]

Parameters

Description

motor

The motor group to spin:

  • ConveyorMotor
  • IntakeMotor

direction

The direction to spin:

    ConveyorMotor
    • up
    • down
    IntakeMotor
    • intake
    • outtake

Example

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

spin for#

The spin for block spins a selected motor or motor group for a specific amount of rotation using the current motor velocity, measured in degrees or turns.

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

Parameters

Description

motor

The motor group to spin:

  • ConveyorMotor
  • IntakeMotor

direction

The direction to spin:

    ConveyorMotor
    • up
    • down
    IntakeMotor
    • intake
    • outtake

distance

The rotation amount, as an integer or decimal.

unit

The measurement unit, which can be one of the following:

  • degrees
  • turns

expanding arrow

By default, this is a waiting block, so the drivetrain will finish moving before running the next block. To make the drivetrain start moving and immediately run the next block right away, expand the block to say and don’t wait.

Example

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

spin to position#

The spin to position block spins a motor or motor group to a specific absolute position using the current motor velocity and motor position.

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

Parameters

Description

motor

The motor group to spin:

  • ConveyorMotor
  • IntakeMotor

position

The target position to spin the motor group to.

unit

The measurement unit, which can be one of the following:

  • degrees
  • turns

expanding arrow

By default, this is a waiting block, so the drivetrain will finish moving before running the next block. To make the drivetrain start moving and immediately run the next block right away, expand the block to say and don’t wait.

Example

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

stop motor#

The stop motor block immediately stops the selected motor or motor group.

    stop [ConveyorMotor v]

Parameters

Description

motor

The motor group to stop:

  • ConveyorMotor
  • IntakeMotor

Example

    when started :: hat events
    [Pick up a second Block.]
    spin [ConveyorMotor v] [up v] for [150] [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 block sets the default spinning speed of a motor or motor group as a percentage for all subsequent Motor blocks in the project.

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

Parameters

Description

motor

The motor group to set the velocity of:

  • ConveyorMotor
  • IntakeMotor

velocity

Sets the default movement velocity from 0 to 100 as a percent.

unit

The unit that represents the velocity:

  • %

Example

    when started :: hat events
    [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 block sets a time limit for how long a Motor block will wait to reach its target. If the robot cannot complete the movement within the set time, it will stop automatically and continue with the next block.

Note: The Motor’s time limit is used to prevent Motor blocks that do not reach their target position from stopping the execution of other blocks in the stack.

    set [ConveyorMotor v] timeout to [1] seconds

Parameters

Description

motor

The motor group to set the timeout of:

  • ConveyorMotor
  • IntakeMotor

time

The maximum number of seconds a Motor block will run before stopping and moving to the next block.

Example

    when started :: hat events
    [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#

The motor position block returns the total distance the selected motor or motor group has rotated.

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

Parameters

Description

motor

The motor group to return the position of:

  • ConveyorMotor
  • IntakeMotor

unit

The unit of measurement, which can be one of the following:

  • degrees
  • turns

Example

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

set motor position#

The set motor position block sets a specific position value to a motor or motor group, which updates the encoder reading.

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

Parameters

Description

motor

The motor group to set the position of:

  • ConveyorMotor
  • IntakeMotor

position

The encoder position value to set.

unit

The measurement unit, which can be one of the following:

  • degrees
  • turns

Example

    when started :: hat events
    [Pick up a second Block.]
    set [ConveyorMotor v] position to [-150] [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? block returns a Boolean indicating whether the motor or motor group is not spinning.

  • True – The motor is not spinning.

  • False – The motor is spinning.

    <[ConveyorMotor v] is done?>

Parameters

Description

motor

The motor group to check if it isn’t spinning:

  • ConveyorMotor
  • IntakeMotor

Example

    when started :: hat events
    [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? block returns a Boolean indicating whether the motor is spinning.

  • True – The motor is spinning.

  • False – The motor is not spinning.

    <[ConveyorMotor v] is spinning?>

Parameters

Description

motor

The motor group to check if it is spinning:

  • ConveyorMotor
  • IntakeMotor

Example

    when started :: hat events
    [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 block returns the current rotational speed of the motor or motor group in a range from -100% to 100%.

    ([ConveyorMotor v] velocity in [% v])

Parameters

Description

motor

The motor group to return the velocity of:

  • ConveyorMotor
  • IntakeMotor

unit

The unit that represents the velocity:

  • %

Example

    when started :: hat events
    [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]) ▶
    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 :: hat events
    [If an object is detected, pick it up.]
    spin [ConveyorMotor v] [up v] for [150] [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 :: hat events
    [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.#
  <AI Vision object exists?>

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [If an an object is detected, pick it up.]
    spin [ConveyorMotor v] [up v] for [150] [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] object is [BlueBlock v] ?>

Parameter

Description

object

Which object to compare the item to:

  • sports ball
  • orange barrel
  • blue barrel
  • AIM robot

Example

    when started :: hat events
    [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 :: hat events
    [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 :: hat events
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [150] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <([AIVision v] object [width 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 :: hat events
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [150] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <([AIVision v] object [height 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 :: hat events
  [Pick up a Block from the top left group.]
  spin [ConveyorMotor v] [up v] for [150] [degrees v] ▶
  turn [left v] for [80] [degrees v] ▶
  drive [forward v] for [100] [mm v] ▶
  set turn velocity to [20] %
  turn [left v]
  forever
  get [AI Classifications v] data from [AIVision v]
  if <[AIVision v] object exists?> then
  if <<[140] < ([AIVision v] object [centerX v])> and <([AIVision v] object [centerX 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 :: hat events
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [150] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <([AIVision v] object [centerY 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 :: hat events
  [Pick up a Block from the top left group.]
  spin [ConveyorMotor v] [up v] for [150] [degrees v] ▶
  turn [left v] for [80] [degrees v] ▶
  drive [forward v] for [100] [mm v] ▶
  set turn velocity to [20] %
  turn [left v]
  forever
  get [AI Classifications v] data from [AIVision v]
  if <[AIVision v] object exists?> then
  if <<[100] < ([AIVision v] object [originX v])> and <([AIVision v] object [originX 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 :: hat events
    [If an an object is detected, approach and pick it up.]
    spin [ConveyorMotor v] [up v] for [150] [degrees v] ▶
    forever
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
    if <[120] < ([AIVision v] object [originY v])>
    stop driving
    break
    else
    spin [IntakeMotor v] [intake v]
    drive [forward v]

Sensing#

Optical#

Optical found object?#

The Optical found object? block returns a Boolean indicating whether the Optical Sensor has detected an object.

  • True – The Optical Sensor has detected an object.

  • False – The Optical Sensor has not detected an object.

    <[Optical v] found an object?>

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [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? block returns a Boolean indicating whether the Optical Sensor has detected a specific color.

  • True – The Optical Sensor has detected the specified color.

  • False – The Optical Sensor has not detected the specified color.

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

Parameters

Description

color

Which color to check for:

  • red
  • green
  • blue
  • yellow
  • orange
  • purple

Example

    when started :: hat events
    [Pick up and move a Blue Block to the top of the Conveyor.]
    spin [ConveyorMotor v] [up v] for [150] [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 block returns the amount of light detected by the Optical Sensor in a range from 0% to 100%.

    ([Optical v] brightness in %)

Parameters

Description

This block has no parameters.

Example

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

Optical hue#

The Optical hue block returns the hue value of the color detected by the Optical Sensor.

Hue values range from 0 to 359 degrees, corresponding to positions on the color wheel shown below.

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 :: hat events
    [Pick up and move a Blue Block to the top of the Conveyor.]
    spin [ConveyorMotor v] [up v] for [150] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v] for [360] [mm v] ▶
    spin [ConveyorMotor v] [up v]
    wait until <[240] = ([Optical v] hue in degrees)>
    stop [ConveyorMotor v]

when Optical#

The when Optical block runs its stack when the Optical Sensor detects or loses an object. You can have multiple when Optical blocks to run multiple stacks of blocks at once.

    when [Optical v] [detects v] an object :: hat events

Parameters

Description

action

Which action to trigger the hat block:

  • detects
  • loses

Example

Example coming soon!

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 acis to report:

  • X
  • Y

units

The unit to represent the position:

  • mm
  • inches

Example

    when started :: hat events
    [Pick up a second Block.]
    spin [ConveyorMotor v] to position [150] [degrees v] ▶
    spin [IntakeMotor v] [intake v]
    drive [forward v]
    wait until <[-450] > ([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 :: hat events
    [Score the preloaded Block into a Center Goal.]
    turn [left v]
    wait until <[40] > ([GPS v] heading in degrees)>
    drive [forward v] for [1000] [mm v] ▶
    turn [right v]
    wait until <([GPS v] heading in degrees) > [310]>
    drive [reverse v] for [200] [mm v] ▶
    spin [ConveyorMotor v] [up v]