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.
Actions
spin motor – Spins a motor in one of its directions forever.
spin motor for – Spins a motor for a specific distance in degrees or turns.
spin motor to position – Spins a motor to a specific position.
stop motor – Stops a motor from spinning.
Settings
set motor velocity – Tells a motor how fast to spin.
set motor timeout – Sets how much time a motor will try to finish a movement.
Position
motor position – Reports the motor’s current position.
set motor position – Changes the motor’s current position to a new value.
Values
motor is done – Reports whether the motor is finished moving.
motor is spinning – Reports whether the motor is spinning.
motor velocity – Reports how fast the motor is spinning, as a percentage from -100% to 100%.
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
set object item - Selects a specific object from the list.
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:
|
Example
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
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:
|
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
spin [ArmMotor v] [up v] for (1) [turns v] ▶
drive [forward v] for (40) [inches v] ▶
spin [IntakeMotor v] [outtake v]
esperar (1) segundos
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
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.
Establezca el tiempo de espera [ArmMotor v] en [1] segundo
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
while <([ArmMotor v] position in [degrees v]) [math_less_than v] [360]>
girar [ArmMotor v] [arriba v]
wait (0.002) seconds
fin
parada [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.
Establezca la posición [ArmMotor v] en (0) [grados 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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
Establezca la posición [ArmMotor v] en [0] [grados 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] ¿está hecho?>
Parameters |
Description |
|---|---|
motor |
The motor to report whether it is finished moving: IntakeMotor or ArmMotor. |
Example
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
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
cuando empezó
[Score a Bean Bag in a Blue Goal.]
girar [izquierda v] por (90) grado ▶
drive [forward v] for (35) [inches v] ▶
girar [derecha v] por (90) grado ▶
spin [ArmMotor v] [up v] for (1) [turns v] ▶
drive [forward v] for (40) [inches v] ▶
spin [IntakeMotor v] [outtake v]
esperar [0.2] segundos
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.
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:
|
Example
cuando empezó :: hat events
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[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
turno [izquierda v]
else if <([AIVision v] object [centerX v]) > (180)> then
turno [derecha v]
demás
deja de conducir
fin
romper
fin
change [object_counter v] by [1]
fin
Settings#
set object item#
The set object item block sets which item in the dataset to use.
set [AIVision v] object item to [1]
Parameters |
Description |
|---|---|
item |
The number of the item in the dataset to use. |
Example
cuando empezó :: hat events
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[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)) ▶
romper
demás
change [object_counter v] by [1]
fin
fin
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.
<[AIVision v] object exists?>
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
cuando empezó :: hat events
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[Turn until a Bean Bag is detected.]
set turn velocity to (30) [% v]
turno [derecha v]
repeat until <[AIVision v] object exists?>
get [AI Classifications v] data from [AIVision v]
fin
deja de conducir
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.
<[AIVision v] object is [RedBeanBag v]?>
Parameter |
Description |
|---|---|
object |
Which object to compare the item to: RedBeanBag, BlueBeanBag, or YellowBeanBag. |
Example
cuando empezó :: hat events
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[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)) ▶
romper
demás
change [object_counter v] by [1]
fin
fin
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.
<[AIVision v] object is AprilTag [0] ?>
Parameter |
Description |
|---|---|
AprilTag ID |
The ID number to compare against the detected AprilTag. |
Example
cuando empezó :: hat events
[Stop when you see the Red Goal!]
set turn velocity to (30) [% v]
turno [derecha v]
repeat until <[AIVision v] object is AprilTag [1] ?>
get [AprilTags v] data from [AIVision v]
fin
deja de conducir
print [Found the Red Goal!] ▶
object count#
The object count block returns the number of detected objects in the dataset as an integer.
([AIVision v] object count)
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
cuando empezó :: hat events
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[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.
([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.
([AIVision v] object [width v])
Example
cuando empezó
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[Approach the Bean Bag, then pick it up.]
set drive velocity to (30) [% v]
para siempre
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] ▶
romper
demás
unidad [adelante v]
fin
fin
fin
fin
height#
The height property reports the height of the detected object in pixels as a whole number from 1 to 240.
([AIVision v] object [height v])
Example
cuando empezó
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[Approach the Bean Bag, then pick it up.]
set drive velocity to (30) [% v]
para siempre
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] ▶
romper
demás
unidad [adelante v]
fin
fin
fin
fin
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.
([AIVision v] object [centerX v])
Example
cuando empezó
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[Steer to keep the Bean Bag centered while approaching.]
set turn velocity to (30) [% v]
set drive velocity to (30) [% v]
para siempre
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 ▶
demás
drive [forward v] for (150) [mm v] ▶
spin [IntakeMotor v] [intake v]
romper
fin
fin
fin
fin
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.
([AIVision v] object [centerY v])
Example
cuando empezó
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[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]) ▶
fin
fin
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.
([AIVision v] object [originX v])
Example
cuando empezó
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[Steer to keep the left edge centered.]
set turn velocity to (30) [% v]
set drive velocity to (30) [% v]
para siempre
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 ▶
demás
drive [forward v] for (150) [mm v] ▶
spin [IntakeMotor v] [intake v]
romper
fin
fin
fin
fin
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.
([AIVision v] object [originY v])
Example
cuando empezó
[Drop the preloaded Bean Bag.]
spin [IntakeMotor v] [outtake v] for (180) [degrees v] ▶
girar [izquierda v] por (90) grado ▶
[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]) ▶
fin
fin