관성#
소개#
IQ(2세대) Brain에는 내장 관성 센서가 포함되어 있습니다. 이 센서는 Brain의 움직임과 회전을 측정합니다.
관성 센서는 이를 위해 두 부분으로 구성됩니다. 자이로스코프는 방향, 회전, 자이로 회전율, 자세 등 회전을 측정합니다. 가속도계는 x, y, z축을 따라 가속하거나 감속하는 것과 같은 운동 변화를 측정합니다.
이 페이지에서는 관성 센서 이름으로 brain_inertial 예시로 사용합니다. 필요에 따라 구성한 이름으로 교체하십시오.
아래는 사용 가능한 모든 방법의 목록입니다.
방향 — 방향, 회전 및 센서 보정을 읽고 제어합니다.
heading— 센서가 향하는 방향을 0~359.99도에서 반환합니다.rotation— 센서가 얼마나 회전했는지 반환합니다.calibrate— 관성 센서를 보정합니다.set_heading— 관성 센서의 현재 방향을 새로운 방향 값으로 설정합니다.set_rotation— 관성 센서의 현재 회전을 새로운 회전 값으로 설정합니다.is_calibrating— 관성 센서가 현재 보정 중인지 여부를 반환합니다.reset_heading— 관성 센서의 현재 방향을 0도로 재설정합니다.reset_rotation— 관성 센서의 현재 회전을 0도로 재설정합니다.changed— 관성 센서의 방향이 변경될 때 실행될 함수를 등록합니다.
동작 — 가속도, 회전 속도 및 기울기를 측정합니다.
acceleration— 선택된 축에서 센서가 얼마나 빠르게 가속되거나 감속하는지 반환합니다.gyro_rate— 선택된 축을 중심으로 센서가 회전하는 속도를 반환합니다.orientation— 관성 센서의 롤, 피치 또는 요 각도를 반환합니다.
생성자 — 관성 센서를 수동으로 초기화하고 구성합니다.
Inertial— 관성 센서를 생성합니다.
정위#
heading#
헤딩은 센서가 향하는 방향을 나타내며, 0도에서 359.99도까지의 각도로 측정됩니다. 헤딩 heading 센서의 현재 헤딩을 나타냅니다.
초기 방향은 0도입니다. 센서가 359.99도를 넘어서 회전하면 방향은 다시 0도로 돌아갑니다.
Usage:
brain_inertial.heading(units)
매개변수 |
설명 |
|---|---|
|
선택 사항입니다. 제목 단위: |
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(brain_inertial.heading())
rotation#
회전은 센서가 회전한 정도를 각도로 측정한 값입니다. 방향과 달리 회전은 359.99도를 초과하거나 0도 미만으로 감소할 수 있습니다. 프로젝트 시작 시 회전 값은 0도로 설정됩니다. rotation 관성 센서의 현재 회전 값을 반환합니다.
오른쪽으로 돌면 회전 각도가 증가하고, 왼쪽으로 돌면 회전 각도가 감소합니다. 예를 들어, 오른쪽으로 두 바퀴를 완전히 돌면 720도 회전하게 됩니다. 0도에서 왼쪽으로 한 바퀴를 완전히 돌면 -360도 회전하게 됩니다.
Usage:
brain_inertial.rotation(units)
매개변수 |
설명 |
|---|---|
|
선택 사항입니다. 회전 단위: |
# Display the rotation value after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(brain_inertial.rotation())
calibrate#
calibrate 센서를 보정합니다. 이후의 모든 줄은 보정이 완료될 때까지 기다린 후 실행됩니다. 보정은 지정된 기간 동안 센서 노이즈와 드리프트를 측정하고 보정하여 센서가 회전을 정확하게 측정하도록 도와줍니다. 이 기간 동안 Brain은 안정적인 표면 위에 완전히 정지된 상태로 유지되어야 합니다. 보정 중에 움직임이 있으면 부정확한 결과가 발생할 수 있습니다.
VEX Brain은 모든 프로젝트 시작 시 내장된 관성 센서를 자동으로 보정하려고 시도합니다. 그러나 프로젝트 시작 중에 로봇을 운반하거나 이동 중인 경우 센서가 제대로 보정되지 않거나 잘못된 보정값을 생성할 수 있습니다.
Usage:
brain_inertial.calibrate()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
# Start calibration
brain_inertial.calibrate()
# Print after calibration
while brain_inertial.is_calibrating():
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Inertial Sensor")
brain.screen.next_row()
brain.screen.print("Calibrating")
wait(50, MSEC)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")
set_heading#
헤딩은 센서가 향하는 방향을 나타내며, 0도에서 359.99도까지의 각도로 측정됩니다. set_heading() set_heading() 관성 센서의 현재 헤딩 값을 새로운 헤딩 값으로 변경합니다.
예를 들어 센서가 오른쪽을 향하도록 회전한 경우, 방향을 0도로 설정하면 오른쪽을 향한 위치가 새로운 0도가 됩니다. 그러면 센서는 이 새로운 방향을 기준으로 다른 방향을 추적할 수 있습니다.
Usage:
brain_inertial.set_heading(value, units)
매개변수 |
설명 |
|---|---|
|
센서에 설정할 방향 값(도)입니다. 이 값은 0에서 359.99 사이일 수 있습니다. |
|
선택 사항입니다. 제목 단위: |
# Turn the robot around
brain_inertial.set_heading(180)
drivetrain.turn_to_heading(0)
set_rotation#
회전은 센서가 회전한 정도를 각도로 측정한 값입니다. 방향과 달리 회전은 359.99도를 초과하거나 0도 미만으로 감소할 수 있습니다. 프로젝트 시작 시 회전 값은 0도로 설정됩니다. set_rotation() 사용하면 관성 센서의 현재 회전 값을 새로운 값으로 변경할 수 있습니다.
예를 들어 센서가 오른쪽으로 두 바퀴를 완전히 돌았다면 회전 값은 720도가 됩니다. 회전 값을 0도로 설정하면 회전 값이 720도에서 0도로 초기화됩니다. 그러면 센서는 이 새로운 값을 기준으로 회전을 추적할 수 있습니다.
Usage:
brain_inertial.set_rotation(value, units)
매개변수 |
설명 |
|---|---|
|
센서에 설정할 회전 값(도 단위)입니다. 정수 또는 소수(부동 소수)일 수 있습니다. |
|
선택 사항입니다. 회전 단위: |
# Turn the robot around
brain_inertial.set_rotation(-180)
drivetrain.turn_to_rotation(0)
is_calibrating#
is_calibrating 관성 센서가 현재 보정 중인지 여부를 반환합니다.
True— 관성 센서가 보정 중입니다.False— 관성 센서가 보정 중이 아닙니다.
Usage:
brain_inertial.is_calibrating()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
# Start calibration
brain_inertial.calibrate()
# Print while waiting for calibration
while brain_inertial.is_calibrating():
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Inertial Sensor")
brain.screen.next_row()
brain.screen.print("Calibrating")
wait(50, MSEC)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")
reset_heading#
reset_heading 은 관성 센서의 현재 방향을 0도로 재설정합니다.
이 방법을 사용하면 센서의 현재 방향이 새로운 0도 방향으로 설정됩니다.
Usage:
brain_inertial.reset_heading()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
# Turn the robot before and after resetting the heading
drivetrain.turn_to_heading(90, DEGREES)
wait(0.5, SECONDS)
brain_inertial.reset_heading()
drivetrain.turn_to_heading(90, DEGREES)
reset_rotation#
reset_rotation 관성 센서의 현재 회전 각도를 0도로 재설정합니다.
이 방법을 사용하면 센서는 새로운 0도 회전 값을 기준으로 향후 회전을 추적합니다.
Usage:
brain_inertial.reset_rotation()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
# Turn the robot before and after resetting the rotation
drivetrain.turn_to_rotation(-90, DEGREES)
wait(0.5, SECONDS)
brain_inertial.reset_rotation()
drivetrain.turn_to_rotation(-90, DEGREES)
changed#
changed 관성 센서의 방향이 변경될 때 호출될 함수를 등록합니다.
Usage:
brain_inertial.changed(callback, arg)
매개변수 |
설명 |
|---|---|
|
관성 센서의 방향이 변경될 때 실행되는 함수입니다. |
|
선택 사항입니다. 콜백 함수에 전달할 인자 튜플입니다. |
def heading_changed():
brain.screen.set_cursor(1, 1)
brain.screen.clear_screen()
brain.screen.print("my heading ")
brain.screen.next_row()
brain.screen.print("has changed!")
wait(0.1, SECONDS)
# Call the function when the inertial heading is changed
wait(1, SECONDS)
drivetrain.turn_for(RIGHT, 90, DEGREES, wait=False)
brain_inertial.changed(heading_changed)
wait(15, MSEC)
운동#
acceleration#
가속도는 센서가 얼마나 빠르게 가속하거나 감속하는지를 나타냅니다. 가속도가 acceleration , 선택된 축에 대한 관성 센서의 가속도를 -4.0G에서 4.0G 사이의 부동 소수점 값으로 반환합니다.
G 가속도를 측정하는 단위입니다. 1G는 가만히 앉아 있을 때 중력으로부터 느끼는 가속도와 거의 같습니다.
해당 값은 선택한 축의 가속도 방향에 따라 양수 또는 음수가 될 수 있습니다. 축 옵션은 XAXIS, YAXIS, ZAXIS 입니다.
Usage:
brain_inertial.acceleration(axis)
매개변수 |
설명 |
|---|---|
중심선 |
가속도를 측정할 축:
|
# Display acceleration after moving
vexcode_brain_precision = 2
drivetrain.set_drive_velocity(100, PERCENT)
brain.screen.print("Resting: ")
brain.screen.next_row()
brain.screen.print(brain_inertial.acceleration(XAXIS))
brain.screen.next_row()
wait(1, SECONDS)
drivetrain.drive_for(FORWARD, 500, MM, wait=False)
wait(0.01, SECONDS)
brain.screen.print("Startup: ")
brain.screen.next_row()
brain.screen.print(brain_inertial.acceleration(XAXIS))
gyro_rate#
자이로 회전율은 관성 센서의 회전 속도를 나타냅니다. gyro_rate 선택된 축에서 관성 센서의 현재 회전 속도를 반환합니다.
센서가 해당 축을 중심으로 회전하는 방향에 따라 값이 양수 또는 음수가 될 수 있습니다.
Usage:
brain_inertial.gyro_rate(axis, units)
매개변수 |
설명 |
|---|---|
|
자이로 회전율을 반환할 축:
|
|
선택 사항입니다. 자이로율 단위:
|
# Display the z-axis gyro rate
drivetrain.turn(RIGHT)
wait(1, SECONDS)
brain.screen.print(brain_inertial.gyro_rate(ZAXIS, RPM))
drivetrain.stop()
orientation#
방향은 선택된 회전축에 대한 관성 센서의 현재 각도입니다. 방향이 orientation 관성 센서의 롤, 피치 또는 요 값을 반환합니다.
롤, 피치, 요는 센서가 기울어지거나 회전할 수 있는 다양한 방식을 나타냅니다.
Usage:
brain_inertial.orientation(axis, units)
매개변수 |
설명 |
|---|---|
|
반환할 방향 각도:
|
|
선택 사항입니다. 방향 단위: |
# Display the roll, pitch, and yaw of the Brain as it
# is rotated by hand
while True:
brain.screen.clear_screen()
brain.screen.print(brain_inertial.orientation(OrientationType.ROLL))
brain.screen.next_row()
brain.screen.print(brain_inertial.orientation(OrientationType.PITCH))
brain.screen.next_row()
brain.screen.print(brain_inertial.orientation(OrientationType.YAW))
brain.screen.next_row()
brain.screen.set_cursor(1, 1)
wait(0.1, SECONDS)
건설업자#
생성자는 VEXcode 외부에서 관성 센서를 구성할 때와 같이 Inertial 객체를 수동으로 생성하는 데 사용됩니다.
Inertial#
Inertial 관성 센서를 생성합니다.
Usage:
Inertial(smartport)
매개변수 |
설명 |
|---|---|
|
선택 사항입니다. IQ(2세대) Brain’s 내장 관성 센서를 사용하는 경우 스마트 포트가 필요하지 않습니다. 외부 관성 센서를 연결하는 경우 관성 센서가 연결된 스마트 포트를 |
# Create a new object "brain_inertial" with the
# Inertial class
brain_inertial = Inertial()
left_drive_smart = Motor(Ports.PORT1, 1.0, False)
right_drive_smart = Motor(Ports.PORT6, 1.0, True)
drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)
brain_inertial.set_heading(180)
drivetrain.turn_to_heading(0)


