Robot-Specific Python#
Introduction#
The V5RC 22-23 Spin Up Playground features methods exclusive to the build designed for this Playground, including a motor group, Line Tracker, Optical Sensor, and Game Positioning System (GPS) Sensor.
All standard VEXcode VR methods are available for use in the V5RC 22-23 Spin Up 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 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 block 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 % or rpm.
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 from 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.
GPS
x_position– Returns the current x coordinate of a GPS Sensor on the field.y_position– Returns the current y coordinate of a GPS Sensor on the field.heading– Returns the heading that the robot is currently facing based on the GPS Sensor’s readings from 0 to 359 degrees.
Line Tracker
reflectivity– Returns the amount of light reflected from the surface.
The examples on this page use the default Playground start position.
Motion#
Actions#
spin#
spin spins a motor or motor group in the specified direction indefinitely.
Usage:
intake_motor_group.spin(direction)
Parameters |
Description |
|---|---|
|
The direction for the motor group to spin:
|
def main():
# Spin the intake forward then stop
intake_motor_group.spin(FORWARD)
wait(0.5, SECONDS)
intake_motor_group.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:
intake_motor_group.spin_for(direction, distance, units, wait)
Parameters |
Description |
|---|---|
|
The direction for the motor group to spin:
|
|
The distance for the motor group to spin as an integer. |
|
The unit that represents the distance to rotate:
|
|
Optional.
|
def main():
# Spin the intake forward then stop
intake_motor_group.spin_for(FORWARD, 1, TURNS)
# VR threads — Do not delete
vr_thread(main)
spin_to_position#
spin_to spins a motor or motor group to a given position.
Usage:
intake_motor_group.spin_to_position(angle, units, wait)
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():
# Spin the intake forward then stop
intake_motor_group.spin_to_position(55, DEGREES)
# VR threads — Do not delete
vr_thread(main)
stop#
stop stops a motor or motor group from spinning.
Usage:
intake_motor_group.stop()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
# Spin the intake forward then stop
intake_motor_group.spin(FORWARD)
wait(0.5, SECONDS)
intake_motor_group.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:
intake_motor_group.set_position(position, units)
Parameters |
Description |
|---|---|
|
The specific integer for the motor group’s encoders to be set to. |
|
The unit that represents the angle to rotate to:
|
def main():
# Spin the intake forward then stop
intake_motor_group.set_position(90, DEGREES)
intake_motor_group.spin_to_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:
intake_motor_group.set_velocity(velocity, units)
Parameters |
Description |
|---|---|
|
The speed that the motor group will spin at, ranging from 0 to 100. |
|
The unit that represents the new velocity:
|
def main():
# Spin the intake forward then stop
intake_motor_group.set_velocity(75, PERCENT)
intake_motor_group.spin_to_position(180, DEGREES)
# 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:
intake_motor_group.set_timeout(value, units)
Parameters |
Description |
|---|---|
|
The amount of time the motor group will wait before stopping. |
|
The unit to represent the timeout:
|
def main():
# Spin the intake forward then stop
intake_motor_group.set_timeout(2, SECONDS)
intake_motor_group.spin_to_position(270, DEGREES)
# 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 is not spinning.False– The specified motor is spinning.
Usage:
intake_motor_group.is_done()
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 is spinning.False– The specified motor is not spinning.
Usage:
intake_motor_group.is_spinning()
Parameters |
Description |
|---|---|
This method has no parameters. |
position#
position returns the total distance the specified motor or motor group has rotated.
Usage:
intake_motor_group.position(units)
Parameters |
Description |
|---|---|
|
The units that represent the motor’s position:
|
velocity#
velocity returns the current rotational speed of the motor or motor group.
Usage:
intake_motor_group.velocity(units)
Parameters |
Description |
|---|---|
|
The unit that represent the motor’s position:
|
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:
roller_optical.is_near_object()
Parameters |
Description |
|---|---|
This method has no parameters. |
color#
color returns the color detected by the Optical Sensor:
Color Returned: |
|---|
|
Usage:
roller_optical.color()
Parameters |
Description |
|---|---|
This method has no parameters. |
brightness#
brightness returns the brightness value detected by the Optical Sensor as a percent from 0% to 100%.
Usage:
roller_optical.brightness()
Parameters |
Description |
|---|---|
This method has no parameters. |
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:
roller_optical.hue()
Parameters |
Description |
|---|---|
This method has no parameters. |
object_detected#
object_detected registers a callback function for when the Optical Sensor detects an object.
Usage:
roller_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. |
object_lost#
object_lost registers a callback function for when the Optical Sensor loses a previously detected object.
Usage:
roller_optical.object_lost(callback, arg)
Parameters |
Description |
|---|---|
|
A function that will be called when a detected object is lost. |
|
Optional. A tuple that is used to pass arguments to the callback function. |
GPS#
x_position#
x_position returns the current x coordinate of a GPS (Game Positioning System™) Sensor on the field.
Usage:
gps.x_position(units)
Parameters |
Description |
|---|---|
units |
The unit of the offset value:
|
y_position#
y_position returns the current y coordinate of a GPS (Game Positioning System™) Sensor on the field.
Usage:
gps.y_position(units)
Parameters |
Description |
|---|---|
units |
The unit of the offset value:
|
heading#
heading returns the heading that the robot is currently facing based on the GPS (Game Positioning System™) Sensor’s readings from 0 to 359 degrees.
Usage:
gps.heading()
Parameters |
Description |
|---|---|
This method has no parameters. |
Line Tracker#
reflectivity#
reflectivity returns the amount of light reflected from the surface as a percent.
Usage:
One of three available line_tracker objects can be used with this method, as shown below:
line_tracker |
Command |
|---|---|
|
|
|
|
|
|
Parameter |
Description |
|---|---|
units |
Optional. The unit to return the reflectivity with:
|