Inercial#
Introducción#
Un sensor inercial mide cómo se mueve y gira el robot.
El sensor inercial utiliza dos componentes para realizar esta función. El giroscopio mide los giros, como la dirección, la rotación, la velocidad angular y la orientación. El acelerómetro mide los cambios en el movimiento, como la aceleración o la desaceleración a lo largo de los ejes x, y y z.
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 direction the sensor is facing, from 0 to 359.99 degrees.rotation— Returns how far the sensor has turned.gyro_rate— Returns how fast the sensor is rotating on the selected axis.orientation— Returns the Inertial Sensor’s roll, pitch, or yaw angle.calibrate— Calibrates the Inertial Sensor.set_heading— Sets the Inertial Sensor’s current heading to a new heading value.set_rotation— Sets the Inertial Sensor’s current rotation to a new rotation value.reset_heading— Resets the Inertial Sensor’s current heading to 0 degrees.reset_rotation— Resets the Inertial Sensor’s current rotation to 0 degrees.is_calibrating— Returns whether the Inertial Sensor is currently calibrating.changed— Registers a function to run when the Inertial Sensor’s value changes.installed— Checks if the Inertial Sensor is installed.
Movimiento: Mide la aceleración, las colisiones y el comportamiento de la dirección de giro.
acceleration— Returns how quickly the sensor is speeding up or slowing down on the selected axis.collision— Registers a function to run when the Inertial Sensor detects a collision.set_turn_type— Sets which turn direction returns positive heading values.get_turn_type— Returns which turn direction returns positive heading values.
Constructor
Inertial– Creates an Inertial Sensor.
Orientación#
heading#
A heading is the direction the sensor is facing, measured in degrees from 0 to 359.99. heading returns the sensor’s current heading as a float.
El rumbo inicial es de 0 grados. Si el sensor gira más allá de los 359,99 grados, el rumbo vuelve a 0 grados.
Usage:
inertial_1.heading(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The heading unit: |
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.heading())
rotation#
Rotation is how much the sensor has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the Inertial Sensor’s current rotation as a float.
Girar a la derecha aumenta la rotación, y girar a la izquierda la disminuye. Por ejemplo, dos giros completos a la derecha producen una rotación de 720 grados. Un giro completo a la izquierda desde 0 grados produce una rotación de -360 grados.
Usage:
inertial_1.rotation(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The rotation unit: |
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.rotation())
gyro_rate#
Gyro rate is how fast the Inertial Sensor is rotating. gyro_rate returns the current rotation speed of the Inertial Sensor on the selected axis as a float.
El valor puede ser positivo o negativo dependiendo de la dirección en la que gire el sensor sobre ese eje.
Usage:
inertial_1.gyro_rate(axis, units)
Parámetros |
Descripción |
|---|---|
|
The axis to return the gyro rate from:
|
|
Optional. The gyro rate unit:
|
# Display the rate of change of
# rotation while turning
drivetrain.turn(RIGHT)
wait(1, SECONDS)
brain.screen.print(inertial_1.gyro_rate(AxisType.ZAXIS, VelocityUnits.DPS))
drivetrain.stop()
orientation#
Orientation is the Inertial Sensor’s current angle on a selected turning axis. orientation returns the roll, pitch, or yaw of the Inertial Sensor, from -180.00 to 180.00 degrees, as a float.
El balanceo, la inclinación y la guiñada describen las diferentes maneras en que el sensor puede inclinarse o girar.
Usage:
inertial_1.orientation(type, units)
Parámetros |
Descripción |
|---|---|
|
The orientation angle to return:
|
|
Optional. The orientation unit:
|
# Display the roll, pitch, and yaw of the Brain as it
# is rotated by hand
while True:
brain.screen.clear_screen()
brain.screen.print(inertial_1.orientation(AxisType.ROLL, DEGREES))
brain.screen.next_row()
brain.screen.print(inertial_1.orientation(AxisType.PITCH, DEGREES))
brain.screen.next_row()
brain.screen.print(inertial_1.orientation(AxisType.YAW, DEGREES))
brain.screen.next_row()
brain.screen.set_cursor(1, 1)
wait(0.1, SECONDS)
calibrate#
calibrate calibrates the Inertial Sensor.
La calibración ayuda al sensor a medir los giros correctamente. Mantenga el sensor inmóvil durante la calibración. Si el sensor se mueve durante la calibración, es posible que los valores de rumbo, rotación, velocidad angular y orientación no se midan correctamente.
El proyecto esperará a que finalice la calibración antes de ejecutar la siguiente línea de código.
Usage:
inertial_1.calibrate()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Start calibration.
inertial_1.calibrate()
# Print that the Inertial Sensor is calibrating while
# waiting for it to finish calibrating.
while inertial_1.is_calibrating():
brain.screen.clear()
brain.screen.print("Inertial Sensor Calibrating")
wait(50, MSEC)
set_heading#
A heading is the direction the sensor is facing, measured in degrees from 0 to 359.99. set_heading changes the Inertial Sensor’s current heading to a new heading value.
Por ejemplo, si el sensor se ha girado hacia la derecha, al ajustar la orientación a 0 grados, esa posición hacia la derecha se convierte en la nueva dirección de 0 grados. De esta forma, el sensor puede seguir otras orientaciones basándose en esa nueva dirección.
Usage:
inertial_1.set_heading(value, units)
Parámetros |
Descripción |
|---|---|
|
El valor de rumbo, en grados, que se configurará para el sensor. Este valor puede estar entre 0 y 359,99. |
|
Optional. The heading unit: |
# Turn the robot around
inertial_1.set_heading(180, DEGREES)
drivetrain.turn_to_heading(0)
set_rotation#
Rotation is how much the sensor has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the Inertial Sensor’s current rotation to a new value.
Por ejemplo, si el sensor ha dado dos vueltas completas a la derecha, su valor de rotación será de 720 grados. Al establecer la rotación en 0 grados, esta volverá a su valor original. De esta forma, el sensor podrá registrar las rotaciones basándose en ese nuevo valor.
Usage:
inertial_1.set_rotation(value, units)
Parámetros |
Descripción |
|---|---|
|
El valor de rotación, en grados, que se configurará para el sensor. Puede ser un número entero o decimal (flotante). |
|
Optional. The rotation unit: |
# Turn the robot around
inertial_1.set_rotation(-180, DEGREES)
drivetrain.turn_to_rotation(0)
reset_heading#
reset_heading resets the Inertial Sensor’s current heading to 0 degrees.
Una vez utilizado este método, la dirección actual del sensor se convierte en la nueva dirección de 0 grados.
Usage:
inertial_1.reset_heading()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
reset_rotation#
reset_rotation resets the Inertial Sensor’s current rotation to 0 degrees.
Una vez utilizado este método, el sensor registra los giros futuros a partir del nuevo valor de rotación de 0 grados.
Usage:
inertial_1.reset_rotation()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
is_calibrating#
is_calibrating returns whether the Inertial Sensor is currently calibrating.
True— The Inertial Sensor is calibrating.False— The Inertial Sensor is not calibrating.
Usage:
inertial_1.is_calibrating()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
changed#
changed registers a function to be called whenever the Inertial Sensor’s value changes.
Usage:
inertial_1.changed(callback, arg)
Parámetros |
Descripción |
|---|---|
|
Una función definida previamente que se ejecuta cuando cambia el valor del sensor inercial. |
|
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. |
def my_function():
brain.screen.print("Value changed!!")
# Call my_function whenever inertial_1's value changes
inertial_1.changed(my_function)
installed#
installed checks if the Inertial Sensor is installed.
True— The Inertial Sensor is installed.False— The Inertial Sensor is not installed.
Usage:
inertial_1.installed()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
Movimiento#
acceleration#
Acceleration is how quickly the sensor is speeding up or slowing down. acceleration returns the acceleration of the Inertial Sensor on the selected axis, from -4.0 G to 4.0 G, as a float.
A G is a unit used to measure acceleration. 1 G is about the acceleration you feel from gravity while sitting still.
The value can be positive or negative depending on the direction of acceleration on the selected axis. The axis options are AxisType.XAXIS, AxisType.YAXIS, and AxisType.ZAXIS.
Usage:
inertial_1.acceleration(type)
Parámetros |
Descripción |
|---|---|
|
The axis to measure acceleration on:
|
# Return the acceleration for the Z axis of the Inertial Sensor
zaccel = inertial_1.acceleration(AxisType.ZAXIS)
collision#
collision registers a function to be called whenever the Inertial Sensor detects a sudden impact or collision.
Usage:
inertial_1.collision(callback, arg)
Parámetros |
Descripción |
|---|---|
|
Una función definida previamente que se ejecuta cuando se detecta una colisión. |
|
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. |
def my_function():
brain.screen.print("Collision!")
# Call my_function whenever a collision is detected
inertial_1.collision(my_function)
set_turn_type#
set_turn_type sets which turn direction returns positive heading values.
Usage:
inertial_1.set_turn_type(turntype)
Parámetros |
Descripción |
|---|---|
|
The turn type to set:
|
get_turn_type#
get_turn_type returns which turn direction returns positive heading values.
LEFT— Left turns return positive heading values.RIGHT— Right turns return positive heading values.
Usage:
inertial_1.get_turn_type()
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 Inertial Sensor is connected to, written as |
# Create a new object "inertial_1" with the Inertial class.
inertial_1 = Inertial(Ports.PORT1)