Inercial#
Introducción#
El sensor inercial mide la rotación y la orientación del robot V5. El sensor puede registrar el movimiento en los ejes x, y, z y puede utilizarse para determinar el rumbo, la rotación y la inclinación. También puede medir su aceleración en los ejes x, y, z.
Para que los comandos inerciales aparezcan en VEXcode V5, se debe configurar un sensor inercial en la ventana Dispositivos.
A continuación se muestra una lista de los métodos disponibles:
Orientación
heading– Returns the current heading.rotation– Returns the current rotation.gyro_rate– Returns the gyro rate for one axis of the Inertial Sensor.orientation– Returns the orientation for one axis of the Inertial Sensor.set_heading– Sets the Inertial Sensor’s heading to a specified value.set_rotation– Sets the Inertial Sensor’s rotation value.calibrate– Calibrates the Inertial Sensor for stable heading tracking.reset_heading– Sets the heading of the Inertial Sensor to 0.reset_rotation– Sets the rotation of the Inertial Sensor to 0.is_calibrating– Returns whether or not the Inertial Sensor is calibrating.changed– Registers a callback function for when the Inertial Sensor’s heading changes.installed– Checks if the Inertial Sensor is installed.
Movimiento
acceleration– Returns the linear acceleration along the x, y, or z axis.collision– Registers a callback function for when the Inertial Sensor detects a collision.set_turn_type– Sets the direction that returns positive values for the heading.get_turn_type– Returns the direction that returns positive values for heading.
Constructor
Inertial– Creates an Inertial Sensor.
Orientación#
heading#
heading returns the current heading of the Inertial Sensor in the specified units as a float.
Uso:
inertial_1.heading(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The unit used to represent the heading:
|
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.heading())
rotation#
rotation returns the current rotation of the Inertial Sensor in the specified units as a float.
Uso:
inertial_1.rotation(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The unit used to represent the rotation:
|
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.rotation())
gyro_rate#
gyro_rate returns the gyro rate for one axis of the Inertial Sensor in the specified units as a float.
Uso:
inertial_1.gyro_rate(axis, units)
Parámetros |
Descripción |
|---|---|
|
The axis to return the gyro rate from:
|
|
Optional. The unit used to represent the gyro rate:
|
# 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 returns the orientation for one axis of the Inertial Sensor as a float.
Uso:
inertial_1.orientation(type, units)
Parámetros |
Descripción |
|---|---|
|
The axis to return the orientation from:
|
|
Optional. The unit used to represent the orientation:
|
# 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)
set_heading#
set_heading sets the heading of the Inertial Sensor to a specified value.
Uso:
inertial_1.set_heading(value, units)
Parámetros |
Descripción |
|---|---|
|
El valor del encabezado a establecer. |
|
Optional. The unit used to represent the heading:
|
# Turn the robot around
inertial_1.set_heading(180, DEGREES)
drivetrain.turn_to_heading(0)
set_rotation#
set_rotation sets the rotation of the Inertial Sensor to a specified value.
Uso:
inertial_1.set_rotation(value, units)
Parámetros |
Descripción |
|---|---|
|
El valor de rotación a establecer. |
|
Optional. The unit used to represent the rotation:
|
# Turn the robot around
inertial_1.set_rotation(-180, DEGREES)
drivetrain.turn_to_rotation(0)
calibrate#
calibrate calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving. Allow at least 2 seconds for calibration to complete.
Uso:
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)
reset_heading#
reset_heading resets the heading of the Inertial Sensor to 0.
Uso:
inertial_1.reset_heading()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
reset_rotation#
reset_rotation resets the rotation of the Inertial Sensor to 0.
Uso:
inertial_1.reset_rotation()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
is_calibrating#
is_calibrating checks if the Inertial Sensor is currently calibrating.
True- The Inertial Sensor is calibrating.False- The Inertial Sensor is not calibrating.
Uso:
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 previamente definida que se ejecuta cuando cambia el valor del sensor inercial. |
|
Opcional. Una tupla que contiene los argumentos que se pasan 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 returns the acceleration of the Inertial Sensor along the specified axis as a float.
Uso:
inertial_1.acceleration(type)
Parámetros |
Descripción |
|---|---|
|
The axis to return the acceleration from:
|
# 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 collision.
Usage:
inertial_1.collision(callback, arg)
Parámetros |
Descripción |
|---|---|
|
Una función previamente definida que se ejecuta cuando se detecta una colisión. |
|
Opcional. Una tupla que contiene los argumentos que se pasan 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 the direction that returns positive values for the heading.
Usage:
inertial_1.set_turn_type(turntype)
Parámetros |
Descripción |
|---|---|
|
The turn type to set:
|
get_turn_type#
get_turn_type returns the direction that returns positive values for heading.
LEFT- The turn type is left.RIGHT- The turn type is right.
Uso:
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(port)
Parámetros |
Descripción |
|---|---|
|
El puerto inteligente al que está conectado el sensor inercial del 1 al 21. |
# Create a new object "inertial_1" with the Inertial class.
inertial_1 = Inertial(Ports.PORT1)