Robot Specific Python#
All standard VEXcode VR commands are available for use in the VIQRC Virtual Skills - Rapid Relay Playground.
Motion#
motor.spin()#
The motor.spin(direction)
command is used to spin a motor indefinitely.
This is a non-waiting command and allows any subsequent commands to execute without delay.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.spin(direction)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
direction |
The direction for the motor to move in: |
Returns: None.
# Spin the Intake Motor to bring a Ball onto the Catapult.
intake_motor.spin(FORWARD)
wait(2, SECONDS)
intake_motor.stop
motor.spin_for()#
The motor.spin_for(direction, distance, units, wait)
command is used to spin a motor for a given amount of degrees or turns.
This is can be a non-waiting or waiting command depending on if the wait
parameter is used.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.spin_for(direction, distance, units, wait)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
direction |
The direction for the motor to move in: |
distance |
The distance for the motor to move as an integer. |
units |
The units that the motor will use: |
wait |
Optional. The wait parameter determines whether the command will block subsequent commands ( |
Returns: None.
# Launch the Ball currently loaded on the Catapult.
catapult_group.spin_for(REVERSE, 5, DEGREES)
# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_for(FORWARD, 1350, DEGREES)
motor.spin_to_position()#
The motor.spin_to(angle, units, wait)
command is used to spin a motor to a given position.
This is can be a non-waiting or waiting command depending on if the wait
parameter is used.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.spin_for(angle, units, wait)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
angle |
The specific angle or number of turns that the motor will spin to. |
units |
The units that the motor will use: |
wait |
Optional. The wait parameter determines whether the command will block subsequent commands ( |
Returns: None.
# Launch the Ball currently loaded on the Catapult.
catapult_group.spin_to_position(-90, DEGREES)
# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_to_position(1260, DEGREES)
motor.stop()#
The motor.stop()
command is used to stop a motor.
This is a non-waiting command and allows any subsequent commands to execute without delay.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.stop()
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Returns: None.
# Spin the Intake Motor to bring a Ball onto the Catapult.
intake_motor.spin(FORWARD)
wait(2, SECONDS)
intake_motor.stop
motor.set_position()#
The motor.set_position(position, units)
command is used to set a motor’s encoder position to the given position value.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.set_position(position, units)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
position |
The specific integer for the Motor’s encoder to be set to. |
units |
The units for the motor to use: |
Returns: None.
# Launch the Ball currently loaded on the Catapult.
catapult_group.spin_for(REVERSE, 5, DEGREES)
# 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)
motor.set_velocity()#
The motor.set_velocity(velocity, units)
command is used to set the speed of a motor.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.set_velocity(velocity, units)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
velocity |
The speed that the Motor will spin at, ranging from -100 to 100. |
units |
The unit for the Motor’s velocity, |
Returns: None.
# Start spinning the Intake Motor to prepare
# for picking up a Ball.
intake_motor.set_velocity(100, PERCENT)
intake_motor.spin(FORWARD)
motor.set_timeout()#
The motor.set_timeout(value, units)
command is used to set a time limit for a motor’s movement commands.
This prevents motion commands that do not reach their intended position from preventing subsequent commands from running.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.set_timeout(value, units)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
value |
The amount of time the motor will wait before stopping. |
units |
The unit for the Motor’s timer, |
Returns: None.
catapult_group.set_timeout(2, SECONDS)
# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_for(6, TURNS)
Events#
intake_optical.object_detected()#
intake_optical.object_detected(callback)
is the same command as eye.object_detected(callback)
.
The command only uses Swish’s Optical Sensor intake_optical
to replace eye
in the standard command.
intake_optical.object_lost()#
intake_optical.object_lost(callback)
is the same command as eye.object_lost(callback)
.
The command only uses Swish’s Optical Sensor intake_optical
to replace eye
in the standard command.
Sensing#
motor.is_done()#
The motor.is_done()
command is used to return a True or False value if the selected motor has completed its movement.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.is_done()
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Returns: This returns a Boolean value.
motor.is_spinning()#
The motor.is_spinning()
command is used to return a True or False value if the selected motor is moving.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.is_spinning()
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Returns: This returns a Boolean value.
motor.position()#
The motor.position(units)
command is used to return the current rotational position of the selected motor.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.position(units)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
units |
The unit of the returned value, |
Returns: This returns a numerical value.
# Lower the Catapult to prepare to load another Ball.
while not catapult_group.position(DEGREES) == 1260:
catapult_group.spin(FORWARD)
motor.velocity()#
The motor.velocity(units)
command is used to return the current velocity of the selected motor.
To use this command, replace motor
with the desired motor or motor group, for example: intake_motor.velocity(units)
.
Objects |
Description |
---|---|
|
Spins Swish’s Intake to collect Balls and put them on its catapult. |
|
Raises or lowers Swish’s catapult to launch Balls. |
Parameters |
Description |
---|---|
units |
The unit of the motor’s velocity, |
Returns: This returns a numerical value.
brain.screen.print(catapult_group.velocity(PERCENT))
intake_optical.is_near_object()#
The intake_optical.near_object()
command is used to report a Boolean value if the Optical Sensor is close enough to a Ball to detect it.
This is a non-waiting command and allows any subsequent commands to execute without delay.
Returns: This reports a Boolean value.
# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.is_near_object():
catapult_group.spin_for(REVERSE, 5, DEGREES)
intake_optical.color()#
The intake_optical.color()
command is used to return the color detected by the Intake Optical Sensor.
The following colors can be used as a comparison to the color detected:
RED
GREEN
BLUE
YELLOW
ORANGE
PURPLE
CYAN
Returns: This returns the name of the detected color as a string.
# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.color() == YELLOW:
catapult_group.spin_for(REVERSE, 5, DEGREES)
intake_optical.brightness()#
The intake_optical.brightness()
command is used to report the amount of light detected by an Optical Sensor within a range of 0 to 100 percent.
Returns: This returns a numeric value.
# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.brightness() > 0:
catapult_group.spin_for(REVERSE, 5, DEGREES)
intake_optical.hue()#
The intake_optical.brightness()
command is used to report the hue of the object detected by an Optical Sensor within a range of 0 to 359. This number represents the location of the detected color on a color wheel.
Returns: This returns a numeric value.
# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.hue() > 100:
catapult_group.spin_for(REVERSE, 5, DEGREES)