Inercial#
Introducción#
El cerebro posee un sensor inercial incorporado. Este sensor puede medir cómo se mueve o gira el cerebro.
El sensor inercial utiliza dos componentes para lograr esto. El giroscopio mide los giros, como la dirección hacia la que apunta el cerebro y la amplitud de su giro. El acelerómetro mide los cambios en el movimiento, como acelerar, desacelerar o detenerse bruscamente durante un choque.
Los métodos inerciales pueden utilizarse para rastrear giros, restablecer valores de rumbo o rotación, medir el balanceo, la inclinación y la guiñada, e informar sobre la aceleración.
Existen muchas maneras de programar el sensor inercial. A continuación se muestra una lista de todos los métodos inerciales:
Orientación: Regrese y configure la orientación, el giro o la inclinación del cerebro.
get_heading— Returns the direction the Brain is facing, from 0 to 359 degrees.get_rotation— Returns how far the Brain has turned.get_yaw— Returns how much the Brain has turned left or right from its starting position.get_roll— Returns how much the Brain is tilted left or right.get_pitch— Returns how much the Brain is tilted forward or backward.calibrate— Calibrates the Brain’s Inertial Sensor.reset_heading— Resets the Brain’s current heading to 0 degrees.reset_rotation— Resets the Brain’s current rotation to 0 degrees.set_heading— Sets the Brain’s current heading to a new heading value.set_rotation— Sets the Brain’s current rotation to a new rotation value.
Movimiento: Devuelve cómo se mueve el cerebro.
get_acceleration— Returns how quickly the Brain is speeding up or slowing down on the selected axis.
Orientación#
get_heading#
A heading is the direction the Brain is facing, measured in degrees from 0 to 359. get_heading returns the Brain’s current heading.
El rumbo inicial es de 0 grados. Si el cerebro gira más allá de los 359 grados, el rumbo vuelve a 0 grados.
Uso:
inertial.get_heading()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
get_rotation#
Rotation is how much the Brain has turned, measured in degrees. Unlike heading, rotation can increase past 359 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. get_rotation returns the Brain’s current rotation.
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.
Uso:
inertial.get_rotation()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
get_yaw#
Yaw is how much the Brain has turned left or right from its starting position, measured in degrees. get_yaw returns the Brain’s current yaw value.
Girar a la derecha aumenta el valor de guiñada, y girar a la izquierda lo disminuye. La guiñada es útil para comprobar los giros a izquierda y derecha sin utilizar el valor de rumbo envuelto.
Uso:
inertial.get_yaw()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
get_roll#
Roll is how much the Brain tilts to the left or right, measured in degrees. get_roll returns the Brain’s current roll value.
Con el cerebro mirando hacia adelante, inclinarlo hacia la izquierda aumenta el valor de balanceo, e inclinarlo hacia la derecha lo disminuye.
Uso:
inertial.get_roll()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
get_pitch#
Pitch is how much the Brain tilts forward or backward, measured in degrees. get_pitch returns the Brain’s current pitch value.
Con el cerebro orientado hacia adelante, inclinarlo hacia adelante aumenta el valor del tono, e inclinarlo hacia atrás lo disminuye.
Uso:
inertial.get_pitch()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
calibrate#
calibrate calibrates the Brain’s Inertial Sensor.
La calibración ayuda al sensor inercial a medir los giros correctamente. Mantenga el dispositivo inmóvil durante aproximadamente 2 segundos durante la calibración. Si el dispositivo se mueve durante la calibración, es posible que los valores de rumbo, rotación, guiñada, alabeo y cabeceo no se midan correctamente.
El proyecto esperará a que finalice la calibración antes de ejecutar la siguiente línea de código.
Uso:
inertial.calibrate()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
reset_heading#
A heading is the direction the Brain is facing, measured in degrees. reset_heading resets the Brain’s current heading to 0 degrees.
Una vez utilizado este método, la dirección actual del cerebro se convierte en la nueva dirección de 0 grados.
Uso:
inertial.reset_heading()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
reset_rotation#
Rotation is how much the Brain has turned, measured in degrees. reset_rotation resets the Brain’s current rotation to 0 degrees.
Una vez utilizado este método, el cerebro realiza un seguimiento de los giros futuros a partir del nuevo valor de rotación de 0 grados.
Uso:
inertial.reset_rotation()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
set_heading#
A heading is the direction the Brain is facing, measured in degrees from 0 to 359. set_heading changes the Brain’s current heading to a new heading value.
Por ejemplo, si el cerebro ha girado para mirar hacia la derecha, al establecer la orientación a 0 grados, esa posición mirando hacia la derecha se convierte en la nueva dirección de 0 grados. Entonces, el cerebro puede seguir otras orientaciones basándose en esa nueva dirección.
Uso:
inertial.set_heading(heading)
Parámetros |
Descripción |
|---|---|
|
El valor del encabezado, en grados, que se establecerá para el Cerebro. Puede ser un número entero entre 0 y 359. |
set_rotation#
Rotation is how much the Brain has turned, measured in degrees. Unlike heading, rotation can increase past 359 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the Brain’s current rotation to a new value.
Por ejemplo, si el cerebro ha dado dos vueltas completas a la derecha, su valor de rotación será de 720 grados. Si se establece la rotación en 0 grados, esta volverá a su valor original. A partir de ahí, el cerebro podrá realizar el seguimiento de las rotaciones basándose en ese nuevo valor.
Usage:
inertial.set_rotation(rotation)
Parámetros |
Descripción |
|---|---|
|
El valor de rotación, en grados, que se configurará para el Cerebro. Puede ser un número entero. |
Movimiento#
get_acceleration#
Acceleration is how quickly the Brain is speeding up or slowing down. get_acceleration returns the acceleration of the Brain on the selected axis, from -4.0 G to 4.0 G.
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 X, Y, and Z.
Uso:
inertial.get_acceleration(axis)
Parámetros |
Descripción |
|---|---|
|
The axis to measure acceleration on: |
# Build Used: Super Code Base 2.0
def main():
# Display the acceleration after moving.
drivetrain.set_drive_velocity(100)
console.print("Resting: ")
console.print(inertial.get_acceleration(X), precision=2)
console.new_line()
wait(1, SECONDS)
drivetrain.drive_for(FORWARD, 500, MM, wait=False)
wait(0.20, SECONDS)
console.print("Startup: ")
console.print(inertial.get_acceleration(X), precision=2)
# Start threads — Do not delete
start_thread(main)