inercial#
Introducción#
El sensor inercial mide la rotación y la orientación del robot V5. El sensor puede registrar el movimiento en los ejes x, y, z y puede utilizarse para determinar el rumbo, la rotación y la inclinación. También puede medir su aceleración en los ejes x, y, z.
Para que los comandos inerciales aparezcan en VEXcode V5, se debe configurar un sensor inercial en la ventana Dispositivos.
This page uses Inertial1 as the example Inertial Sensor name. If using a smart drivetrain, the example Inertial Sensor name will be DrivetrainInertial. Replace these with your own configured name as needed.
A continuación se muestra una lista de los métodos disponibles:
Orientación: lee y controla el rumbo, la rotación y la calibración del sensor.
heading— Returns the current heading.rotation— Returns the current 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.resetHeading— Sets the heading of the Inertial Sensor to 0.resetRotation— Sets the rotation of the Inertial Sensor to 0.isCalibrating— Returns whether or not the Inertial Sensor is calibrating.changed— Registers a callback function for when the Inertial Sensor’s heading changes.installed— Checks if the Inertial Sensor is installed.
Movimiento: mide la aceleración, la velocidad angular y la inclinación.
acceleration— Returns the linear acceleration along the x, y, or z axis.gyroRate— Returns the gyro rate for one axis of the Inertial Sensor.orientation— Returns the orientation for one axis of the Inertial Sensor.collision— Registers a callback function for when the Inertial Sensor detects a collision.setTurnType— Sets the direction that returns positive values for the heading.getTurnType— Returns the direction that returns positive values for heading.
Constructor: inicializa y configura manualmente un sensor inercial.
inertial— Creates an Inertial Sensor.
Orientación#
heading#
heading returns the current heading of the Inertial Sensor in the specified units as a float.
Uso:
DrivetrainInertial.heading(units)
Parámetros |
Descripción |
|---|---|
|
The unit used to 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", DrivetrainInertial.heading(degrees));
}
rotation#
rotation returns the current rotation of the Inertial Sensor in the specified units as a float.
Uso:
DrivetrainInertial.rotation(units)
Parámetros |
Descripción |
|---|---|
|
The unit used to represent the rotation:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn, then show the current rotation
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", DrivetrainInertial.rotation(degrees));
}
setHeading#
setHeading sets the heading of the Inertial Sensor to a specified value.
Uso:
DrivetrainInertial.setHeading(value, units);
Parámetros |
Descripción |
|---|---|
|
El valor del encabezado a establecer de 0 a 359 como doble. |
|
The unit used to represent the heading:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn the robot around
DrivetrainInertial.setHeading(180, degrees);
Drivetrain.turnToHeading(0, degrees);
}
setRotation#
setRotation sets the rotation of the Inertial Sensor to a specified value.
Uso:
DrivetrainInertial.setRotation(value, units);
Parámetros |
Descripción |
|---|---|
|
El valor de rotación que se establecerá como doble. |
|
The unit used to represent the rotation:
|
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Pretend we have already turned 180 degrees
DrivetrainInertial.setRotation(-180, degrees);
Drivetrain.turnToRotation(0, degrees);
}
calibrate#
calibrate calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving. Allow at least 2 seconds for calibration to complete.
Uso:
Inertial1.calibrate();
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
resetHeading#
resetHeading resets the heading of the Inertial Sensor to 0.
Uso:
Inertial1.resetHeading();
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
resetRotation#
resetRotation resets the rotation of the Inertial Sensor to 0.
Uso:
Inertial1.resetRotation();
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
isCalibrating#
isCalibrating checks if the Inertial Sensor is currently calibrating.
True— The Inertial Sensor is calibrating.False— The Inertial Sensor is not calibrating.
Uso:
Inertial1.isCalibrating()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
changed#
changed registers a callback function that runs when the Inertial Sensor’s heading value changes.
Usage:
DrivetrainInertial.changed(callback);
Parámetros |
Descripción |
|---|---|
|
Una función previamente definida que se ejecuta cuando cambia el valor del encabezado. |
Callback Signature:
void callback();
Argumentos |
Descripción |
|---|---|
Esta función de devolución de llamada no tiene argumentos. |
// Called when the inertial sensor's heading value changes
void onHeadingChanged() {
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Heading: %.2f", DrivetrainInertial.heading());
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Register the onHeadingChanged callback
// Rotate the robot by hand to see the heading change
DrivetrainInertial.changed(onHeadingChanged);
}
installed#
installed checks if the Inertial Sensor is installed.
true— The Inertial Sensor is installed.false— The Inertial Sensor is not installed.
Usage:
Inertial1.installed()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
Movimiento#
acceleration#
acceleration returns the acceleration of the Inertial Sensor along the specified axis as a double.
Uso:
Inertial1.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 in the specified units as a double.
Uso:
DrivetrainInertial.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();
// Display the rate of change of rotation while turning in dps
Drivetrain.turn(right);
wait(1, seconds);
Brain.Screen.print(DrivetrainInertial.gyroRate(zaxis, dps));
Drivetrain.stop();
}
orientation#
orientation returns the orientation for one axis of the Inertial Sensor in the specified units as a double.
Uso:
DrivetrainInertial.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();
// Let the Inertial Sensor calibrate
wait(2, seconds);
while (true) {
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
// Show the Inertial Sensor's orientation value
// for roll in degrees
double orient = DrivetrainInertial.orientation(roll, degrees);
Brain.Screen.print("%f", orient);
wait(0.1, seconds);
}
}
collision#
collision registers a callback function that runs when the Inertial Sensor detects a sudden acceleration change indicative of a collision.
Usage:
DrivetrainInertial.collision(callback);
Parámetros |
Descripción |
|---|---|
|
Una función de devolución de llamada previamente definida que se llama automáticamente cuando cambia el valor del eje. La función debe coincidir con la firma de devolución de llamada requerida. Consulte Funciones de devolución de llamada para obtener más información. |
Callback Signature:
void callback(axisType axis, double x, double y, double z);
Argumentos |
Descripción |
|---|---|
|
The axis on which the collision was detected:
|
|
Lectura de aceleración en el eje x en el momento de la colisión como doble. |
|
Lectura de aceleración en el eje y en el momento de la colisión como doble. |
|
Lectura de aceleración en el eje z en el momento de la colisión como doble. |
void onCollision(axisType axis, double x, double y, double z) {
Brain.Screen.print("Collision detected!");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Firmly move the robot by hand briefly to simulate
// a collision and call the onCollision function
DrivetrainInertial.collision(onCollision);
}
setTurnType#
setTurnType sets the direction that returns positive values for the heading.
Usage:
Inertial1.setTurnType(direction);
Parámetros |
Descripción |
|---|---|
|
The turn direction that will return positive values:
|
getTurnType#
getTurnType returns the direction that returns positive values for heading.
left— The turn type is left.right— The turn type is right.
Uso:
Inertial1.getTurnType();
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
Constructores#
inertial#
inertial creates an Inertial Sensor.
Usage:
inertial(smartport)
Parámetros |
Descripción |
|---|---|
|
The Smart Port that the AI Vision Sensor is connected to, written as |
// Create a new object "inertial" with the inertial class.
inertial Inertial1 = inertial(PORT1);