Robot-Specific Python#
Introduction#
The VR Rover Robot includes a Drivetrain, Distance Sensor and actions unique to the Rover Rescue Playground.
All standard VEXcode VR methods are available for use in the Rover Rescue Playground. Below is a list of all available Playground-specific methods:
Drivetrain - Move and monitor the VR Rover.
Actions
drive- Moves the VR Rover forward or reverse forever.drive_for- Moves the VR Rover forward or reverse for a specific distance.turn- Turns the VR Rover left or right forever.turn_for- Turns the VR Rover left or right for a specific number of degrees.turn_to_heading- Turns the VR Rover to face a specific heading from -359 to 359 degrees.drive_to- Drives the VR Rover straight toward the selected object.turn_to- Turns the VR Rover to face the selected object.go_to- Turns and drives the VR Rover to the selected object.stop- Stops the VR Rover’s movement.
Mutators
set_heading– Changes the VR Rover’s current heading to a new heading.set_timeout- Sets how much time the VR Rover will try to finish a movement.set_drive_velocity– Tells the VR Rover how fast to drive.set_turn_velocity– Tells the VR Rover how fast to turn.
Getters
Sensing - Detect nearby objects with the rover’s Distance Sensor.
Distance
found_object- Returns whether the Distance Sensor detects an object.get_distance- Returns the distance to the nearest detected object.
Actions - Interact with the rover’s resources, enemies, and built-in AI systems.
Actions
pickup- Picks up minerals.drop- Drops minerals.use- Uses minerals to restore energy.absorb_radiation- Absorbs radiation from an enemy.standby- Puts the VR Rover into standby mode until a battery threshold is reached.
Getters
angle- Returns the direction to an object in degrees.get_distance- Returns the distance to an object in millimeters or inches.location- Returns the X or Y coordinate of an object in millimeters or inches.battery- Returns the VR Rover’s battery level.minerals_stored- Returns how many minerals the VR Rover is carrying.storage_capacity- Returns the VR Rover’s carrying capacity.level- Returns the VR Rover’s current level.exp- Returns the VR Rover’s current experience points.enemy_level- Returns the level of the closest detected enemy.enemy_radiation- Returns the radiation of the closest detected enemy.detects- Returns whether the VR Rover detects minerals or enemies in its detect radius.sees- Returns whether the VR Rover sees an object in its vision range.under_attack- Returns whether the VR Rover is currently under attack.
Callbacks
on_under_attack- Runs a callback when the VR Rover is attacked.on_level_up- Runs a callback when the VR Rover levels up.
The examples on this page use the default Playground start position.
Drivetrain#
The drivetrain controls how the VR Rover drives and turns. The drivetrain can move forward or reverse, turn left or right, turn to headings, and drive toward minerals, enemies, or the base.
Actions#
drive#
drive moves the VR Rover forward or reverse forever. The VR Rover will continue to move until it is given another action, like turning or stopping.
Usage:
drivetrain.drive(direction)
Parameters |
Description |
|---|---|
|
The direction the VR Rover moves: |
def main():
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
drive_for#
drive_for moves the VR Rover forward or reverse for a specific distance. The project will wait until the VR Rover is done moving before the next line of code runs.
Usage:
drivetrain.drive_for(direction, distance, units, wait=True)
Parameters |
Description |
|---|---|
|
The direction the VR Rover moves: |
|
The distance the VR Rover drives. This can be an |
|
The distance unit: |
|
Optional. |
def main():
drivetrain.drive_for(FORWARD, 200, MM)
# VR threads — Do not delete
vr_thread(main)
turn#
turn turns the VR Rover left or right forever. The VR Rover will continue to turn until it is given another action, like driving or stopping.
Usage:
drivetrain.turn(direction)
Parameters |
Description |
|---|---|
|
The direction the VR Rover turns: |
def main():
drivetrain.turn(RIGHT)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
turn_for#
turn_for turns the VR Rover left or right for a specific number of degrees. The turn is relative to the current position of the VR Rover. The project will wait until the VR Rover is done turning before the next line of code runs.
Usage:
drivetrain.turn_for(direction, angle, units, wait=True)
Parameters |
Description |
|---|---|
|
The direction the VR Rover turns: |
|
The number of degrees the VR Rover turns. This can be an |
|
The rotation unit: |
|
Optional. |
def main():
drivetrain.turn_for(RIGHT, 90, DEGREES)
# VR threads — Do not delete
vr_thread(main)
turn_to_heading#
A heading is the direction the VR Rover is facing, measured in degrees. turn_to_heading turns the VR Rover to face a specific heading from -359 to 359 degrees. The VR Rover will turn the shortest direction to reach the target heading.
The VR Rover’s starting heading is 0 degrees.
The project will wait until the VR Rover is done turning before the next line of code runs.
Usage:
drivetrain.turn_to_heading(heading, units, wait=True)
Parameters |
Description |
|---|---|
|
The direction the VR Rover should face, in degrees. This can be an |
|
The heading unit: |
|
Optional. |
def main():
drivetrain.turn_to_heading(90, DEGREES)
# VR threads — Do not delete
vr_thread(main)
drive_to#
drive_to drives the VR Rover straight toward the selected object.
Usage:
drivetrain.drive_to(object, wait=True)
Parameters |
Description |
|---|---|
|
Which object the VR Rover will drive to:
|
|
Optional. |
If a mineral or enemy is not detected in the VR Rover’s visual range when drive_to is called, the VR Rover will not drive. The base can always be targeted.
If the VR Rover detects multiple minerals or multiple enemies, it will drive toward the closer option.
def main():
drivetrain.drive_to(MINERALS)
# VR threads — Do not delete
vr_thread(main)
turn_to#
turn_to turns the VR Rover to face the selected object.
Usage:
drivetrain.turn_to(object, wait=True)
Parameters |
Description |
|---|---|
|
Which object the VR Rover will turn toward:
|
|
Optional.
|
If a mineral or enemy is not detected in the VR Rover’s visual range when turn_to is called, the VR Rover will not turn. The base can always be targeted.
If the VR Rover detects multiple minerals or multiple enemies, it will turn toward the closer option.
def main():
drivetrain.turn_to(MINERALS)
# VR threads — Do not delete
vr_thread(main)
go_to#
go_to turns and drives the VR Rover to the selected object.
Usage:
drivetrain.go_to(object, wait=True)
Parameters |
Description |
|---|---|
|
Which object the VR Rover will turn and drive to:
|
|
Optional. |
If a mineral or enemy is not detected in the VR Rover’s visual range when go_to is called, the VR Rover will not drive. The base can always be targeted.
If the VR Rover detects multiple minerals or multiple enemies, it will move to the closer option.
def main():
drivetrain.go_to(MINERALS)
# VR threads — Do not delete
vr_thread(main)
stop#
stop stops the VR Rover’s movement.
Usage:
drivetrain.stop()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
Mutators#
set_heading#
A heading is the direction the VR Rover is facing, measured in degrees. set_heading changes the VR Rover’s current heading to a new heading value.
For example, if the VR Rover has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the VR Rover can turn to other positions based on that new heading.
Usage:
drivetrain.set_heading(heading, units)
Parameters |
Description |
|---|---|
|
The heading value, in degrees, to set for the VR Rover. This can be an |
|
The heading unit: |
def main():
drivetrain.set_heading(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
set_timeout#
set_timeout sets how much time the VR Rover will try to finish a movement. If the VR Rover cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the VR Rover from getting stuck on a movement.
Usage:
drivetrain.set_timeout(value, units)
Parameters |
Description |
|---|---|
|
The amount of time the VR Rover can try to finish a movement. This can be a positive |
|
The time unit: |
def main():
drivetrain.set_timeout(1, SECONDS)
# VR threads — Do not delete
vr_thread(main)
set_drive_velocity#
set_drive_velocity tells the VR Rover how fast to drive. A higher percentage makes the VR Rover drive faster and a lower percentage makes the VR Rover drive slower.
Every project begins with the VR Rover driving at 50% velocity by default.
Note: A higher velocity makes the VR Rover drive faster, but it may be less precise. A lower velocity makes the VR Rover drive slower, but it can be more precise.
Usage:
drivetrain.set_drive_velocity(velocity, units)
Parameters |
Description |
|---|---|
|
The velocity to drive with from 0% to 100%. This can be an |
|
The velocity unit: |
def main():
drivetrain.set_drive_velocity(50, PERCENT)
# VR threads — Do not delete
vr_thread(main)
set_turn_velocity#
set_turn_velocity tells the VR Rover how fast to turn. A higher percentage makes the VR Rover turn faster and a lower percentage makes the VR Rover turn slower.
Every project begins with the VR Rover turning at 50% velocity by default.
Note: A higher velocity makes the VR Rover turn faster, but it may be less precise. A lower velocity makes the VR Rover turn slower, but it can be more precise.
Usage:
drivetrain.set_turn_velocity(velocity, units)
Parameters |
Description |
|---|---|
|
The velocity to turn with from 0% to 100%. This can be an |
|
The velocity unit: |
def main():
drivetrain.set_turn_velocity(50, PERCENT)
# VR threads — Do not delete
vr_thread(main)
Getters#
heading#
A heading is the direction the VR Rover is facing, measured in degrees. heading returns the VR Rover’s current heading from 0 to 359.99 degrees.
The VR Rover’s starting heading is 0 degrees.
Usage:
drivetrain.heading(units)
Parameters |
Description |
|---|---|
|
The heading unit: |
def main():
brain.screen.print(drivetrain.heading(DEGREES))
# VR threads — Do not delete
vr_thread(main)
is_done#
is_done returns whether the VR Rover is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the VR Rover’s movement.
True— The VR Rover is finished moving.False— The VR Rover is still moving.
This method works together with Drivetrain methods that have the wait parameter, such as drive_for, turn_for, turn_to_heading, drive_to, turn_to, and go_to.
Usage:
drivetrain.is_done()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
drivetrain.drive_for(FORWARD, 200, MM, wait=False)
wait(0.1, SECONDS)
if drivetrain.is_done():
brain.screen.print("Drive complete")
# VR threads — Do not delete
vr_thread(main)
is_moving#
is_moving returns whether the VR Rover is moving, as a Boolean value. This can be used to control the timing of other behaviors based on the VR Rover’s movement.
True— The VR Rover is moving.False— The VR Rover is not moving.
Usage:
drivetrain.is_moving()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
drivetrain.drive_for(FORWARD, 200, MM, wait=False)
wait(0.1, SECONDS)
if drivetrain.is_moving():
brain.screen.print("Still moving")
# VR threads — Do not delete
vr_thread(main)
Sensing#
Distance#
found_object#
found_object returns whether the Distance Sensor detects an object.
Usage:
distance.found_object()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
if distance.found_object():
brain.screen.print("Object detected")
# VR threads — Do not delete
vr_thread(main)
get_distance#
get_distance returns the distance to the nearest detected object from the Distance Sensor.
Usage:
distance.get_distance(units)
Parameters |
Description |
|---|---|
|
The distance unit: |
def main():
brain.screen.print(distance.get_distance(MM))
# VR threads — Do not delete
vr_thread(main)
Actions#
Actions#
pickup#
pickup picks up minerals.
Usage:
rover.pickup(object)
Parameters |
Description |
|---|---|
|
The object the VR Rover can pick up:
|
def main():
rover.pickup(MINERALS)
# VR threads — Do not delete
vr_thread(main)
drop#
drop drops carried minerals.
Usage:
rover.drop(object)
Parameters |
Description |
|---|---|
|
The object the VR Rover can drop:
|
def main():
rover.drop(MINERALS)
# VR threads — Do not delete
vr_thread(main)
use#
use uses minerals to restore energy. Minerals must be on the ground to be used.
Usage:
rover.use(object)
Parameters |
Description |
|---|---|
|
The object the VR Rover can use:
|
def main():
rover.use(MINERALS)
# VR threads — Do not delete
vr_thread(main)
absorb_radiation#
absorb_radiation absorbs radiation from an enemy.
Usage:
rover.absorb_radiation(object)
Parameters |
Description |
|---|---|
|
The object the VR Rover can absorb radiation from:
|
def main():
rover.absorb_radiation(ENEMY)
# VR threads — Do not delete
vr_thread(main)
standby#
standby puts the VR Rover into standby mode until the specified battery threshold is reached.
Usage:
rover.standby(percent)
Parameters |
Description |
|---|---|
|
The battery threshold that causes the VR Rover to exit standby mode, from |
If the selected threshold is equal to or above the current battery level, the VR Rover will not enter standby mode.
def main():
rover.standby(50)
# VR threads — Do not delete
vr_thread(main)
Getters#
angle#
angle returns the direction in degrees to the selected object.
Usage:
rover.angle(object)
Parameters |
Description |
|---|---|
|
The object to report the direction of:
|
For minerals and enemies, the object must be within 1000 mm and in the VR Rover’s field of view. The base can always be reported.
def main():
brain.screen.print(rover.angle(MINERALS))
# VR threads — Do not delete
vr_thread(main)
get_distance#
get_distance returns the distance from the VR Rover to the selected object.
Usage:
rover.get_distance(object, units=MM)
Parameters |
Description |
|---|---|
|
The object to report distance to:
|
|
Optional. The unit used to report the distance: |
For minerals and enemies, the object must be within 1000 mm and in the VR Rover’s field of view. The base can always be reported.
For obstacles and hazards, the method reports the visible object distance. If none is in view, it returns 1000 mm or 39.37 inches.
def main():
brain.screen.print(rover.get_distance(MINERALS, MM))
# VR threads — Do not delete
vr_thread(main)
location#
location returns the X or Y coordinate location of the selected object.
Usage:
rover.location(object, axis, units)
Parameters |
Description |
|---|---|
|
The object to report the location of:
|
|
Which coordinate to return:
|
|
The unit used to report the location: |
For minerals and enemies, the object must be within 1000 mm and in the VR Rover’s field of view. The base can always be reported.
def main():
brain.screen.print(rover.location(MINERALS, X, MM))
# VR threads — Do not delete
vr_thread(main)
battery#
battery returns the current battery level of the VR Rover.
Usage:
rover.battery()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
brain.screen.print(rover.battery())
# VR threads — Do not delete
vr_thread(main)
minerals_stored#
minerals_stored returns the current amount of minerals the VR Rover has in storage.
Usage:
rover.minerals_stored()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
brain.screen.print(rover.minerals_stored())
# VR threads — Do not delete
vr_thread(main)
storage_capacity#
storage_capacity returns the carrying capacity of the VR Rover.
Usage:
rover.storage_capacity()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
brain.screen.print(rover.storage_capacity())
# VR threads — Do not delete
vr_thread(main)
level#
level returns the current level of the VR Rover.
Usage:
rover.level()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
brain.screen.print(rover.level())
# VR threads — Do not delete
vr_thread(main)
exp#
exp returns the number of Experience Points the VR Rover has at the current level.
Usage:
rover.exp()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
brain.screen.print(rover.exp())
# VR threads — Do not delete
vr_thread(main)
enemy_level#
enemy_level returns the level of the closest enemy detected by the VR Rover.
Usage:
rover.enemy_level()
Parameters |
Description |
|---|---|
This method has no parameters. |
When no enemy is detected within the rover’s detect radius, this method returns 0.
def main():
brain.screen.print(rover.enemy_level())
# VR threads — Do not delete
vr_thread(main)
enemy_radiation#
enemy_radiation returns the radiation of the closest enemy detected by the VR Rover.
Usage:
rover.enemy_radiation()
Parameters |
Description |
|---|---|
This method has no parameters. |
When no enemy is detected within the rover’s detect radius, this method returns 0.
def main():
brain.screen.print(rover.enemy_radiation())
# VR threads — Do not delete
vr_thread(main)
detects#
detects returns whether the VR Rover detects minerals or enemies in its detect radius.
Usage:
rover.detects(object)
Parameters |
Description |
|---|---|
|
The object to detect:
|
The VR Rover’s detect radius is 800 mm.
def main():
if rover.detects(MINERALS):
brain.screen.print("Minerals detected")
# VR threads — Do not delete
vr_thread(main)
sees#
sees returns whether the VR Rover sees the selected object in its vision range.
Usage:
rover.sees(object)
Parameters |
Description |
|---|---|
|
The object to see:
|
The VR Rover can see objects within 1000 mm and inside its 40 degree field of view.
def main():
if rover.sees(MINERALS):
brain.screen.print("Minerals in view")
# VR threads — Do not delete
vr_thread(main)
under_attack#
under_attack returns whether the VR Rover is currently under attack from an enemy.
Usage:
rover.under_attack()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
if rover.under_attack():
brain.screen.print("The rover is under attack!")
# VR threads — Do not delete
vr_thread(main)
Callbacks#
on_under_attack#
on_under_attack registers a callback function that runs when the VR Rover takes damage from an enemy.
Usage:
rover.on_under_attack(callback)
Parameters |
Description |
|---|---|
|
The function to run when the VR Rover is under attack. |
def under_attack():
brain.screen.print("The rover is under attack!")
def main():
rover.on_under_attack(under_attack)
wait(0.15, SECONDS)
# VR threads — Do not delete
vr_thread(main)
on_level_up#
on_level_up registers a callback function that runs when the VR Rover moves from one level to the next.
Usage:
rover.on_level_up(callback)
Parameters |
Description |
|---|---|
|
The function to run when the VR Rover levels up. |
def level_up():
brain.screen.print("The rover leveled up!")
def main():
rover.on_level_up(level_up)
wait(0.15, SECONDS)
# VR threads — Do not delete
vr_thread(main)