パワートレイン#
導入#
駆動系は、VRロボットの走行と旋回を制御します。駆動系は、前進、後退、左折、右折、方向転換、回転などを行うことができます。
ドライブトレインをコーディングする方法は数多くあります。以下に、ドライブトレインのすべてのメソッドの一覧を示します。
動作 — ロボットを移動および旋回させる。
drive— ロボットを永久に前進または後退させます。drive_for— ロボットを特定の距離だけ前進または後退させます。turn— ロボットを永久に左または右に回転させます。turn_for— ロボットを特定の角度だけ左または右に回転させます。turn_to_heading— ロボットを-359度から359度までの特定の方向に向けて回転させます。turn_to_rotation— ロボットを特定の回転方向に回転させます。stop— ロボットの動きを停止します。
ミューテーター — ドライブトレインの設定を調整します。
set_heading— ロボットの現在の進行方向を新しい進行方向に変更します。set_rotation— ロボットの現在の回転を新しい回転に変更します。set_timeout— ロボットが動作を完了しようとする時間を設定します。set_drive_velocity— ロボットに走行速度を指示します。set_turn_velocity— ロボットに旋回速度を指示します。
ゲッターズ — ドライブトレインの状態を確認してください。
行動#
drive#
ドライブdrive 組み合わせでは、ロボットは永久に前進または後退します。ロボットは、旋回や停止などの別の動作が与えられるまで動き続けます。
Usage:
drivetrain.drive(direction)
パラメータ |
説明 |
|---|---|
|
ロボットの移動方向: |
def main():
# Drive forward then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
drive_for#
drive_for は、ロボットを特定の距離だけ前進または後退させます。プロジェクトは、ロボットの移動が完了するまで待機し、その後次のコードが実行されます。
Usage:
drivetrain.drive_for(direction, distance, units, wait)
パラメータ |
説明 |
|---|---|
|
ロボットの移動方向: |
|
ロボットが走行する距離。これは、 |
|
オプション。距離の単位: |
|
オプション |
def main():
# Drive forward and backward
drivetrain.drive_for(FORWARD, 200, MM)
drivetrain.drive_for(REVERSE, 200, MM)
# VR threads — Do not delete
vr_thread(main)
turn#
turn ロボットを左右に永久に回転させます。ロボットは、走行や停止などの別の動作が与えられるまで回転し続けます。
Usage:
drivetrain.turn(direction)
パラメータ |
説明 |
|---|---|
|
ロボットが回転する方向: |
def main():
# Turn right and left, then stop
drivetrain.turn(RIGHT)
wait(2, SECONDS)
drivetrain.turn(LEFT)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
turn_for#
turn_for は、ロボットを指定された角度だけ左右に回転させます。回転角度はロボットの現在位置を基準としています。プロジェクトは、ロボットの回転が完了するまで次のコード行を実行しません。
Usage:
drivetrain.turn_for(direction, angle, units, wait)
パラメータ |
説明 |
|---|---|
|
ロボットが回転する方向: |
|
ロボットが回転する角度。これは、整数 |
|
オプション。回転単位: |
|
オプション |
def main():
# Turn the robot right and left
drivetrain.turn_for(RIGHT, 90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_for(LEFT, 90, DEGREES)
# VR threads — Do not delete
vr_thread(main)
turn_to_heading#
方位とは、ロボットが向いている方向のことで、度数で表されます。0 turn_to_heading 、ロボットを-359度から359度までの特定の方位に向けます。ロボットは、目標の方位に到達するために最短の方向へ旋回します。
ロボットの初期進行方向は0度です。
プロジェクトは、ロボットの旋回が完了するまで待機し、その後次のコードが実行されます。
Usage:
drivetrain.turn_to_heading(angle, units, wait)
パラメータ |
説明 |
|---|---|
|
ロボットが向くべき方向(度数) |
|
オプション。回転単位: |
|
オプション |
def main():
# Turn to face the cardinal directions
drivetrain.turn_to_heading(90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(180, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(270, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
turn_to_rotation#
turn_to_rotation はロボットを特定の回転方向に回転させます。
回転とは、ロボットがどれだけ回転したかを示すもので、度数で表されます。プロジェクトの開始時には、回転値は0度に設定されます。回転は、set_rotation メソッドを使用して設定することもできます。
回転値は絶対値です。つまり、旋回方向はロボットの現在の回転角度によって決まります。右に旋回すると回転角度が大きくなり、左に旋回すると回転角度が小さくなります。
例えば、ロボットが0度の位置から始まり、720度回転させると、右に2回転します。次に360度回転させると、360度は720度より小さいため、左に1回転します。
プロジェクトは、ロボットの旋回が完了するまで待機し、その後次のコードが実行されます。
Usage:
drivetrain.turn_to_rotation(angle, units, wait)
パラメータ |
説明 |
|---|---|
|
ロボットが回転する角度(度)。これは、整数 |
|
オプション。回転単位: |
|
オプション |
def main():
# Turn left, then spin in a circle
# clockwise and face right
drivetrain.turn_to_rotation(-90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_rotation(450, DEGREES)
# VR threads — Do not delete
vr_thread(main)
stop#
stop ロボットの動きを停止します。
Usage:
drivetrain.stop()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
def main():
# Drive forward then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
変異誘発者#
set_heading#
方位とは、ロボットが向いている方向のことで、度数で表されます。0 set_heading ロボットの現在の方位を新しい方位値に変更します。
例えば、ロボットが右を向いた場合、方位を0度に設定すると、その右向きの位置が新たな0度になります。その後、ロボットはその新たな方位に基づいて他の位置に旋回することができます。
Usage:
drivetrain.set_heading(heading, units)
パラメータ |
説明 |
|---|---|
|
ロボットに設定する方位角の値(度)。これは、整数 |
|
オプション。見出し単位: |
def main():
# Face the new 0 degrees
drivetrain.set_heading(90, DEGREES)
drivetrain.turn_to_heading(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
set_rotation#
回転とは、ロボットがどれだけ回転したかを示すもので、度数で表されます。プロジェクトの開始時には、回転値は0度に設定されます。0 set_rotation 実行すると、ロボットの現在の回転が新しい値に変更されます。
例えば、ロボットが右に2回転した場合、回転角度は720度になります。回転角度を0度に設定すると、720度から0度にリセットされます。その後、ロボットはその新しい値に基づいて回転することができます。
Usage:
drivetrain.set_rotation(rotation, units)
パラメータ |
説明 |
|---|---|
|
ロボットに設定する回転値(度)。これは、整数 |
|
オプション。回転単位: |
def main():
# Spin counterclockwise two times
drivetrain.set_rotation(720, DEGREES)
drivetrain.turn_to_rotation(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
set_timeout#
set_timeout は、ロボットが動作を完了しようとする時間を設定します。ロボットがその時間内に動作を完了できない場合、試行を停止して次のコード行に進みます。これにより、ロボットが動作中に停止してしまうのを防ぎます。
Usage:
drivetrain.set_timeout(value, units)
パラメータ |
説明 |
|---|---|
|
ロボットが動作を完了しようと試みる時間。これは、正の整数 |
|
オプション。時間単位: |
def main():
# Turn right after driving forward
drivetrain.set_timeout(1, SECONDS)
drivetrain.drive_for(FORWARD, 25, INCHES)
drivetrain.turn_for(RIGHT, 90)
# VR threads — Do not delete
vr_thread(main)
set_drive_velocity#
set_drive_velocity は、ロボットの走行速度を指定します。パーセンテージが高いほどロボットは速く走行し、低いほど遅く走行します。
すべてのプロジェクトは、ロボットがデフォルトで50%の速度で走行するところから始まります。
注: 速度を速くするとロボットの走行速度は速くなりますが、精度が低下する可能性があります。速度を遅くするとロボットの走行速度は遅くなりますが、精度は向上する可能性があります。
Usage:
drivetrain.set_drive_velocity(velocity, units)
パラメータ |
説明 |
|---|---|
|
0%から100%までの走行速度。0は整数、 |
|
オプション。速度の単位: |
def main():
# Drive forward at different velocities
# Default velocity
drivetrain.drive_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Drive slower
drivetrain.set_drive_velocity(20, PERCENT)
drivetrain.drive_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Drive faster
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive_for(FORWARD, 150, MM)
# VR threads — Do not delete
vr_thread(main)
set_turn_velocity#
set_turn_velocity は、ロボットの旋回速度を指定します。パーセンテージが高いほどロボットの旋回速度は速くなり、低いほど旋回速度は遅くなります。
すべてのプロジェクトは、ロボットがデフォルトで50%の速度で旋回するところから始まります。
注: 速度が速いほどロボットの旋回速度は速くなりますが、精度が低下する可能性があります。速度が遅いほどロボットの旋回速度は遅くなりますが、精度は向上する可能性があります。
Usage:
drivetrain.set_turn_velocity(velocity, units)
パラメータ |
説明 |
|---|---|
|
0%から100%までの旋回速度。0は整数、 |
|
オプション。速度の単位: |
def main():
# Turn at different velocities
# Default velocity
drivetrain.turn_for(RIGHT, 120, DEGREES)
wait(1, SECONDS)
# Turn slower
drivetrain.set_turn_velocity(20, PERCENT)
drivetrain.turn_for(RIGHT, 120, DEGREES)
wait(1, SECONDS)
# Turn faster
drivetrain.set_turn_velocity(100, PERCENT)
drivetrain.turn_for(RIGHT, 120, DEGREES)
# VR threads — Do not delete
vr_thread(main)
ゲッター#
heading#
方位とは、ロボットが向いている方向のことで、度数で表されます。0 heading は ロボットの現在の方位を0度から359.99度の範囲で返します。
ロボットの初期進行方向は0度です。
Usage:
drivetrain.heading(units)
パラメータ |
説明 |
|---|---|
|
オプション。見出し単位: |
def main():
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.print("Heading: ")
brain.print(drivetrain.heading(DEGREES))
# VR threads — Do not delete
vr_thread(main)
rotation#
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the robot’s current rotation.
右に回すと回転角度が大きくなり、左に回すと回転角度が小さくなります。例えば、右に2回転すると720度回転します。
Usage:
drivetrain.rotation(units)
パラメータ |
説明 |
|---|---|
|
オプション。回転単位: |
def main():
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.print("Rotation: ")
brain.print(drivetrain.rotation(DEGREES))
# VR threads — Do not delete
vr_thread(main)
is_done#
is_doneが 場合は、ロボットの移動が完了したかどうかをブール値で返します。1の場合は、ロボットの移動に基づいて他の動作のタイミングを制御するために使用できます。
True— ロボットの移動が完了しました。False— ロボットはまだ動いています。
このメソッドは、 wait パラメータを持つ以下の Drivetrain メソッドと連携して動作します: drive_for、turn_for、turn_to_heading、および turn_to_rotation。
Usage:
drivetrain.is_done()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
is_moving#
is_moving は、ロボットが移動中かどうかをブール値で返します。これは、ロボットの動きに基づいて他の動作のタイミングを制御するために使用できます。
True— ロボットが動いています。False— ロボットは動いていません。
Usage:
drivetrain.is_moving()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |