惯性#
介绍#
大脑内置惯性传感器。该传感器可以测量大脑的运动或转动情况。
惯性传感器由两部分组成。陀螺仪测量转向,例如大脑朝向哪个方向以及转向的角度。加速度计测量运动变化,例如加速、减速或在碰撞过程中突然停止。
惯性方法可用于跟踪转弯、重置航向或旋转值、测量横滚、俯仰和偏航,以及报告加速度。
惯性传感器的编码方式有很多种。以下列出了所有惯性传感器的编码方式:
方向调整——返回并设置大脑的朝向、转动或倾斜方向。
get_heading— 返回大脑面向的方向,从 0 到 359 度。get_rotation— 返回大脑旋转了多远。get_yaw— 返回大脑从其起始位置向左或向右旋转了多少。get_roll— 返回大脑向左或向右倾斜的程度。get_pitch— 返回大脑向前或向后倾斜的程度。calibrate— 校准大脑的惯性传感器。reset_heading— 将大脑的当前航向重置为 0 度。reset_rotation— 将大脑的当前旋转重置为 0 度。set_heading— 将大脑的当前方向设置为新的方向值。set_rotation— 将大脑的当前旋转设置为新的旋转值。
运动——反馈大脑的运动方式。
get_acceleration— 返回大脑在选定轴上加速或减速的速度。
方向#
get_heading#
航向是指大脑面向的方向,以 0 到 359 度为单位测量 get_heading 返回大脑的当前航向。
起始航向为0度。如果大脑转动超过359度,航向将回转至0度。
用法:
inertial.get_heading()
参数 |
描述 |
|---|---|
该方法没有参数。 |
get_rotation#
旋转角度是指大脑旋转的程度,以度为单位。与方向不同,旋转角度可以超过 359 度 get_rotation 返回大脑当前的旋转角度。
向右转动会增加旋转角度,向左转动会减少旋转角度。例如,向右转动两圈将旋转 720 度。从 0 度向左转动一圈将旋转 -360 度。
用法:
inertial.get_rotation()
参数 |
描述 |
|---|---|
该方法没有参数。 |
get_yaw#
偏航角是指大脑相对于其起始位置向左或向右旋转的角度,以度为单位。0 get_yaw 返回大脑当前的偏航角值。
右转会增加偏航角,左转会减小偏航角。偏航角可用于在不使用环绕航向值的情况下检查左右转弯情况。
用法:
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 校准大脑的惯性传感器。
校准有助于惯性传感器正确测量转向角度。校准期间,请保持主机静止约 2 秒钟。如果在校准期间主机移动,则航向、旋转、偏航、横滚和俯仰值可能无法正确测量。
程序将等待校准完成后再运行下一行代码。
用法:
inertial.calibrate()
参数 |
描述 |
|---|---|
该方法没有参数。 |
reset_heading#
航向角是指大脑朝向的方向,以度为单位。0 reset_heading 将大脑的当前航向角重置为 0 度。
使用这种方法后,大脑的当前方向将变为新的 0 度航向。
用法:
inertial.reset_heading()
参数 |
描述 |
|---|---|
该方法没有参数。 |
reset_rotation#
旋转角度是指大脑旋转的程度,以度为单位。0 reset_rotation 将大脑当前的旋转角度重置为 0 度。
使用这种方法后,大脑会从新的 0 度旋转值开始跟踪未来的转弯。
用法:
inertial.reset_rotation()
参数 |
描述 |
|---|---|
该方法没有参数。 |
set_heading#
航向是指大脑面向的方向,以 0 到 359 度为单位测量 set_heading 将大脑的当前航向更改为新的航向值。
例如,如果大脑转向右侧,将航向设置为 0 度,则该右侧位置将成为新的 0 度。然后,大脑可以根据这个新方向跟踪其他航向。
用法:
inertial.set_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)
参数 |
描述 |
|---|---|
|
大脑的旋转值,以度为单位。该值可以是整数。 |
运动#
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.
用法:
inertial.get_acceleration(axis)
参数 |
描述 |
|---|---|
|
测量加速度的轴: |
# 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)