Python específico para robots#

Todos los comandos VR estándar de VEXcode están disponibles para su uso en el patio de juegos V5RC Virtual Skills - Spin Up.

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_group.spin(direction).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

Parámetros

Descripción

dirección

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

Devoluciones: Ninguna.

def main():
    # Spin the intake motor forward.
    intake_motor_group.spin(FORWARD)
    # Wait half a second.
    wait(0.5, SECONDS)
    # Stop spinning the intake motor group.
    intake_motor_group.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_group.spin_for(direction, distance, units, wait).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

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.

def main():
    # Spin the intake motor forward for 1 turn.
    intake_motor_group.spin_for(FORWARD, 1, TURNS)

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_group.spin_for(angle, units, wait).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

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.

def main():
    # Spin the intake motor to 55 degrees.
    intake_motor_group.spin_to_position(55, 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_group.stop().

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

Devoluciones: Ninguna.

def main():
    # Spin the intake motor forward.
    intake_motor_group.spin(FORWARD)
    # Wait half a second.
    wait(0.5, SECONDS)
    # Stop spinning the intake motor group.
    intake_motor_group.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.

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_group.set_position(position, units).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

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.

def main():
    # Set the current motor position to 90 degrees.
    intake_motor_group.set_position(90, DEGREES)
    # Spin the intake motor back to 0 degrees.
    intake_motor_group.spin_to_position(0, DEGREES)

motor.set_velocity()#

The motor.set_velocity(velocity, units) command is used to set the speed of 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_group.set_velocity(velocity, units).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

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.

def main():
    # Set the intake motor velocity to 75 percent.
    intake_motor_group.set_velocity(75, PERCENT)
    # Spin the intake motor to 180 degrees.
    intake_motor_group.spin_to_position(180, DEGREES)

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.

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_group.set_timeout(value, units).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

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.

def main():
    # Set the intake motor's timeout to 2 seconds.
    intake_motor_group.set_timeout(2, SECONDS)
    # Spin the intake motor to 270 degrees.
    intake_motor_group.spin_to_position(270, DEGREES)

Eventos#

roller_optical.object_detected()#

roller_optical.object_detected(callback) is the same command as eye.object_detected(callback).

The command only uses Disco’s Optical Sensor roller_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.

roller_optical.object_lost()#

roller_optical.object_lost(callback) is the same command as eye.object_lost(callback).

The command only uses Disco’s Optical Sensor roller_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_group.is_done().

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

Devuelve: Esto devuelve un valor booleano.

def main():
    # Move the Arm so it doesn't block the Front Distance Sensor.
    arm_motor_group.spin_to_position(1000, DEGREES)
    # Wait until the arm_motor_group has finished moving.
    if arm_motor_group.is_done():
        # Print the distance from the Front Distance Sensor to the closest
        # object in front of it.
        brain.screen.print(front_distance.object_distance(MM))

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

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

Devuelve: Esto devuelve un valor booleano.

# Example coming soon.

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_group.position(units).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

Parámetros

Descripción

unidades

The unit of the returned value, DEGREES or TURNS.

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the current position of the intake_motor_group in degrees.
    brain.screen.print(intake_motor_group.position(DEGREES))

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_group.velocity(units).

Objetos

Descripción

intake_motor_group

Gira la entrada de Disco para recoger elementos del juego del campo.

Parámetros

Descripción

unidades

The unit of the motor’s velocity, PERCENT.

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the current velocity of the arm_motor_group.
    brain.screen.print(arm_motor_group.velocity(PERCENT))

line_tracker.reflectivity()#

The line_tracker.reflectivity(units) command is used to return the amount of light reflected using the Line Tracker Sensor.

Este comando informará un rango de 0% a 100%. Las superficies con colores más claros tienen valores de reflectividad más altos, mientras que las superficies más oscuras tienen valores de reflectividad más bajos.

Parámetros

Descripción

unidades

The unit of the reflected light, PERCENT.

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the current reflectivity.
    brain.screen.print(line_tracker.reflectivity(PERCENT))

roller_optical.is_near_object()#

The roller_optical.near_object() command is used to report a Boolean value if the Optical Sensor is close enough to an object to detect a color.

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

Devuelve: Esto informa un valor booleano.

def main():
    # Print if the Front Optical Sensor is detecting a color.
    brain.print(roller_optical.near_object())

roller_optical.color()#

The roller_optical.color() command is used to return the color detected by an Optical Sensor.

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

Los siguientes colores se pueden utilizar como comparación con el color detectado por un sensor óptico:

  • ROJO

  • VERDE

  • AZUL

  • AMARILLO

  • NARANJA

  • PÚRPURA

  • CIAN

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

def main():
    # Print the color of the object that the Front Optical Sensor sees.
    brain.print(roller_optical.color())

roller_optical.brightness()#

The roller_optical.brightness() command is used to report the amount of light detected by an Optical Sensor within a range of 0 to 100 percent.

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

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the brightness of the object in front of Disco.
    brain.print(roller_optical.brightness())

roller_optical.hue()#

The roller_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.

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

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the hue of the object in front of Disco.
    brain.screen.print("Hue: ", optical.hue())

gps.x_position()#

The gps.x_position(units) command is used to report the X positional offset of a GPS Sensor or defined origin point from the center of a field.

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

Parámetros

Descripción

unidades

The unit of the offset value, INCHES or MM (Millimeters).

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the current X positional offset of the robot.
    brain.screen.print(gps.x_position(MM))

gps.y_position()#

The gps.y_position(units) command is used to report the Y positional offset of a GPS Sensor or defined origin point from the center of a field.

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

Parámetros

Descripción

unidades

The unit of the offset value, INCHES or MM (Millimeters).

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the current Y positional offset of the robot.
    brain.screen.print(gps.y_position(MM))

gps.heading()#

The gps.heading() command is used to report the heading that a robot is currently facing based on a GPS Sensor’s readings from the VEX GPS Field Code.

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

Devuelve: Esto devuelve un valor numérico.

def main():
    # Print the current heading of the robot.
    brain.screen.print(gps.heading())