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

El puerto de 3 cables al que está conectado el sensor giroscópico, ya sea un puerto en el Cerebro o un Expandedor de 3 cables.

Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de clase gyro.

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

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);
}

resetAngle()#

Este método se llama de las siguientes maneras:

The resetAngle() method resets the angle of the Gyro Sensor to 0.

Devoluciones: Ninguna.

The resetAngle(value, units) method resets the angle of the Gyro Sensor to a specified value.

Parámetros

Descripción

valor

El valor a utilizar para el nuevo ángulo.

unidades

Una rotationUnit válida.

Devoluciones: Ninguna.

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();

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);
}