Robot-Specific Python#
Introduction#
The VIQRC 24-25 Rapid Relay Playground features methods exclusive to this Playground, including two motor options and the Intake Optical Sensor.
All standard VEXcode VR methods are available for use in the VIQRC 24-25 Rapid Relay Playground.
Below is a list of all available Playground-specific methods:
Motion - Move and track the robot’s motors.
Actions
spin- Spins the selected motor or motor group indefinitely.spin_for- Spins a motor or motor group for a specific distance in degrees or turns.spin_to_position- Spins a motor or motor group to a set position.stop- Stops a specific motor or motor group from spinning.
Mutators
set_position- Sets the encoder value of a motor or motor group.set_velocity- Sets the speed of a motor or motor group as a percentage.set_timeout- Limits how long a motor command waits before giving up if movement is blocked.
Getters
is_done- Returns a Boolean indicating whether the motor is no longer spinning.is_spinning- Returns a Boolean indicating whether the motor is currently spinning.position- Returns the motor’s current rotational position in degrees or turns.velocity- Returns the motor’s current velocity in percent.
Sensing - Utilize the robot’s various sensors.
Optical
is_near_object- Returns whether a detected object is near the Optical Sensor.color- Returns the color detected by the Optical Sensor.brightness- Returns the brightness percentage detected by the sensor.hue- Returns the hue value of the detected color.object_detected- Registers a callback function for when the Optical Sensor detects an object.object_lost- Registers a callback function for when the Optical Sensor loses an object.
The examples on this page use the default Playground start position.
Motion#
Actions#
spin#
spin spins a motor or motor group indefinitely.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The direction for the motor to spin:
|
def main():
# Spin the Intake Motor to bring a Ball onto the Catapult
intake_motor.spin(FORWARD)
wait(2, SECONDS)
intake_motor.stop()
# VR threads — Do not delete
vr_thread(main)
spin_for#
spin_for spins a motor or motor group for a given amount of degrees or turns.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The direction for the motor to spin:
|
|
The distance for the motor to spin as an integer. |
|
The unit that represents the distance to rotate:
|
|
Optional.
|
def main():
# Release the preloaded Ball
catapult_group.spin_for(REVERSE, 5, DEGREES)
# Lower the Catapult to prepare to load another Ball
catapult_group.spin_for(FORWARD, 1350, DEGREES)
# VR threads — Do not delete
vr_thread(main)
spin_to_position#
spin_to_position spins a motor or motor group to a given position.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The specific angle or number of turns that the motor will spin to. |
|
The unit that represents the angle to rotate to:
|
|
Optional.
|
def main():
# Release the preloaded Ball
catapult_group.spin_to_position(-90, DEGREES)
# Lower the Catapult to prepare to load another Ball
catapult_group.spin_to_position(1260, DEGREES)
# VR threads — Do not delete
vr_thread(main)
stop motor#
stop stops a motor or motor group from spinning.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
# Spin the Intake Motor to bring a Ball onto the Catapult
intake_motor.spin(FORWARD)
wait(2, SECONDS)
intake_motor.stop()
# VR threads — Do not delete
vr_thread(main)
Mutators#
set_position#
set_position sets a motor’s or motor group’s encoder position to the given position value.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The specific integer for the motor’s encoder to be set to. |
|
The unit that represents the angle to rotate to:
|
def main():
# Lower the Catapult to prepare to load another Ball
catapult_group.spin_to_position(1260, DEGREES)
# Set the new Catapult position to be 0 degrees
catapult_group.set_position(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
set_velocity#
set_velocity sets the speed of a motor or motor group.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The speed that the motor will spin at, ranging from -100 to 100. |
|
The unit that represents the new velocity:
|
def main():
# Start spinning the Intake Motor to prepare for picking up a Ball
intake_motor.set_velocity(100, PERCENT)
intake_motor.spin(FORWARD)
# VR threads — Do not delete
vr_thread(main)
set_timeout#
set_timeout sets a time limit for a motor’s or motor group’s movement commands. This prevents motion commands that do not reach their intended position from preventing subsequent commands from running.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The amount of time the motor will wait before stopping. |
|
The unit to represent the timeout:
|
def main():
# Limit how long the Catapult waits to reach its target
catapult_group.set_timeout(2, SECONDS)
catapult_group.spin_for(FORWARD, 6, TURNS)
# VR threads — Do not delete
vr_thread(main)
Getters#
is_done#
is_done returns a Boolean indicating whether the specified motor or motor group is not spinning.
True- The specified motor or motor group is not spinning.False- The specified motor or motor group is spinning.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
This method has no parameters. |
is_spinning#
is_spinning returns a Boolean indicating whether the specified motor or motor group is spinning.
True- The specified motor or motor group is spinning.False- The specified motor or motor group is not spinning.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
This method has no parameters. |
position#
position returns the total distance the specified motor or motor group has rotated.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The units that represent the motor’s position:
|
def main():
# Lower the Catapult to prepare to load another Ball
while not catapult_group.position(DEGREES) == 1260:
catapult_group.spin(FORWARD)
# VR threads — Do not delete
vr_thread(main)
velocity#
velocity returns the current rotational speed of the motor or motor group.
Usage:
One of two available motor objects can be used with this method, as shown below:
motor |
Command |
|---|---|
|
|
|
|
Parameters |
Description |
|---|---|
|
The unit that represents the motor’s velocity:
|
def main():
# Print the current Catapult velocity
brain.screen.print(catapult_group.velocity(PERCENT))
# VR threads — Do not delete
vr_thread(main)
Sensing#
Optical#
is_near_object#
is_near_object returns a Boolean indicating whether or not the Optical Sensor detects an object close to the sensor.
True- The object is close to the Optical Sensor.False- The object is not close to the Optical Sensor.
Usage:
intake_optical.is_near_object()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
# Launch a loaded Ball once the Intake Optical Sensor detects a Ball
if intake_optical.is_near_object():
catapult_group.spin_for(REVERSE, 5, DEGREES)
# VR threads — Do not delete
vr_thread(main)
color#
color returns the color detected by the Optical Sensor:
Color Returned: |
|---|
|
Usage:
intake_optical.color()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
# Launch a loaded Ball once yellow is detected in the Intake
if intake_optical.color() == YELLOW:
catapult_group.spin_for(REVERSE, 5, DEGREES)
# VR threads — Do not delete
vr_thread(main)
brightness#
brightness returns the brightness value detected by the Optical Sensor as a percent from 0% to 100%.
Usage:
intake_optical.brightness()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
# Launch a loaded Ball once the Intake Optical Sensor sees a Ball
if intake_optical.brightness() > 0:
catapult_group.spin_for(REVERSE, 5, DEGREES)
# VR threads — Do not delete
vr_thread(main)
hue#
hue returns the hue detected by the Optical Sensor.
Hue values range from 0 to 359 degrees, corresponding to positions on the color wheel shown below.

Usage:
intake_optical.hue()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
# Launch a loaded Ball once the Intake Optical Sensor reports a hue value
if intake_optical.hue() > 100:
catapult_group.spin_for(REVERSE, 5, DEGREES)
# VR threads — Do not delete
vr_thread(main)
object_detected#
object_detected registers a callback function for when the Optical Sensor detects an object.
Usage:
intake_optical.object_detected(callback, arg)
Parameters |
Description |
|---|---|
|
A function that will be called when an object is detected. |
|
Optional. A tuple that is used to pass arguments to the callback function. |
def launch_ball():
catapult_group.spin_for(REVERSE, 5, DEGREES)
def main():
# Launch the Ball when the Intake Optical Sensor detects an object
intake_optical.object_detected(launch_ball)
# VR threads — Do not delete
vr_thread(main)
object_lost#
object_lost registers a callback function for when the Optical Sensor loses an object.
Usage:
intake_optical.object_lost(callback, arg)
Parameters |
Description |
|---|---|
|
A function that will be called when an object is lost. |
|
Optional. A tuple that is used to pass arguments to the callback function. |
def lower_catapult():
catapult_group.spin_to_position(1260, DEGREES)
def main():
# Lower the Catapult when the Intake Optical Sensor no longer detects an object
intake_optical.object_lost(lower_catapult)
# VR threads — Do not delete
vr_thread(main)