Inercial#
Introducción#
El cerebro VEX IQ (2.ª generación) incluye un giroscopio de 3 ejes integrado para medir el movimiento de rotación y un acelerómetro de 3 ejes para detectar cambios de movimiento. Estos sensores permiten al robot rastrear su orientación, rumbo y aceleración.
For the examples below, the configured Inertial Sensors will be named BrainInertial, and will be used in all subsequent examples throughout this API documentation when referring to Inertial class methods.
A continuación se muestra una lista de todos los métodos disponibles:
Orientación: mide el movimiento de rotación del sensor inercial.
heading– Returns the current heading.rotation– Returns the cumulative rotation.setHeading– Sets the Inertial Sensor’s heading to a specified value.setRotation– Sets the Inertial Sensor’s rotation value.calibrate– Calibrates the Inertial Sensor for stable heading tracking.isCalibrating– Returns whether or not the Inertial Sensor is calibrating.resetHeading– Sets the heading of the Inertial Sensor to 0.resetRotation– Sets the rotation of the Inertial Sensor to 0.
Movimiento – Detecta cambios en el movimiento.
acceleration– Returns the linear acceleration along the x, y, or z axis.gyroRate– Returns the angular velocity around the x, y, or z axis.orientation– Returns the roll, pitch, or yaw based on tilt and rotation.changed– Registers a function to call when the Inertial Sensor detects change.
Constructores: inicializan y configuran manualmente un sensor inercial.
inertial– Creates an Inertial Sensor.
Orientación#
heading#
heading returns the current heading of the Inertial Sensor.
Usage:
BrainInertial.heading(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The units that represent the heading:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn, then show the current heading
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", BrainInertial.heading(degrees));
}
rotation#
rotation returns the current rotation of the Inertial Sensor.
Usage:
BrainInertial.rotation(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The units that represent the rotation:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn, then show the total rotation
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", BrainInertial.rotation(degrees));
}
setHeading#
setHeading sets the heading of the Inertial Sensor to a specific value.
Usage:
BrainInertial.setHeading(value, units);
Parámetros |
Descripción |
|---|---|
|
El valor del encabezado a establecer. |
|
The unit that represents the new heading:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Make current facing equal to 90 degrees
BrainInertial.setHeading(90, degrees);
// Turn to 0 degrees using that new reference
Drivetrain.turnToHeading(0, degrees);
}
setRotation#
setRotation sets the rotation of the Inertial Sensor to a specific value.
Usage:
BrainInertial.setRotation(value, units);
Parámetros |
Descripción |
|---|---|
|
El valor de rotación a establecer. |
|
The unit that represents the new rotation:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Pretend we have already turned 180 degrees
BrainInertial.setRotation(180, degrees);
// Spin back to the 0 degree rotation
Drivetrain.turnToRotation(0, degrees);
}
calibrate#
calibrate calibrates the Inertial Sensor. All subsequent lines will wait for the calibration to complete before executing. Calibration is an internal procedure that measures and compensates for sensor noise and drift over a specified period. During this time, the Brain must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.
Los cerebros VEX intentan calibrarse automáticamente al inicio de cada proyecto. Sin embargo, si el robot se transporta o se mueve durante el inicio del proyecto, el sensor podría no calibrarse correctamente o generar una calibración incorrecta.
Usage:
BrainInertial.calibrate();
Parámetro |
Descripción |
|---|---|
Este método no tiene parámetros. |
isCalibrating#
isCalibrating checks if the Inertial Sensor is currently calibrating.
1- The Inertial Sensor is calibrating.0- The Inertial Sensor is not calibrating.
Usage:
isCalibrating()
Parámetro |
Descripción |
|---|---|
Este método no tiene parámetros. |
resetHeading#
resetHeading resets the heading of the Inertial Sensor to 0.
Usage:
BrainInertial.resetHeading();
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn to 90, reset heading, then turn to 90 again
Drivetrain.turnToHeading(90, degrees);
wait(0.5, seconds);
BrainInertial.resetHeading();
Drivetrain.turnToHeading(90, degrees);
}
resetRotation#
resetRotation resets the rotation of the Inertial Sensor to 0.
Usage:
BrainInertial.resetRotation();
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn to rotation -90, reset, then turn to -90 again
Drivetrain.turnToRotation(-90, degrees);
wait(0.5, seconds);
BrainInertial.resetRotation();
Drivetrain.turnToRotation(-90, degrees);
}
Movimiento#
acceleration#
acceleration returns the acceleration of the Inertial Sensor in terms of G (gravity).
Usage:
BrainInertial.acceleration(axis);
Parámetros |
Descripción |
|---|---|
|
The axis to return the acceleration from:
|
gyroRate#
gyroRate returns the gyro rate for one axis of the Inertial Sensor.
Usage:
BrainInertial.gyroRate(axis, units);
Parámetros |
Descripción |
|---|---|
|
The axis to return the gyro rate from:
|
|
The unit used to represent the gyro rate:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn, then display z-axis rate in degrees per second
Drivetrain.turn(right);
wait(1, seconds);
Brain.Screen.print("%f", BrainInertial.gyroRate(zaxis, dps));
Drivetrain.stop();
}
orientation#
orientation returns the orientation for one axis of the Inertial Sensor.
Usage:
BrainInertial.orientation(type, units);
Parámetros |
Descripción |
|---|---|
|
The axis to return the orientation from:
|
|
The unit used to represent the orientation:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Display the changes in orientation as the Brain
// Tilt and rotate the Brain to see the values change
while (true) {
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Roll: %f", BrainInertial.orientation(roll, degrees));
Brain.Screen.newLine();
Brain.Screen.print("Pitch: %f", BrainInertial.orientation(pitch, degrees));
Brain.Screen.newLine();
Brain.Screen.print("Yaw: %f", BrainInertial.orientation(yaw, degrees));
wait(100, msec);
}
}
changed#
changed registers a callback function for when the Inertial Sensor’s heading changes.
Usage:
BrainInertial.changed(callback);
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando cambie el rumbo del sensor inercial. |
void onHeadingChange() {
// Show a message when heading changes
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Heading changed!");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Register callback and cause a heading change
BrainInertial.changed(onHeadingChange);
Drivetrain.turnFor(right, 90, degrees);
}
Constructores#
inertial#
inertial creates an Inertial Sensor.
Usage:
inertial BrainInertial = inertial();
Parámetro |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Create an Inertial object and read heading
inertial BrainInertial = inertial();
}


