GPS#

Para que los comandos GPS aparezcan en VEXcode V5, se debe configurar un sensor GPS (Game Positioning System™) en la ventana Dispositivos.

Para obtener más información, consulte estos artículos:

Inicializando la clase Gps#

Un sensor GPS se crea utilizando el siguiente constructor:

Gps(port, origin_x, origin_y, units, heading_offset)

Este constructor utiliza cinco parámetros:

Parámetro

Descripción

port

Un Puerto inteligente válido al que está conectado el sensor de distancia.

origin_x

Optional. The X location of the GPS Sensor with respect to origin (also known as the reference point) of the robot. By default, this is 0.
Note: If the Y location is provided, the origin_x parameter must also be provided.

origin_y

Optional. The Y location of the GPS Sensor with respect to origin (also known as the reference point) of the robot. By default, this is 0.
Note: If the Y location is provided, the origin_x parameter must also be provided.

units

Opcional. Las unidades en las que se especifican las ubicaciones X e Y. De manera predeterminada, es MM.

heading_offset

Opcional. El ángulo en grados para desplazar la orientación del sensor GPS. Por defecto, es 180°.

# Create a GPS Sensor "gps_1" with the
# Gps class.
gps_1 = Gps(Ports.PORT1, 0.00, 0.00, MM, 180)

This gps_1 object will be used in all subsequent examples throughout this API documentation when referring to Gps class methods.

Métodos de clase#

calibrate()#

The calibrate() method calibrates the GPS Sensor when the sensor has been configured as a part of a V5 Drivetrain. This will set the GPS’ configured heading (according to its angle offset) as the current heading of the Drivetrain.

El sensor GPS y la transmisión deben permanecer quietos durante el proceso de calibración.

Devoluciones: Ninguna

En este ejemplo, se calibrará el sensor GPS y luego se utilizará el rumbo del sensor para girar el robot hacia el rumbo de 180 grados del campo.

# Turn to face the lower Field wall using data from the GPS Sensor.
drivetrain_gps.calibrate()
drivetrain.turn_to_heading(180, DEGREES)

is_calibrating()#

The is_calibrating() method checks if the GPS Sensor is currently calibrating or not.

Devuelve: Verdadero si el sensor GPS se está calibrando. Falso si no lo está.

set_heading()#

The set_heading() method sets the GPS Sensor’s heading to a new value. The new value for heading should be in the range 0 - 359.99 degrees.

Parámetros

Descripción

valor

El nuevo valor a utilizar para el encabezado.

unidades

Optional. A valid RotationUnit. The default is DEGREES.

Devoluciones: Ninguna

# Set the current GPS Sensor's heading to 180 degrees.
gps_1.set_heading(180)

reset_heading()#

The reset_heading() method sets the GPS Sensor’s heading to 0 degrees.

Devoluciones: Ninguna

heading()#

The heading() method reports the heading of a GPS Sensor on a Field based on the sensor’s readings from the GPS Field Code.

Parámetros

Descripción

unidades

Optional. A valid RotationUnit. The default is DEGREES.

The gps.heading command reports a range from 0.00 to 359.99 degrees.

El rumbo corresponde al rumbo de campo, que abarca un rango de 0° a 359,9° en sentido horario. El 0° se encuentra a las 12 en punto.

establecer_campo_de_ubicación_gps

By default the gps.heading command reports the heading of a GPS Sensor.

Si se agrega un desplazamiento de ángulo al configurar el sensor GPS, el rumbo informado será el del punto de referencia en el robot.

Devuelve: Un valor para el encabezado en el rango especificado por las unidades.

En este ejemplo, el robot (que comienza mirando hacia las 12 en punto del campo) gira hacia la pared derecha del campo hasta que se informa que su rumbo es mayor de 90 grados. Entonces, el robot deja de moverse.

# Turn slowly to face the right wall.
drivetrain.set_turn_velocity(20, PERCENT)
drivetrain.turn(RIGHT)
# Stop turning when the GPS reports a heading greater than 90 degrees.
while not gps_20.heading() > 90:
    wait(5, MSEC)
drivetrain.stop()

set_rotation()#

The set_rotation() method sets the GPS Sensor’s rotation to a new value.

Parámetros

Descripción

valor

El nuevo valor a utilizar para la rotación.

unidades

Optional. A valid RotationUnit. The default is DEGREES.

Devoluciones: Ninguna

# Set the current rotation of the GPS Sensor to 400 degrees.
gps_1.set_rotation(400)

reset_rotation()#

The reset_rotation() method resets the GPS Sensor’s rotation to 0 degrees.

Devoluciones: Ninguna

rotation()#

The rotation() method reads the current rotation of the GPS Sensor. Rotation is not limited; it can be both positive and negative and shows the absolute angle of the GPS Sensor.

Parámetros

Descripción

unidades

Optional. A valid RotationUnit. The default is DEGREES.

Devuelve: Un valor para el encabezado en el rango especificado por las unidades.

# Report the current rotation of the GPS Sensor.
rotation = gps_1.rotation()

x_position()#

The x_position() method returns the current x coordinate of a GPS Sensor on the Field.

Parámetros

Descripción

unidades

Optional. A valid DistanceUnit. The default is MM.

By default the x_position method returns the X coordinate location of a GPS Sensor.

Si se agrega un desplazamiento al configurar el sensor GPS, la posición X informada será la del punto de referencia en el robot.

Devuelve: Un valor para la coordenada x en las unidades especificadas.

En este ejemplo, el robot (que comienza en el lado derecho del campo) avanza hacia el centro hasta que la posición X se indica inferior a 0 mm. Entonces, el robot deja de avanzar.

# Drive slowly towards the center of the Field.
drivetrain.set_drive_velocity(20, PERCENT)
drivetrain.drive(FORWARD)
# Stop driving when the GPS reports an X position near the center of the Field.
while not gps_20.x_position(MM) < 0:
    wait(5, MSEC)
drivetrain.stop()

y_position()#

The y_position() method returns the current y coordinate of a GPS Sensor on the Field.

Parámetros

Descripción

unidades

Optional. A valid DistanceUnit. The default is MM.

By default the y_position method returns the Y coordinate location of a GPS Sensor.

Si se agrega un desplazamiento al configurar el sensor GPS, la posición Y informada será la del punto de referencia en el robot.

Devuelve: Un valor para la coordenada y en las unidades especificadas.

En este ejemplo, el robot (que comienza en la parte superior del campo) avanza hacia el centro hasta que la posición Y se indica inferior a 0 mm. A continuación, el robot detiene su avance.

# Drive slowly towards the center of the Field.
drivetrain.set_drive_velocity(20, PERCENT)
drivetrain.drive(FORWARD)
# Stop driving when the GPS reports an Y position near the center of the Field.
while not gps_20.y_position(MM) < 0:
    wait(5, MSEC)
drivetrain.stop()

quality()#

The quality() method returns a numerical value from 0-100 representing the current signal quality of a GPS Sensor.

Valor reportado

Descripción

100

Todos los datos de posición y rumbo informados por un sensor GPS son válidos.

~90

Los datos de posición ya no se calculan capturando información del código de campo VEX, sino a través de medios alternativos.

0 - 80

Solo los valores de rumbo del sensor GPS son válidos, pero a medida que pasa el tiempo en el que un sensor GPS no escanea lo suficiente del código de campo VEX para determinar con precisión la información de posición y rumbo, la calidad de la señal informada continuará cayendo hasta 0, donde todos los datos del sensor GPS quedan efectivamente congelados y ya no son válidos.

Devuelve: Un valor de calidad en el rango de 0 a 100.

In this code snippet, the signal quality will constantly be checked due to the while True loop. The true branch will only run if the signal quality from the GPS Sensor is reporting values above 90, to ensure the GPS Sensor data being used in the project is valid.

while True:
    if gps_20.quality() > 90:
        pass
    else:
        pass
    wait(5, MSEC)

set_origin()#

The set_origin() method sets the origin of the GPS Sensor. An alternate way of setting sensor origin if not provided in the Gps class constructor.

Parámetros

Descripción

incógnita

La ubicación X del sensor GPS con respecto al origen del robot.

y

La ubicación Y del sensor GPS con respecto al origen del robot.

unidades

Optional. A valid DistanceUnit. The default is MM.

Devoluciones: Ninguna

# Set the GPS Sensor's origin +6 inches on the x axis and
# -6 inches on the y axis.
gps_1.set_origin(6, -6, INCHES)

set_location()#

The set_location() method sets the X, Y coordinates, and heading of a GPS Sensor to a known value at the beginning of a project. This can be done to help reduce GPS data inaccuracies due a the sensor’s proximity to field walls when a project is started.

Parámetros

Descripción

incógnita

La coordenada X.

y

La coordenada Y.

unidades

Optional. A valid DistanceUnit. The default is MM.

ángulo

Opcional. El rumbo del robot.

unidades_r

Optional. A valid RotationUnit. The default is DEGREES.

Cuando un sensor GPS está demasiado cerca de las paredes del campo para leer el código de campo (por ejemplo, cuando un robot está en la posición de inicio de un juego en un campo), a menudo pueden ocurrir comportamientos inesperados si el código se basa en los datos de coordenadas y rumbo del GPS.

establecer_campo_de_ubicación_gps

The X and Y parameters are the X and Y coordinates of the reference point on your robot on the field in this known location. The reference point on your robot is the same location that was used to calculate the offsets when configuring the GPS Sensor.

The HEADING parameter is the heading of the reference point on your robot. Using the example image above, the GPS Sensor is mounted facing behind the robot, while the reference point is at the end of the arm on the robot. Because the reference point is facing the right wall (heading of 90), the heading value that should be input is 90.

Devoluciones: Ninguna

El ejemplo que se muestra aquí establece la posición del punto de referencia en el robot, el brazo, para que coincida con la ubicación del robot en el campo.

# Wait so the GPS has time to initialize.
wait(0.5, SECONDS)
# Set the starting position to the bottom left corner of the Field facing the right wall.
drivetrain_gps.set_location(-1200, -1200, MM, 90)

Devuelve: Falso

orientation()#

The orientation() method reads the orientation for one axis of the GPS Sensor.

Parámetros

Descripción

eje

Un OrientationType válido.

unidades

Optional. A valid RotationUnit. The default is DEGREES.

  • El eje OrientationType.ROLL informa un valor entre -180 y 180 grados, que representa la orientación cuando el sensor GPS está inclinado hacia la izquierda o hacia la derecha.

  • El eje OrientationType.PITCH informa un valor entre -90 y 90 grados, que representa la orientación cuando el sensor GPS está inclinado hacia adelante o hacia atrás.

  • El eje OrientationType.YAW informa un valor entre -180 y 180 grados, que representa la orientación cuando el sensor GPS gira sobre el eje vertical.

Devuelve: Un valor para la orientación del eje en las unidades especificadas.

gyro_rate()#

The gyro_rate() method reads the gyro rate for one axis of the GPS Sensor.

Parámetros

Descripción

eje

Un AxisType válido.

unidades

Optional. A valid VelocityUnit. The default is DPS.

Devuelve: Un valor para la velocidad del giro del eje en las unidades especificadas.

acceleration()#

The acceleration() method reads the acceleration for one axis of the GPS Sensor.

Parámetros

Descripción

eje

Un AxisType válido.

Devuelve: Un valor para la aceleración del eje en unidades de gravedad.

set_sensor_rotation()#

The set_sensor_rotation() method sets the sensor rotation of the GPS Sensor with respect to the robot. This allows heading and rotation methods to return angles relative to the robot rather than the GPS Sensor itself.

Parámetros

Descripción

valor

El ángulo del sensor GPS con respecto al robot.

unidades

Optional. A valid RotationUnit. The default is DEGREES.

Devoluciones: Ninguna

changed()#

The changed() method registers a function to be called when the value of the GPS Sensor’s heading changes. This is not particularly useful as GPS Sensor’s heading is not stable and will cause many events.

Parámetros

Descripción

llamar de vuelta

Una función que se llamará cuando cambie el valor del rumbo del sensor GPS.

arg

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

Devuelve: Una instancia de la clase Event.

# Define the function to occur when the GPS Sensor's
# heading changes.
def heading_changed():
    brain.screen.print("heading changed")

# Set the function to occur when the GPS Sensor's
# heading changes.
gps_1.changed(heading_changed())

set_turn_type()#

The set_turn_type(turntype) method sets the direction that returns positive values for heading.

Parámetros

Descripción

tipo de giro

Un TurnType válido.

Devoluciones: Ninguna

get_turn_type()#

The get_turn_type() method gets the direction that returns positive values for heading.

Returns: The current TurnType, LEFT or RIGHT.

installed()#

The installed() method checks for device connection.

Devuelve: Verdadero o Falso

timestamp()#

The timestamp() method requests the timestamp of the last received status packet from the GPS Sensor.

Devuelve: Marca de tiempo del último paquete de estado recibido en milisegundos.