Python específico para robots#

Todos los comandos VR estándar de VEXcode están disponibles para su uso en el patio de juegos VIQRC Virtual Skills - Rapid Relay.

Movimiento#

motor.spin()#

The motor.spin(direction) command is used to spin a motor indefinitely.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.spin(direction).

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

dirección

The direction for the motor to move in: FORWARD or REVERSE.

Devoluciones: Ninguna.

# 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).

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

dirección

The direction for the motor to move in: FORWARD or REVERSE.

distancia

La distancia que debe recorrer el motor, expresada en un número entero.

unidades

The units that the motor will use: DEGREES or TURNS.

esperar

Optional. The wait parameter determines whether the command will block subsequent commands (wait=True) or allow immediate execution (wait=False). If unspecified, the default for the wait parameter is wait=True.

Devoluciones: Ninguna.

# 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).

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

ángulo

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

unidades

The units that the motor will use: DEGREES or TURNS.

esperar

Optional. The wait parameter determines whether the command will block subsequent commands (wait=True) or allow immediate execution (wait=False). If unspecified, the default for the wait parameter is wait=True.

Devoluciones: Ninguna.

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

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.stop().

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Devoluciones: Ninguna.

# 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).

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

posición

El entero específico que se debe configurar para el codificador del motor.

unidades

The units for the motor to use: DEGREES or TURNS.

Devoluciones: Ninguna.

# 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).

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

velocidad

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

unidades

The unit for the Motor’s velocity, PERCENT.

Devoluciones: Ninguna.

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

Esto evita que los comandos de movimiento que no llegan a su posición prevista impidan la ejecución de los comandos posteriores.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.set_timeout(value, units).

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

valor

La cantidad de tiempo que el motor esperará antes de detenerse.

unidades

The unit for the Motor’s timer, SECONDS.

Devoluciones: Ninguna.

catapult_group.set_timeout(2, SECONDS)

# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_for(6, TURNS)

Eventos#

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.

For information on how to use the eye.object_detected(callback) command, go to its API documentation here.

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.

For information on how to use the eye.object_lost(callback) command, go to its API documentation here.

Detección#

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

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Devuelve: Esto devuelve un valor booleano.

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

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Devuelve: Esto devuelve un valor booleano.

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

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

unidades

The unit of the returned value, DEGREES or TURNS.

Devuelve: Esto devuelve un valor numérico.

# 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).

Objetos

Descripción

intake_motor

Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta.

catapult_group

Sube o baja la catapulta de Swish para lanzar bolas.

Parámetros

Descripción

unidades

The unit of the motor’s velocity, PERCENT.

Devuelve: Esto devuelve un valor numérico.

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.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Devuelve: Esto informa un valor booleano.

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

Los siguientes colores se pueden utilizar como comparación con el color detectado:

  • RED

  • GREEN

  • BLUE

  • YELLOW

  • ORANGE

  • PURPLE

  • CYAN

Devuelve: Esto devuelve el nombre del color detectado como una cadena.

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

Devuelve: Esto devuelve un valor numérico.

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

Devuelve: Esto devuelve un valor numérico.

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