感應器#

介紹#

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