Inercial#
Inicializando la clase inercial#
Un sensor inercial se crea utilizando el siguiente constructor:
Inertial(port)
Parámetro |
Descripción |
---|---|
|
Opcional. Si se utiliza el sensor inercial integrado del EXP Brain, no se necesita un puerto inteligente. Si se conecta un sensor inercial externo, especifique el Puerto inteligente al que está conectado el sensor inercial. |
# Create a new object "brain_inertial" with the
# Inertial class.
brain_inertial = Inertial()
This brain_inertial
object will be used in all subsequent examples throughout this API documentation when referring to Inertial class methods.
Métodos de clase#
calibrate()#
El sensor giroscópico o inercial ajustará automáticamente sus valores dependiendo de la orientación del EXP Brain durante la calibración para que permanezca consistente en todas las posibles orientaciones del EXP Brain.
The calibrate()
method calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving. Allow at least 2 seconds for calibration to complete.
Devoluciones: Ninguna.
# Start calibration.
brain_inertial.calibrate()
# Print that the Inertial Sensor is calibrating while
# waiting for it to finish calibrating.
while brain_inertial.is_calibrating():
brain.screen.clear()
brain.screen.print("Inertial Sensor Calibrating")
wait(50, MSEC)
is_calibrating()#
The is_calibrating()
method checks if the Inertial Sensor is currently calibrating.
Returns: True
if the Inertial Sensor is calibrating. False
if it is not.
# Start calibration.
brain_inertial.calibrate()
# Print that the Inertial Sensor is calibrating while
# waiting for it to finish calibrating.
while brain_inertial.is_calibrating():
brain.screen.clear()
brain.screen.print("Inertial Sensor Calibrating")
wait(50, MSEC)
set_heading()#
The set_heading(value, units)
method sets the heading of the Inertial Sensor to a specified value.
Parámetros |
Descripción |
---|---|
valor |
El valor del encabezado a establecer. |
unidades |
Optional. A valid RotationUnits type. The default is |
Devoluciones: Ninguna.
# Set the Inertial Sensor's heading to 180 degrees.
brain_inertial.set_heading(180)
reset_heading()#
The reset_heading()
method resets the heading of the Inertial Sensor to 0.
Devoluciones: Ninguna.
heading()#
The heading(units)
method returns the current heading of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid RotationUnits type. The default is |
Devuelve: El rumbo actual del sensor inercial en las unidades especificadas.
# Get the current heading for the Inertial Sensor.
value = brain_inertial.heading()
set_rotation()#
The set_rotation(value, units)
method sets the rotation of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
valor |
El valor de rotación a establecer. |
unidades |
Optional. A valid RotationUnits type. The default is |
Devoluciones: Ninguna.
# Set the Inertial Sensor's rotation to 180 degrees.
brain_inertial.set_rotation(180)
reset_rotation()#
The reset_rotation()
method resets the rotation of the Inertial Sensor to 0.
Devoluciones: Ninguna.
rotation()#
The rotation(units)
method returns the current rotation of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid RotationUnits type. The default is |
Devuelve: La rotación actual del sensor inercial en las unidades especificadas.
# Print the value of the current rotation of the
# Inertial Sensor to the Brain's screen.
brain.screen.print(brain_inertial.rotation())
orientation()#
The orientation(axis, units)
method returns the orientation for one axis of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
eje |
Un AxisType válido. |
unidades |
Optional. A valid RotationUnits type. The default is |
Devuelve: Un valor para la orientación del eje en las unidades especificadas.
# Get the pitch value for the Inertial Sensor.
pitch = brain_inertial.orientation(OrientationType.PITCH)
gyro_rate()#
The gyro_rate(axis, units)
method returns the gyro rate for one axis of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
eje |
Un AxisType válido. |
unidades |
Optional. A valid VelocityUnits type. The default is |
Devuelve: Un valor para la velocidad del giro del eje en las unidades especificadas.
# Get the gyro rate for the Z axis of the Inertial Sensor.
zrate = brain_inertial.gyro_rate(ZAXIS)
acceleration()#
The acceleration(axis)
method returns the acceleration of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
eje |
Un AxisType válido. |
Devuelve: Un valor para la aceleración del eje en unidades de gravedad.
# Get the acceleration for the Z axis of the Inertial Sensor.
zaccel = brain_inertial.acceleration(ZAXIS)
# Print the value of the current acceleration of the z-axis
# of the Inertial Sensor to the Brain's screen.
brain.screen.print(zaccel)
changed()#
The changed(callback, arg)
method registers a callback function for when the Inertial Sensor’s heading changes.
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. |
Devuelve: Una instancia de la clase Event.
# Define a function heading_changed()
def heading_changed():
# The Brain will print that the heading changed on the
# Brain's screen.
brain.screen.print("heading changed ")
# Run heading_changed when the heading for this
# Inertial Sensor changes.
brain_inertial.changed(heading_changed)
collision()#
The collision(callback, arg)
method registers a callback function for when the Inertial Sensor detects a collision.
Parámetros |
Descripción |
---|---|
llamar de vuelta |
La función de devolución de llamada que se llamará cuando se detecte una colisión. |
arg |
Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada. |
Devuelve: Una instancia de la clase Event.
# Define a function collision_occur().
def collision_occur():
# The Brain will print that a collision was detected by
# the Inertial Sensor on the Brain's screen.
brain.screen.print("collision detected ")
# Run collision_occur when the heading for this
# Inertial Sensor detects a collision.
brain_inertial.collision(collision_occur)
set_turn_type()#
The set_turn_type(turntype)
method sets the direction that returns positive values for the heading.
Parámetros |
Descripción |
---|---|
tipo de giro |
Un TurnType válido. |
Devoluciones: Ninguna.
# Set the turn type to left.
brain_inertial.set_turn_type(LEFT)
# Set the turn type to right.
brain_inertial.set_turn_type(RIGHT)
get_turn_type()#
The get_turn_type()
method returns the direction that returns positive values for heading.
Devuelve: El tipo de giro del sensor inercial en las unidades especificadas.
installed()#
The installed()
method checks if the Inertial Sensor is installed.
Returns: True
if the Inertial Sensor is installed. False
if it is not.
timestamp()#
The timestamp()
method returns the timestamp of the last received status packet from the Inertial Sensor.
Devuelve: La marca de tiempo del último paquete de estado recibido en milisegundos.