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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
The direction for the motor to move in: |
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
The direction for the motor to move in: |
|
La distancia que debe recorrer el motor, expresada en un número entero. |
|
The units that the motor will use: |
|
Optional. The wait parameter determines whether the command will block subsequent commands ( |
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
El ángulo específico o número de vueltas que dará el motor. |
|
The units that the motor will use: |
|
Optional. The wait parameter determines whether the command will block subsequent commands ( |
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
El entero específico que se debe configurar para el codificador del motor. |
|
The units for the motor to use: |
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
La velocidad a la que girará el motor, que varía entre -100 y 100. |
|
The unit for the Motor’s velocity, |
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
La cantidad de tiempo que el motor esperará antes de detenerse. |
|
The unit for the Motor’s timer, |
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.
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.
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
The unit of the returned value, |
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 |
|---|---|
|
Hace girar la toma de Swish para recoger bolas y colocarlas en su catapulta. |
|
Sube o baja la catapulta de Swish para lanzar bolas. |
Parámetros |
Descripción |
|---|---|
|
The unit of the motor’s velocity, |
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:
REDGREENBLUEYELLOWORANGEPURPLECYAN
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)