Sensor inercial#

Introducción#

The inertial class is used to control and access data from the V5 Inertial Sensor. This sensor provides heading, rotation, and acceleration information to help your robot track orientation and movement.

Constructores de clases#

inertial(
  int32_t  index,
  turnType dir = turnType::right );

Instructor de clase#

Destroys the inertial object and releases associated resources.

~inertial();

Parámetros#

Parámetro

Tipo

Descripción

index

int32_t

The Smart Port that the Inertial Sensor is connected to, written as PORTx, where x is the port number (for example, PORT1).

dir

turnType

The direction that will return a positive value when turning:

  • right (default) — clockwise
  • left

Ejemplos#

// Create the inertial instance
inertial myInertial = inertial(
    PORT1,      // Smart Port 1
    right);     // dir

Funciones de los miembros#

The inertial class includes the following member functions:

  • heading — Returns the current heading value.

  • rotation — Returns the current rotation value.

  • setHeading — Sets the sensor’s heading to a specified value.

  • setRotation — Sets the sensor’s rotation to a specified value.

  • calibrate — Calibrates the sensor for accurate heading tracking.

  • resetHeading — Resets the heading to 0.

  • resetRotation — Resets the rotation to 0.

  • isCalibrating — Returns whether the sensor is currently calibrating.

  • changed — Registers a callback function that runs when the heading changes.

  • installed — Returns whether the sensor is installed.

  • acceleration — Returns linear acceleration along the specified axis.

  • gyroRate — Returns the angular velocity for the specified axis.

  • orientation — Returns the orientation for the specified axis.

  • collision — Registers a callback function that runs when a collision is detected.

  • setTurnType — Sets which turn direction returns positive heading values.

  • getTurnType — Returns which turn direction produces positive heading values.

Before calling any inertial member functions, a inertial instance must be created, as shown below:

/* This constructor is required when using VS Code.
Inertial Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create the inertial instance
inertial myInertial = inertial(
    PORT1);      // Smart Port 1

heading#

Devuelve la orientación actual (ángulo de guiñada) del sensor inercial.

Available Functions
double heading( rotationUnits units = degrees );

Parameters

Parámetro

Tipo

Descripción

units

rotationUnits

The unit of measurement for the returned heading value:

  • deg / degrees (default) — degrees
  • turns / rev — revolutions

Return Values

Devuelve un valor de tipo double que representa la orientación actual del sensor en las unidades especificadas.

Notes
  • The heading value is wrapped between 0 and 360 degrees. Use rotation to access the continuous (unbounded) rotation value.

Examples
// Turn, then show the current heading
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", myInertial.heading(degrees));

rotation#

Devuelve la rotación absoluta (ángulo de guiñada sin límites) del sensor inercial.

Available Functions
double rotation( rotationUnits units = degrees );

Parameters

Parámetro

Tipo

Descripción

units

rotationUnits

The unit of measurement for the returned rotation value:

  • deg / degrees (default) — degrees
  • turns / rev — revolutions

Return Values

Returns a double representing the current rotation in the specified units.

Notes
  • The rotation value is continuous and does not wrap between 0 and 360 degrees. Use heading to access the wrapped heading value.

Examples
// Turn, then show the current rotation
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", myInertial.rotation(degrees));

setHeading#

Establece la orientación del sensor inercial a un valor específico.

Available Functions
void setHeading( double value, rotationUnits units );

Parameters

Parámetro

Tipo

Descripción

value

double

El nuevo valor de rumbo que se asignará al sensor.

units

rotationUnits

The unit of measurement for the heading value:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

Esta función no devuelve ningún valor.

Examples
// Turn the robot around
myInertial.setHeading(180, degrees);
Drivetrain.turnToHeading(0, degrees);

setRotation#

Establece la rotación absoluta del sensor inercial a un valor específico.

Available Functions
void setRotation( double value, rotationUnits units );

Parameters

Parámetro

Tipo

Descripción

value

double

El nuevo valor de rotación absoluto que se asignará al sensor.

units

rotationUnits

The unit of measurement for the rotation value:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

Esta función no devuelve ningún valor.

Examples
// Turn the robot around
myInertial.setRotation(-180, degrees);
Drivetrain.turnToRotation(0, degrees);

calibrate#

Inicia la calibración del sensor inercial.

Available Functions
void calibrate( );

Parameters

Esta función no acepta ningún parámetro.

Return Values

Esta función no devuelve ningún valor.

Notes
  • El sensor debe permanecer inmóvil mientras se realiza la calibración.

  • Use isCalibrating to determine when calibration has completed.

resetHeading#

Establece la orientación del sensor inercial en 0.

Available Functions
void resetHeading();

Parameters

Esta función no requiere ningún parámetro.

Return Values

Esta función no devuelve ningún valor.

resetRotation#

Establece la rotación del sensor inercial a 0.

Available Functions
void resetRotation();

Parameters

Esta función no requiere ningún parámetro.

Return Values

Esta función no devuelve ningún valor.

isCalibrating#

Indica si el sensor inercial se está calibrando actualmente.

Available Functions
bool isCalibrating();

Parameters

Esta función no requiere ningún parámetro.

Return Values

Devuelve un valor booleano que indica si el sensor inercial se está calibrando:

  • true — The sensor is currently calibrating.
  • false — The sensor is not currently calibrating.

changed#

Registra una función de devolución de llamada que se ejecuta cuando cambia el valor de rumbo del sensor inercial.

Available Functions
void changed( void (* callback)(void) );

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(void)

A pointer to a function that will be called when the heading value changes. The function must take no parameters and return void.

Return Values

Esta función no devuelve ningún valor.

Examples
// Called when the inertial sensor's heading value changes
void onHeadingChanged() {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Heading: %.2f", myInertial.heading());
}

myInertial.changed(onHeadingChanged);

installed#

Indica si el sensor inercial está conectado.

Available Functions
bool installed();

Parameters

Esta función no requiere ningún parámetro.

Return Values

Devuelve un valor booleano que indica si el sensor inercial está conectado:

  • true — The sensor is connected and responding.
  • false — The sensor is not connected or not detected.

acceleration#

Devuelve la aceleración lineal medida por el sensor inercial a lo largo del eje especificado.

Available Functions
double acceleration( axisType axis );

Parameters

Parámetro

Tipo

Descripción

axis

axisType

The axis for which acceleration will be returned:

  • xaxis
  • yaxis
  • zaxis

Return Values

Returns a double representing the acceleration along the specified axis in G (gravitational units).

Notes
  • Los valores de aceleración se expresan en unidades de G, donde 1 G equivale a la aceleración debida a la gravedad en la superficie terrestre.

gyroRate#

Devuelve la velocidad angular medida por el sensor inercial a lo largo del eje especificado.

Available Functions
double gyroRate( axisType axis, velocityUnits units );

Parameters

Parámetro

Tipo

Descripción

axis

axisType

The axis for which angular velocity will be returned:

  • xaxis
  • yaxis
  • zaxis

units

velocityUnits

The unit of measurement for the returned angular velocity:

  • dps — degrees per second
  • rpm — revolutions per minute

Return Values

Returns a double representing the angular velocity along the specified axis in the selected units.

Examples
// Display the rate of change of rotation while turning in dps
Drivetrain.turn(right);
wait(1, seconds);

Brain.Screen.print(myInertial.gyroRate(zaxis, dps));

Drivetrain.stop();

orientation#

Devuelve la orientación actual del sensor inercial para el eje especificado.

Available Functions
double orientation( 
  axisType      axis, 
  rotationUnits units );

Parameters

Parámetro

Tipo

Descripción

axis

axisType

The axis for which orientation will be returned:

  • xaxis
  • yaxis
  • zaxis

units

rotationUnits

The unit of measurement for the returned orientation value:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

Returns a double representing the orientation of the specified axis in the selected units.

Examples
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  // Show the Inertial Sensor's orientation value
  // for roll in degrees
  double orient = myInertial.orientation(xaxis, deg);
  Brain.Screen.print("%f", orient);
  wait(0.1, seconds);
}

collision#

Registra una función de devolución de llamada que se ejecuta cuando el sensor inercial detecta una colisión.

Available Functions
void collision( void (* callback)(axisType, double, double, double) );

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(axisType, double, double, double)

A pointer to a function that will be called when a collision is detected. The callback function must accept the following parameters:

  • axisType — The axis on which the collision was detected.
  • Acceleration values at the time of impact, in order:
    • double — Acceleration along the x-axis (in G).
    • double — Acceleration along the y-axis (in G).
    • double — Acceleration along the z-axis (in G).
The function must return void.

Return Values

Esta función no devuelve ningún valor.

Examples
// Called when the inertial sensor's detects a collision
void onCollision(axisType axis, double x, double y, double z) {
  Brain.Screen.print("Collision detected!");
}

// Firmly move the robot by hand briefly to simulate
// a collision and call the onCollision function
myInertial.collision(onCollision);

setTurnType#

Los conjuntos que indican la dirección de giro devuelven valores de rumbo positivos.

Available Functions
void setTurnType( turnType dir );

Parameters

Parámetro

Tipo

Descripción

dir

turnType

The direction that will return positive heading values:

  • right
  • left

Return Values

Esta función no devuelve ningún valor.

Notes

getTurnType#

Los retornos que cambian de dirección producen valores de rumbo positivos.

Available Functions
turnType getTurnType();

Parameters

Esta función no requiere ningún parámetro.

Return Values

Returns a turnType indicating which direction produces positive values:

  • right — Clockwise rotation returns positive values.
  • left — Counterclockwise rotation returns positive values.
Notes