시간제 노동자#

소개#

VEX GO의 타이머를 사용하면 경과 시간을 추적하고 시간 간격에 따라 작업을 수행할 수 있습니다. 특정 작업에 걸리는 시간을 측정하거나 새로운 타이밍 작업을 위해 재설정하는 데 사용할 수 있습니다.

다음은 모든 방법 목록입니다.

방법 – 브레인의 타이머를 제어하고 상호 작용합니다.

  • reset – 타이머를 0으로 리셋합니다.

  • time – 경과된 시간을 반환합니다.

  • event – 지정된 밀리초 후에 호출될 함수를 등록합니다.

생성자 – 추가 타이머를 생성합니다.

  • Timer – 추가 타이머를 생성합니다.

다시 놓기#

reset 타이머를 0으로 설정합니다. 이 기능은 동일한 프로젝트 내의 다른 코드 섹션의 실행 시간을 측정하는 데 사용할 수 있습니다.

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)

매개변수

설명

units

시간을 나타내는 단위: MSEC (기본값) – 밀리초, 또는 SECONDS

# 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)

매개변수

설명

callback

타이머 이벤트가 발생했을 때 실행될 함수입니다.

delay

함수가 호출되기 전의 지연 시간(밀리초).

arg

선택 사항입니다. 콜백 함수에 전달할 인수를 포함하는 튜플입니다. 자세한 내용은 매개변수가 있는 함수를 참조하세요.

# 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)