惯性#

介绍#

VEX 123 机器人内置惯性传感器。该传感器可以测量机器人的运动状态。

惯性传感器使用加速度计来测量运动变化,例如在碰撞过程中加速、减速或突然停止。

以下是所有惯性测量方法的列表:

获取器 — 返回机器人的移动方式。

  • is_crashed — Returns whether the robot has detected a crash.

  • get_acceleration — Returns how quickly the robot is speeding up or slowing down on the selected axis.

获取器#

is_crashed#

is_crashed returns a Boolean that reports whether the robot has detected a crash — a sudden stop or impact.

  • True — The robot has detected a crash.

  • False — The robot has not detected a crash.

Usage:
robot.is_crashed()

参数

描述

此方法没有参数。

# Back up after a crash.
robot.drive(FORWARD)
while not robot.is_crashed():
    wait(0.05, SECONDS)
robot.drive_for(REVERSE, 200, MM)

get_acceleration#

Acceleration is how quickly the robot is speeding up or slowing down. get_acceleration returns the acceleration of the robot 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.

Usage:
robot.inertial.get_acceleration(axis)

参数

描述

axis

The axis to measure acceleration on: X, Y, or Z.

# Display the acceleration on the X axis
while True:
    console.clear()
    console.print(robot.inertial.get_acceleration(X), precision=2)
    wait(0.1, SECONDS)