giroscopio#

Inicializando la clase giroscópica#

Un sensor giroscópico se crea utilizando el siguiente constructor:

The gyro constructor creates a gyro object in the specified Three Wire Port:

Parámetro

Descripción

port

Un Puerto inteligente válido al que está conectado el sensor giroscópico.

// Create the Brain.
brain Brain;
// Construct a Gyro Sensor "Gyro" with the
// gyro class.
gyro Gyro = gyro(PORT1);

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

Métodos de clase#

calibrate()#

Este método se llama de las siguientes maneras:

The calibrate() method calibrates the Gyro Sensor. Calibration should be done when the Gyro Sensor is not moving.

Devoluciones: Ninguna.

// Start calibration.
Gyro.calibrate();

The calibrate(value) method calibrates the Gyro Sensor. Calibration should be done when the Gyro Sensor is not moving.

Parámetros

Descripción

valor

Establece el tiempo de calibración. El valor predeterminado es 0.

Devoluciones: Ninguna.

// Start calibration with the calibration time set to 3 seconds.
Gyro.calibrate(3);

isCalibrating()#

The isCalibrating() method checks if the Gyro Sensor is currently calibrating.

Returns: true if the Gyro is calibrating. false if it is not.

// Start calibration.
Gyro.calibrate();
// Print that the Gyro is calibrating while waiting for it to
// finish calibrating.
while(Gyro.isCalibrating()){
    Brain.Screen.clear();
    Brain.Screen.print("Gyro Calibrating");
    wait(50, msec);
}

resetHeading()#

The resetHeading() method resets the heading of the Gyro Sensor to 0.

Devoluciones: Ninguna.

resetRotation()#

The resetRotation() method resets the rotation of the Gyro Sensor to 0.

Devoluciones: Ninguna.

setHeading()#

The setHeading(value, units) method sets the heading of the Gyro Sensor to a specific value.

Parámetros

Descripción

valor

El valor a utilizar para el nuevo encabezado.

unidades

Una rotationUnit válida.

Devoluciones: Ninguna.

angle()#

The angle(units) method returns the current angle of the Gyro Sensor.

Parámetros

Descripción

unidades

A valid rotationUnit. The default is degrees.

Devuelve: Un doble que representa el ángulo actual del sensor giroscópico en las unidades especificadas.

// Get the current angle for the Gyro.
double value = Gyro.angle()

heading()#

The heading(units) method returns the current heading of the Gyro Sensor.

Parámetros

Descripción

unidades

A valid rotationUnit. The default is degrees.

Devuelve: Un doble que representa el rumbo actual del sensor giroscópico en las unidades especificadas.

// Get the current heading for the Gyro.
double value = Gyro.heading()

setRotation()#

The setRotation(value, units) method sets the rotation of the Gyro Sensor to a specific value.

Parámetros

Descripción

valor

El valor a utilizar para la nueva rotación.

unidades

Una rotationUnit válida.

Devoluciones: Ninguna.

rotation()#

The rotation(units) method returns the current rotation of the Gyro Sensor.

Parámetros

Descripción

unidades

A valid rotationUnit. The default is degrees.

Devuelve: Un doble que representa la rotación actual del sensor giroscópico en las unidades especificadas.

// Get the current rotation for the Gyro.
double value = Gyro.rotation()

setTurnType()#

The setTurnType(dir) command sets the direction which returns positive heading.

Parámetros

Descripción

director

Un turnType válido.

Devoluciones: Ninguna.

// Set the direction for positive angles to right.
Gyro.setTurnType(right);

getTurnType()#

The getTurnType() method returns the direction that returns positive heading values with the Gyro Sensor.

Devuelve: El tipo de giro del sensor giroscópico en las unidades especificadas.

changed()#

The changed(callback) method registers a callback function for when the Gyro Sensor’s 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 sensor giroscópico.

Devoluciones: Ninguna.

// Define the GyroChanged function with a void return type,
// showing it doesn't return a value.
void GyroChanged() {
  // The Brain will print that the Gyro Sensor changed on the
  // Brain's screen.
  Brain.Screen.print("Gyro changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Turn the robot right.
  Drivetrain.turn(right);

  // Run GyroChanged when the value of the
  // Gyro Sensor changes.
  Gyro.changed(GyroChanged);
}

timestamp()#

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

Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.