慣性#

介紹#

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)