Sensor giroscópico#
Introducción#
The gyro class is used to measure the robot’s heading and rotational movement, allowing tracking of orientation over time.
Constructor de clases#
gyro(
triport::port &port);
Instructor de clase#
Destroys the gyro object and releases associated resources.
virtual ~gyro();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The 3-Wire Port that the Gyro Sensor is connected to, written as |
Ejemplo#
// Create a gyro instance in Port A
gyro GyroA = gyro(Brain.ThreeWirePort.A);
Funciones de los miembros#
The gyro class includes the following member functions:
calibrate— Calibrates the gyro for stable heading tracking.setHeading— Sets the heading of the gyro.setRotation— Sets the current rotation value of the gyro.heading— Returns the heading of the gyro.rotation— Returns the rotation of the gyro.
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 A
gyro GyroA = gyro(Brain.ThreeWirePort.A);
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.
Notescalibrateshould only be called when the sensor is not moving.
// Start calibration with the calibration time set to 3 seconds.
GyroA.calibrate(3);
setHeading#
Establece la orientación del sensor giroscópico a un valor específico.
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 del sensor giroscópico a un valor específico.
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.
Available Functionsdouble heading(
rotationUnits units = degrees );
| Parameter | Type | Description |
| :—————-: | :————————————– |
| units | rotationUnits | The unit that represents the heading:
degrees(default)turns
- |
Return Values
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 = GyroA.heading();
Brain.Screen.print(value);
rotation#
Devuelve la rotación actual del sensor giroscópico.
Available Functionsdouble rotation(
rotationUnits units = degrees );
| Parameter | Type | Description |
| :—————-: | :————————————– |
| units | rotationUnits | The unit that represents the rotation value:
degrees(default)turns
- |
Return Values
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 = GyroA.rotation();
Brain.Screen.print(value);