Inercial#

Introducción#

El sensor inercial del robot de codificación VEX AIM incluye un giroscopio de 3 ejes integrado para medir el movimiento de rotación y un acelerómetro de 3 ejes para detectar cambios en el 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:

Orientación: obtenga la dirección y los ángulos del robot.

Choque – Detecta colisiones.

  • crashed – Registers a function to run when a collision is detected.

  • set_crash_sensitivity – Set the acceleration to trigger a crash event.

Movimiento – Mide la aceleración y la velocidad de giro.

Calibración – Administrar la calibración del sensor.

  • calibrate – Calibrates the inertial sensor.

  • is_calibrating – Returns whether the sensor is currently calibrating.

Orientación#

get_rotation#

get_rotation returns the robot’s net rotation in degrees as a float.

Usage:
robot.inertial.get_rotation()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the robot's rotation as it rotates
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    robot.screen.print(f"Rotation: {robot.inertial.get_rotation():.2f}")
    wait(50, MSEC)

get_heading#

get_heading returns the robot’s heading angle as a float in the range 0 to 359.99 degrees.

Uso:

robot.inertial.get_heading()

Parámetros

Descripción

Este método no tiene parámetros.

# Turn right until the heading reaches 90 degrees
robot.turn(RIGHT)
while robot.inertial.get_heading() < 90:
    wait(50, MSEC)
robot.stop_all_movement()

# Display the robot's heading as it is rotated by hand
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    robot.screen.print(f"Heading: {robot.inertial.get_heading()} degrees")
    wait(50, MSEC)

get_yaw#

get_yaw returns the robot’s yaw angle in the range –180.00 to 180.00 degrees as a float.

La imagen a continuación utiliza flechas para mostrar la dirección de rotación positiva para guiñada.

Un robot de codificación VEX AIM con una flecha azul que apunta hacia abajo desde el centro del robot. Alrededor de la flecha azul, una flecha curva negra apunta en el sentido de las agujas del reloj, indicando la dirección positiva del giro.

Uso:

robot.inertial.get_yaw()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the robot's yaw angle as it is rotated by hand
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    robot.screen.print(robot.inertial.get_yaw())
    wait(50, MSEC)

get_roll#

get_roll returns the robot’s roll angle in the range –180.00 to 180.00 degrees as a float.

La imagen a continuación utiliza flechas para mostrar la dirección de rotación positiva del rollo.

Un robot de codificación VEX AIM con una flecha verde que se extiende hacia el frente del robot, en el centro del sensor de visión de IA. Alrededor de la flecha verde, una flecha negra se curva en sentido contrario a las agujas del reloj, indicando la dirección positiva para el balanceo.

Uso:

robot.inertial.get_roll()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the robot's roll angle as it is tilted by hand
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    robot.screen.print(robot.inertial.get_roll())
    wait(50, MSEC)

get_pitch#

get_pitch returns the robot’s pitch angle in the range –90.00 to 90.00 degrees as a float.

La imagen a continuación utiliza flechas para mostrar la dirección de rotación positiva del paso.

Un robot de codificación VEX AIM con una flecha roja que sobresale del lateral, debajo del logotipo de VEX. Alrededor de la flecha roja, una flecha negra se curva en sentido contrario a las agujas del reloj, indicando la dirección positiva para el cabeceo.

Uso:

robot.inertial.get_pitch()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the robot's pitch angle as it is tilted by hand
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    robot.screen.print(robot.inertial.get_pitch())
    wait(50, MSEC)

reset_rotation#

reset_rotation resets the robot’s gyro rotation value to 0 degrees.

Usage:
robot.inertial.reset_rotation()

Parámetros

Descripción

Este método no tiene parámetros.

# Reset the robot's rotation if it exceeds 180 degrees
while True:
    if robot.inertial.get_rotation() >= 180:
        robot.inertial.reset_rotation()
    
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    robot.screen.print(f"Rotation: {robot.inertial.get_rotation():.2f}")
    
    wait(50, MSEC)

reset_heading#

reset_heading resets the robot’s heading to 0 degrees.

Uso:

robot.inertial.reset_heading()

Parámetros

Descripción

Este método no tiene parámetros.

# Turn the robot around using a new 90 degree heading
robot.turn_to(90)
wait(1, SECONDS)
robot.inertial.reset_heading()
robot.turn_to(90)

set_heading#

set_heading sets the robot’s heading to a specified value in the range 0 to 359.99 degrees.

Uso:

robot.inertial.set_heading(heading)

Parámetros

Descripción

heading

El valor a utilizar para el nuevo rumbo en el rango de 0 a 359,99 grados.

# Turn the robot to 90 degrees using its new heading
robot.inertial.set_heading(45)
robot.turn_to(90)

Chocar#

crashed#

crashed registers a function to be called when the robot detects a collision.

Uso:

robot.inertial.crashed(callback, arg)

Parámetros

Descripción

callback

Una función que se define previamente para ejecutarse cuando se detecta una colisión.

arg

Opcional. Una tupla que contiene los argumentos que se pasarán a la función de devolución de llamada. Consulte Uso de funciones con parámetros para obtener más información.

# Define what happens when a crash occurs
def crash_detected():
    # Stop all movement and indicate a crash occurred
    robot.screen.print("Crash detected")
    robot.stop_all_movement()

robot.inertial.crashed(crash_detected)

# Drive forward until crash
robot.move_at(0, 100)

set_crash_sensitivity#

set_crash_sensitivity adjusts the acceleration threshold required to trigger a crash response.

Usage:
robot.inertial.set_crash_sensitivity(sensitivity)

Parámetros

Descripción

sensitivity

The crash sensitivity:

  • HIGH – Most sensitive, triggers at 1G.
  • NORMAL – Default sensitivity, triggers at 1.5G.
  • LOW – Least sensitive, triggers at 2G.

def crashed_callback():
    robot.stop_all_movement()
    robot.sound.play(CRASH)

# system event handlers
robot.inertial.crashed(crashed_callback)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)

# Detect a crash at a slow velocity.
robot.set_move_velocity(35, PERCENT)
robot.inertial.set_crash_sensitivity(HIGH)
robot.move_at(0)

Movimiento#

get_acceleration#

get_acceleration returns the robot’s acceleration in a specified direction as a float in the range –4.00 to 4.00 g.

Un robot de codificación VEX AIM con flechas direccionales que se extienden desde el centro del robot. Una flecha verde etiquetada como "adelante" se extiende desde la parte frontal del robot, una flecha azul etiquetada como "abajo" se extiende desde la parte inferior del robot y una flecha roja etiquetada como "a la derecha" se extiende desde el lateral del robot debajo del logotipo de VEX.

Uso:

robot.inertial.get_acceleration(type)

Parámetros

Descripción

type

The direction of acceleration to return:

  • DOWNWARD – Acceleration affecting the robot’s vertical movement.
  • FORWARD – Acceleration affecting the robot’s movement along its front-to-back direction.
  • RIGHTWARD – Acceleration affecting the robot’s movement along its side-to-side direction.
  • # Display the acceleration as the robot begins to move
    robot.screen.set_cursor(4,1)
    sitting_accel = robot.inertial.get_acceleration(RIGHTWARD)
    robot.screen.print(f"Resting: {sitting_accel:.2f}")
    wait(0.5, SECONDS)
    robot.screen.next_row()
    
    robot.move_at(90, 100)
    wait(0.1, SECONDS)
    
    robot.screen.print(f"Startup: {robot.inertial.get_acceleration(RIGHTWARD):.2f}")
    
    

    get_turn_rate#

    get_turn_rate returns the robot’s turning rate in degrees per second (DPS) as a float, from –1000.00 to 1000.00 dps.

    La imagen a continuación utiliza flechas para mostrar la dirección de rotación positiva para balanceo, cabeceo y guiñada.

    Un robot de codificación VEX AIM con flechas direccionales que se extienden desde el centro del robot. Una flecha verde etiquetada como "roll" se extiende desde la parte frontal del robot con una flecha curva negra que apunta en sentido contrario a las agujas del reloj a su alrededor. Una flecha azul etiquetada como "Yaw" se extiende desde la parte inferior del robot con una flecha curva negra que apunta en el sentido de las agujas del reloj a su alrededor. Y una flecha roja etiquetada como "Pitch" se extiende desde el lateral del robot debajo del logotipo de VEX, con una flecha curva negra que apunta en sentido contrario a las agujas del reloj a su alrededor.

    Uso:

    robot.inertial.get_turn_rate(axis)

    Parámetros

    Descripción

    axis

    Which orientation to return:

    • YAW
    • ROLL
      • PITCH

    # Display the gyro rate as the robot is rotated by hand
    while True:
        robot.screen.clear_screen()
        robot.screen.set_cursor(1, 1)
        robot.screen.print(robot.inertial.get_turn_rate(YAW))
        wait(50, MSEC)
    
    

    Calibración#

    La calibración es un procedimiento interno que mide y compensa el ruido y la deriva del sensor durante un periodo de 2 segundos. Durante este tiempo, el robot 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 robots VEX intentan calibrarse automáticamente al iniciarse, esperando hasta que no detecten movimiento. Sin embargo, si el robot se transporta o se mueve durante el inicio, el sensor podría no calibrarse correctamente o generar una calibración incorrecta.

    If your project relies heavily on having an accurate heading, or if you need consistent and repeatable turns, calling calibrate at the beginning of your code can help. It’s good practice to display a message like “Calibrating…” on the robot’s screen during calibration, then update it to “Calibration complete.” afterward to remind you (and anyone else using the robot) that the robot must remain motionless during this period.

    calibrate#

    calibrate calibrates the gyro. Calibration is an internal procedure that measures and compensates for sensor noise and drift over a 2-second period. During this time, the robot must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

    Los robots VEX intentan calibrarse automáticamente al iniciarse, esperando hasta que no detecten movimiento. Sin embargo, si el robot se transporta o se mueve durante el inicio, el sensor podría no calibrarse correctamente o generar una calibración incorrecta.

    Uso:

    robot.inertial.calibrate()

    Parámetros

    Descripción

    Este método no tiene parámetros.

    # Calibrate the gryo before moving
    robot.inertial.calibrate()
    robot.screen.show_emoji(THINKING)
    wait(2,SECONDS)
    robot.screen.show_emoji(PROUD)
    robot.move_for(50, 90)
    
    

    is_calibrating#

    is_calibrating returns a Boolean indicating whether the gyro is calibrating.

    • True – The gyro is calibrating.

    • False – The gyro is not calibrating.

    Usage: robot.inertial.is_calibrating()

    Parámetros

    Descripción

    Este método no tiene parámetros.

    # Move after the calibration is completed
    robot.inertial.calibrate()
    while robot.inertial.is_calibrating():
        robot.screen.show_emoji(THINKING)
        wait(50, MSEC)
    robot.screen.show_emoji(PROUD)
    robot.move_for(50, 90)