Robot-Specific Blocks#

Introduction#

The V5RC 24-25 High Stakes Playground features blocks exclusive to the build designed for this Playground, including two motor options, AI Vision Sensor, Optical Sensor, Rotation Sensor, and 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 Playground-specific Blocks:

Motion – Move and track the robot’s motors.

  • Actions

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

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

    • spin motor 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 on this page use the default Playground start position.

Motion#

Actions#

spin motor#

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

    spin [ArmMotor v] [up v]

Parameters

Description

motor

The motor group to spin:

  • ArmMotor
  • PusherMotor

direction

The direction to spin:

  • ArmMotor
    • up
    • down
  • PusherMotor
    • lower
    • raiser

Example

    when started
    [Lift the Arm before moving to a Mobile Goal.]
    spin [ArmMotor v] [up v]
    wait (1) seconds
    stop [ArmMotor v]

spin motor for#

The spin motor 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 [ArmMotor v] [up v] for (90) [degrees v] ▶

Parameters

Description

motor

The motor group to spin:

  • ArmMotor
  • PusherMotor

direction

The direction to spin:

  • ArmMotor
    • up
    • down
  • PusherMotor
    • lower
    • raise

distance

The rotation amount, as an integer or decimal.

unit

The unit of measurement:

  • degrees
  • turns

expanding arrow

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

Example

    when started
    [Lift the Arm.]
    spin [ArmMotor v] [up v] for [200] [degrees v] ▶

spin motor to position#

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

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

Parameters

Description

motor

The motor group to spin:

  • ArmMotor
  • PusherMotor

position

The target position to spin to.

unit

The unit of measurement:

  • degrees
  • turns

expanding arrow

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

Example

    when started
    [Lift the Arm.]
    spin [ArmMotor v] to position [350] [degrees v] ▶

stop motor#

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

    stop [ArmMotor v]

Parameters

Description

motor

The motor group to stop:

  • ArmMotor
  • PusherMotor

Example

    when started
    spin [ArmMotor v] [up v]
    wait (1) seconds
    stop [ArmMotor 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 [ArmMotor v] velocity to [50] [% v]

Parameters

Description

motor

The motor group to set:

  • ArmMotor
  • PusherMotor

velocity

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

unit

The unit that represents the velocity:

  • %

Example

    when started
    set [ArmMotor v] velocity to [100] [% v]
    spin [ArmMotor v] [up v] for [200] [degrees 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 [ArmMotor v] timeout to [1] seconds

Parameters

Description

motor

The motor group to set:

  • ArmMotor
  • PusherMotor

time

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

Example

    when started
    set [ArmMotor v] timeout to [1] seconds
    spin [ArmMotor v] [up v] for [5] [turns v] ▶

Position#

motor position#

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

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

Parameters

Description

motor

The motor group to return the position of:

  • ArmMotor
  • PusherMotor

unit

The unit of measurement:

  • degrees
  • turns

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 [ArmMotor v] position to (0) [degrees v]

Parameters

Description

motor

The motor group to set the position of:

  • ArmMotor
  • PusherMotor

position

The encoder position value to set.

unit

The unit of measurement:

  • degrees
  • turns

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.

    <[ArmMotor v] is done?>

Parameters

Description

motor

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

  • ArmMotor
  • PusherMotor

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.

    <[ArmMotor v] is spinning?>

Parameters

Description

motor

The motor group to check if it is spinning:

  • ArmMotor
  • PusherMotor

motor velocity#

The motor velocity block returns the current rotational speed of the motor or motor group in a range from -100% to 100%.

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

Parameters

Description

motor

The motor group to return the velocity of:

  • ArmMotor
  • PusherMotor

unit

The unit that represents the velocity:

  • %

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 [AIVision v]

Parameter

Description

signature

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

  • AI Classifications – Detects Mobile Goals, Red Rings, and Blue Rings

Example

    when started
    [Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
    spin [ArmMotor v] [up v] for [270] [degrees v] ▶
    get [AI Classifications v] data from [AIVision v]
    [Check if any AI Classifications were detected in the last snapshot.]
    if <[AIVision v] object exists?> then
    [Only if an AI Classification is detected, then print data from the largest AI Classification.]
    print [Largest object's width:] ▶
    print ([AIVision v] object [width v]) ◀ and set cursor to next row
    end

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
    [Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
    spin [ArmMotor v] [up v] for [270] [degrees v] ▶
    get [AI Classifications v] data from [AIVision v]
    [Check if any AI Classifications were detected in the last snapshot.]
    if <[AIVision v] object exists?> then
    [If any AI Classification is detected, check if any of them are a Mobile Goal.]
    if <[AIVision v] AI Classification is [MobileGoal v]?> then
    print [Mobile Goal is detected.] ▶
    else
    print [Mobile Goal is not detected.] ▶
    end
    end

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
    [Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
    spin [ArmMotor v] [up v] for [270] [degrees v] ▶
    get [AI Classifications v] data from [AIVision v]
    [Check if any AI Classifications were detected in the last snapshot.]
    if <[AIVision v] object exists?> then
    print ([AIVision v] object count) ◀ and set cursor to next row
    end

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 [MobileGoal v]?>

Parameter

Description

object

Which object to compare the item to:

  • MobileGoal
  • RedRing
  • BlueRing

Example

    when started
    [Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
    spin [ArmMotor v] [up v] for [270] [degrees v] ▶
    get [AI Classifications v] data from [AIVision v]
    [Check if any AI Classifications were detected in the last snapshot.]
    if <[AIVision v] object exists?> then
    [If any AI Classification is detected, check if any of them are a Mobile Goal.]
    if <[AIVision v] AI Classification is [MobileGoal v]?> then
    print [Mobile Goal is detected.] ▶
    else
    print [Mobile Goal is not detected.] ▶
    end
    end

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
    [Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
    spin [ArmMotor v] [up v] for [270] [degrees v] ▶
    get [AI Classifications v] data from [AIVision v]
    [Check if any AI Classifications were detected in the last snapshot.]
    if <[AIVision v] object exists?> then
    print ([AIVision v] object count) ◀ and set cursor to next row
    end

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
    [Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
    spin [ArmMotor v] [up v] for [270] [degrees v] ▶
    get [AI Classifications v] data from [AIVision v]
    [Check if any AI Classifications were detected in the last snapshot.]
    if <[AIVision v] object exists?> then
    [Only if an AI Classification is detected, then print data from the largest AI Classification.]
    print [Largest object's width:] ▶
    print ([AIVision v] object [width v]) ◀ and set cursor to next row
    end
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])
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])
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])
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])
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])

Sensing#

Optical#

Optical found an object?#

The Optical found an object? block returns a Boolean indicating whether the sensor is detecting an object.

  • True – The Optical Sensor is detecting an object.

  • False – The Optical Sensor is not detecting an object.

  <[FrontOptical v] found an object?>

Parameters

Description

This block has no parameters.

Optical detects color?#

The Optical detects color? block returns a Boolean indicating whether the sensor is detecting a specified color.

  • True – The Optical Sensor is detecting the specified color.

  • False – The Optical Sensor is not detecting the specified color.

Note: The Optical Sensor is looking for hue ranges that match the specified color. For detecting specific hue ranges, see the Optical hue block.

  <[FrontOptical 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°.

Optical brightness#

The Optical brightness block returns the amount of light reflected from the object as a percent.

  ([FrontOptical v] brightness in %)

Parameters

Description

This block has no parameters.

Optical hue#

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

This value ranges from 0 to 359 degrees, which correlates to the color wheel:

The VEX Color Wheel showing the degrees of colors around a circle, with red at 0 degrees and transitioning through the rainbow as the value increases.

  ([FrontOptical v] hue in degrees)

Parameters

Description

This block has no parameters.

when Optical#

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

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

Parameters

Description

state

When the attached stack of blocks will run:

  • detects – An undetected object is now detected
  • loses – A detected object is now no longer detected

Rotation#

set Rotation Sensor position#

The set Rotation Sensor position block sets the current position of the Rotation Sensor to a value in degrees.

  set [PusherRotation v] position to [0] degrees

Parameters

Description

position

The position to set the Rotation Sensor to.

Examples

  when started
  [Make lower Pusher position the new 0 degrees rotation position.]
  spin [PusherMotor v] [lower v] for [270] [degrees v] ▶
  set [PusherRotation v] position to [0] degrees

Rotation Sensor angle#

The Rotation Sensor angle block returns the current angle of the sensor between 0 and 359.99 degrees.

  ([PusherRotation v] angle in degrees)

Parameters

Description

This block has no parameters.

Examples

  when started
  [Make lower Pusher position the new 0 degrees rotation position.]
  spin [PusherMotor v] [lower v] for [270] [degrees v] ▶
  print ([PusherRotation v] angle in degrees) ▶

Rotation Sensor position#

The Rotation Sensor position block returns the total rotational position in degrees or turns.

  ([PusherRotation v] position in [degrees v] :: custom-sensing)

Parameters

Description

units

The unit of measurement:

  • degrees
  • turns

Examples

  when started
  [Make lower Pusher position the new 0 degrees rotation position.]
  spin [PusherMotor v] [lower v] for [270] [degrees v] ▶
  print ([PusherRotation v] position in [degrees v] :: custom-sensing) ▶

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
  • inches

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.