실#
소개#
스레드를 사용하면 VEX AIR 드론 컨트롤러가 동일한 프로그램 내에서 여러 작업을 동시에 실행할 수 있습니다. 이를 통해 멀티태스킹이 가능해지며, VEX AIR 드론이 동시에 독립적인 동작을 수행할 수 있습니다.
Note: You must first define a function to use it with a thread.
생성자 – 새 스레드를 생성하고 시작합니다.
Thread– 지정된 함수를 메인 프로그램과 병렬로 실행하는 새 스레드를 시작합니다.
건설자#
Thread#
Thread 스레드를 생성하고 시작합니다. 스레드를 생성할 때 이름을 지정하여 더 이상 필요하지 않을 때 중지할 수 있습니다.
용법:
my_thread = Thread(my_function)
매개변수 |
설명 |
|---|---|
|
(선택 사항) 새 게시글의 이름입니다. |
|
이전에 정의된 함수의 이름입니다. |
참고: 함수는 호출되기 전에 반드시 정의되어 있어야 합니다.
# Only play sounds when the drone moves laterally
def moving_sounds():
while True:
if drone.is_move_active():
controller.sound.play(LOOPING)
while controller.sound.is_active():
wait(50, MSEC)
wait(5, MSEC)
# Run moving_sounds at the same time
moving_sounds_thread = Thread(moving_sounds)
# Fly the drone using the controller
drone.take_off(climb_to=500)
while True:
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)