Robot-Specific Blocks#

Introduction#

The VIQRC 25-26 Mix & Match Playground features blocks exclusive to this Playground, including two motor options, the IQ AI Vision Sensor, the Optical Sensor, and the Touch LED.

All standard VEXcode VR Blocks are available for use in the VIQRC 25-26 Mix & Match Playground.

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

Motion - Move and track the robot’s motors.

AI Vision - Capture and analyze objects using the IQ 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 in a specified direction using the current motor velocity.

    spin [ClawMotor v] [open v]

Parameters

Description

motor

The motor to spin:

  • ClawMotor
  • LiftMotor

direction

The direction to spin:

  • ClawMotor
    • open
    • close
  • LiftMotor
    • down
    • up

Example

    when started
    [Place a pin atop another pin.]
    spin [LiftMotor v] [up v] for [600] [degrees v] ▶
    drive [forward v] for (140) [mm v] ▶
    spin [ClawMotor v] [open v]

spin motor for#

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

    spin [ClawMotor v] [open v] for (90) [degrees v] ▶

Parameters

Description

motor

The motor to spin:

  • ClawMotor
  • LiftMotor

direction

The direction to spin:

  • ClawMotor
    • open
    • close
  • LiftMotor
    • down
    • up

distance

The rotation amount, as an integer or decimal.

unit

The unit of measurement representing the distance:

  • degrees
  • turns

expanding arrow

By default, this is a waiting block, so the motor will finish moving before running the next block. Expand the block to say and don’t wait to make it non-waiting.

Example

    when started
    [Place a pin atop another pin.]
    spin [LiftMotor v] [up v] for [600] [degrees v] ▶
    drive [forward v] for (140) [mm v] ▶
    spin [ClawMotor v] [open v]

spin motor to position#

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

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

Parameters

Description

motor

The motor to spin:

  • ClawMotor
  • LiftMotor

position

The target position to spin the motor to.

unit

The unit of measurement:

  • degrees
  • turns

expanding arrow

By default, this is a waiting block. Expand the block to say and don’t wait to make it non-waiting.

Example

    when started
    [Place a pin atop another pin.]
    spin [LiftMotor v] to position [-2] [turns v] ▶
    drive [forward v] for (140) [mm v] ▶
    spin [ClawMotor v] [open v]

stop motor#

The stop motor block immediately stops the selected motor.

    stop [ClawMotor v]

Parameters

Description

motor

The motor to stop:

  • ClawMotor
  • LiftMotor

Example

    when started
    [Raise the lift for 2 seconds, then stop.]
    spin [LiftMotor v] [up v]
    wait (2) seconds
    stop [LiftMotor v]

Settings#

set motor velocity#

The set motor velocity block sets the default spinning speed of a motor as a percentage for all subsequent Motor blocks in the project.

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

Parameters

Description

motor

The motor to set the velocity of:

  • ClawMotor
  • LiftMotor

velocity

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

unit

The unit that represents the velocity:

  • %

Example

    when started
    [Raise the lift at full speed.]
    set [LiftMotor v] velocity to [100] [% v]
    spin [LiftMotor v] [up v] for [600] [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.

    set [ClawMotor v] timeout to (1) seconds

Parameters

Description

motor

The motor to set the timeout of:

  • ClawMotor
  • LiftMotor

time

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

Example

    when started
    set [LiftMotor v] timeout to [2] seconds
    spin [LiftMotor v] [up v] for [5] [turns v] ▶

Position#

motor position#

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

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

Parameters

Description

motor

The motor to return the position of:

  • ClawMotor
  • LiftMotor

unit

The unit of measurement:

  • degrees
  • turns

Example

    when started
    [Raise the lift until it reaches 600 degrees.]
    spin [LiftMotor v] [up v]
    wait until <([LiftMotor v] position in [degrees v]) [math_less_than v] [-600]>
    stop [LiftMotor v]

set motor position#

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

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

Parameters

Description

motor

The motor to set the position of:

  • ClawMotor
  • LiftMotor

position

The encoder position value to set.

unit

The unit of measurement:

  • degrees
  • turns

Example

    when started
    set [LiftMotor v] position to [100] [degrees v]
    spin [LiftMotor v] to position [-500] [degrees v] ▶

Values#

motor is done#

The motor is done? block returns a Boolean indicating whether the motor is not spinning.

  • True - The motor is not spinning.

  • False - The motor is spinning.

    <[ClawMotor v] is done?>

Parameters

Description

motor

The motor to check if it is done spinning:

  • ClawMotor
  • LiftMotor

Example

    when started
    [Flash the Touch LED while the lift is moving.]
    spin [LiftMotor v] [up v] for [600] [degrees v] ◀ and don't wait
    wait [0.1] seconds
    repeat until <[LiftMotor v] is done?>
        set [TouchLED v] color to [red v]
        wait [0.5] seconds
        set [TouchLED v] color to [none v]
        wait [0.5] seconds
    end

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.

    <[ClawMotor v] is spinning?>

Parameters

Description

motor

The motor to check if it is currently spinning:

  • ClawMotor
  • LiftMotor

Example

    when started
    [Flash the Touch LED while the lift is spinning.]
    spin [LiftMotor v] [up v] for [600] [degrees v] ◀ and don't wait
    wait [0.1] seconds
    repeat until <not <[LiftMotor v] is spinning?>>
        set [TouchLED v] color to [red v]
        wait [0.5] seconds
        set [TouchLED v] color to [none v]
        wait [0.5] seconds
    end

motor velocity#

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

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

Parameters

Description

motor

The motor to return the velocity of:

  • ClawMotor
  • LiftMotor

unit

The unit that represents the velocity:

  • %

Example

    when started
    set [LiftMotor v] velocity to [100] [% v]
    spin [LiftMotor v] [up v] for [600] [degrees v] ◀ and don't wait
    wait [0.5] seconds
    print ([LiftMotor v] velocity in [% v] :: custom-motion) ▶

AI Vision#

Actions#

get object data#

The get object data block filters data from the IQ AI Vision Sensor frame. The IQ 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 the 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 Beams and Blue, Red, and Orange Pins.

Example

    when started
    [Place the Red Pin on the top left Blue Pin.]
    spin [LiftMotor v] [up v] for [600] [degrees v] ▶
    turn [left v] for [38] degrees ▶
    repeat until <([AIVision v] object [width v]) [math_greater_than v] [48]>
        get [AI Classifications v] data from [AIVision v]
        drive [forward v]
    end
    drive [forward v] for [160] [mm v] ▶
    spin [ClawMotor v] [open v]

Settings#

set object item#

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

The set 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
    [Find the object index of the nearest Orange Pin.]
    set [object_counter v] to [1]
    get [AI Classifications v] data from [AIVision v]
    repeat ([AIVision v] object count)
        set [AIVision v] object item to (object_counter)
        if <[AIVision v] object is [Orange Pin v]> then
            print (join [Nearest Orange Pin is ] (object_counter)) ▶
        else
            change [object_counter v] by [1]
        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
    [Raise the Lift until a Pin or Beam is detected.]
    repeat until <[AIVision v] object exists?>
        get [AI Classifications v] data from [AIVision v]
        spin [LiftMotor v] [up v]
    end
    stop [LiftMotor v]

object count#

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

The object count reporter block.#
  ([AIVision v] object count)

Parameters

Description

This block has no parameters.

Example

    when started
    get [AI Classifications v] data from [AIVision v]
    print ([AIVision v] object count) ▶

object property#

There are six properties that are included with each object 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 on the detected object’s position in the IQ AI Vision Sensor’s view at the time that the get object data block was used. The IQ 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 reporter block with width selected.#
  ([AIVision v] object [width v])
height#

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

The AI Vision object property reporter block with height selected.#
  ([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 reporter block with centerX selected.#
  ([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 reporter block with centerY selected.#
  ([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 reporter block with originX selected.#
  ([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 reporter block with originY selected.#
  ([AIVision v] object [originY v])

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 Classification is Boolean block.#
  <[AIVision v] object is [Beam v]?>

Parameter

Description

object

Which object to compare the item to:

  • Beam
  • Blue Pin
  • Red Pin
  • Orange Pin

Example

    when started
    [Find the object index of the nearest Orange Pin.]
    set [object_counter v] to [1]
    get [AI Classifications v] data from [AIVision v]
    repeat ([AIVision v] object count)
        set [AIVision v] object item to (object_counter)
        if <[AIVision v] object is [Orange Pin v]> then
            print (join [Nearest Orange Pin is ] (object_counter)) ▶
        else
            change [object_counter v] by [1]
        end
    end

Sensing#

Optical#

Optical found an object?#

The Optical found an 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
    [Place a pin atop another pin.]
    spin [LiftMotor v] [up v] for [600] [degrees v] ▶
    drive [forward v] for (140) [mm v] ▶
    spin [ClawMotor v] [open v]
    wait until <not <[Optical v] found an object?>>
    spin [LiftMotor v] to position [0] [degrees 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
  • white
  • yellow
  • orange
  • purple
  • red violet
  • violet
  • blue violet
  • blue green
  • yellow green
  • yellow orange
  • red orange

Example

    when started
    [Place a pin atop another pin.]
    spin [LiftMotor v] [up v] for [600] [degrees v] ▶
    drive [forward v] for (140) [mm v] ▶
    spin [ClawMotor v] [open v]
    wait until <[Optical v] detects [red v]?>
    spin [LiftMotor v] to position [0] [degrees 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.

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 degrees at the top to 360 degrees.

    ([Optical v] hue in degrees)

Parameters

Description

This block has no parameters.

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

Parameters

Description

action

Which action triggers the hat block:

  • detects
  • loses

Example

    when [Optical v] [loses v] an object
    [Lower the lift when the object is no longer in the claw.]
    spin [LiftMotor v] to position [0] [degrees v] ▶

Touch LED#

set TouchLED color#

The set TouchLED color block sets the color of the Touch LED.

    set [TouchLED v] color to [none v]

Parameters

Description

color

Sets the LED’s color to:

  • none - Turns off the Touch LED
  • red
  • green
  • blue
  • white
  • yellow
  • orange
  • purple
  • red violet
  • violet
  • blue violet
  • blue green
  • yellow green
  • yellow orange
  • red orange

Example

    when started
    [Light the Touch LED while placing a pin.]
    set [TouchLED v] color to [red v]
    spin [LiftMotor v] [up v] for [600] [degrees v] ▶
    drive [forward v] for (140) [mm v] ▶
    spin [ClawMotor v] [open v]
    set [TouchLED v] color to [none v]