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#
This gps
constructor creates an object of the gps Class in the specified port with the specified rotational offset.
Parámetro |
Descripción |
---|---|
|
Un Puerto inteligente válido al que está conectado el sensor GPS. |
|
Desplazamiento rotacional del sensor GPS en grados, de 0,00 a 359,99. |
// Construct a GPS Sensor "GPS1" with the gps class, using
// a 180 degree offset.
gps GPS1 = gps(PORT1, 180);
This gps
constructor creates an object of the gps Class in the specified port with a specified origin position and rotational offset.
Parámetro |
Descripción |
---|---|
|
Un Puerto inteligente válido al que está conectado el sensor GPS. |
|
La ubicación X del sensor GPS con respecto al origen (también conocido como punto de referencia) del robot. |
|
La ubicación Y del sensor GPS con respecto al origen (también conocido como punto de referencia) del robot. |
|
Una unidad de distancia válida. |
|
Desplazamiento rotacional del sensor GPS en grados, de 0,00 a 359,99. |
// Construct a GPS Sensor "GPS1" with the gps class, with
// the origin at (10, 10) and using a 180 degree offset.
gps GPS1 = gps(PORT1, 10.00, 10.00, mm, 180);
This GPS1
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.
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.
DrivetrainGPS.calibrate()
Drivetrain.turnToHeading(180, degrees)
Devoluciones: Ninguna.
isCalibrating()#
The isCalibrating()
method returns true while the GPS Sensor is performing a requested recalibration, changing to false
once recalibration has completed.
Returns: Returns true
if GPS Sensor is still calibrating.
resetHeading()#
The resetHeading()
method sets the heading of the GPS Sensor to 0.
Devoluciones: Ninguna.
resetRotation()#
The resetRotation()
method sets the rotation angle of the GPS Sensor to 0.
Devoluciones: Ninguna.
setHeading()#
The setHeading(value, units)
method sets the heading of the GPS Sensor to a new value.
Parámetros |
Descripción |
---|---|
valor |
El valor de rotación a establecer. |
unidades |
Optional. A valid rotationUnit. The default is |
Devoluciones: Ninguna.
setRotation()#
The setRotation(value, units)
method sets the rotation of the GPS Sensor to a new value.
Parámetros |
Descripción |
---|---|
valor |
El valor de rotación a establecer. |
unidades |
Optional. A valid rotationUnit. The default is |
Devoluciones: Ninguna.
roll()#
The roll(units)
method returns the roll of the GPS Sensor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid rotationUnit. The default is |
Devuelve: El resultado del sensor GPS en las unidades especificadas.
pitch()#
The pitch(units)
method returns the pitch of the GPS Sensor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid rotationUnit. The default is |
Devuelve: El paso del sensor GPS en las unidades especificadas.
yaw()#
The yaw(units)
method returns the yaw of the GPS Sensor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid rotationUnit. The default is |
Devuelve: La guiñada del sensor GPS en las unidades especificadas.
xPosition()#
The xPosition(units)
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 |
By default the xPosition()
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: La coordenada x del sensor GPS 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.setDriveVelocity(20.0, percent);
Drivetrain.drive(forward);
// Stop driving when the GPS reports an x position near the center of the Field.
waitUntil((GPS20.xPosition(mm) < 0.0));
Drivetrain.stop();
yPosition()#
The yPosition(units)
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 |
By default the yPosition()
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: La coordenada y del sensor GPS en las unidades especificadas.
// Get the current y coordinate for the GPS Sensor.
yPos = GPS1.yPosition();
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.setDriveVelocity(20.0, percent);
Drivetrain.drive(forward);
// Stop driving when the GPS reports an y position near the center of the Field.
waitUntil((GPS20.yPosition(mm) < 0.0));
Drivetrain.stop();
orientation()#
The orientation(axis, units)
method returns the orientation for one axis of the gps.
Parámetros |
Descripción |
---|---|
eje |
Un axisType válido. |
unidades |
Optional. A valid rotationUnit. The default is |
El eje x, o 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 y, o de paso, 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 z, guiñada 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.
// Get the orientation of the x axis on the GPS Sensor.
pitch = GPS1.orientation(xaxis);
heading()#
The heading(units)
method returns 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 |
The heading
method 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.
By default the heading
method 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: El rumbo actual del sensor GPS en las unidades especificadas.
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.setTurnVelocity(20.0, percent);
Drivetrain.turn(right);
// Stop turningwhen the GPS reports a heading greater than 90 degrees.
waitUntil((GPS20.heading() > 90.0));
Drivetrain.stop();
rotation()#
The rotation(units)
method returns the current rotation of the GPS Sensor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid rotationUnit. The default is |
Devuelve: La rotación actual del sensor GPS en las unidades especificadas.
// Get the current rotation for the GPS Sensor.
rotation = GPS1.rotation();
gyroRate()#
The gyroRate(axis, units)
method returns 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 |
Devuelve: Un valor para la velocidad del giro del eje en las unidades especificadas.
// Get the gyro rate for the z axis of the GPS Sensor.
gyroRate = GPS1.gyroRate(zaxis);
acceleration()#
The acceleration(axis)
method returns the acceleration for an 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.
// Get the acceleration for the Zz axis of the GPS Sensor.
accel = GPS1.acceleration(zaxis);
quality()#
The quality()
method reports 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. |
Devoluciones: La calidad del sensor GPS en el rango 0 – 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 (GPS20.quality() > 90.0) {} else {}
wait(5, msec);
}
return 0;
setOrigin()#
The setOrigin(x, y, units)
method sets the origin of the GPS Sensor.
Parámetros |
Descripción |
---|---|
incógnita |
La ubicación X del GPS con respecto al origen del robot. |
y |
La ubicación Y del GPS con respecto al origen del robot. |
unidades |
Optional. A valid distanceUnit. The default is |
Devoluciones: Ninguna.
// Set the origin of the GPS Sensor.
GPS1.setOrigin(6, -6, inches);
setLocation()#
The setLocation(x, y, units, angle, units_r)
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 inicial. |
y |
La coordenada y inicial. |
unidades |
Optional. A valid distanceUnit. The default is |
ángulo |
Opcional. El rumbo inicial del robot. |
unidades_r |
Optional. A valid rotationUnit. The default is |
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.
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.
DrivetrainGPS.setLocation(-1200, -1200, mm, 90)
changed()#
The changed(callback)
method registers a callback function for when the value for the GPS heading changes.
Parámetros |
Descripción |
---|---|
llamar de vuelta |
La función de devolución de llamada que se llamará cuando cambie el rumbo del GPS. |
Devuelve: Una instancia de la clase Event.
// Define the headingChanged function with a void return
// type, showing it doesn't return a value.
void headingChanged() {
// The Brain will print that the GPS Sensor's heading
// changed on the Brain's screen.
Brain.Screen.print("GPS heading changed");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn the robot right.
Drivetrain.turn(right);
// Run headingChanged when the value of the GPS Sensor's
// heading changes.
GPS1.changed(headingChanged);
}
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 como un entero de 32 bits sin signo en milisegundos.
installed()#
The installed()
method checks if the GPS Sensor is installed.
Returns: true
if the GPS Sensor is installed. false
if it is not.