惯性#

介绍#

大脑内置惯性传感器。该传感器可以测量大脑的运动或转动情况。

惯性传感器由两部分组成。陀螺仪测量转向,例如大脑朝向哪个方向以及转向的角度。加速度计测量运动变化,例如加速、减速或在碰撞过程中突然停止。

惯性方法可用于跟踪转弯、重置航向或旋转值、测量横滚、俯仰和偏航,以及报告加速度。

惯性传感器的编码方式有很多种。以下列出了所有惯性传感器的编码方式:

方向调整——返回并设置大脑的朝向、转动或倾斜方向。

  • get_heading — Returns the direction the Brain is facing, from 0 to 359 degrees.

  • get_rotation — Returns how far the Brain has turned.

  • get_yaw — Returns how much the Brain has turned left or right from its starting position.

  • get_roll — Returns how much the Brain is tilted left or right.

  • get_pitch — Returns how much the Brain is tilted forward or backward.

  • calibrate — Calibrates the Brain’s Inertial Sensor.

  • reset_heading — Resets the Brain’s current heading to 0 degrees.

  • reset_rotation — Resets the Brain’s current rotation to 0 degrees.

  • set_heading — Sets the Brain’s current heading to a new heading value.

  • set_rotation — Sets the Brain’s current rotation to a new rotation value.

运动——反馈大脑的运动方式。

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

方向#

get_heading#

A heading is the direction the Brain is facing, measured in degrees from 0 to 359. get_heading returns the Brain’s current heading.

起始航向为0度。如果大脑转动超过359度,航向将回转至0度。

用法:
inertial.get_heading()

参数

描述

该方法没有参数。

get_rotation#

Rotation is how much the Brain has turned, measured in degrees. Unlike heading, rotation can increase past 359 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. get_rotation returns the Brain’s current rotation.

向右转动会增加旋转角度,向左转动会减少旋转角度。例如,向右转动两圈将旋转 720 度。从 0 度向左转动一圈将旋转 -360 度。

用法:
inertial.get_rotation()

参数

描述

该方法没有参数。

get_yaw#

Yaw is how much the Brain has turned left or right from its starting position, measured in degrees. get_yaw returns the Brain’s current yaw value.

右转会增加偏航角,左转会减小偏航角。偏航角可用于在不使用环绕航向值的情况下检查左右转弯情况。

用法:
inertial.get_yaw()

参数

描述

该方法没有参数。

get_roll#

Roll is how much the Brain tilts to the left or right, measured in degrees. get_roll returns the Brain’s current roll value.

大脑朝向前方时,向左倾斜会增加滚动值,向右倾斜会减少滚动值。

用法:
inertial.get_roll()

参数

描述

该方法没有参数。

get_pitch#

Pitch is how much the Brain tilts forward or backward, measured in degrees. get_pitch returns the Brain’s current pitch value.

大脑朝向前方,向前倾斜会增加音调值,向后倾斜会降低音调值。

用法:
inertial.get_pitch()

参数

描述

该方法没有参数。

calibrate#

calibrate calibrates the Brain’s Inertial Sensor.

校准有助于惯性传感器正确测量转向角度。校准期间,请保持主机静止约 2 秒钟。如果在校准期间主机移动,则航向、旋转、偏航、横滚和俯仰值可能无法正确测量。

程序将等待校准完成后再运行下一行代码。

用法:
inertial.calibrate()

参数

描述

该方法没有参数。

reset_heading#

A heading is the direction the Brain is facing, measured in degrees. reset_heading resets the Brain’s current heading to 0 degrees.

使用这种方法后,大脑的当前方向将变为新的 0 度航向。

用法:
inertial.reset_heading()

参数

描述

该方法没有参数。

reset_rotation#

Rotation is how much the Brain has turned, measured in degrees. reset_rotation resets the Brain’s current rotation to 0 degrees.

使用这种方法后,大脑会从新的 0 度旋转值开始跟踪未来的转弯。

用法:
inertial.reset_rotation()

参数

描述

该方法没有参数。

set_heading#

A heading is the direction the Brain is facing, measured in degrees from 0 to 359. set_heading changes the Brain’s current heading to a new heading value.

例如,如果大脑转向右侧,将航向设置为 0 度,则该右侧位置将成为新的 0 度。然后,大脑可以根据这个新方向跟踪其他航向。

用法:
inertial.set_heading(heading)

参数

描述

heading

要为大脑设置的航向值,以度为单位。该值可以是 0 到 359 之间的整数。

set_rotation#

Rotation is how much the Brain has turned, measured in degrees. Unlike heading, rotation can increase past 359 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the Brain’s current rotation to a new value.

例如,如果大脑向右旋转了两圈,其旋转角度将为 720 度。将旋转角度设置为 0 度会将旋转角度从 720 度重置为 0 度。然后,大脑可以根据这个新值跟踪旋转。

Usage:
inertial.set_rotation(rotation)

参数

描述

rotation

大脑的旋转值,以度为单位。该值可以是整数。

运动#

get_acceleration#

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

用法:
inertial.get_acceleration(axis)

参数

描述

axis

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

# Build Used: Super Code Base 2.0
def main():
    # Display the acceleration after moving.
    drivetrain.set_drive_velocity(100)
    console.print("Resting: ")
    console.print(inertial.get_acceleration(X), precision=2)
    console.new_line()
    wait(1, SECONDS)
    drivetrain.drive_for(FORWARD, 500, MM, wait=False)
    wait(0.20, SECONDS)
    console.print("Startup: ")
    console.print(inertial.get_acceleration(X), precision=2)

# Start threads — Do not delete
start_thread(main)