Inercial#
Introduction#
The Inertial Sensor measures the rotation and orientation of the V5 robot. The sensor can report movement along the x, y, and z axes and can be used to determine heading, rotation, and tilt. The sensor can also measure its acceleration along the x, y, and z axes.
Para que los comandos inerciales aparezcan en VEXcode V5, se debe configurar un sensor inercial en la ventana Dispositivos.
Below is a list of available methods:
Orientation
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.
Motion
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.
Orientation#
heading#
heading returns the current heading of the Inertial Sensor in the specified units as a float.
Usage:
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.
Usage:
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.
Usage:
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.
Usage:
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.
Usage:
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.
Usage:
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.
Usage:
inertial_1.calibrate()
Parámetros |
Descripción |
|---|---|
This method has no parameters. |
# 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.
Usage:
inertial_1.reset_heading()
Parámetros |
Descripción |
|---|---|
This method has no parameters. |
reset_rotation#
reset_rotation resets the rotation of the Inertial Sensor to 0.
Usage:
inertial_1.reset_rotation()
Parámetros |
Descripción |
|---|---|
This method has no parameters. |
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.
Usage:
inertial_1.is_calibrating()
Parámetros |
Descripción |
|---|---|
This method has no parameters. |
# 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)
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 |
|---|---|
|
A previously defined function that executes when the Inertial Sensor’s value changes. |
|
Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information. |
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 |
|---|---|
This method has no parameters. |
Motion#
acceleration#
acceleration returns the acceleration of the Inertial Sensor along the specified axis as a float.
Usage:
inertial_1.acceleration(type)
Parámetros |
Descripción |
|---|---|
|
The axis to return the acceleration from:
|
# Get 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 |
|---|---|
|
A previously defined function that executes when a collision is detected. |
|
Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information. |
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.
Usage:
inertial_1.get_turn_type()
Parámetros |
Descripción |
|---|---|
This method has no parameters. |
Constructors#
Inertial#
Inertial creates an Inertial Sensor.
Usage:
Inertial(port)
Parámetros |
Descripción |
|---|---|
|
The Smart Port that the Inertial Sensor is connected to from 1 to 21. |
# Create a new object "inertial_1" with the Inertial class.
inertial_1 = Inertial(Ports.PORT1)