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.
A continuación se muestra una lista de todos los métodos disponibles:
Orientación: mide el movimiento de rotación del sensor inercial.
encabezado – Devuelve el encabezado actual.
rotación – Devuelve la rotación acumulada.
setHeading – Establece el rumbo del sensor inercial en un valor específico.
setRotation – Establece el valor de rotación del sensor inercial.
calibrar – Calibra el sensor inercial para un seguimiento de rumbo estable.
isCalibrating – Devuelve si el sensor inercial está calibrando o no.
resetHeading – Establece el rumbo del sensor inercial en 0.
resetRotation – Establece la rotación del sensor inercial en 0.
Movimiento – Detecta cambios en el movimiento.
aceleración – Devuelve la aceleración lineal a lo largo del eje x, y o z.
gyroRate – Devuelve la velocidad angular alrededor del eje x, y o z.
orientación – Devuelve el balanceo, cabeceo o guiñada en función de la inclinación y la rotación.
cambiado – Registra una función para llamar cuando el sensor inercial detecta un cambio.
Constructores: inicializan y configuran manualmente un sensor inercial.
inertial – Creates an Inertial Sensor.
Orientación#
título#
heading
returns the current heading of the Inertial Sensor in degrees.
Usage:
heading()
Parámetros |
Descripción |
---|---|
Este método no tiene parámetros. |
// Display the heading after turning
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", BrainInertial.heading());
Overload:
heading(units)
Parámetros |
Descripción |
---|---|
units |
The unit used to represent the heading:
|
// Display the heading after turning
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", BrainInertial.heading(turns));
rotación#
rotation
returns the current rotation of the Gyro Sensor in degrees.
Usage:
rotation()
Parámetros |
Descripción |
---|---|
Este método no tiene parámetros. |
// Display the rotation after turning
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", DrivetrainGyro.rotation());
Overload:
rotation(units)
Parámetros |
Descripción |
---|---|
units |
The unit used to represent the rotation:
|
// Display the rotation after turning
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", DrivetrainGyro.rotation(turns));
establecerEncabezado#
setHeading
establece el rumbo del sensor inercial a un valor específico.
Usage:
setHeading(value, units)
Parámetros |
Descripción |
---|---|
value |
El valor del encabezado a establecer. |
units |
La unidad que representa el nuevo rumbo:
|
// Turn the robot around
BrainInertial.setHeading(180, degrees);
Drivetrain.turnToHeading(0, degrees);
setRotation#
setRotation
establece la rotación del sensor inercial a un valor específico.
Usage:
setRotation(value, units)
Parámetros |
Descripción |
---|---|
value |
El valor de rotación a establecer. |
units |
La unidad que representa la nueva rotación:
|
// Turn the robot around
BrainInertial.setRotation(-180, degrees);
Drivetrain.turnToRotation(0, degrees);
calibrar#
calibrate
calibra el sensor inercial. Todas las líneas subsiguientes esperarán a que se complete la calibración antes de ejecutarse. La calibración es un procedimiento interno que mide y compensa el ruido y la deriva del sensor durante un período específico. Durante este tiempo, el cerebro debe permanecer completamente inmóvil (es decir, sobre una superficie estable sin ningún movimiento externo). El movimiento durante la calibración producirá resultados inexactos.
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:
calibrate()
Parámetro |
Descripción |
---|---|
Este método no tiene parámetros. |
// Start calibration
BrainInertial.calibrate();
// Print after calibration
while (BrainInertial.isCalibrating()){
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Inertial Sensor");
Brain.Screen.newLine();
Brain.Screen.print("Calibrating");
wait(50, msec);
}
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Done!");
está calibrando#
isCalibrate
verifica si el sensor inercial se está calibrando actualmente.
1
- El sensor inercial se está calibrando.0
- El sensor inercial no está calibrando.
Uso:
isCalibrating()
Parámetro |
Descripción |
---|---|
Este método no tiene parámetros. |
// Start calibration
BrainInertial.calibrate();
// Print while calibrating
while (BrainInertial.isCalibrating()){
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Inertial Sensor");
Brain.Screen.newLine();
Brain.Screen.print("Calibrating");
wait(50, msec);
}
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Done!");
restablecerEncabezado#
resetHeading
restablece el rumbo del sensor inercial a 0.
Usage:
resetHeading()
Parámetros |
Descripción |
---|---|
Este método no tiene parámetros. |
// Turn the robot before and after resetting the heading
Drivetrain.turnToHeading(90, degrees);
wait(0.5, seconds);
BrainInertial.resetHeading();
Drivetrain.turnToHeading(90, degrees);
restablecerRotación#
resetRotation
restablece la rotación del sensor inercial a 0.
Usage:
resetRotation()
Parámetros |
Descripción |
---|---|
Este método no tiene parámetros. |
// Turn the robot before and after resetting the rotation
Drivetrain.turnToRotation(-90, degrees);
wait(0.5, seconds);
BrainInertial.resetRotation();
Drivetrain.turnToRotation(-90, degrees);
Movimiento#
aceleración#
acceleration
returns the acceleration of the Inertial Sensor.
Usage:
acceleration(axis)
Parámetros |
Descripción |
---|---|
axis |
El eje desde el que se retorna la aceleración:
|
// Display acceleration after moving
Drivetrain.setDriveVelocity(100, percent);
Brain.Screen.print("Resting: ");
Brain.Screen.newLine();
Brain.Screen.print("%.2f", BrainInertial.acceleration(xaxis));
Brain.Screen.newLine();
wait(1, seconds);
Drivetrain.driveFor(forward, 500, mm, false);
wait(0.01,seconds);
Brain.Screen.print("Startup: ");
Brain.Screen.newLine();
Brain.Screen.print("%.2f", BrainInertial.acceleration(xaxis));
tasa de giro#
gyroRate
devuelve la velocidad del giroscopio para un eje del sensor inercial.
Usage:
gyroRate(axis, units)
Parámetros |
Descripción |
---|---|
axis |
El eje desde el que se retorna la velocidad del giroscopio:
|
units |
The unit used to represent the gyro rate:
|
// Display the z-axis gyro rate
Drivetrain.turn(right);
wait(1, seconds);
Brain.Screen.print("%f", BrainInertial.gyroRate(zaxis, rpm));
Drivetrain.stop();
orientación#
orientation
devuelve la orientación de un eje del sensor inercial.
Usage:
orientation(axis, units)
Parámetros |
Descripción |
---|---|
axis |
El eje desde el que se retorna la orientación:
|
units |
La unidad utilizada para representar la orientación:
|
// Display the roll, pitch, and yaw of the Brain as it
// is rotated by hand
while (true){
Brain.Screen.clearScreen();
Brain.Screen.print("%f", BrainInertial.orientation(roll, degrees));
Brain.Screen.newLine();
Brain.Screen.print("%f", BrainInertial.orientation(pitch, degrees));
Brain.Screen.newLine();
Brain.Screen.print("%f", BrainInertial.orientation(yaw, degrees));
Brain.Screen.setCursor(1, 1);
wait(0.1,seconds);
}
cambió#
changed
registra una función de devolución de llamada para cuando cambia el rumbo del sensor inercial.
Usage:
changed(callback)
Parámetros |
Descripción |
---|---|
callback |
La función de devolución de llamada que se llamará cuando cambie el rumbo del sensor inercial. |
void headingChanged(){
Brain.Screen.setCursor(1, 1);
Brain.Screen.clearScreen();
Brain.Screen.print("My heading ");
Brain.Screen.newLine();
Brain.Screen.print("has changed!");
wait(0.1, seconds);
}
int main() {
vexcodeInit();
// Call when Inertial heading is changed
wait(1, seconds);
Drivetrain.turnFor(right, 90, degrees, false);
BrainInertial.changed(headingChanged);
wait(15, msec);
}
Constructores#
Constructors are used to manually create inertial
objects, which are necessary for configuring an Inertial Sensor outside of VEXcode.
For the examples below, the configured Inertial Sensor will be named BrainInertial
and will be used in all subsequent examples throughout this API documentation when referring to inertial
class methods.
inercial#
inertial
crea un sensor inercial.
Usage:
inertial()
Parámetro |
Descripción |
---|---|
Este método no tiene parámetros. |
// Create a new object "BrainInertial" with the
// inertial class
inertial BrainInertial = inertial();
motor LeftDriveSmart = motor(PORT1, 1, false);
motor RightDriveSmart = motor(PORT6, 1, true);
smartdrive Drivetrain = smartdrive(LeftDriveSmart, RightDriveSmart, BrainInertial, 200);
BrainInertial.setHeading(180);
Drivetrain.turnToHeading(0);