Python específico para robots#

Introducción#

El parque infantil VIQRC 21-22 Pitching In incorpora métodos exclusivos de este modelo, incluyendo tres opciones de motor y el sensor de color.

Todos los métodos VEXcode VR estándar están disponibles para su uso en el entorno de pruebas VIQRC 21-22 Pitching In.

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

    • spin_for - Spins a motor for a specific distance in degrees or turns.

    • spin_to_position - Spins a motor to a set position.

    • stop - Stops a specific motor from spinning.

  • Mutadores

    • set_position - Sets the encoder value of a motor.

    • set_velocity - Sets the speed of a motor as a percentage.

    • set_timeout - Limits how long a motor command 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 percent.

Detección: Utilice los diversos sensores del robot.

  • Color

    • color - Returns the color detected by the Color Sensor.

    • brightness - Returns the brightness percentage detected by the sensor.

    • hue - Returns the hue value of the detected color.

    • is_near_object - Returns whether a detected object is near the Color Sensor.

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

Movimiento#

Comportamiento#

girar#

spin spins a motor indefinitely.

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

motor

Dominio

intake_motor

intake_motor.spin(direction) - The intake motor

catapult_motor

catapult_motor.spin(direction) - The catapult motor

catapult_tension_motor

catapult_tension_motor.spin(direction) - The catapult tension motor

Parámetros

Descripción

direction

The direction for the motor to spin depends on the selected motor.

  • FORWARD - Spins the Intake Motor in the intake direction or moves the selected catapult motor forward.
  • REVERSE - Spins the Intake Motor in the outtake direction or moves the selected catapult motor in reverse.

def main():
    # Spin the Intake Motor to collect a Ball
    intake_motor.spin(FORWARD)
    wait(1, SECONDS)
    intake_motor.stop()

# VR threads — Do not delete
vr_thread(main)

girar_para#

spin_for spins a motor for a given amount of degrees or turns.

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

motor

Dominio

intake_motor

intake_motor.spin_for(direction, distance, units, wait=True) - The intake motor

catapult_motor

catapult_motor.spin_for(direction, distance, units, wait=True) - The catapult motor

catapult_tension_motor

catapult_tension_motor.spin_for(direction, distance, units, wait=True) - The catapult tension motor

Parámetros

Descripción

direction

La dirección de giro del motor depende del motor seleccionado.

distance

La distancia que debe girar el 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.

def main():
    # Collect a Ball with the Intake Motor
    intake_motor.spin_for(FORWARD, 1, TURNS)

# VR threads — Do not delete
vr_thread(main)

girar_a_posición#

spin_to_position spins a motor to a given position.

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

motor

Dominio

intake_motor

intake_motor.spin_to_position(angle, units, wait=True) - The intake motor

catapult_motor

catapult_motor.spin_to_position(angle, units, wait=True) - The catapult motor

catapult_tension_motor

catapult_tension_motor.spin_to_position(angle, units, wait=True) - The catapult tension motor

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.

def main():
    # Move the Catapult Motor to a launch position
    catapult_motor.spin_to_position(2600, DEGREES)

# VR threads — Do not delete
vr_thread(main)

motor de parada#

stop stops a motor from spinning.

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

motor

Dominio

intake_motor

intake_motor.stop() - The intake motor

catapult_motor

catapult_motor.stop() - The catapult motor

catapult_tension_motor

catapult_tension_motor.stop() - The catapult tension motor

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    # Spin the Intake Motor, then stop it
    intake_motor.spin(FORWARD)
    wait(1, SECONDS)
    intake_motor.stop()

# VR threads — Do not delete
vr_thread(main)

Mutadores#

posición_de_establecer#

set_position sets a motor’s encoder position to the given position value.

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

motor

Dominio

intake_motor

intake_motor.set_position(position, units) - The intake motor

catapult_motor

catapult_motor.set_position(position, units) - The catapult motor

catapult_tension_motor

catapult_tension_motor.set_position(position, units) - The catapult tension motor

Parámetros

Descripción

position

El número entero específico al que se debe configurar el codificador del motor.

units

The unit that represents the angle to rotate to:

  • DEGREES
  • TURNS

def main():
    # Set the Catapult Motor position, then return it to 0 degrees
    catapult_motor.set_position(2600, DEGREES)
    catapult_motor.spin_to_position(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

establecer_velocidad#

set_velocity sets the speed of a motor.

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

motor

Dominio

intake_motor

intake_motor.set_velocity(velocity, units) - The intake motor

catapult_motor

catapult_motor.set_velocity(velocity, units) - The catapult motor

catapult_tension_motor

catapult_tension_motor.set_velocity(velocity, units) - The catapult tension motor

Parámetros

Descripción

velocity

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

units

The unit that represents the new velocity:

  • PERCENT

def main():
    # Set the Catapult Motor velocity before moving it
    catapult_motor.set_velocity(75, PERCENT)
    catapult_motor.spin_to_position(2600, DEGREES)

# VR threads — Do not delete
vr_thread(main)

establecer_tiempo_de_espera#

set_timeout sets 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.

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

motor

Dominio

intake_motor

intake_motor.set_timeout(value, units) - The intake motor

catapult_motor

catapult_motor.set_timeout(value, units) - The catapult motor

catapult_tension_motor

catapult_tension_motor.set_timeout(value, units) - The catapult tension motor

Parámetros

Descripción

value

El tiempo que el motor esperará antes de detenerse.

units

The unit to represent the timeout:

  • SECONDS
  • MSEC - milliseconds

def main():
    # Limit how long the Catapult Motor waits to reach its target
    catapult_motor.set_timeout(2, SECONDS)
    catapult_motor.spin_to_position(5000, DEGREES)

# VR threads — Do not delete
vr_thread(main)

Getters#

está_hecho#

is_done returns a Boolean indicating whether the specified motor is not spinning.

  • True - The specified motor is not spinning.

  • False - The specified motor is spinning.

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

motor

Dominio

intake_motor

intake_motor.is_done() - The intake motor

catapult_motor

catapult_motor.is_done() - The catapult motor

catapult_tension_motor

catapult_tension_motor.is_done() - The catapult tension motor

Parámetros

Descripción

Este método no tiene parámetros.

está_girando#

is_spinning returns a Boolean indicating whether the specified motor is spinning.

  • True - The specified motor is spinning.

  • False - The specified motor is not spinning.

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

motor

Dominio

intake_motor

intake_motor.is_spinning() - The intake motor

catapult_motor

catapult_motor.is_spinning() - The catapult motor

catapult_tension_motor

catapult_tension_motor.is_spinning() - The catapult tension motor

Parámetros

Descripción

Este método no tiene parámetros.

posición#

position returns the total distance the specified motor has rotated.

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

motor

Dominio

intake_motor

intake_motor.position(units) - The intake motor

catapult_motor

catapult_motor.position(units) - The catapult motor

catapult_tension_motor

catapult_tension_motor.position(units) - The catapult tension motor

Parámetros

Descripción

units

The units that represent the motor’s position:

  • DEGREES
  • TURNS

def main():
    # Print the current Catapult Motor position
    brain.screen.print(catapult_motor.position(DEGREES))

# VR threads — Do not delete
vr_thread(main)

velocidad#

velocity returns the current rotational speed of the motor.

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

motor

Dominio

intake_motor

intake_motor.velocity(units) - The intake motor

catapult_motor

catapult_motor.velocity(units) - The catapult motor

catapult_tension_motor

catapult_tension_motor.velocity(units) - The catapult tension motor

Parámetros

Descripción

units

The unit that represents the motor’s velocity:

  • PERCENT

def main():
    # Print the current Intake Motor velocity
    brain.screen.print(intake_motor.velocity(PERCENT))

# VR threads — Do not delete
vr_thread(main)

Detección#

Color#

color#

color returns the color detected by the Color Sensor:

Color devuelto:

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

Usage:
color.color()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    # Print the color detected by the Color Sensor
    brain.screen.print(color.color())

# VR threads — Do not delete
vr_thread(main)

brillo#

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

Usage:
color.brightness()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    # Print the Color Sensor brightness
    brain.screen.print(color.brightness())

# VR threads — Do not delete
vr_thread(main)

matiz#

hue returns the hue detected by the Color 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 grados en la parte superior hasta 360 grados.

Usage:
color.hue()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    # Print the hue detected by the Color Sensor
    brain.screen.print(color.hue())

# VR threads — Do not delete
vr_thread(main)

is_near_object#

is_near_object returns a Boolean indicating whether or not the Color Sensor detects an object close to the sensor.

  • True - The object is close to the Color Sensor.

  • False - The object is not close to the Color Sensor.

Usage:
color.is_near_object()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    # Print whether the Color Sensor detects an object nearby
    brain.screen.print(color.is_near_object())

# VR threads — Do not delete
vr_thread(main)