惯性#

介绍#

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

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

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

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

  • is_crashed — 返回机器人是否检测到碰撞。

  • get_acceleration — 返回机器人在选定轴上加速或减速的速度。

获取器#

is_crashed#

is_crashed 返回一个 Boolean,报告机器人是否检测到碰撞——突然停止或撞击。

  • True — 机器人检测到碰撞。

  • False ​​— 机器人未检测到碰撞。

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#

加速度是指机器人加速或减速的快慢。0 get_acceleration 返回机器人在所选轴上的加速度,范围从 -4.0 G 到 4.0 G。

G 相当于你静止坐着时感受到的重力加速度。

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

测量加速度的轴: X Y,或 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)