Robot-Specific Blocks#
Introduction#
The Hero Bot, Flex, includes a ClawMotor, an ArmMotor, an AI Vision Sensor, a Distance Sensor, and a Game Positioning System (GPS) Sensor.
All standard VEXcode VR Blocks are available for use in the V5 26-27 Override Playground.
Below is a list of all available Robot-specific Blocks:
Drivetrain – Move and turn the robot.
Actions
drive — Moves the robot forward or reverse forever.
drive for — Moves the robot forward or reverse for a specific distance.
turn — Turns the robot left or right forever.
turn for — Turns the robot left or right for a specific number of degrees.
turn to heading — Turns the robot to face a specific heading.
turn to rotation — Turns the robot to a specific rotation.
stop driving — Stops the robot’s movement.
Settings
set drive velocity — Tells the robot how fast to drive.
set turn velocity — Tells the robot how fast to turn.
set drive heading — Changes the robot’s current heading to a new heading.
set drive rotation — Changes the robot’s current rotation to a new rotation.
set drive timeout — Sets how many seconds the robot will try to finish a movement.
Values
drive is done — Reports whether the robot is finished moving.
drive is moving — Reports whether the robot is moving.
drive heading — Reports the robot’s current heading from 0 to 359.99 degrees.
drive rotation — Reports the robot’s current rotation.
drive velocity — Reports how fast the robot is driving.
Motion – Move and track the robot’s motors.
Actions
spin motor – Spins a motor forward or reverse 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.
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 position – Reports the motor’s current position.
motor velocity – Reports how fast the motor is spinning, as a percentage from -100% to 100%.
AI Vision – Capture and analyze objects using the 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 if a 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 details such as:
Sensing – Utilize the robot’s various sensors.
Distance
Distance found an object – Reports whether the Distance Sensor detects an object within range.
object distance – Reports the distance between the Distance Sensor and the nearest detected object.
GPS
GPS position – Returns the X or Y position from the GPS Sensor.
GPS heading – Returns the heading the robot is currently facing.
The examples on this page use Starting Location C from the Playground’s Pre-Match checklist.
Drivetrain#
The drivetrain controls how the VR Robot drives and turns. The drivetrain can move forward or reverse, turn left or right, turn to headings, and track its rotation.
Actions#
drive#
The drive stack block moves the robot forward or reverse forever. The robot will continue to move until it is given another action, like turning or stopping.
drive [forward v]
Parameters |
Description |
|---|---|
direction |
The direction the robot moves: forward or reverse. |
Example
when started :: hat events
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v]
wait (0.5) seconds
stop driving
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
drive for#
The drive for stack block moves the robot forward or reverse for a specific distance. The project will wait until the robot is done moving before the next block in the stack runs.
drive [forward v] for (200) [mm v] ▶
Parameters |
Description |
|---|---|
direction |
The direction the robot moves: forward or reverse. |
distance |
The distance the robot drives. This can be an integer or a decimal. |
unit |
The distance unit: mm (millimeters) or inches |
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 :: hat events
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn#
The turn stack block turns the robot left or right forever. The robot will continue to turn until it is given another action, like driving or stopping.
turn [right v]
Parameters |
Description |
|---|---|
direction |
The direction the robot turns: left or right. |
Example
when started :: hat events
[Score a Pin in a Neutral Goal.]
turn [left v]
wait (0.78) seconds
stop driving
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
drive [forward v] for (25) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn for#
The turn for stack block turns the robot left or right for a specific number of degrees. The turn is relative to the current position of the robot. The project will wait until the robot is done turning before the next block in the stack runs.
turn [right v] for (90) degrees ▶
Parameters |
Description |
|---|---|
direction |
The direction the robot turns: left or right. |
angle |
The number of degrees the robot turns. This can be an integer or a decimal. |
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 :: hat events
[Score a Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
drive [forward v] for (25) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn to heading#
A heading is the direction the robot is facing, measured in degrees. The turn to heading stack block turns the robot to face a specific heading from -359 to 359 degrees. The robot will turn the shortest direction to reach the target heading.
The starting heading is 0 degrees.
The project will wait until the robot is done turning before the next block in the stack runs.
turn to heading (90) degrees ▶
Parameters |
Description |
|---|---|
heading |
The heading the robot should face, from -359 to 359 degrees. |
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 :: hat events
[Score a Pin in a Neutral Goal.]
turn to heading (-110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
drive [forward v] for (25) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn to rotation#
The turn to rotation stack block turns the robot to a specific rotation.
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. Rotation can also be set using the set drive rotation block.
Rotation values are absolute. This means the direction of the turn depends on the robot’s current rotation. Turning right increases the rotation, and turning left decreases the rotation.
For example, if the robot starts at 0 degrees and you turn to a rotation of 720 degrees, it will turn right twice. If you then turn to a rotation of 360 degrees, it will turn left once, because 360 is less than 720.
The project will wait until the robot is done turning before the next block in the stack runs.
turn to rotation (90) degrees ▶
Parameters |
Description |
|---|---|
rotation |
The rotation value, in degrees, that the robot will turn to. This can be an integer or a decimal. |
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 :: hat events
[Score a Pin in a Neutral Goal.]
turn to rotation (-110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
drive [forward v] for (25) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
stop driving#
The stop driving stack block stops the robot’s movement.
stop driving
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Score a Pin in a Neutral Goal.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v]
wait (0.5) seconds
stop driving
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
Settings#
set drive velocity#
The set drive velocity stack block tells the robot how fast to drive. A higher percentage makes the robot drive faster and a lower percentage makes the robot drive slower.
Every project begins with the robot driving at 50% velocity by default.
Note: A higher velocity makes the robot drive faster, but it may be less precise. A lower velocity makes the robot drive slower, but it can be more precise.
set drive velocity to (50) [% v]
Parameters |
Description |
|---|---|
velocity |
The velocity to drive with from 0% to 100%. |
unit |
The velocity unit: % |
Example
when started :: hat events
[Score a Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
set drive velocity to (100) [% v]
drive [forward v] for (25) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
set turn velocity#
The set turn velocity stack block tells the robot how fast to turn. A higher percentage makes the robot turn faster and a lower percentage makes the robot turn slower.
Every project begins with the robot turning at 50% velocity by default.
Note: A higher velocity makes the robot turn faster, but it may be less precise. A lower velocity makes the robot turn slower, but it can be more precise.
set turn velocity to (50) [% v]
Parameters |
Description |
|---|---|
velocity |
The velocity to turn with from 0% to 100%. |
unit |
The velocity unit: % |
Example
when started :: hat events
[Turn to face the Neutral Goal faster.]
set turn velocity to (100) [% v]
turn [left v] for (110) degrees ▶
set drive heading#
A heading is the direction the robot is facing, measured in degrees. The set drive heading stack block changes the robot’s current heading to a new heading value.
For example, if the robot has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the robot can turn to other positions based on that new heading.
set drive heading to (0) degrees
Parameters |
Description |
|---|---|
heading |
The heading value, in degrees, to set for the robot. |
Example
when started :: hat events
[Make facing the Neutral Goal the new heading.]
set drive heading to (110) degrees
turn to heading (0) degrees ▶
set drive rotation#
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. The set drive rotation stack block changes the robot’s current rotation to a new value.
For example, if the robot has made two full turns to the right, its rotation value will be 720 degrees. Setting the rotation to 0 degrees will reset that rotation from 720 to 0 degrees. Then the robot can turn to rotations based on that new value.
set drive rotation to (0) degrees
Parameters |
Description |
|---|---|
rotation |
The rotation value, in degrees, to set for the robot. This can be an integer or a decimal. |
Example
when started :: hat events
[Make facing the Neutral Goal the new rotation.]
set drive rotation to (110) degrees
turn to rotation (0) degrees ▶
set drive timeout#
The set drive timeout stack block sets how many seconds the robot will try to finish a movement. If the robot cannot finish in that time it will stop trying and move on to the next block in the stack. This keeps the robot from getting stuck on a movement.
set drive timeout to (1) seconds
Parameters |
Description |
|---|---|
time |
The number of seconds the robot can try to finish a movement. This can be a whole number or a decimal. |
Example
when started :: hat events
[Turn to face the Neutral Goal.]
set drive timeout to (0.8) seconds
turn [left v] for (180) degrees ▶
Values#
drive is done#
The drive is done Boolean block reports whether the robot is finished moving. This can be used to control the timing of other behaviors based on the robot’s movement.
True — The robot is finished moving.
False — The robot is still moving.
This block works together with drivetrain blocks that have the and don’t wait parameter.
<drive is done?>
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Score a Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
drive [forward v] for (25) [inches v] ◀ and don't wait
wait until <drive is done?>
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
drive is moving#
The drive is moving Boolean block reports whether the robot is moving. This can be used to control the timing of other behaviors based on the robot’s movement.
True — The robot is moving.
False — The robot is not moving.
This block works together with drivetrain blocks that have the and don’t wait parameter.
<drive is moving?>
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Raise the Arm once stopped near the Goal.]
turn [left v] for (110) degrees ▶
drive [forward v] for (25) [inches v] ◀ and don't wait
while <drive is moving?>
wait (0.005) seconds
end
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
drive heading#
A heading is the direction the robot is facing, measured in degrees. The drive heading reporter block reports that heading from 0 to 359.99 degrees.
The robot’s starting heading is 0 degrees.
(drive heading in degrees)
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Turn to the Goal, then show heading.]
turn [right v] for (450) degrees ▶
print (drive heading in degrees) on screen ◀ and set cursor to next row
drive rotation#
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. The drive rotation reporter block reports the robot’s current rotation.
Turning right increases the rotation, and turning left decreases the rotation. For example, making two full turns to the right will report a rotation of 720 degrees.
(drive rotation in degrees)
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Spin to find a Pin, then show rotation.]
turn [right v] for (450) degrees ▶
print (drive rotation in degrees) on screen ◀ and set cursor to next row
drive velocity#
The drive velocity reporter block reports how fast the robot is driving.
(drive velocity in [% v])
Parameters |
Description |
|---|---|
unit |
The velocity unit: % |
Example
when started :: hat events
[Show speed while driving to the Goal.]
drive [forward v] for (150) [mm v] ▶
print (drive velocity in [% v]) on screen ◀ and set cursor to next row
Motion#
Flex uses the ArmMotor to lift and lower the arm, and the ClawMotor to open and close the claw.
Each motor has its own direction options. The direction names describe how that motor moves on Flex.
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 [ArmMotor v] [up v]
Parameters |
Description |
|---|---|
motor |
The motor to spin: ArmMotor or ClawMotor. |
direction |
The direction the motor spins:
|
Example
when started
[Raise the Arm before driving toward a Pin.]
spin [ArmMotor v] [up v]
wait (1) seconds
stop [ArmMotor 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 (90) [degrees v] ▶
Parameters |
Description |
|---|---|
motor |
The motor to spin: ArmMotor or ClawMotor. |
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
when started
[Raise the Arm to carry the Pin to the Goal.]
spin [ArmMotor v] [up v] for (800) [degrees 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 ArmMotor’s position is set to 0 degrees. The ClawMotor is the exception — it starts at 467 degrees (fully closed). 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 (90) [degrees v] ▶
Parameters |
Description |
|---|---|
motor |
The motor to spin: ArmMotor or ClawMotor. |
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
[Raise the Arm, then release the Pin.]
spin [ArmMotor v] to position (800) [degrees v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
stop motor#
The stop motor stack block stops the selected motor.
stop [ArmMotor v]
Parameters |
Description |
|---|---|
motor |
The motor to stop: ArmMotor or ClawMotor. |
Example
when started
[Raise the Arm partway to hold the Pin.]
spin [ArmMotor v] [up v]
wait (1) seconds
stop [ArmMotor 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 [ArmMotor v] velocity to [50] [% v]
Parameters |
Description |
|---|---|
motor |
The motor to set the velocity of: ArmMotor or ClawMotor. |
velocity |
The speed the motor will spin at. Percent uses whole numbers from 0% to 100%. |
unit |
The velocity unit: %. |
Example
when started
[Raise the Arm fast to release the Pin.]
set [ArmMotor v] velocity to [100] [% v]
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
spin [ClawMotor v] [open v] for (180) [degrees 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: ArmMotor or ClawMotor. |
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 Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
set [ArmMotor v] timeout to [1] seconds
spin [ArmMotor v] [up v] for (1800) [degrees v] ▶
drive [forward v] for (25) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees 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 ArmMotor’s position is set to 0 degrees. The ClawMotor is the exception — it starts at 467 degrees (fully closed). If the motor spins one full turn forward, the position increases. If the motor spins the other direction, the position decreases.
([ArmMotor v] position in [degrees v])
Parameters |
Description |
|---|---|
motor |
The motor to report the position of: ArmMotor or ClawMotor. |
unit |
The unit to report the motor position in: degrees or turns. |
Example
when started
[Raise the Arm, then release the Pin.]
while <([ArmMotor v] position in [degrees v]) < (800)>
spin [ArmMotor v] [up v]
wait (0.002) seconds
end
stop [ArmMotor v]
spin [ClawMotor v] [open v] for (180) [degrees 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: ArmMotor or ClawMotor. |
position |
The position value to set for the motor. Degrees use integers. Turns can use integers or decimals. |
unit |
The position unit: degrees or turns. |
Example
when started
[Reset encoder, raise Arm, place Pin.]
set [ArmMotor v] position to (0) [degrees v]
spin [ArmMotor v] to position (800) [degrees v] ▶
spin [ClawMotor v] [open v] for (180) [degrees 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: ArmMotor or ClawMotor. |
Example
when started
[Raise the Arm while driving to the Goal.]
spin [ArmMotor v] to position (800) [degrees v] ◀ and don't wait
wait (0.1) seconds
while <not <[ArmMotor v] is done?>>
drive [forward v]
wait (0.005) seconds
end
stop driving
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.
<[ArmMotor v] is spinning?>
Parameters |
Description |
|---|---|
motor |
The motor to report whether it is spinning: ArmMotor or ClawMotor. |
Example
when started
[Raise the Arm while driving to the Goal, then release the Pin.]
spin [ArmMotor v] to position (800) [degrees v] ◀ and don't wait
wait (0.1) seconds
while <[ArmMotor v] is spinning?>
drive [forward v] for (20) [mm v] ▶
end
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
motor velocity#
The motor velocity reporter block reports how fast the motor is spinning, as a percentage from -100% to 100%.
([ArmMotor v] velocity in [% v] :: custom-motion)
Parameters |
Description |
|---|---|
motor |
The motor to report the velocity of: ArmMotor or ClawMotor. |
unit |
The unit to report the motor velocity in: %. |
Example
when started
[Show Arm Motor velocity while raising.]
set [ArmMotor v] velocity to [100] [% v]
spin [ArmMotor v] to position (800) [degrees v] ◀ and don't wait
wait (0.2) seconds
print ([ArmMotor v] velocity in [% v] :: custom-motion) on screen ◀ and set cursor to next row
AI Vision#
Actions#
get object data#
The get object data block filters data from the 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 AI Vision 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
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Turn to face the Pin.]
set turn velocity to (30) [% v]
forever
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> 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
break
end
end
end
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
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
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 specific game element.]
if <[AIVision v] object is [RedBluePin v]?> then
print [RedBluePin detected.] ▶
else
print [No RedBluePin 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.
<[AIVision v] object exists?>
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
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 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 [RedBluePin v]?>
Parameter |
Description |
|---|---|
object |
Which object to compare the item to:
|
Example
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <[AIVision v] object is [RedBluePin v]?> then
print [RedBluePin detected.] ▶
else
print [No RedBluePin detected.] ▶
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.
<[AIVision v] object is AprilTag [0] ?>
Parameter |
Description |
|---|---|
AprilTag ID |
The ID number to compare against the detected AprilTag. |
Example
when started
[Report if AprilTag 3 is detected.]
get [AprilTags v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <[AIVision v] object is AprilTag [3] ?> then
print [That is 3!] ▶
else
print [That isn't 3!] ▶
end
end
object count#
The object count block returns the number of detected objects in the dataset as an integer.
([AIVision] object count)
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
get [AI Classifications v] data from [AIVision v]
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.
([AIVision v] object [width v])
All property values describe the detected object’s position and size in the 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#
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
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
forever
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [width v]) > (140)> then
stop driving
break
else
drive [forward v]
end
end
end
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
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
forever
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [height v]) > (200)> then
stop driving
break
else
drive [forward v]
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.
([AIVision v] object [centerX v])
Example
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Turn and approach the next Cup and Pin.]
set turn velocity to (30) [% v]
forever
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [centerX v]) < (140)> then
turn [left v] for (5) degrees ▶
else
drive [forward v] for (25) [inches v] ▶
break
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.
([AIVision v] object [centerY v])
Example
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
forever
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [centerY v]) > (230)> then
stop driving
break
else
drive [forward v]
end
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.
([AIVision v] object [originX v])
Example
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Turn and approach the next Cup and Pin.]
set turn velocity to (30) [% v]
forever
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [originX v]) < (100)> then
turn [left v] for (5) degrees ▶
else
drive [forward v] for (25) [inches v] ▶
break
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.
([AIVision v] object [originY v])
Example
when started
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
forever
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [originY v]) > (140)> then
stop driving
break
else
drive [forward v]
end
end
end
Sensing#
Distance#
Distance found an object#
The Distance found an object Boolean block reports whether the Distance Sensor currently detects an object within 2000mm.
True — The Distance Sensor detects an object.
False — The Distance Sensor does not detect an object.
<[FrontDistance v] found an object?>
Parameters |
Description |
|---|---|
distance sensor |
The Distance Sensor to use. Choose from the Distance Sensors available for Flex. |
Example
when started :: hat events
[Turn until something is detected, then release the Pin.]
turn [right v]
wait until <[FrontDistance v] found an object?>
stop driving
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
object distance#
The object distance reporter block reports the distance between the Distance Sensor and the nearest detected object.
([FrontDistance v] distance in [mm v])
Parameters |
Description |
|---|---|
distance sensor |
The Distance Sensor to use. Choose from the Distance Sensors available for Flex. |
unit |
The distance unit: mm or inches. |
Example
when started :: hat events
[Drive until 200 mm from the Goal, then release the Pin.]
drive [forward v]
wait until <([FrontDistance v] distance in [mm v]) < (200)>
stop driving
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
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:
|
units |
The unit to represent the position: mm or inches |
Example
when started :: hat events
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v]
wait until <([GPS v] position [X v] in [mm v]) > (-1370)>
stop driving
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
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
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
[Turn left to face the Neutral Goal.]
set turn velocity to (30) [% v]
turn [left v]
wait until <([GPS v] heading in degrees) < (18)>
stop driving