传感器#
简介#
VEX AIR 无人机内置惯性仪,用于测量旋转运动和检测运动变化,以及测距传感器,用于测量距离。VEX AIR 无人机还可以跟踪电池电量。这些传感器使无人机能够追踪其方向、航向、加速度以及与物体的距离。
以下是所有可用方法的列表:
惯性仪 - 跟踪无人机的旋转运动。
get_rotation– 返回无人机自启动以来的旋转角度。get_heading– 返回无人机当前的航向角(0 至 359.99°)。get_yaw– 返回偏航角(–180 至 180°)。get_roll– 返回横滚角(–180 至 180°)。get_pitch– 返回俯仰角(–180 至 180°)。reset_rotation– 将旋转角度值重置为 0。reset_heading– 将当前航向角设置为 0。set_heading– 将航向角设置为指定值。get_acceleration–返回特定方向的加速度。get_turn_rate–返回以度/秒为单位的转速。
测距范围 — 通过无人机的测距传感器检测距离。
get_distance— 返回所选测距传感器与检测到的最近物体之间的距离。
电池 - 返回无人机的电池百分比。
get_battery_level– 返回无人机的电池电量百分比。
惯性仪#
get_rotation#
get_rotation 返回无人机自启动以来转动了多少度。它将所有转数相加,并以度为单位返回总数:顺时针方向为正,逆时针方向为负。
用法:
drone.inertial.get_rotation()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the rotation after turning
drone.take_off(climb_to=500)
drone.turn_for(LEFT, 450, 50)
print(drone.inertial.get_rotation(), end="")
drone.land()
get_heading#
get_heading 返回无人机的航向角,范围为 0 至 359.99 度,返回值为浮点数。
用法:
drone.inertial.get_heading()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the drone's heading after turning
drone.take_off(climb_to=500)
drone.set_turn_velocity(100)
drone.turn(RIGHT)
wait(5, SECONDS)
controller.screen.print("Heading: ")
controller.screen.print(drone.inertial.get_heading())
drone.land()
get_yaw#
get_yaw 以浮点形式返回在范围-180.0 到 180.0 之间的无人机的偏航角。
下图使用箭头表示偏航的正旋转方向。

用法:
drone.inertial.get_yaw
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the yaw angle as you rotate the drone by hand
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Yaw: ")
controller.screen.print(drone.inertial.get_yaw())
wait(0.2, SECONDS)
get_roll#
get_roll 返回无人机的横滚角,范围为 –180.0 至 180.0 度,返回值为浮点数。
下图用箭头表示滚动的正向旋转方向。

用法:
drone.inertial.get_roll()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the roll angle as you rotate the drone by hand
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Roll: ")
controller.screen.print(drone.inertial.get_roll())
wait(0.2, SECONDS)
get_pitch#
get_pitch 返回无人机的俯仰角,范围为 –180.0 至 180.0 度,返回值为浮点数。
下图使用箭头表示俯仰的正向旋转方向。

用法:
drone.inertial.get_pitch()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the pitch angle as you rotate the drone by hand
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Pitch: ")
controller.screen.print(drone.inertial.get_pitch())
wait(0.2, SECONDS)
reset_rotation#
reset_rotation 将无人机的旋转值重置为0度。
用法:
drone.inertial.reset_rotation()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the new rotation after resetting
drone.take_off(climb_to=500)
drone.turn(RIGHT)
while not drone.inertial.get_rotation() > 360:
wait(5, MSEC)
drone.hover()
drone.inertial.reset_rotation()
wait(1, SECONDS)
print(drone.inertial.get_rotation(), end="")
drone.land()
reset_heading#
reset_heading 将无人机的航向重置为0度。
用法:
drone.inertial.reset_heading()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Turn to a heading, reset the heading, and turn to the same heading.
drone.take_off(climb_to=500)
drone.turn_to(heading=180, velocity=50)
wait(3,SECONDS)
drone.inertial.reset_heading()
drone.turn_to(heading=180, velocity=50)
wait(3,SECONDS)
drone.land()
set_heading#
set_heading 将无人机的航向设置为指定的度数值。
用法:
drone.inertial.set_heading(heading)
参数 |
描述 |
|---|---|
|
新航向使用的值在 0 到 359.99 度范围内。 |
# Turn to a heading, set the heading, and turn to the same heading.
drone.take_off(climb_to=500)
drone.turn_to(heading=180, velocity=50)
wait(3,SECONDS)
drone.inertial.set_heading(90)
drone.turn_to(heading=180, velocity=50)
wait(3,SECONDS)
drone.land()
get_acceleration#
get_acceleration 返回无人机在指定方向上的加速度。返回值表示速度的变化率,以g ( 1g ≈ 9.81 m/s ² )为单位,浮点数范围为-4.00至4.00。
下图用箭头表示向前和向右的正加速度方向,向下的负加速度方向。

用法:
drone.inertial.get_acceleration(type)
参数 |
描述 |
|---|---|
|
要报告的加速度方向:
|
# Display the acceleration as the drone takes off
drone.take_off(500, wait=False)
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print(drone.inertial.get_acceleration(DOWNWARD))
wait(5, MSEC)
get_turn_rate#
get_turn_rate 返回无人机绕指定轴旋转的角速度。返回值以度每秒(dps)为单位,为 –1000.00 至 1000.00 dps 范围内的浮点数。
下图使用箭头显示横滚、俯仰和偏航的正旋转方向。

用法:
drone.inertial.get_turn_rate(axis)
参数 |
描述 |
|---|---|
|
要报告的姿态方向:
|
# Display the drone turn rate as it is rotated by hand.
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(7, 1)
controller.screen.print(drone.inertial.get_turn_rate(ROLL))
范围#
get_distance#
get_distance 返回所选测距传感器与检测到的最近物体之间的距离。
用法:
drone.range.get_distance(range, units)
参数 |
描述 |
|---|---|
|
要使用的测距传感器: |
|
可选。距离单位:
|
# Fly forward until close to an object
drone.take_off(climb_to=500)
drone.move_at(direction=0, velocity=50)
while not drone.range.get_distance(FORWARD_RANGE, MM) < 750:
wait(0.1, SECONDS)
drone.land()
电池#
get_battery_level#
get_battery_level 返回无人机的电池电量百分比。返回值为 0 至 100 之间的数值。
用法:
drone.get_battery_level()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the drone's battery level
if drone.get_battery_level() < 25:
controller.screen.print("Charge the drone Battery!")
else:
controller.screen.print("Ready to fly!")