Sensor giroscópico#
Introducción#
The gyro class is used with a Gyro Sensor to measure rotational movement around a single axis. It can track which direction the robot is facing and how far the robot has turned.
Constructor de clases#
gyro(
int32_t index );
Instructor de clase#
Destroys the gyro object and releases associated resources.
virtual ~gyro();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The Smart Port that the Gyro Sensor is connected to, written as |
Ejemplo#
// Create a gyro instance in Port 1
gyro Gyro1 = gyro(PORT1);
Funciones de los miembros#
The gyro class includes the following member functions:
calibrate— Calibrates the Gyro Sensor.setHeading— Sets the Gyro Sensor’s current heading to a new heading value.setRotation— Sets the Gyro Sensor’s current rotation to a new rotation value.heading— Returns the direction the Gyro Sensor is facing.rotation— Returns how far the Gyro Sensor has turned.rate— Returns how fast the Gyro Sensor is rotating.
Before calling any gyro member functions, a gyro instance must be created, as shown below:
/* This constructor is required when using VS Code.
Gyro Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a gyro instance in Port 1
gyro Gyro1 = gyro(PORT1);
calibrate#
Calibra el sensor giroscópico.
Available Functionsvoid calibrate();
Esta función no acepta ningún parámetro.
Return ValuesEsta función no devuelve ningún valor.
NotesLa calibración ayuda al sensor giroscópico a medir los giros correctamente. Mantenga el sensor inmóvil durante la calibración. Si el sensor se mueve durante la calibración, los valores de rumbo, rotación y velocidad podrían no medir los giros correctamente.
// Calibrate the Gyro Sensor before turning.
Gyro1.calibrate();
setHeading#
Establece la orientación actual del sensor giroscópico a un valor específico.
El rumbo es la dirección hacia la que apunta el sensor giroscópico, medida de 0 a 359,99 grados. Al ajustar el rumbo, cambia la referencia de dirección actual del sensor.
Available Functionsvoid setHeading(
double value,
rotationUnits units );
Parámetros |
Tipo |
Descripción |
|---|---|---|
|
|
El valor que se utilizará para el nuevo encabezado. |
|
|
The unit that represents the heading:
|
Esta función no devuelve ningún valor.
setRotation#
Establece la rotación actual del sensor giroscópico a un valor específico.
La rotación indica cuánto ha girado el sensor giroscópico. A diferencia de la dirección, la rotación puede superar los 359,99 grados o disminuir por debajo de los 0 grados.
Available Functionsvoid setRotation(
double value,
rotationUnits units );
Parámetros |
Tipo |
Descripción |
|---|---|---|
|
|
El valor que se utilizará para el nuevo valor de rotación. |
|
|
The unit that represents the rotation value:
|
Esta función no devuelve ningún valor.
heading#
Devuelve la orientación actual del sensor giroscópico.
El rumbo es la dirección hacia la que apunta el sensor giroscópico, medida de 0 a 359,99 grados. Si el sensor gira más allá de los 359,99 grados, el rumbo vuelve a 0 grados.
Available Functionsdouble heading(
rotationUnits units = degrees );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The unit that represents the heading:
|
Returns a double representing the current heading of the Gyro Sensor in the specified units, defaulting to degrees.
// Get the current heading for the Gyro.
double value = Gyro1.heading();
Brain.Screen.print(value);
rotation#
Devuelve la rotación actual del sensor giroscópico.
La rotación indica cuánto ha girado el sensor giroscópico. A diferencia de la dirección, la rotación puede superar los 359,99 grados o disminuir por debajo de 0 grados. Por ejemplo, dos giros completos a la derecha producen una rotación de 720 grados. Un giro completo a la izquierda desde 0 grados produce una rotación de -360 grados.
Available Functionsdouble rotation(
rotationUnits units = degrees );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The unit that represents the rotation value:
|
Returns a double representing the current rotation value of the Gyro Sensor in the specified units, defaulting to degrees.
// Get the current rotation for the Gyro.
double value = Gyro1.rotation();
Brain.Screen.print(value);
rate#
Devuelve la velocidad de giro del sensor giroscópico.
La velocidad de giro indica la rapidez con la que rota el sensor giroscópico. Su valor puede ser positivo o negativo, dependiendo de la dirección de rotación del sensor.
Available Functionsdouble rate(
rateUnits units = rateUnits::dps );
| Parameter | Type | Description |
| :—————-: | :————————————– |
| units | rateUnits | The unit that represents the rate:
rateUnits::dps(default) — degrees per secondrateUnits::rpm— rotations per minute
Returns a double representing the current rate of change of the Gyro Sensor in the specified units, defaulting to rateUnits::dps.