慣性#
介紹#
大腦內置慣性感測器。此感測器可以測量大腦的運動或轉動情況。
慣性感測器由兩部分組成。陀螺儀測量轉向,例如大腦朝向哪個方向以及轉向的角度。加速度計測量運動變化,例如加速、減速或在碰撞過程中突然停止。
慣性方法可用於追蹤轉彎、重置航向或旋轉值、測量橫滾、俯仰和偏航,以及報告加速度。
慣性感測器的編碼方式有很多種。以下列出了所有慣性感測器的編碼方式:
方向調整-返回並設定大腦的朝向、轉動或傾斜方向。
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)