传感器#

简介#

VEX AIR 无人机内置惯性仪,用于测量旋转运动和检测运动变化,以及测距传感器,用于测量距离。VEX AIR 无人机还可以跟踪电池电量。这些传感器使无人机能够追踪其方向、航向、加速度以及与物体的距离。

以下是所有可用方法的列表:

惯性仪 - 跟踪无人机的旋转运动。

测距范围 — 通过无人机的测距传感器检测距离。

  • get_distance — 返回所选测距传感器与检测到的最近物体之间的距离。

电池 - 返回无人机的电池百分比。

惯性仪#

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 之间的无人机的偏航角。

下图使用箭头表示偏航的正旋转方向。

一架 VEX AIR 无人机,机头朝向右下角,中心向下延伸出一个蓝色箭头。蓝色箭头周围环绕着一个顺时针方向的黑色弯曲箭头,并标有“Yaw”(偏航),表示偏航的正方向。

用法:
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 度,返回值为浮点数。

下图用箭头表示滚动的正向旋转方向。

一架VEX AIR无人机,机头朝向右下角,机头伸出一个绿色箭头。绿色箭头周围有一个黑色弯箭头,指向逆时针方向,表示正滚转方向。

用法:
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 度,返回值为浮点数。

下图使用箭头表示俯仰的正向旋转方向。

一架 VEX AIR 无人机朝向右下角,无人机右侧伸出一个红色箭头,旁边是 VEX 标志。红色箭头周围环绕着一个黑色弯曲箭头,逆时针方向表示俯仰的正方向。

用法:
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)

参数

描述

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。

下图用箭头表示向前和向右的正加速度方向,向下的负加速度方向。

图中展示了一架 VEX AIR 无人机,一支绿色箭头从无人机机头向前延伸,标注为“向前”;一支蓝色箭头从无人机底部中央向下延伸,标注为“向下”;一支红色箭头从无人机右侧的 VEX 标志旁向外延伸,标注为“向右”。

用法:

drone.inertial.get_acceleration(type)

参数

描述

type

要报告的加速度方向:

  • DOWNWARD
  • FORWARD
  • RIGHTWARD

# 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 范围内的浮点数。

下图使用箭头显示横滚、俯仰和偏航的正旋转方向。

图中显示了一架带有方向箭头的 VEX AIR 无人机。绿色箭头从无人机机头延伸而出,其周围环绕着一个黑色弯曲箭头,逆时针方向指向,并标注为“横滚 (Roll)”。蓝色箭头从无人机底部中心延伸而出,其周围环绕着一个黑色弯曲箭头,顺时针方向指向,并标注为“偏航 (Yaw)”。红色箭头从无人机右侧 VEX 标志旁延伸而出,其周围环绕着一个黑色弯曲箭头,逆时针方向指向,并标注为“俯仰 (Pitch)”。

用法:
drone.inertial.get_turn_rate(axis)

参数

描述

axis

要报告的姿态方向:

  • YAW
  • ROLL
  • PITCH

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

参数

描述

range

要使用的测距传感器:FORWARD_RANGE 或 DOWNWARD_RANGE。FORWARD_RANGE 报告无人机前方与物体之间的距离。DOWNWARD_RANGE 报告无人机底部与物体之间的距离。

units

可选。距离单位:

  • MM(默认)— 毫米
  • CM — 厘米
  • INCHES

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