로봇 전용 파이썬#
소개#
히어로 봇인 플렉스에는 집게 모터, 팔 모터, AI 비전 센서, 거리 센서 및 게임 위치 시스템(GPS) 센서가 포함되어 있습니다.
모든 표준 VEXcode VR 메서드는 V5 26-27 Override Playground에서 사용할 수 있습니다.
다음은 사용 가능한 모든 로봇 전용 메서드 목록입니다.
구동계 – 로봇을 움직이고 회전시킵니다.
행위
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— 로봇에게 회전 속도를 알려줍니다.
게터
모션 – 로봇 모터의 움직임과 추적을 제어합니다.
행위
spin— 모터를 영원히 정방향 또는 역방향으로 회전시킵니다.spin_for— 특정 거리만큼 모터를 회전시킵니다.spin_to_position— 모터를 특정 위치로 회전시킵니다.stop— 모터의 회전을 멈춥니다.
변이 유발인자
set_position— 모터의 현재 위치를 새 값으로 변경합니다.set_velocity— 모터에게 얼마나 빠르게 회전해야 하는지 알려줍니다.set_timeout— 모터가 동작을 완료하려고 시도하는 시간을 설정합니다.
게터
is_done— 모터가 이동을 완료했는지 여부를 부울 값으로 반환합니다.is_spinning— 모터가 회전하는지 여부를 부울 값으로 반환합니다.position— 모터의 현재 위치를 반환합니다.velocity— 모터가 회전하는 속도를 반환합니다.
AI 비전 – AI 비전 센서를 사용하여 사물을 포착하고 분석합니다.
게터
take_snapshot– 특정 시그니처에 대해 감지된 객체의 튜플을 반환합니다.
속성
콘솔 - 콘솔에 출력하고 값을 모니터링합니다.
인쇄
brain.screen.print— 콘솔에 텍스트, 숫자 또는 변수 값을 표시합니다.brain.screen.next_row— 콘솔 커서를 다음 행의 시작 부분으로 이동합니다.brain.screen.clear_screen— 콘솔의 모든 행을 지웁니다.
감시 장치
monitor_variable— 모니터 탭에 하나 이상의 미리 정의된 변수를 추가합니다.monitor_sensor— 모니터 탭에 하나 이상의 센서 값을 추가합니다.
감지 – 로봇의 다양한 센서를 활용합니다.
거리
found_object– 거리 센서가 범위 내에 있는 물체를 감지했는지 여부를 반환합니다.object_distance– 거리 센서와 가장 가까운 감지된 객체 사이의 거리를 반환합니다.
GPS
x_position– 필드의 GPS 센서의 현재 x좌표를 반환합니다.y_position– 필드의 GPS 센서의 현재 y 좌표를 반환합니다.heading– GPS 센서를 기반으로 로봇이 현재 향하고 있는 방향을 반환합니다.
이 페이지의 예시에서는 경기장의 경기 전 체크리스트에 있는 시작 위치 C를 사용합니다.
구동계#
구동계는 VR 로봇의 주행 및 회전을 제어합니다. 구동계를 통해 전진 또는 후진, 좌회전 또는 우회전, 방향 전환, 그리고 회전 추적이 가능합니다.
행위#
운전하다#
drive 로봇을 전진 또는 후진으로 무한히 움직이게 합니다. 로봇은 방향 전환이나 정지와 같은 다른 동작이 주어질 때까지 계속 움직입니다.
Usage:
drivetrain.drive(direction)
매개변수 |
설명 |
|---|---|
|
로봇의 이동 방향: |
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive(FORWARD)
wait(0.5, SECONDS)
drivetrain.stop()
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
드라이브_포#
<code>drive_for</code> 값이 이 특정 거리만큼 앞뒤로 이동합니다. 프로젝트는 로봇의 이동이 완료될 때까지 기다린 후 다음 코드를 실행합니다.
Usage:
drivetrain.drive_for(direction, distance, units, wait)
매개변수 |
설명 |
|---|---|
|
로봇의 이동 방향: |
|
로봇이 주행한 거리입니다. 이 값은 |
|
선택 사항입니다. 거리 단위는 |
|
선택 사항입니다. |
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
회전하다#
turn 턴은 로봇을 왼쪽 또는 오른쪽으로 계속 회전시킵니다. 로봇은 주행이나 정지와 같은 다른 동작을 명령받을 때까지 계속 회전합니다.
Usage:
drivetrain.turn(direction)
매개변수 |
설명 |
|---|---|
|
로봇이 회전하는 방향: |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn(LEFT)
wait(0.78, SECONDS)
drivetrain.stop()
arm_motor.spin_for(FORWARD, 800, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
턴_포#
turn_for 로봇을 지정된 각도만큼 왼쪽 또는 오른쪽으로 회전시킵니다. 회전은 로봇의 현재 위치를 기준으로 합니다. 프로젝트는 로봇이 회전을 완료할 때까지 기다린 후 다음 코드를 실행합니다.
Usage:
drivetrain.turn_for(direction, angle, units, wait)
매개변수 |
설명 |
|---|---|
|
로봇이 회전하는 방향: |
|
로봇이 회전하는 각도(도)입니다. |
|
선택 사항입니다. 각도 단위: |
|
선택 사항입니다. |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn_for(LEFT, 110, DEGREES)
arm_motor.spin_for(FORWARD, 800, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
제목으로 전환#
헤딩은 로봇이 향하는 방향을 도 단위로 나타낸 것입니다. turn_to_heading 은 로봇을 -359도에서 359도 사이의 특정 방향으로 회전시킵니다. 로봇은 목표 방향에 도달하기 위해 가장 짧은 경로로 회전합니다.
초기 방향은 0도입니다.
Usage:
drivetrain.turn_to_heading(heading, units, wait)
매개변수 |
설명 |
|---|---|
|
로봇이 향해야 할 방향은 -359도에서 359도 사이입니다. |
|
선택 사항입니다. 각도 단위: |
|
선택 사항입니다. |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn_to_heading(-110, DEGREES)
arm_motor.spin_for(FORWARD, 800, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
회전#
turn_to_rotation 로봇을 특정 회전 방향으로 회전시킵니다.
회전은 로봇이 회전한 정도를 각도로 나타낸 것입니다. 프로젝트 시작 시 회전 값은 0도로 설정됩니다. 오른쪽으로 회전하면 회전값이 증가하고, 왼쪽으로 회전하면 회전값이 감소합니다.
예를 들어, 로봇이 0도에서 시작하여 720도를 회전하면 오른쪽으로 두 번 회전합니다. 그런 다음 360도를 회전하면 왼쪽으로 한 번 회전하는데, 360도가 720도보다 작기 때문입니다.
Usage:
drivetrain.turn_to_rotation(rotation, units, wait)
매개변수 |
설명 |
|---|---|
|
로봇이 회전할 각도(도)입니다. 이 값은 |
|
선택 사항입니다. 각도 단위: |
|
선택 사항입니다. |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn_to_rotation(-110, DEGREES)
arm_motor.spin_for(FORWARD, 800, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
멈추다#
stop 로봇의 움직임을 멈춥니다.
Usage:
drivetrain.stop()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn(LEFT)
wait(0.78, SECONDS)
drivetrain.stop()
arm_motor.spin_for(FORWARD, 800, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
돌연변이체#
제목 설정#
헤딩은 로봇이 바라보는 방향을 도 단위로 나타낸 것입니다. set_heading 은 로봇의 현재 헤딩 값을 새로운 헤딩 값으로 변경합니다.
예를 들어, 로봇이 오른쪽을 향하도록 회전한 상태에서 방향을 0도로 설정하면 오른쪽을 향한 위치가 새로운 0도가 됩니다. 그러면 로봇은 이 새로운 방향을 기준으로 다른 위치로 회전할 수 있습니다.
Usage:
drivetrain.set_heading(heading, units)
매개변수 |
설명 |
|---|---|
|
로봇의 진행 방향 값을 도 단위로 설정합니다. |
|
선택 사항입니다. 각도 단위: |
def main():
# Make facing the Neutral Goal the new heading
drivetrain.set_heading(110, DEGREES)
drivetrain.turn_to_heading(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
회전 설정#
회전은 로봇이 회전한 정도를 각도로 나타낸 것입니다. set_rotation 로봇의 현재 회전 값을 새로운 값으로 변경합니다.
Usage:
drivetrain.set_rotation(rotation, units)
매개변수 |
설명 |
|---|---|
|
로봇의 회전 값을 도 단위로 설정합니다. 이 값은 |
|
선택 사항입니다. 각도 단위: |
def main():
# Make facing the Neutral Goal the new rotation
drivetrain.set_rotation(110, DEGREES)
drivetrain.turn_to_rotation(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
set_timeout#
set_timeout 로봇이 동작을 완료하려고 시도하는 시간을 초 단위로 설정합니다. 로봇이 해당 시간 내에 동작을 완료하지 못하면 시도를 중단하고 다음 코드 줄로 넘어갑니다. 이렇게 하면 로봇이 동작 중에 멈추는 것을 방지할 수 있습니다.
Usage:
drivetrain.set_timeout(time, units)
매개변수 |
설명 |
|---|---|
|
로봇이 동작을 완료하려고 시도할 수 있는 시간(초)입니다. 이 값은 |
|
선택 사항입니다. 시간 단위: |
def main():
# Turn to face the Neutral Goal
drivetrain.set_timeout(0.8, SECONDS)
drivetrain.turn_for(LEFT, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
주행 속도 설정#
set_drive_velocity 로봇이 얼마나 빠르게 주행해야 하는지를 알려줍니다. 백분율이 높을수록 로봇은 더 빠르게 주행하고, 백분율이 낮을수록 로봇은 더 느리게 주행합니다.
모든 프로젝트는 로봇이 기본적으로 50% 속도로 주행하는 것으로 시작합니다.
참고: 속도가 높을수록 로봇의 주행 속도는 빨라지지만 정밀도는 떨어질 수 있습니다. 속도가 낮을수록 로봇의 주행 속도는 느려지지만 정밀도는 높아질 수 있습니다.
Usage:
drivetrain.set_drive_velocity(velocity, units)
매개변수 |
설명 |
|---|---|
|
주행 속도는 0%에서 100%까지입니다. 정수 |
|
선택 사항입니다. 속도 단위: |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn_for(LEFT, 110, DEGREES)
arm_motor.spin_for(FORWARD, 800, DEGREES)
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive_for(FORWARD, 25, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
회전 속도 설정#
set_turn_velocity 로봇이 회전하는 속도를 지정합니다. 백분율이 높을수록 로봇은 더 빠르게 회전하고, 백분율이 낮을수록 로봇은 더 느리게 회전합니다.
모든 프로젝트는 로봇이 기본적으로 50% 속도로 회전하는 것으로 시작합니다.
참고: 속도가 높을수록 로봇의 회전 속도는 빨라지지만 정밀도는 떨어질 수 있습니다. 속도가 낮을수록 로봇의 회전 속도는 느려지지만 정밀도는 높아질 수 있습니다.
Usage:
drivetrain.set_turn_velocity(velocity, units)
매개변수 |
설명 |
|---|---|
|
회전 속도는 0%에서 100%까지입니다. 이 값은 |
|
선택 사항입니다. 속도 단위: |
def main():
# Turn to face the Neutral Goal faster
drivetrain.set_turn_velocity(100, PERCENT)
drivetrain.turn_for(LEFT, 110, DEGREES)
# VR threads — Do not delete
vr_thread(main)
게터스#
표제#
헤딩은 로봇이 향하는 방향을 도 단위로 나타낸 것입니다. heading 로봇의 현재 헤딩 값을 0도에서 359.99도 사이의 값으로 반환합니다.
로봇의 초기 진행 방향은 0도입니다.
Usage:
drivetrain.heading(units)
매개변수 |
설명 |
|---|---|
|
선택 사항입니다. 제목 단위: |
def main():
# Turn to the Goal, then show heading
drivetrain.turn_for(LEFT, 110, DEGREES)
brain.screen.print("Heading: ")
brain.screen.print(drivetrain.heading(DEGREES))
# VR threads — Do not delete
vr_thread(main)
회전#
회전은 로봇이 회전한 정도를 각도로 나타낸 값입니다. 프로젝트 시작 시 회전 값은 0도로 설정됩니다. rotation 입력하면 로봇의 현재 회전 값이 반환됩니다.
오른쪽으로 돌면 회전 각도가 증가하고, 왼쪽으로 돌면 회전 각도가 감소합니다. 예를 들어, 오른쪽으로 두 바퀴를 완전히 돌면 720도 회전하게 됩니다.
Usage:
drivetrain.rotation(units)
매개변수 |
설명 |
|---|---|
|
선택 사항입니다. 회전 단위: |
def main():
# Spin to find a Pin, then show rotation
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print("Rotation: ")
brain.screen.print(drivetrain.rotation(DEGREES))
# VR threads — Do not delete
vr_thread(main)
완료됨#
is_done is_done 로봇의 이동이 완료되었는지 여부를 부울 값으로 반환합니다. 이 값은 로봇의 움직임에 따라 다른 동작의 타이밍을 제어하는 데 사용할 수 있습니다.
True— 로봇의 이동이 완료되었습니다.False— 로봇은 여전히 움직이고 있습니다.
이 방법은 wait 매개변수를 갖는 다음 드라이브트레인 방법과 함께 작동합니다: drive_for, turn_for, turn_to_heading, 및 turn_to_rotation.
Usage:
drivetrain.is_done()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn_for(LEFT, 110, DEGREES)
arm_motor.spin_for(FORWARD, 800, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES, wait=False)
wait(0.5, SECONDS)
while not drivetrain.is_done():
wait(5, MSEC)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
이동 중입니다#
is_moving 부울 값으로 반환합니다. 이 값은 로봇의 움직임에 따라 다른 동작의 타이밍을 제어하는 데 사용할 수 있습니다.
True— 로봇이 움직이고 있습니다.False— 로봇이 움직이지 않습니다.
Usage:
drivetrain.is_moving()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Raise the Arm once stopped near the Goal
drivetrain.turn_for(LEFT, 110, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES, wait=False)
wait (0.5, SEC)
while drivetrain.is_moving():
wait(5, MSEC)
arm_motor.spin_for(FORWARD, 800, DEGREES)
# VR threads — Do not delete
vr_thread(main)
속도#
velocity 로봇의 주행 속도를 -100%에서 100%까지의 백분율로 반환합니다.
Usage:
drivetrain.velocity(units)
매개변수 |
설명 |
|---|---|
|
선택 사항입니다. 속도 단위: |
def main():
# Show speed while driving to the Goal
drivetrain.drive_for(FORWARD, 150, MM)
brain.screen.print("Velocity: ")
brain.screen.print(drivetrain.velocity(PERCENT))
# VR threads — Do not delete
vr_thread(main)
운동#
Flex는 팔 모터를 사용하여 팔을 올리고 내리고, 집게 모터를 사용하여 집게를 열고 닫습니다.
각 모터는 고유한 방향 동작을 가지고 있습니다. 방향 설명은 Flex에서 각 방향으로 모터가 어떻게 움직이는지 설명합니다.
행위#
회전#
spin 스핀은 모터를 두 방향 중 하나로 계속 회전시킵니다. 모터는 다른 방향 회전이나 정지 등의 추가 동작이 주어질 때까지 계속 회전합니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
모터 회전 방향:
|
def main():
# Raise the Arm before driving toward a Pin
arm_motor.spin(FORWARD)
wait(1, SECONDS)
arm_motor.stop()
# VR threads — Do not delete
vr_thread(main)
스핀_포#
spin_for 모터를 특정 거리만큼 회전시킵니다. 회전 거리는 모터의 현재 위치를 기준으로 합니다. 프로젝트는 모터 회전이 완료될 때까지 기다린 후 다음 코드를 실행합니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
모터 회전 방향:
|
|
모터가 회전하는 거리. |
|
선택 사항입니다. 거리 단위: |
|
선택 사항.
|
def main():
# Raise the Arm to carry the Pin to the Goal
arm_motor.spin_for(FORWARD, 800, DEGREES)
# VR threads — Do not delete
vr_thread(main)
스핀투위치#
spin_to_position 모터를 특정 위치로 회전시킵니다.
모터의 위치는 회전한 정도를 나타내며 DEGREES 회전 또는 TURNS으로 측정됩니다. 1회전은 360도와 같습니다. 프로젝트 시작 시 암 모터의 위치는 0도로 설정됩니다. 클로 모터는 예외적으로 467도(완전히 닫힌 상태)에서 시작합니다. 모터 위치는 set_position 메서드를 사용하여 설정할 수도 있습니다.
위치 값은 절대값입니다. 즉, 회전 방향은 모터의 현재 위치에 따라 달라집니다.
예를 들어, 모터가 0도에서 시작하여 720도까지 회전하면 정방향으로 두 바퀴 회전합니다. 그런 다음 360도까지 회전하면 720도보다 360도가 작으므로 역방향으로 한 바퀴 회전합니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
모터가 회전할 위치 값입니다. |
|
선택 사항입니다. 위치 단위: |
|
선택 사항.
|
def main():
# Raise the Arm, then release the Pin
arm_motor.spin_to_position(800, DEGREES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
멈추다#
stop 모터의 회전을 멈춥니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Raise the Arm partway to hold the Pin
arm_motor.spin(FORWARD)
wait(1, SECONDS)
arm_motor.stop()
# VR threads — Do not delete
vr_thread(main)
돌연변이체#
위치 설정#
모터의 위치는 회전한 정도를 나타내며, DEGREES 회전 또는 TURNS으로 측정됩니다. 1회전은 360도입니다. set_position set_position 모터의 현재 위치를 새로운 값으로 변경합니다.
예를 들어 모터가 180도 회전한 경우, 위치를 0도로 설정하면 해당 위치가 180도에서 0도로 재설정됩니다. 그러면 모터는 새로운 값에 따라 회전할 수 있습니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
모터에 설정할 위치 값입니다. |
|
선택 사항입니다. 위치 단위: |
def main():
# Reset encoder, raise Arm, place Pin
arm_motor.set_position(0, DEGREES)
arm_motor.spin_to_position(800, DEGREES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
속도 설정#
set_velocity 모터의 회전 속도를 지정합니다. 백분율이 높을수록 모터 회전 속도가 빨라지고, 낮을수록 모터 회전 속도가 느려집니다.
모든 프로젝트는 기본적으로 각 모터가 50% 속도로 회전하는 상태에서 시작됩니다.
참고: 회전 속도가 높을수록 모터 회전 속도는 빨라지지만 정밀도가 떨어질 수 있습니다. 회전 속도가 낮을수록 모터 회전 속도는 느려지지만 정밀도가 높아질 수 있습니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
회전 속도는 0%에서 100%까지입니다. 정수 |
|
속도 단위: |
def main():
# Raise the Arm fast to release the Pin
arm_motor.set_velocity(100, PERCENT)
arm_motor.spin_for(FORWARD, 800, DEGREES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
set_timeout#
set_timeout 모터가 동작을 완료하려고 시도하는 시간을 설정합니다. 모터가 해당 시간 내에 동작을 완료하지 못하면 시도를 중지하고 다음 코드 줄로 이동합니다. 이렇게 하면 모터가 특정 동작에서 멈추는 것을 방지할 수 있습니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
모터가 동작을 완료하려고 시도할 수 있는 시간입니다. 이 값은 양수 |
|
시간 단위: |
def main():
# Score a Pin in a Neutral Goal
drivetrain.turn_for(LEFT, 110, DEGREES)
arm_motor.set_timeout(1, SECONDS)
arm_motor.spin_for(FORWARD, 1800, DEGREES)
drivetrain.drive_for(FORWARD, 25, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
게터스#
완료됨#
is_done 모터의 움직임이 완료되었는지 여부를 부울 값으로 반환합니다. 이 값은 모터의 움직임에 따라 다른 동작의 타이밍을 제어하는 데 사용할 수 있습니다.
True— 모터가 회전을 멈췄습니다.False— 모터는 여전히 움직이고 있습니다.
이 방법은 wait 매개변수를 갖는 다음 모션 방법과 함께 작동합니다: spin_for 및 spin_to_position.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Raise the Arm while driving to the Goal
arm_motor.spin_to_position(800, DEGREES, wait=False)
wait(0.1, SECONDS)
while not arm_motor.is_done():
drivetrain.drive(FORWARD)
wait(5, MSEC)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
회전하고 있습니다#
is_spinning 모터가 회전하는지 여부를 나타냅니다. 이 값은 모터의 움직임에 따라 다른 동작의 타이밍을 제어하는 데 사용할 수 있습니다.
True— 모터가 회전하고 있습니다.False— 모터가 회전하지 않습니다.
이 방법은 wait 매개변수를 갖는 다음 모션 방법과 함께 작동합니다: spin_for 및 spin_to_position.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Raise the Arm while driving to the Goal, then release the Pin
arm_motor.spin_to_position(800, DEGREES, wait=False)
wait(0.1, SECONDS)
while arm_motor.is_spinning():
drivetrain.drive_for(FORWARD, 25, MM)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
위치#
모터의 위치는 회전한 정도를 나타내며, DEGREES 회전 또는 TURNS으로 측정됩니다. 1회전은 360도와 같습니다. position 모터의 현재 위치를 반환합니다.
프로젝트 시작 시, 로봇 팔 모터의 위치는 0도로 설정됩니다. 집게발 모터는 예외적으로 467도(완전히 닫힌 상태)에서 시작합니다. 모터가 한 바퀴 완전히 앞으로 회전하면 위치가 증가하고, 반대 방향으로 회전하면 위치가 감소합니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
모터 위치를 |
def main():
# Raise the Arm, then release the Pin
while arm_motor.position(DEGREES) < 800:
arm_motor.spin(FORWARD)
wait(2, MSEC)
arm_motor.stop()
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
속도#
velocity 모터가 회전하는 속도를 반환합니다.
양수 값은 모터가 정방향으로 회전하고 있음을 의미합니다. 음수 값은 모터가 역방향으로 회전하고 있음을 의미합니다.
사용법:
아래 그림과 같이 사용 가능한 두 가지 모터 객체 중 하나를 이 방법과 함께 사용할 수 있습니다.
모터 |
명령 |
|---|---|
|
|
|
|
매개변수 |
설명 |
|---|---|
|
반환할 속도 단위: |
def main():
# Show Arm Motor velocity while raising
arm_motor.set_velocity(100, PERCENT)
arm_motor.spin_to_position(800, DEGREES, wait=False)
wait(0.2, SECONDS)
brain.screen.print(arm_motor.velocity(PERCENT))
# VR threads — Do not delete
vr_thread(main)
AI 비전#
게터스#
스냅샷을 찍다#
take_snapshot AI 비전 센서 프레임의 데이터를 단일 시그니처(센서가 인식할 수 있는 대상에 대한 저장된 설명, 예를 들어 경기장의 게임 요소 등)로 필터링하고 튜플을 반환합니다.
튜플은 인덱스 0부터 시작하여 너비가 큰 순서부터 작은 순서로 정렬된 객체를 저장합니다. 각 객체의 속성은 해당 인덱스를 사용하여 접근할 수 있습니다. 일치하는 객체가 감지되지 않으면 빈 튜플이 반환됩니다.
Usage:
ai_vision.take_snapshot(signature)
매개변수 |
설명 |
|---|---|
|
지정된 시그니처에 해당하는 데이터만 포함하도록 데이터셋을 필터링합니다. 사용 가능한 시그니처는 다음과 같습니다:
|
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Turn to face the Pin
drivetrain.set_turn_velocity(30, PERCENT)
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
if ai_objects[0].centerX < 140:
drivetrain.turn(LEFT)
elif ai_objects[0].centerX > 180:
drivetrain.turn(RIGHT)
else:
drivetrain.stop()
break
# VR threads — Do not delete
vr_thread(main)
속성#
take_snapshot를 사용한 후 튜플에 저장된 각 객체에는 7개의 속성이 포함됩니다.
All property values except .id describe the detected object’s position and size in the AI Vision Sensor’s view at the moment take_snapshot was used. These values are measured in pixels, based on the sensor’s 320 by 240 pixel resolution.
.너비#
.width 감지된 객체의 너비를 픽셀 단위로 반환하며, 이는 1에서 320 사이의 정수입니다.
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Approach the next Cup and Pin
drivetrain.set_drive_velocity(30, PERCENT)
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
if ai_objects[0].width > 140:
drivetrain.stop()
break
else:
drivetrain.drive(FORWARD)
# VR threads — Do not delete
vr_thread(main)
.키#
.height 감지된 객체의 높이를 픽셀 단위로 반환하며, 이는 1에서 240 사이의 정수입니다.
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Approach the next Cup and Pin
drivetrain.set_drive_velocity(30, PERCENT)
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
if ai_objects[0].height > 200:
drivetrain.stop()
break
else:
drivetrain.drive(FORWARD)
# VR threads — Do not delete
vr_thread(main)
.centerX#
.centerX 감지된 객체의 중심의 x 좌표를 픽셀 단위로 반환하며, 이 값은 0에서 320 사이의 정수입니다.
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Turn and approach the next Cup and Pin
drivetrain.set_turn_velocity(30, PERCENT)
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
if ai_objects[0].centerX < 140:
drivetrain.turn_for(LEFT, 5, DEGREES)
else:
drivetrain.drive_for(FORWARD, 25, INCHES)
break
# VR threads — Do not delete
vr_thread(main)
.센터Y#
.centerY 감지된 객체 중심의 y 좌표를 픽셀 단위로 반환하며, 이 값은 0에서 240 사이의 정수입니다.
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Approach the next Cup and Pin
drivetrain.set_drive_velocity(30, PERCENT)
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
if ai_objects[0].centerY > 230:
drivetrain.stop()
break
else:
drivetrain.drive(FORWARD)
# VR threads — Do not delete
vr_thread(main)
.오리진X#
.originX 감지된 객체의 경계 상자의 왼쪽 상단 모서리의 x 좌표를 픽셀 단위로 반환하며, 이는 0에서 320 사이의 정수입니다.
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Turn and approach the next Cup and Pin
drivetrain.set_turn_velocity(30, PERCENT)
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
if ai_objects[0].originX < 100:
drivetrain.turn_for(LEFT, 5, DEGREES)
else:
drivetrain.drive_for(FORWARD, 25, INCHES)
break
# VR threads — Do not delete
vr_thread(main)
.오리진Y#
.originY 감지된 객체의 경계 상자의 왼쪽 상단 모서리의 y 좌표를 픽셀 단위로 반환하며, 이는 0에서 240 사이의 정수입니다.
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Approach the next Cup and Pin
drivetrain.set_drive_velocity(30, PERCENT)
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
if ai_objects[0].originY > 140:
drivetrain.stop()
break
else:
drivetrain.drive(FORWARD)
# VR threads — Do not delete
vr_thread(main)
.ID#
.id 감지된 AI 분류의 ID를 정수로 반환합니다.
AI 분류 |
ID |
서명 |
|---|---|---|
레드블루핀 |
0 |
|
블루옐로핀 |
1 |
|
레드옐로핀 |
2 |
|
옐로우핀 |
3 |
|
컵 |
4 |
|
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
drivetrain.turn_for(LEFT, 70, DEGREES)
# Display the ID of the next closest object
while True:
ai_objects = ai_vision.take_snapshot(AiVision.ALL_AIOBJS)
if ai_objects:
brain.screen.print(ai_objects[0].id)
break
# VR threads — Do not delete
vr_thread(main)
콘솔#
콘솔에는 프로젝트 실행 중에 텍스트, 숫자 및 변수 값이 표시됩니다. 콘솔 메서드를 사용하여 커서를 새 행으로 이동하거나, 콘솔을 지우거나, 모니터 탭에 변수 또는 센서 값을 추가할 수도 있습니다.
인쇄#
뇌.화면.인쇄#
brain.screen.print 현재 커서 위치를 사용하여 콘솔에 텍스트, 숫자 또는 변수 값을 표시합니다.
다음 출력값이 새 행에서 시작되도록 하려면 brain.screen.next_row를 사용하세요.
Usage:
brain.screen.print(value)
매개변수 |
설명 |
|---|---|
|
콘솔에 표시할 텍스트, 숫자 또는 변수 값입니다. |
def main():
# Display a message in the Console
brain.screen.print("Hello, robot!")
# VR threads — Do not delete
vr_thread(main)
뇌.화면.다음_행#
brain.screen.next_row 콘솔에서 커서를 다음 행의 첫 번째 열로 이동합니다. 다음에 출력될 값은 해당 행에 나타납니다.
Usage:
brain.screen.next_row()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Print on two rows
brain.screen.print("Row 1")
brain.screen.next_row()
brain.screen.print("Row 2")
# VR threads — Do not delete
vr_thread(main)
뇌.화면.화면지우기#
brain.screen.clear_screen 은 콘솔의 모든 행을 지우고 커서를 1행으로 되돌립니다.
Usage:
brain.screen.clear_screen()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Display text, then clear it after two seconds
brain.screen.print("This will disappear...")
wait(2, SECONDS)
brain.screen.clear_screen()
# VR threads — Do not delete
vr_thread(main)
감시 장치#
모니터 변수#
monitor_variable VEXcode의 모니터 탭에 하나 이상의 미리 정의된 변수를 추가합니다. 이를 통해 프로젝트 실행 중에 변수 값의 변화를 모니터링할 수 있습니다.
변수를 성공적으로 모니터링하려면 전역 monitor_variable 문자열로 제공하십시오.
Usage:
monitor_variable(“variable”)
monitor_variable(“variable1”, “variable2”)
매개변수 |
설명 |
|---|---|
|
모니터링할 미리 정의된 전역 변수의 이름을 문자열로 지정합니다. 둘 이상의 변수를 모니터링하려면 각 변수 이름을 쉼표로 구분하십시오. |
def main():
# Monitor the number of loops
global loops
monitor_variable("loops")
# Turn in a full circle 3 times
for loops in range(12):
drivetrain.turn_for(RIGHT, 90, DEGREES)
# VR threads — Do not delete
vr_thread(main)
모니터 센서#
monitor_sensor 명령어를 사용하면 VEXcode의 모니터 탭에 하나 이상의 센서 값을 추가할 수 있습니다. 이를 통해 프로젝트 실행 중에 센서 값의 변화를 확인할 수 있습니다.
각 센서 값을 문자열로 제공하십시오.
Usage:
monitor_sensor(“sensor”)
monitor_sensor(“sensor1”, “sensor2”)
매개변수 |
설명 |
|---|---|
|
The sensor value to monitor, given as a string. To monitor more than one sensor value, separate each sensor value with a comma. Supported sensor identifiers include:
|
def main():
# Monitor the robot's heading
monitor_sensor("drivetrain.heading")
drivetrain.turn_for(RIGHT, 450, DEGREES)
# VR threads — Do not delete
vr_thread(main)
감지#
거리#
found_object#
found_object 거리 센서가 현재 2000mm 이내에 물체를 감지했는지 여부를 반환합니다.
True— 거리 센서가 물체를 감지했습니다.False— 거리 센서가 물체를 감지하지 못했습니다.
Usage:
distance.found_object()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Turn until something is detected, then release the Pin
drivetrain.turn(RIGHT)
while True:
wait(5, MSEC)
if distance.found_object():
drivetrain.stop()
break
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
객체 거리#
object_distance 거리 센서와 가장 가까운 감지된 객체 사이의 거리를 반환합니다.
Usage:
distance.object_distance(units)
매개변수 |
설명 |
|---|---|
|
거리 단위: |
def main():
# Drive until 200 mm from the Goal, then release the Pin
while distance.object_distance(MM) > 200:
wait(5, MSEC)
drivetrain.drive(FORWARD)
drivetrain.stop()
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
GPS#
x_위치#
x_position 필드에 설치된 GPS(Game Positioning System™) 센서의 현재 x좌표를 반환합니다.
Usage:
gps.x_position(units)
매개변수 |
설명 |
|---|---|
단위 |
오프셋 값의 단위: |
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive(FORWARD)
while not gps.x_position(MM) > -1370:
wait(2, MSEC)
drivetrain.stop()
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
y_위치#
y_position 필드에 설치된 GPS(Game Positioning System™) 센서의 현재 y 좌표를 반환합니다.
Usage:
gps.y_position(units)
매개변수 |
설명 |
|---|---|
단위 |
오프셋 값의 단위: |
def main():
# Raise the Arm, drive to the Goal, release the Pin
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive(FORWARD)
while not gps.y_position(MM) < -450:
wait(2, MSEC)
drivetrain.stop()
claw_motor.spin_for(REVERSE, 180, DEGREES)
# VR threads — Do not delete
vr_thread(main)
표제#
heading 은 GPS(Game Positioning System™) 센서 판독값을 기반으로 로봇이 현재 향하고 있는 방향을 0도에서 359도 사이의 값으로 반환합니다.
Usage:
gps.heading()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
def main():
# Raise the Arm, drive to the Goal, release the Pin
monitor_sensor("gps.heading")
arm_motor.spin_for(FORWARD, 300, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
claw_motor.spin_for(REVERSE, 180, DEGREES)
# Turn left to face the Neutral Goal
drivetrain.set_turn_velocity(30, PERCENT)
drivetrain.turn(LEFT)
while not gps.heading() < 18:
wait(2, MSEC)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)