慣性#
導入#
慣性センサーは、ロボットの動きや旋回状態を測定します。
慣性センサーは、この目的のために2つの部分を使用します。ジャイロスコープは、方位、回転、ジャイロレート、向きなどの回転を測定します。加速度計は、x軸、y軸、z軸に沿った加速や減速などの動きの変化を測定します。
利用可能なメソッドの一覧は以下のとおりです。
方位設定 ― 方位、回転、センサーのキャリブレーションを読み取り、制御します。
heading— センサーが向いている方向を0度から359.99度の範囲で返します。rotation— センサーがどれだけ回転したかを返します。gyro_rate— センサーが選択された軸を中心に回転する速度を返します。orientation— 慣性センサーのロール、ピッチ、またはヨー角を返します。calibrate— 慣性センサーを校正します。set_heading— 慣性センサーの現在の方位を新しい方位値に設定します。set_rotation— 慣性センサーの現在の回転を新しい回転値に設定します。reset_heading— 慣性センサーの現在の方位を0度にリセットします。reset_rotation— 慣性センサーの現在の回転を0度にリセットします。is_calibrating— 慣性センサーが現在キャリブレーション中かどうかを返します。changed— 慣性センサーの値が変化したときに実行される関数を登録します。installed— 慣性センサーがインストールされているかどうかを確認します。
動作 — 加速度、衝突、旋回方向の挙動を測定します。
acceleration— センサーが選択された軸でどれだけ速く加速または減速しているかを返します。collision— 慣性センサーが衝突を検出したときに実行する関数を登録します。set_turn_type— 正の進行方向値を返す旋回方向を設定します。get_turn_type— 正の進行方向値を返す旋回方向を返します。
コンストラクタ
Inertial– 慣性センサーを作成します。
オリエンテーション#
heading#
方位とは、センサーが向いている方向のことで、0度から359.99度までの角度で測定されます heading は、センサーの現在の方位を浮動小数点数として返します。
開始時の方位は0度です。センサーが359.99度を超えて回転すると、方位は0度に戻ります。
Usage:
inertial_1.heading(units)
パラメータ |
説明 |
|---|---|
|
オプション。方位単位: |
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.heading())
rotation#
Rotation is how much the sensor has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the Inertial Sensor’s current rotation as a float.
右に回すと回転角度が大きくなり、左に回すと回転角度が小さくなります。例えば、右に2回転すると720度回転します。0度から左に1回転すると-360度回転します。
Usage:
inertial_1.rotation(units)
パラメータ |
説明 |
|---|---|
|
オプション。回転単位: |
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.rotation())
gyro_rate#
ジャイロレートとは、慣性センサーが回転する速度のことです。0 gyro_rate 選択した軸における慣性センサーの現在の回転速度を float 型で返します。
センサーがその軸を中心に回転する方向によって、値は正にも負にもなり得る。
Usage:
inertial_1.gyro_rate(axis, units)
パラメータ |
説明 |
|---|---|
|
ジャイロレートを返す軸:
|
|
オプション。ジャイロレート単位:
|
# Display the rate of change of
# rotation while turning
drivetrain.turn(RIGHT)
wait(1, SECONDS)
brain.screen.print(inertial_1.gyro_rate(AxisType.ZAXIS, VelocityUnits.DPS))
drivetrain.stop()
orientation#
方向は、選択された回転軸に対する慣性センサーの現在の角度です。0 方向 orientation 、慣性センサーのロール、ピッチ、またはヨーを -180.00 度から 180.00 度の範囲で浮動小数点数として返します。
ロール、ピッチ、ヨーは、センサーが傾いたり回転したりするさまざまな方法を表します。
Usage:
inertial_1.orientation(type, units)
パラメータ |
説明 |
|---|---|
|
返す方向角度:
|
|
オプション。方向単位:
|
# Display the roll, pitch, and yaw of the Brain as it
# is rotated by hand
while True:
brain.screen.clear_screen()
brain.screen.print(inertial_1.orientation(AxisType.ROLL, DEGREES))
brain.screen.next_row()
brain.screen.print(inertial_1.orientation(AxisType.PITCH, DEGREES))
brain.screen.next_row()
brain.screen.print(inertial_1.orientation(AxisType.YAW, DEGREES))
brain.screen.next_row()
brain.screen.set_cursor(1, 1)
wait(0.1, SECONDS)
calibrate#
calibrate 慣性センサーを校正します。
キャリブレーションは、センサーが回転を正確に測定するのに役立ちます。キャリブレーション中はセンサーを動かさないでください。キャリブレーション中にセンサーが動くと、方位、回転、ジャイロレート、および姿勢の値が正しく測定されない可能性があります。
プロジェクトは、キャリブレーションが完了するまで次のコード行の実行を待ちます。
Usage:
inertial_1.calibrate()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Start calibration.
inertial_1.calibrate()
# Print that the Inertial Sensor is calibrating while
# waiting for it to finish calibrating.
while inertial_1.is_calibrating():
brain.screen.clear()
brain.screen.print("Inertial Sensor Calibrating")
wait(50, MSEC)
set_heading#
方位とは、センサーが向いている方向のことで、0度から359.99度までの度数で表されます set_heading は、慣性センサーの現在の方位を新しい方位値に変更します。
例えば、センサーが右を向いた場合、方位を0度に設定すると、その右向きの位置が新たな0度になります。その後、センサーはその新たな方向に基づいて他の方位を追跡できます。
Usage:
inertial_1.set_heading(value, units)
パラメータ |
説明 |
|---|---|
|
センサーに設定する方位角の値(度単位)。0~359.99の範囲の値を指定できます。 |
|
オプション。方位単位: |
# Turn the robot around
inertial_1.set_heading(180, DEGREES)
drivetrain.turn_to_heading(0)
set_rotation#
回転とは、センサーがどれだけ回転したかを示す度数です。方位とは異なり、回転は359.99度を超えて増加したり、0度未満に減少したりすることがあります。プロジェクトの開始時には、回転値は0度に設定されます。0 set_rotation 慣性センサーの現在の回転を新しい値に変更します。
例えば、センサーが右に2回転した場合、回転値は720度になります。回転を0度に設定すると、回転値は720度から0度にリセットされます。その後、センサーはその新しい値に基づいて回転を追跡できます。
Usage:
inertial_1.set_rotation(value, units)
パラメータ |
説明 |
|---|---|
|
センサーに設定する回転角度(度数)。整数または小数(浮動小数点数)を指定できます。 |
|
オプション。回転単位: |
# Turn the robot around
inertial_1.set_rotation(-180, DEGREES)
drivetrain.turn_to_rotation(0)
reset_heading#
reset_heading は慣性センサーの現在の方位を 0 度にリセットします。
この方法を用いると、センサーの現在の方向が新たな0度の方位角となる。
Usage:
inertial_1.reset_heading()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
reset_rotation#
reset_rotation は慣性センサーの現在の回転を 0 度にリセットします。
この方法を用いると、センサーは新しい0度の回転値から将来の回転を追跡する。
Usage:
inertial_1.reset_rotation()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
is_calibrating#
is_calibrating は、慣性センサーが現在キャリブレーション中かどうかを返します。
True— 慣性センサーが校正中です。False— 慣性センサーが校正されていません。
Usage:
inertial_1.is_calibrating()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
changed#
changed 慣性センサーの値が変化するたびに呼び出される関数を登録します。
Usage:
inertial_1.changed(callback, arg)
パラメータ |
説明 |
|---|---|
|
慣性センサーの値が変化したときに実行される、事前に定義された 関数。 |
|
オプション。コールバック関数に渡す引数を含むタプル。詳細については、パラメーター付き関数の使用を参照してください。 |
def my_function():
brain.screen.print("Value changed!!")
# Call my_function whenever inertial_1's value changes
inertial_1.changed(my_function)
installed#
installed 慣性センサーがインストールされているかどうかを確認します。
True— 慣性センサーが設置されています。False— 慣性センサーがインストールされていません。
Usage:
inertial_1.installed()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
モーション#
acceleration#
加速度とは、センサーが加速または減速する速さのことです。加速度が acceleration 、選択された軸の慣性センサーの加速度(-4.0 Gから4.0 Gまで)が浮動小数点数として返されます。
G は加速度を測定するために使用される単位です。1Gは、静止しているときに重力によって感じる加速度に相当します。
The value can be positive or negative depending on the direction of acceleration on the selected axis. The axis options are AxisType.XAXIS, AxisType.YAXIS, and AxisType.ZAXIS.
Usage:
inertial_1.acceleration(type)
パラメータ |
説明 |
|---|---|
|
加速度を測定する軸:
|
# Return the acceleration for the Z axis of the Inertial Sensor
zaccel = inertial_1.acceleration(AxisType.ZAXIS)
collision#
collision 、慣性センサーが突然の衝撃や衝突を検出したときに呼び出される関数を登録します。
Usage:
inertial_1.collision(callback, arg)
パラメータ |
説明 |
|---|---|
|
衝突が検出されたときに実行される、事前に定義された 関数。 |
|
オプション。コールバック関数に渡す引数を含むタプル。詳細については、パラメーター付き関数の使用を参照してください。 |
def my_function():
brain.screen.print("Collision!")
# Call my_function whenever a collision is detected
inertial_1.collision(my_function)
set_turn_type#
set_turn_type は、正の進行方向値を返す旋回方向を設定します。
Usage:
inertial_1.set_turn_type(turntype)
パラメータ |
説明 |
|---|---|
|
設定するターンタイプ:
|
get_turn_type#
get_turn_type は、どの旋回方向が正の進行方向値を返すかを示します。
LEFT— 左折は正の進行方向値を返します。RIGHT— 右折は正の進行方向値を返します。
Usage:
inertial_1.get_turn_type()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
建設業者#
Inertial#
Inertial は慣性センサーを作成します。
Usage:
Inertial(smartport)
パラメータ |
説明 |
|---|---|
|
慣性センサーが接続されているスマートポートは、 |
# Create a new object "inertial_1" with the Inertial class.
inertial_1 = Inertial(Ports.PORT1)