Inercial#
Introducción#
El cerebro IQ (2.ª generación) incluye un sensor inercial integrado con un giroscopio y un acelerómetro de 3 ejes. Esto permite al robot rastrear su orientación, rumbo y aceleración.
A continuación se muestra una lista de todos los métodos disponibles:
Métodos – Medir el movimiento de rotación y detectar cambios en el movimiento.
calibrar – Calibra el sensor inercial para un seguimiento de rumbo estable.
set_heading – Establece el rumbo del sensor inercial en un valor específico.
set_rotation – Establece el valor de rotación del sensor inercial.
encabezado – Devuelve el encabezado actual.
rotación – Devuelve la rotación acumulada.
aceleración – Devuelve la aceleración lineal a lo largo del eje x, y o z.
gyro_rate – 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.
is_calibrating – Devuelve si el sensor inercial está calibrando o no.
reset_heading – Establece el rumbo del sensor inercial en 0.
reset_rotation – Establece la rotación del sensor inercial en 0.
cambiado – Registra una función para llamar cuando el sensor inercial detecta un cambio.
Constructores: inicializan y configuran manualmente un sensor inercial.
Inercial – Crea un sensor inercial.
Métodos#
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.
Uso:
calibrate()
Parámetro |
Descripción |
---|---|
Este método no tiene parámetros. |
# Start calibration
brain_inertial.calibrate()
# Print after calibration
while brain_inertial.is_calibrating():
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Inertial Sensor")
brain.screen.next_row()
brain.screen.print("Calibrating")
wait(50, MSEC)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")
establecer_encabezado#
set_heading()
establece el rumbo del sensor inercial a un valor especificado.
Uso:
set_heading(valor, unidades)
Parámetros |
Descripción |
---|---|
valor |
El valor del encabezado a establecer. |
unidades |
Opcional. Unidad utilizada para representar el nuevo rumbo:
|
# Turn the robot around
brain_inertial.set_heading(180)
drivetrain.turn_to_heading(0)
rotación_del_conjunto#
set_rotation()
establece la rotación del sensor inercial.
Uso:
set_rotation(valor, unidades)
Parámetros |
Descripción |
---|---|
valor |
El valor de rotación a establecer. |
unidades |
Opcional. Unidad utilizada para representar el nuevo valor de rotación:
|
# Turn the robot around
brain_inertial.set_rotation(-180)
drivetrain.turn_to_rotation(0)
título#
heading
devuelve el rumbo actual del sensor inercial.
Uso:
heading(unidades)
Parámetros |
Descripción |
---|---|
unidades |
Opcional. Unidad utilizada para representar el rumbo:
|
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(brain_inertial.heading())
rotación#
rotation
devuelve la rotación actual del sensor inercial.
Uso:
rotación(unidades)
Parámetros |
Descripción |
---|---|
unidades |
Opcional. Unidad utilizada para representar la rotación:
|
# Display the rotation value after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(brain_inertial.rotation())
aceleración#
acceleration
devuelve la aceleración del sensor inercial.
Uso:
aceleración(eje)
Parámetros |
Descripción |
---|---|
eje |
El eje desde el que se retorna la aceleración:
|
# Display acceleration after moving
vexcode_brain_precision = 2
drivetrain.set_drive_velocity(100,PERCENT)
brain.screen.print("Resting: ")
brain.screen.next_row()
brain.screen.print(brain_inertial.acceleration(XAXIS))
brain.screen.next_row()
wait(1, SECONDS)
drivetrain.drive_for(FORWARD, 500, MM, wait=False)
wait(0.01,SECONDS)
brain.screen.print("Startup: ")
brain.screen.next_row()
brain.screen.print(brain_inertial.acceleration(XAXIS))
tasa de giro#
gyro_rate
devuelve la velocidad del giroscopio para un eje del sensor inercial.
Uso:
gyro_rate(axis, units)
Parámetros |
Descripción |
---|---|
eje |
El eje desde el que se retorna la velocidad del giroscopio:
|
unidades |
Opcional. Unidad utilizada para representar la velocidad del giroscopio:
|
# Display the z-axis gyro rate
drivetrain.turn(RIGHT)
wait(1, SECONDS)
brain.screen.print(brain_inertial.gyro_rate(ZAXIS, RPM))
drivetrain.stop()
orientación#
orientation
devuelve la orientación de un eje del sensor inercial.
Uso:
orientación(eje, unidades)
Parámetros |
Descripción |
---|---|
eje |
El eje desde el que se retorna la orientación:
|
unidades |
Opcional. 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.clear_screen()
brain.screen.print(brain_inertial.orientation(OrientationType.ROLL))
brain.screen.next_row()
brain.screen.print(brain_inertial.orientation(OrientationType.PITCH))
brain.screen.next_row()
brain.screen.print(brain_inertial.orientation(OrientationType.YAW))
brain.screen.next_row()
brain.screen.set_cursor(1, 1)
wait(0.1,SECONDS)
está_calibrando#
is_calibrating
verifica si el sensor inercial se está calibrando actualmente.
Verdadero
: el sensor inercial se está calibrando.Falso
: el sensor inercial no está calibrando.
Uso:
is_calibrating()
Parámetro |
Descripción |
---|---|
Este método no tiene parámetros. |
# Start calibration
brain_inertial.calibrate()
# Print while waiting for calibration
while brain_inertial.is_calibrating():
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Inertial Sensor")
brain.screen.next_row()
brain.screen.print("Calibrating")
wait(50, MSEC)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")
restablecer_encabezado#
reset_heading
restablece el rumbo del sensor inercial a 0.
Uso:
reset_heading()
Parámetros |
Descripción |
---|---|
Este método no tiene parámetros. |
# Turn the robot before and after resetting the heading
drivetrain.turn_to_heading(90, DEGREES)
wait(0.5,SECONDS)
brain_inertial.reset_heading()
drivetrain.turn_to_heading(90, DEGREES)
restablecer_rotación#
reset_rotation
restablece la rotación del sensor inercial a 0.
Uso:
reset_rotation()
Parámetros |
Descripción |
---|---|
Este método no tiene parámetros. |
# Turn the robot before and after resetting the rotation
drivetrain.turn_to_rotation(-90, DEGREES)
wait(0.5,SECONDS)
brain_inertial.reset_rotation()
drivetrain.turn_to_rotation(-90, DEGREES)
cambió#
changed
registra una función de devolución de llamada para cuando cambia el rumbo del sensor inercial.
Uso:
changed(callback, arg)
Parámetros |
Descripción |
---|---|
llamar de vuelta |
La función de devolución de llamada que se llamará cuando cambie el rumbo del sensor inercial. |
arg |
Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada. |
def heading_changed():
brain.screen.set_cursor(1, 1)
brain.screen.clear_screen()
brain.screen.print("my heading ")
brain.screen.next_row()
brain.screen.print("has changed!")
wait(0.1, SECONDS)
# Call the function when the inertial heading is changed
wait(1, SECONDS)
drivetrain.turn_for(RIGHT, 90, DEGREES, wait=False)
brain_inertial.changed(heading_changed)
wait(15, MSEC)
Constructores#
Los constructores se utilizan para crear manualmente objetos “inerciales”, que son necesarios para configurar un sensor inercial fuera de VEXcode.
Para los ejemplos a continuación, el sensor inercial configurado se llamará brain_inertial
y se utilizará en todos los ejemplos posteriores en esta documentación de API cuando se haga referencia a los métodos de la clase Inertial
.
Inercial#
Inercial
crea un sensor inercial.
Uso:
Inercial(puerto)
Parámetro |
Descripción |
---|---|
|
Opcional. Si se utiliza el sensor inercial integrado del cerebro IQ (2.ª generación), no se necesita un puerto inteligente. Si se conecta un sensor inercial externo, especifique el puerto inteligente al que está conectado el sensor inercial como “PUERTO” seguido del número de puerto, del 1 al 12. |
# Create a new object "brain_inertial" with the
# Inertial class
brain_inertial = Inertial()
left_drive_smart = Motor(Ports.PORT1, 1.0, False)
right_drive_smart = Motor(Ports.PORT6, 1.0, True)
drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)
brain_inertial.set_heading(180)
drivetrain.turn_to_heading(0)