Robot-Specific Blocks#

Introduction#

The Hero Bot, Flop, includes an IntakeMotor, an ArmMotor, and an IQ AI Vision Sensor.

All standard VEXcode VR Blocks are available for use in the IQ 26-27 Level Up Playground.

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

Motion – Move and track the robot’s motors.

AI Vision - Capture and analyze objects using the IQ AI Vision Sensor.

  • Actions

    • get object data - Captures data for a specific signature, such as a detected AI Classification.

  • Settings

  • Values

    • object exists - Returns whether any classification was detected.

    • object is - Returns whether a specific classification is detected.

    • object is AprilTag - Returns whether the detected object is an AprilTag matching a specific ID.

    • object count - Returns how many objects were detected.

    • object property - Returns width, height, centerX, centerY, originX, or originY.

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

Motion#

Flop uses the intake motor to collect and eject game elements. The arm motor raises and lowers the arm.

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

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 [IntakeMotor v] [intake v]

Parameters

Description

motor

The motor to spin: IntakeMotor or ArmMotor.

direction

The direction the motor spins:

  • IntakeMotorintake or outtake
  • ArmMotorup or down

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake 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 [ArmMotor v] [up v] for (500) [degrees v] ▶

Parameters

Description

motor

The motor to spin: IntakeMotor or ArmMotor.

direction

The direction the motor spins:

  • IntakeMotorintake or outtake
  • ArmMotorup or down

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
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake 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 [ArmMotor v] to position (500) [degrees v] ▶

Parameters

Description

motor

The motor to spin: IntakeMotor or ArmMotor.

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
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] to position (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake v]

stop motor#

The stop motor stack block stops the selected motor.

    stop [IntakeMotor v]

Parameters

Description

motor

The motor to stop: IntakeMotor or ArmMotor.

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake v]
    wait (1) seconds
    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 [IntakeMotor v] velocity to [50] [% v]

Parameters

Description

motor

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

velocity

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

unit

The velocity unit: %.

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    set [IntakeMotor v] velocity to [100] [% v]
    spin [IntakeMotor v] [outtake 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 [ArmMotor v] timeout to [1] seconds

Parameters

Description

motor

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

time

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

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    set [ArmMotor v] timeout to [2] seconds
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake 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.

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

Parameters

Description

motor

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

unit

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

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    while <([ArmMotor v] position in [degrees v]) [math_less_than v] [360]>
    spin [ArmMotor v] [up v]
    wait (0.002) seconds
    end
    stop [ArmMotor v]
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake 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 [ArmMotor v] position to (0) [degrees v]

Parameters

Description

motor

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

position

The position value to set. Degrees use integers. Turns can use integers or decimals.

unit

The position unit: degrees or turns.

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    set [ArmMotor v] position to [0] [degrees v]
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake 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.

    <[ArmMotor v] is done?>

Parameters

Description

motor

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

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] to position (1) [turns v] ◀ and don't wait
    wait until <[ArmMotor v] is done?>
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake 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.

    <[IntakeMotor v] is spinning?>

Parameters

Description

motor

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

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake v]
    wait until <not <[IntakeMotor v] is spinning?>>
    stop [IntakeMotor v]

motor velocity#

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

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

Parameters

Description

motor

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

unit

The unit to report the motor velocity in: %.

Example

    when started
    [Score a Bean Bag in a Blue Goal.]
    turn [left v] for (90) degrees ▶
    drive [forward v] for (35) [inches v] ▶
    turn [right v] for (90) degrees ▶
    spin [ArmMotor v] [up v] for (1) [turns v] ▶
    drive [forward v] for (40) [inches v] ▶
    spin [IntakeMotor v] [outtake v]
    wait [0.2] seconds
    print ([IntakeMotor 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 to a single signature — a saved description of something the sensor can recognize, such as a game element 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. Available signatures are:

  • AI Classifications — Detects Red Bean Bag, Blue Bean Bag, and Yellow Bean Bag.
  • AprilTags — Detects the AprilTag IDs found on the sides of the Goals.

Example

  when started :: hat events
  [Drop the preloaded Bean Bag.]
  spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
  turn [left v] for (90) degrees ▶
  [Find and face the nearest red Bean Bag.]
  set turn velocity to (30) [% v]
  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 [RedBeanBag v]?> then
          if <([AIVision v] object [centerX v]) < (140)> then
              turn [left v]
          else if <([AIVision v] object [centerX v]) > (180)> then
              turn [right v]
          else
              stop driving
          end
          break
      end
      change [object_counter v] by [1]
  end

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 :: hat events
  [Drop the preloaded Bean Bag.]
  spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
  turn [left v] for (90) degrees ▶
  [Find the index of the nearest red Bean Bag.]
  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 [RedBeanBag v]?> then
          print (join [Nearest Red Bean Bag is ] (object_counter)) ▶
          break
      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 :: hat events
  [Drop the preloaded Bean Bag.]
  spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
  turn [left v] for (90) degrees ▶
  [Turn until a Bean Bag is detected.]
  set turn velocity to (30) [% v]
  turn [right v]
  repeat until <[AIVision v] object exists?>
      get [AI Classifications v] data from [AIVision v]
  end
  stop driving

object is#

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

Parameter

Description

object

Which object to compare the item to: RedBeanBag, BlueBeanBag, or YellowBeanBag.

Example

  when started :: hat events
  [Drop the preloaded Bean Bag.]
  spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
  turn [left v] for (90) degrees ▶
  [Find the index of the nearest red Bean Bag.]
  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 [RedBeanBag v]?> then
          print (join [Nearest Red Bean Bag is ] (object_counter)) ▶
          break
      else
          change [object_counter v] by [1]
      end
  end

object is AprilTag#

The object is AprilTag block returns a Boolean indicating whether the detected object is an AprilTag that matches a specific ID.

  • True - The detected object is an AprilTag with the given ID.

  • False - The detected object is not an AprilTag with the given ID.

The object is AprilTag Boolean block.#
  <[AIVision v] object is AprilTag [0] ?>

Parameter

Description

AprilTag ID

The ID number to compare against the detected AprilTag.

Example

  when started :: hat events
  [Stop when you see the Red Goal!]
  set turn velocity to (30) [% v]
  turn [right v]
  repeat until <[AIVision v] object is AprilTag [1] ?>
      get [AprilTags v] data from [AIVision v]
  end
  stop driving
  print [Found the Red Goal!] ▶

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 :: hat events
  [Drop the preloaded Bean Bag.]
  spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
  turn [left v] for (90) degrees ▶
  [Print how many Bean Bags are detected.]
  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])

All property values describe the detected object’s position and size in the IQ AI Vision Sensor’s view at the moment the get object data block was used. These values are measured in pixels, based on the sensor’s 320 by 240 pixel resolution.

Parameter

Description

property

Which property of the detected object to use: width, height, centerX, centerY, originX, or originY.

width#

The width property reports the width of the detected object in pixels as a whole number from 1 to 320.

The AI Vision object property reporter block with width selected.#
  ([AIVision v] object [width v])

Example

    when started
    [Drop the preloaded Bean Bag.]
    spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
    turn [left v] for (90) degrees ▶
    [Approach the Bean Bag, then pick it up.]
    set drive velocity to (30) [% v]
    forever
        get [AI Classifications v] data from [AIVision v]
        if <[AIVision v] object exists?> then
            set [AIVision v] object item to [1]
            if <[AIVision v] object is [RedBeanBag v]?> then
                if <([AIVision v] object [width v]) > (180)> then
                    drive [forward v] for [50] [mm v] ▶
                    spin [IntakeMotor v] [intake v] for [90] [degrees v] ▶
                    break
                else
                    drive [forward v]
                end
            end
        end
    end
height#

The height property reports the height of the detected object in pixels as a whole number from 1 to 240.

The AI Vision object property reporter block with height selected.#
  ([AIVision v] object [height v])

Example

    when started
    [Drop the preloaded Bean Bag.]
    spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
    turn [left v] for (90) degrees ▶
    [Approach the Bean Bag, then pick it up.]
    set drive velocity to (30) [% v]
    forever
        get [AI Classifications v] data from [AIVision v]
        if <[AIVision v] object exists?> then
            set [AIVision v] object item to [1]
            if <[AIVision v] object is [RedBeanBag v]?> then
                if <([AIVision v] object [height v]) > (100)> then
                    drive [forward v] for [50] [mm v] ▶
                    spin [IntakeMotor v] [intake v] for [90] [degrees v] ▶
                    break
                else
                    drive [forward v]
                end
            end
        end
    end
centerX#

The centerX property reports the x-coordinate of the center of the detected object in pixels as a whole number from 0 to 320.

The AI Vision object property reporter block with centerX selected.#
  ([AIVision v] object [centerX v])

Example

    when started
    [Drop the preloaded Bean Bag.]
    spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
    turn [left v] for (90) degrees ▶
    [Steer to keep the Bean Bag centered while approaching.]
    set turn velocity to (30) [% v]
    set drive velocity to (30) [% v]
    forever
        get [AI Classifications v] data from [AIVision v]
        if <[AIVision v] object exists?> then
            set [AIVision v] object item to [1]
            if <[AIVision v] object is [RedBeanBag v]?> then
                if <([AIVision v] object [centerX v]) < (140)> then
                    turn [left v] for (5) degrees ▶
                else
                    drive [forward v] for (150) [mm v] ▶
                    spin [IntakeMotor v] [intake v]
                    break
                end
            end
        end
    end
centerY#

The centerY property reports the y-coordinate of the center of the detected object in pixels as a whole number from 0 to 240.

The AI Vision object property reporter block with centerY selected.#
  ([AIVision v] object [centerY v])

Example

    when started
    [Drop the preloaded Bean Bag.]
    spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
    turn [left v] for (90) degrees ▶
    [Print the y-position of the Bean Bag.]
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
        set [AIVision v] object item to [1]
        if <[AIVision v] object is [RedBeanBag v]?> then
            print ([AIVision v] object [centerY v]) ▶
        end
    end
originX#

The originX property reports the x-coordinate of the top-left corner of the detected object’s bounding box in pixels as a whole number from 0 to 320.

The AI Vision object property reporter block with originX selected.#
  ([AIVision v] object [originX v])

Example

    when started
    [Drop the preloaded Bean Bag.]
    spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
    turn [left v] for (90) degrees ▶
    [Steer to keep the left edge centered.]
    set turn velocity to (30) [% v]
    set drive velocity to (30) [% v]
    forever
        get [AI Classifications v] data from [AIVision v]
        if <[AIVision v] object exists?> then
            set [AIVision v] object item to [1]
            if <[AIVision v] object is [RedBeanBag v]?> then
                if <([AIVision v] object [originX v]) < (100)> then
                    turn [left v] for (5) degrees ▶
                else
                    drive [forward v] for (150) [mm v] ▶
                    spin [IntakeMotor v] [intake v]
                    break
                end
            end
        end
    end
originY#

The originY property reports the y-coordinate of the top-left corner of the detected object’s bounding box in pixels as a whole number from 0 to 240.

The AI Vision object property reporter block with originY selected.#
  ([AIVision v] object [originY v])

Example

    when started
    [Drop the preloaded Bean Bag.]
    spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
    turn [left v] for (90) degrees ▶
    [Print the y-position of the Bean Bag's top edge.]
    get [AI Classifications v] data from [AIVision v]
    if <[AIVision v] object exists?> then
        set [AIVision v] object item to [1]
        if <[AIVision v] object is [RedBeanBag v]?> then
            print ([AIVision v] object [originY v]) ▶
        end
    end