Python específico para robots#

Introducción#

El entorno de entrenamiento Rover Rescue incluye métodos exclusivos para el VR Rover, como métodos personalizados de las categorías Tren motriz, Detección y Acciones.

El VR Rover tiene acceso a los comandos estándar de Eventos, Control, Variables y Funciones de VR.

A continuación se muestra una lista de todos los métodos disponibles específicos de Playground:

Sistema de transmisión: Mueva y supervise el VR Rover.

  • Comportamiento

    • drive - Drives the VR Rover continuously forward or in reverse.

    • drive_for - Drives the VR Rover for a set distance.

    • turn - Turns the VR Rover continuously left or right.

    • turn_for - Turns the VR Rover a specific number of degrees.

    • turn_to_heading - Turns the VR Rover to face a specific heading.

    • 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 all rover movement.

  • Mutadores

  • Obtenidos

    • heading - Returns the drivetrain’s current heading.

    • is_done - Returns whether the drivetrain is no longer moving.

    • is_moving - Returns whether the drivetrain is currently moving.

Detección: Detecta objetos cercanos con el sensor de distancia del rover.

  • Distancia

    • found_object - Returns whether the Distance Sensor detects an object.

    • get_distance - Returns the distance to the nearest detected object.

Acciones: Interactúa con los recursos, los enemigos y los sistemas de IA integrados del vehículo explorador.

  • Comportamiento

    • 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.

  • Obtenidos

    • 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.

  • Llamadas de retorno

Los ejemplos de esta página utilizan la posición de inicio predeterminada del Playground.

Tren de transmisión#

Comportamiento#

conducir#

drive drives the VR Rover continuously forward or in reverse.

Usage:
drivetrain.drive(direction)

Parámetros

Descripción

direction

The direction the robot drives:

  • FORWARD
  • REVERSE

def main():
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

impulso_por#

drive_for drives the VR Rover for a set distance.

Usage:
drivetrain.drive_for(direction, distance, units, wait=True)

Parámetros

Descripción

direction

The direction the robot drives:

  • FORWARD
  • REVERSE

distance

La distancia a recorrer, como número entero o decimal.

units

The unit of measurement:

  • INCHES
  • MM

wait

Optional.

  • wait=True (default) - Wait for the motion to finish.
  • wait=False - Start the motion and continue immediately.

def main():
    drivetrain.drive_for(FORWARD, 200, MM)

# VR threads — Do not delete
vr_thread(main)

doblar#

turn turns the VR Rover continuously left or right.

Usage:
drivetrain.turn(direction)

Parámetros

Descripción

direction

The direction the robot turns:

  • LEFT
  • RIGHT

def main():
    drivetrain.turn(RIGHT)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

turno_para#

turn_for turns the VR Rover a specific number of degrees.

Usage:
drivetrain.turn_for(direction, angle, units, wait=True)

Parámetros

Descripción

direction

The direction the robot turns:

  • LEFT
  • RIGHT

angle

La cantidad a girar, como un número entero o decimal.

units

The unit of measurement. In this Playground, use DEGREES.

wait

Optional.

  • wait=True (default) - Wait for the motion to finish.
  • wait=False - Start the motion and continue immediately.

def main():
    drivetrain.turn_for(RIGHT, 90, DEGREES)

# VR threads — Do not delete
vr_thread(main)

girar_hacia_rumbo#

turn_to_heading turns the VR Rover to face a specific heading.

Usage:
drivetrain.turn_to_heading(heading, units, wait=True)

Parámetros

Descripción

heading

El rumbo a seguir, de -360 a 360.

units

The unit of measurement. In this Playground, use DEGREES.

wait

Optional.

  • wait=True (default) - Wait for the motion to finish.
  • wait=False - Start the motion and continue immediately.

def main():
    drivetrain.turn_to_heading(90, DEGREES)

# VR threads — Do not delete
vr_thread(main)

conducir_a#

drive_to drives the VR Rover straight toward the selected object.

Usage:
drivetrain.drive_to(object, wait=True)

Parámetros

Descripción

object

Which object the VR Rover will drive to:

  • BASE
  • ENEMY
  • MINERALS

wait

Optional.

  • wait=True (default) - Wait for the motion to finish.
  • wait=False - Start the motion and continue immediately.

If a mineral or enemy is not detected in the VR Rover’s visual range when drive_to is called, the rover will not drive. The base can always be targeted.

def main():
    drivetrain.drive_to(MINERALS)

# VR threads — Do not delete
vr_thread(main)

girar_a#

turn_to turns the VR Rover to face the selected object.

Usage:
drivetrain.turn_to(object, wait=True)

Parámetros

Descripción

object

Which object the VR Rover will turn toward:

  • BASE
  • ENEMY
  • MINERALS

wait

Optional.

  • wait=True (default) - Wait for the turn to finish.
  • wait=False - Start the turn and continue immediately.

If a mineral or enemy is not detected in the VR Rover’s visual range when turn_to is called, the rover will not turn. The base can always be targeted.

def main():
    drivetrain.turn_to(MINERALS)

# VR threads — Do not delete
vr_thread(main)

ir a#

go_to turns and drives the VR Rover to the selected object.

Usage:
drivetrain.go_to(object, wait=True)

Parámetros

Descripción

object

Which object the VR Rover will turn and drive to:

  • BASE
  • ENEMY
  • MINERALS

wait

Optional.

  • wait=True (default) - Wait for the movement to finish.
  • wait=False - Start the movement and continue immediately.

If a mineral or enemy is not detected in the VR Rover’s visual range when go_to is called, the rover will not drive. The base can always be targeted.

def main():
    drivetrain.go_to(MINERALS)

# VR threads — Do not delete
vr_thread(main)

detener#

stop stops all movement of the drivetrain.

Usage:
drivetrain.stop()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

Mutadores#

establecer_encabezado#

set_heading sets the rover’s current heading value.

Usage:
drivetrain.set_heading(heading, units)

Parámetros

Descripción

heading

El valor del encabezado que se asignará.

units

The unit of measurement. In this Playground, use DEGREES.

def main():
    drivetrain.set_heading(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

establecer_tiempo_de_espera#

set_timeout sets a time limit for how long drivetrain methods wait to reach their target.

Usage:
drivetrain.set_timeout(value, units)

Parámetros

Descripción

value

El tiempo que el sistema de transmisión esperará antes de detenerse.

units

The unit used to represent the timeout:

  • MSEC
  • SECONDS

def main():
    drivetrain.set_timeout(1, SECONDS)

# VR threads — Do not delete
vr_thread(main)

establecer_velocidad_de_conducción#

set_drive_velocity sets the default movement speed used by drive methods.

Usage:
drivetrain.set_drive_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad de conducción predeterminada va de 0 a 100.

units

The unit used to represent the velocity. In this Playground, use PERCENT.

def main():
    drivetrain.set_drive_velocity(50, PERCENT)

# VR threads — Do not delete
vr_thread(main)

establecer_velocidad_de_giro#

set_turn_velocity sets the default speed used by turn methods.

Usage:
drivetrain.set_turn_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad de giro predeterminada va de 0 a 100.

units

The unit used to represent the velocity. In this Playground, use PERCENT.

def main():
    drivetrain.set_turn_velocity(50, PERCENT)

# VR threads — Do not delete
vr_thread(main)

Getters#

título#

heading returns the drivetrain’s current heading.

Usage:
drivetrain.heading(units)

Parámetros

Descripción

units

The unit used to report the heading. In this Playground, use DEGREES.

def main():
    print(drivetrain.heading(DEGREES))

# VR threads — Do not delete
vr_thread(main)

está_hecho#

is_done returns whether the drivetrain is no longer moving.

Usage:
drivetrain.is_done()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    drivetrain.drive_for(FORWARD, 200, MM, wait=False)
    wait(0.1, SECONDS)
    if drivetrain.is_done():
        print("Drive complete")

# VR threads — Do not delete
vr_thread(main)

se está moviendo#

is_moving returns whether the drivetrain is currently moving.

Usage:
drivetrain.is_moving()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    drivetrain.drive_for(FORWARD, 200, MM, wait=False)
    wait(0.1, SECONDS)
    if drivetrain.is_moving():
        print("Still moving")

# VR threads — Do not delete
vr_thread(main)

Detección#

Distancia#

objeto_encontrado#

found_object returns whether the Distance Sensor detects an object.

Usage:
distance.found_object()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    if distance.found_object():
        print("Object detected")

# VR threads — Do not delete
vr_thread(main)

obtener_distancia#

get_distance returns the distance to the nearest detected object from the Distance Sensor.

Usage:
distance.get_distance(units)

Parámetros

Descripción

units

The unit of measurement:

  • INCHES
  • MM

def main():
    print(distance.get_distance(MM))

# VR threads — Do not delete
vr_thread(main)

Comportamiento#

Comportamiento#

levantar#

pickup picks up minerals.

Usage:
rover.pickup(object)

Parámetros

Descripción

object

The object the VR Rover can pick up:

  • MINERALS

def main():
    rover.pickup(MINERALS)

# VR threads — Do not delete
vr_thread(main)

gota#

drop drops carried minerals.

Usage:
rover.drop(object)

Parámetros

Descripción

object

The object the VR Rover can drop:

  • MINERALS

def main():
    rover.drop(MINERALS)

# VR threads — Do not delete
vr_thread(main)

usar#

use uses minerals to restore energy. Minerals must be on the ground to be used.

Usage:
rover.use(object)

Parámetros

Descripción

object

The object the VR Rover can use:

  • MINERALS

def main():
    rover.use(MINERALS)

# VR threads — Do not delete
vr_thread(main)

absorber_radiación#

absorb_radiation absorbs radiation from an enemy.

Usage:
rover.absorb_radiation(object)

Parámetros

Descripción

object

The object the VR Rover can absorb radiation from:

  • ENEMY

def main():
    rover.absorb_radiation(ENEMY)

# VR threads — Do not delete
vr_thread(main)

apoyar#

standby puts the VR Rover into standby mode until the specified battery threshold is reached.

Usage:
rover.standby(percent)

Parámetros

Descripción

percent

The battery threshold that causes the VR Rover to exit standby mode, from 0 to 100.

Si el umbral seleccionado es igual o superior al nivel actual de la batería, el VR Rover no entrará en modo de espera.

def main():
    rover.standby(50)

# VR threads — Do not delete
vr_thread(main)

Getters#

ángulo#

angle returns the direction in degrees to the selected object.

Usage:
rover.angle(object)

Parámetros

Descripción

object

The object to report the direction of:

  • BASE
  • ENEMY
  • MINERALS

Para detectar minerales y enemigos, el objeto debe estar a menos de 1000 mm y dentro del campo de visión del VR Rover. La base siempre puede ser reportada.

def main():
    print(rover.angle(MINERALS))

# VR threads — Do not delete
vr_thread(main)

obtener_distancia#

get_distance returns the distance from the VR Rover to the selected object.

Usage:
rover.get_distance(object, units=MM)

Parámetros

Descripción

object

The object to report distance to:

  • BASE
  • ENEMY
  • HAZARD
  • MINERALS
  • OBSTACLE

units

Optional. The unit used to report the distance:

  • INCHES
  • MM

Para detectar minerales y enemigos, el objeto debe estar a menos de 1000 mm y dentro del campo de visión del VR Rover. La base siempre puede ser reportada.

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():
    print(rover.get_distance(MINERALS, MM))

# VR threads — Do not delete
vr_thread(main)

ubicación#

location returns the X or Y coordinate location of the selected object.

Usage:
rover.location(object, axis, units)

Parámetros

Descripción

object

The object to report the location of:

  • BASE
  • ENEMY
  • HAZARD
  • MINERALS
  • OBSTACLE

axis

Which coordinate to return:

  • X
  • Y

units

The unit used to report the location:

  • INCHES
  • MM

Para detectar minerales y enemigos, el objeto debe estar a menos de 1000 mm y dentro del campo de visión del VR Rover. La base siempre puede ser reportada.

def main():
    print(rover.location(MINERALS, X, MM))

# VR threads — Do not delete
vr_thread(main)

batería#

battery returns the current battery level of the VR Rover.

Usage:
rover.battery()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    print(rover.battery())

# VR threads — Do not delete
vr_thread(main)

minerales_almacenados#

minerals_stored returns the current amount of minerals the VR Rover has in storage.

Usage:
rover.minerals_stored()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    print(rover.minerals_stored())

# VR threads — Do not delete
vr_thread(main)

capacidad_de_almacenamiento#

storage_capacity returns the carrying capacity of the VR Rover.

Usage:
rover.storage_capacity()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    print(rover.storage_capacity())

# VR threads — Do not delete
vr_thread(main)

nivel#

level returns the current level of the VR Rover.

Usage:
rover.level()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    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()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    print(rover.exp())

# VR threads — Do not delete
vr_thread(main)

nivel_enemigo#

enemy_level returns the level of the closest enemy detected by the VR Rover.

Usage:
rover.enemy_level()

Parámetros

Descripción

Este método no tiene parámetros.

When no enemy is detected within the rover’s detect radius, this method returns 0.

def main():
    print(rover.enemy_level())

# VR threads — Do not delete
vr_thread(main)

radiación enemiga#

enemy_radiation returns the radiation of the closest enemy detected by the VR Rover.

Usage:
rover.enemy_radiation()

Parámetros

Descripción

Este método no tiene parámetros.

When no enemy is detected within the rover’s detect radius, this method returns 0.

def main():
    print(rover.enemy_radiation())

# VR threads — Do not delete
vr_thread(main)

detecta#

detects returns whether the VR Rover detects minerals or enemies in its detect radius.

Usage:
rover.detects(object)

Parámetros

Descripción

object

The object to detect:

  • ENEMY
  • MINERALS

El radio de detección del VR Rover es de 800 mm.

def main():
    if rover.detects(MINERALS):
        print("Minerals detected")

# VR threads — Do not delete
vr_thread(main)

ve#

sees returns whether the VR Rover sees the selected object in its vision range.

Usage:
rover.sees(object)

Parámetros

Descripción

object

The object to see:

  • BASE
  • ENEMY
  • HAZARD
  • MINERALS
  • OBSTACLE

El VR Rover puede detectar objetos a una distancia de hasta 1000 mm y dentro de su campo de visión de 40 grados.

def main():
    if rover.sees(MINERALS):
        print("Minerals in view")

# VR threads — Do not delete
vr_thread(main)

bajo ataque#

under_attack returns whether the VR Rover is currently under attack from an enemy.

Usage:
rover.under_attack()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    if rover.under_attack():
        print("The rover is under attack!")

# VR threads — Do not delete
vr_thread(main)

Devoluciones de llamada#

bajo ataque#

on_under_attack registers a callback function that runs when the VR Rover takes damage from an enemy.

Usage:
rover.on_under_attack(callback)

Parámetros

Descripción

callback

La función que se ejecutará cuando el VR Rover esté bajo ataque.

def under_attack():
    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)

al subir de nivel#

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)

Parámetros

Descripción

callback

La función que se ejecutará cuando el VR Rover suba de nivel.

def level_up():
    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)