タイマー#
導入#
VEX GOのタイマー機能を使うと、経過時間を追跡し、時間間隔に基づいて動作を実行できます。何かにかかる時間を計測したり、新しいタイミング操作のためにリセットしたりするのに使用できます。
以下にすべてのメソッドの一覧を示します。
方法 – 脳のタイマーを制御し、操作する。
コンストラクタ – 追加のタイマーを作成します。
Timer– 追加のタイマーを作成します。
リセット#
reset はタイマーをゼロに設定します。これは、同じプロジェクト内の他のコードセクションの時間を計測するために使用できます。
Usage:
timer.reset()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Build Used: Super Code Base 2.0
def main():
# Reset the timer when the bumper is pressed
while True:
console.clear()
console.print(timer.time(SECONDS))
wait(50, MSEC)
if bumper.is_pressed():
timer.reset()
# Start threads — Do not delete
start_thread(main)
時間#
time は、タイマーが最後にリセットされてからの時間を小数で返します。タイマーはプロジェクトの開始時に自動的にリセットされます。
Usage:
timer.time(units)
パラメータ |
説明 |
|---|---|
|
時間を表す単位: |
# Build Used: Super Code Base 2.0
def main():
# Display the time until the bumper is pressed
while True:
console.clear()
console.print(timer.time(SECONDS))
wait(50, MSEC)
if bumper.is_pressed():
timer.reset()
# Start threads — Do not delete
start_thread(main)
イベント#
event は、指定された時間が経過した後に関数を呼び出します。
Usage:
timer.event(callback, delay, arg)
パラメータ |
説明 |
|---|---|
|
タイマーイベントが発生したときに実行される関数。 |
|
関数が呼び出されるまでの遅延時間(ミリ秒単位)。 |
|
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
# Build Used: Super Code Base 2.0
def timer_event():
drivetrain.drive_for(FORWARD, 200, MM)
def main():
# Drive forward after a 5000 millisecond delay
timer.event(timer_event, 5000)
# Start threads — Do not delete
start_thread(main)
建設業者#
Timer#
Timer は新しいタイマーを作成します。 Timer オブジェクトは作成された瞬間にカウントを開始し、すべての timer メソッドで動作します。
Usage:
my_timer = Timer()
パラメータ |
説明 |
|---|---|
このコンストラクタにはパラメータがありません。 |
def main():
# Display the time of two timers
wait(2, SECONDS)
timer_1 = Timer()
while True:
console.clear()
console.print("Timer: ", timer.time(SECONDS))
console.new_line()
console.print("timer_1: ", timer_1.time(SECONDS))
wait(15, MSEC)
# Start threads — Do not delete
start_thread(main)