Python específico para robots#

Introducción#

El V5RC 22-23 Spin Up Playground incorpora métodos exclusivos para el diseño específico de este modelo, incluyendo un grupo motor, un rastreador de línea, un sensor óptico y un sensor de sistema de posicionamiento de juego (GPS).

Todos los métodos VEXcode VR estándar están disponibles para su uso en el entorno de pruebas V5RC 22-23 Spin Up.

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

Movimiento: Mueve y rastrea los motores del robot.

  • Comportamiento

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

  • Mutadores

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

  • Obtenidos

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

Detección: Utilice los diversos sensores del robot.

  • Óptico

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

  • Seguimiento de la línea

    • reflectivity – Returns the amount of light reflected from the surface.

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

Movimiento#

Comportamiento#

girar#

spin spins a motor or motor group in the specified direction indefinitely.

Usage:
intake_motor_group.spin(direction)

Parámetros

Descripción

direction

The direction for the motor group to spin:

  • FORWARD
  • REVERSE
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)

girar_para#

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)

Parámetros

Descripción

direction

The direction for the motor group to spin:

  • FORWARD – Spins the Conveyor up or the Intake in the intake direction.
  • REVERSE – Spins the Conveyor down or the Intake in the outtake direction.

distance

La distancia que debe girar el grupo motor como un número entero.

units

The unit that represents the distance to rotate:

  • DEGREES
  • TURNS

wait

Optional.

  • wait=True (default) — The robot waits until spin_for is complete before executing the next line of code.
  • wait=False — The robot starts the action and moves on to the next line of code right away, without waiting for spin_for to finish.

def main():
    # Spin the intake forward then stop
    intake_motor_group.spin_for(FORWARD, 1, TURNS)

# VR threads — Do not delete
vr_thread(main)

girar_a_posición#

spin_to spins a motor or motor group to a given position.

Usage:
intake_motor_group.spin_to_position(angle, units, wait)

Parámetros

Descripción

angle

El ángulo específico o el número de vueltas que girará el motor.

units

The unit that represents the angle to rotate to:

  • DEGREES
  • TURNS

wait

Optional.

  • wait=True (default) — The robot waits until spin_to_position is complete before executing the next line of code.
  • wait=False — The robot starts the action and moves on to the next line of code right away, without waiting for spin_to_position to finish.

def main():
    # Spin the intake forward then stop
    intake_motor_group.spin_to_position(55, DEGREES)

# VR threads — Do not delete
vr_thread(main)

detener#

stop stops a motor or motor group from spinning.

Usage:
intake_motor_group.stop()

Parámetros

Descripción

Este método no tiene parámetros.

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)

Mutadores#

posición_de_establecer#

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)

Parámetros

Descripción

position

El número entero específico al que se deben configurar los codificadores del grupo de motores.

units

The unit that represents the angle to rotate to:

  • DEGREES
  • TURNS
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)

establecer_velocidad#

set_velocity sets the speed of a motor or motor group.

Usage:
intake_motor_group.set_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad a la que girará el grupo motor, que oscila entre 0 y 100.

units

The unit that represents the new velocity:

  • PERCENT
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)

establecer_tiempo_de_espera#

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)

Parámetros

Descripción

value

El tiempo que el grupo motor esperará antes de detenerse.

units

The unit to represent the timeout:

  • SECONDS
  • MSEC — milliseconds
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#

está_hecho#

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()

Parámetros

Descripción

Este método no tiene parámetros.

está_girando#

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()

Parámetros

Descripción

Este método no tiene parámetros.

posición#

position returns the total distance the specified motor or motor group has rotated.

Usage:
intake_motor_group.position(units)

Parámetros

Descripción

units

The units that represent the motor’s position:

  • DEGREES
  • TURNS

velocidad#

velocity returns the current rotational speed of the motor or motor group.

Usage:
intake_motor_group.velocity(units)

Parámetros

Descripción

units

The unit that represent the motor’s position:

  • PERCENT

Detección#

Óptico#

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()

Parámetros

Descripción

Este método no tiene parámetros.

color#

color returns the color detected by the Optical Sensor:

Color devuelto:

  • NONE – No color detected.
  • RED
  • GREEN
  • BLUE
  • YELLOW
  • ORANGE
  • PURPLE
  • CYAN

Usage:
roller_optical.color()

Parámetros

Descripción

Este método no tiene parámetros.

brillo#

brightness returns the brightness value detected by the Optical Sensor as a percent from 0% to 100%.

Usage:
roller_optical.brightness()

Parámetros

Descripción

Este método no tiene parámetros.

matiz#

hue returns the hue detected by the Optical Sensor.

Los valores de tono van de 0 a 359 grados, lo que corresponde a las posiciones en la rueda de colores que se muestra a continuación.

Una rueda de colores circular que muestra un espectro completo de tonalidades etiquetadas con valores de grados alrededor del perímetro, aumentando en incrementos de 30 grados desde 0° en la parte superior hasta 360°.

Usage:
roller_optical.hue()

Parámetros

Descripción

Este método no tiene parámetros.

objeto_detectado#

object_detected registers a callback function for when the Optical Sensor detects an object.

Usage:
roller_optical.object_detected(callback, arg)

Parámetros

Descripción

callback

Una función que se llamará cuando se detecte un objeto.

arg

Opcional. Una tupla que se utiliza para pasar argumentos a la función de devolución de llamada.

objeto_perdido#

object_lost registers a callback function for when the Optical Sensor loses a previously detected object.

Usage:
roller_optical.object_lost(callback, arg)

Parámetros

Descripción

callback

Una función que se llamará cuando se pierda un objeto detectado.

arg

Opcional. Una tupla que se utiliza para pasar argumentos a la función de devolución de llamada.

GPS#

posición_x#

x_position returns the current x coordinate of a GPS (Game Positioning System™) Sensor on the field.

Usage:
gps.x_position(units)

Parámetros

Descripción

unidades

The unit of the offset value:

  • INCHES
  • MM

posición_y#

y_position returns the current y coordinate of a GPS (Game Positioning System™) Sensor on the field.

Usage:
gps.y_position(units)

Parámetros

Descripción

unidades

The unit of the offset value:

  • INCHES
  • MM

título#

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()

Parámetros

Descripción

Este método no tiene parámetros.

Rastreador de línea#

reflectividad#

reflectivity returns the amount of light reflected from the surface as a percent.

Uso:
Se puede utilizar uno de los tres objetos line_tracker disponibles con este método, como se muestra a continuación:

rastreador de línea

Dominio

top_line_tracker

top_line_tracker.reflectivity(units) — Top Line Tracker

middle_line_tracker

middle_line_tracker.reflectivity(units) — Middle Line Tracker

bottom_line_tracker

bottom_line_tracker.reflectivity(units) — Bottom Line Tracker

Parámetro

Descripción

unidades

Optional. The unit to return the reflectivity with:

  • PERCENT (default)