运动#
简介#
VEX AIR 无人机配备四个螺旋桨,使其能够向任意方向移动并独立旋转。运动控制功能提供了移动、转向、速度调节和位置跟踪等方法。

以下是所有可用方法的列表:
动作
take_off– 将无人机升至指定高度。land– 使无人机降落。hover- 使无人机悬停在其当前位置。climb– 使无人机沿指定的垂直方向移动。climb_for– 使无人机沿指定的垂直方向移动指定距离。climb_to– 使无人机移动到指定高度。move_at– 使无人机以指定的航向和速度移动。move_for– 使无人机沿指定航向移动指定距离。move_to– 使无人机移动到指定位置,同时保持航向不变。turn– 使无人机向左或向右转向。turn_for– 使无人机转动指定的度数。turn_to– 使无人机转向以面向指定航向。move_with_vectors– 使用基于向量的 x、y、z 和旋转值移动无人机。
修改方法
set_steering_mode– 设置用于操控无人机的视角。set_movement_mode– 设置无人机的移动风格。set_climb_velocity– 设置默认爬升速度。set_move_velocity– 设置默认移动速度。set_turn_velocity- 设置默认转向速度。set_max_z_height- 设置无人机飞行高度的上限。set_xyz_position– 设置无人机的当前位置。
获取方法
get_max_z_height– 返回无人机可达到的最大高度。get_flight_state–返回无人机的当前状态。get_x_position– 返回无人机的 x 坐标。get_y_position–返回无人机的y坐标。get_z_position–返回无人机的z坐标。get_safe_mode–返回无人机的螺旋桨锁定状态。is_climb_active–返回无人机当前是否正在爬升。is_move_active– 返回无人机当前是否正在移动。is_turn_active– 返回无人机当前是否正在转向。is_hovering- 返回无人机当前是否正在悬停。is_taking_off– 返回无人机当前是否正在起飞。is_landing– 返回无人机当前是否正在降落。is_landed- 返回无人机当前是否已着陆。
动作#
take_off#
take_off 启动螺旋桨并将无人机升空。必须先使用此方法,才能进行其他移动。
In VEX AIR Competition Matches, take_off must be the first method in your project. The Field Control System (FCS) does not make the drone take off automatically, so your project must handle takeoff. Your project starts running on its own when the FCS enables flight at the start of a Match.
用法:
drone.take_off(climb_to, units, wait)
参数 |
描述 |
|---|---|
|
无人机将飞到的z轴位置(高度)。 |
|
要使用的单位:
|
|
可选。 |
# Fly for 1 second
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.land()
land#
land 使无人机降落到地面。螺旋桨将持续旋转,直到项目停止运行。
用法:
drone.land(wait)
参数 |
描述 |
|---|---|
|
可选。 |
# Land after 1 second
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.land()
hover#
hover 使无人机停止向任何方向移动,并保持当前在空中的位置。
用法:
drone.hover()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Hold current position for 3 seconds after moving forward
drone.take_off(climb_to=500, units=MM)
drone.move_at(angle=0, velocity=50)
wait(1, SECONDS)
drone.hover()
wait(3, SECONDS)
drone.land()
climb#
[climb]– 使无人机沿指定的垂直方向移动。
用法: drone.climb(direction, velocity)
参数 |
描述 |
|---|---|
|
无人机的飞行方向: |
|
无人机爬升的速度百分比。 |
# Climb upwards for 2 seconds
drone.take_off(climb_to=500, units=MM)
wait(2, SECONDS)
drone.climb(UP, 50)
wait(2, SECONDS)
drone.land()
climb_for#
climb_for 使无人机沿指定的垂直方向移动特定距离。
用法:
drone.climb_for(direction, distance, units, velocity, wait)
参数 |
描述 |
|---|---|
|
无人机的飞行方向: |
|
无人机的飞行距离。 |
|
可选。表示距离的单位:
|
|
可选。无人机爬升的速度(以百分比表示)。如果未指定速度,则默认速度为 50%。 |
|
可选。 |
# Lower drone before landing
drone.take_off(climb_to=700, units=MM)
wait(2, SECONDS)
drone.climb_for(direction=DOWN, distance=300, units=MM, velocity=50)
wait(2, SECONDS)
drone.land()
climb_to#
climb_to使无人机移动到指定高度。
用法:
drone.climb_to(z, units, velocity, wait)
参数 |
描述 |
|---|---|
|
无人机将爬升至的 z 位置(整数或小数)。 |
|
可选。表示距离的单位:
|
|
可选。无人机爬升的速度百分比。 |
|
可选。 |
# Reach 500 mm after takeoff
drone.take_off(climb_to=300, units=MM)
wait(1, SECONDS)
drone.climb_to(z=500, units=MM, velocity=50)
wait(1, SECONDS)
drone.land()
move_at#
move_at 使无人机以指定的角度和速度移动。
用法:
drone.move_at(angle, velocity)
参数 |
描述 |
|---|---|
|
无人机移动的角度,以整数或小数表示,范围从 0 到 359 度。 |
|
无人机移动的速度(以百分比表示)。 |
# Move left for 2 seconds
drone.take_off(climb_to=500, units=MM)
drone.move_at(angle=270, velocity=50)
wait(2, SECONDS)
drone.land()
move_for#
move_for 使用当前的 set_move_velocity,使无人机沿特定方向移动特定距离。
用法:
drone.move_for(angle, distance, units, velocity, wait)
参数 |
描述 |
|---|---|
|
无人机移动的角度,以整数或十进制数表示 (float),范围从 0 到 359 度。 |
|
无人机移动的距离,以整数或小数表示。 |
|
可选。表示距离的单位:
|
|
可选。无人机移动的速度(百分比)。 |
|
可选。 |
# Move forward for 200 mm
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.move_for(angle=0, distance=200, units=MM, velocity=50)
wait(1, SECONDS)
drone.land()
move_to#
move_to 使无人机在空中移动到指定位置,同时保持航向不变。
用法:
drone.move_to(x, y, z, units, move_velocity, climb_velocity, wait)
参数 |
描述 |
|---|---|
|
无人机将移动到的 x 坐标。 |
|
无人机将移动到的 y 坐标。 |
|
无人机将移动到的 z 坐标。 |
|
可选。表示距离的单位:
|
|
可选。无人机移动的速度(百分比)。 |
|
可选。无人机爬升的速度百分比。 |
|
可选。 |
# Move diagonally to (300, 300, 800)
drone.take_off(climb_to=300, units=MM)
wait(2, SECONDS)
drone.move_to(x=300, y=300, z=800, units=MM, move_velocity=50, climb_velocity=50)
wait(2, SECONDS)
drone.land()
turn#
turn 使用当前的 set_turn_velocity,使无人机朝特定方向转向。
用法:
drone.turn(direction, velocity)
参数 |
描述 |
|---|---|
|
无人机将转向的方向: |
|
可选。无人机转弯的速度(百分比)。 |
# Turn to the right for 2 seconds
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.turn(RIGHT, 50)
wait(2, SECONDS)
drone.land()
turn_for#
turn_for 使用当前的 set_turn_velocity,使无人机相对于其当前朝向,朝指定方向转动设定距离。
用法:
drone.turn_for(direction, angle, velocity, wait)
参数 |
描述 |
|---|---|
|
无人机将转向的方向: |
|
无人机转弯的角度,以整数或十进制数表示 (float),范围从 0 到 359 度。 |
|
可选。无人机转弯的速度(百分比)。 |
|
可选。 |
# Turn around, then land
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.turn_for(RIGHT, 180)
wait(1, SECONDS)
drone.land()
turn_to#
turn_to 使用当前的 set_turn_velocity 设置的转向速度,使无人机转向指定的航向。
用法:
drone.turn_to(heading, velocity, wait)
参数 |
描述 |
|---|---|
|
无人机将转向的方向,范围为 0 到 360 度。 |
|
可选。无人机转弯的速度(百分比)。 |
|
可选。 |
# Turn to face each of the cardinal headings
drone.take_off(climb_to=500, units=MM)
drone.turn_to(heading=90, velocity=50)
wait(3, SECONDS)
drone.turn_to(heading=180, velocity=50)
wait(3, SECONDS)
drone.turn_to(heading=270, velocity=50)
wait(3, SECONDS)
drone.turn_to(heading=0, velocity=50)
wait(3, SECONDS)
drone.land()
move_with_vectors#
move_with_vectors 使用基于向量的运动方式,使无人机沿 x 轴(水平方向)和 y 轴(垂直方向)组合移动,同时使无人机旋转。
注意: 此方法直接设置运动和转速值,因此不使用set_move_velocity或set_turn_velocity。
用法:
drone.move_with_vectors(forward, rightward, upward, rotation)
参数 |
描述 |
|---|---|
|
无人机沿 Y 轴的速度(前后移动)。接受 -100 到 100 之间的百分比值,负值表示向后移动,正值表示向前移动。 |
|
无人机沿 X 轴(左右移动)的速度。接受 -100 到 100 之间的百分比值,负值向左移动,正值向右移动。 |
|
无人机沿 Z 轴(上下运动)的速度。接受 -100 到 100 之间的百分比值,负值表示向下移动,正值表示向上移动。 |
|
无人机的旋转速度。接受 -100 到 100 之间的百分比值,其中负值表示逆时针旋转,正值表示顺时针旋转。 |
# Move with controller
drone.take_off(climb_to=500, units=MM)
while True:
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
修改方法#
set_steering_mode#
set_steering_mode 设置操控无人机时使用的视角。
用法:
drone.set_steering_mode(style)
参数 |
描述 |
|---|---|
|
设置用于操控无人机的视角。 |
# Steer based on the drone's starting orientation
# until button 7 is pressed
drone.take_off(climb_to=500, units=MM)
drone.set_steering_mode(HEADLESS)
while not controller.button7.pressing():
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
drone.land()
set_movement_mode#
set_movement_mode 设置无人机的移动模式。
这种运动方式用于使用遥控器驾驶无人机时。
用法:
drone.set_movement_mode(style)
参数 |
描述 |
|---|---|
|
设置用于操控无人机的速度。
|
# Control the drone with the balanced movement style
drone.take_off(climb_to=500, units=MM)
drone.set_movement_mode(BALANCED)
while not controller.button5.pressing():
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
drone.land()
set_climb_velocity#
set_climb_velocity 以百分比形式设置默认爬升速度。这将影响后续所有与爬升相关的方法。默认爬升速度为 50%。
用法:
drone.set_climb_velocity(velocity)
参数 |
描述 |
|---|---|
|
无人机爬升的速度百分比。 |
# Raise the drone quickly before landing
drone.take_off(climb_to=300, units=MM)
wait(1, SECONDS)
drone.set_climb_velocity(100)
drone.climb_for(direction=UP, distance=500, units=MM, velocity=100)
wait(1, SECONDS)
drone.land()
set_move_velocity#
set_move_velocity 以百分比形式设置默认移动速度。这将影响后续所有与移动相关的方法。默认移动速度为 50%。
用法:
drone.set_move_velocity(velocity)
参数 |
描述 |
|---|---|
|
无人机移动的速度(以百分比表示)。 |
# Move forward quickly, then reverse slowly
drone.take_off(climb_to=500, units=MM)
drone.set_move_velocity(100)
drone.move_for(angle=0, distance=500, units=MM, velocity=100)
wait(3, SECONDS)
drone.set_move_velocity(20)
drone.move_for(angle=180, distance=500, units=MM, velocity=20)
wait(5, SECONDS)
drone.land()
set_turn_velocity#
set_turn_velocity 以百分比形式设置默认转向速度。这将影响后续所有与转向相关的方法。默认转向速度为 50%。
用法:
drone.set_turn_velocity(velocity)
参数 |
描述 |
|---|---|
|
无人机转弯的速度(以百分比表示)。 |
# Turn clockwise quickly, then counterclockwise slowly
drone.take_off(climb_to=500, units=MM)
drone.set_turn_velocity(100)
drone.turn_for(RIGHT, 360)
wait(3, SECONDS)
drone.set_turn_velocity(20)
drone.turn_for(LEFT, 360)
wait(5, SECONDS)
drone.land()
set_max_z_height#
set_max_z_height 设置无人机的最大飞行高度限制。
用法:
drone.set_max_z_height(z_height, units)
参数 |
描述 |
|---|---|
|
无人机不会飞过的最大 z 轴值(整数或小数),范围为 1000 至 5000 毫米或 40 至 196 英寸。 |
|
可选。距离单位包括:
|
# Fly with controller under 1000 mm
drone.set_max_z_height(1000, MM)
drone.take_off(climb_to=500, units=MM)
while not controller.button7.pressing():
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
drone.land()
set_xyz_position#
set_xyz_position 将无人机当前的 x、y 或 z 坐标设置为指定值。
用法:
drone.set_xyz_position(x, y, z, units)
注意: 所有参数均为可选,但至少必须指定一个(x、y 或 z)。
参数 |
描述 |
|---|---|
|
可选。要为无人机设置的 x 坐标,以 |
|
可选。要为无人机设置的 y 坐标,以 |
|
可选。要为无人机设置的 z 坐标,以 |
|
可选。表示距离的单位:
|
# Reset the position to (0, 0, 0), then fly to z position -300
drone.take_off(climb_to=800, units=MM)
drone.set_xyz_position(x=0, y=0, z=0, units=MM)
wait(1, SECONDS)
drone.climb(DOWN, 50)
while not drone.get_z_position() < -300:
wait(5, MSEC)
drone.hover()
wait(1, SECONDS)
drone.land()
获取方法#
get_max_z_height#
get_max_z_height 返回无人机能够达到的最大高度,返回值为整数。
用法:
drone.get_max_z_height(units)
参数 |
描述 |
|---|---|
|
可选。测量单位:
|
# Display the new z height limit
controller.screen.print(drone.get_max_z_height(MM))
controller.screen.next_row()
drone.take_off(climb_to=500, units=MM)
drone.set_max_z_height(1000, MM)
controller.screen.print(drone.get_max_z_height(MM))
wait(1, SECONDS)
drone.land()
get_flight_state#
get_flight_state 返回无人机当前的飞行状态,返回值类型为 DroneFlightStateType:
MOTOR_OFF- 其他飞行状态均不成立。CALIBRATION- 无人机正在校准传感器。MOTOR_START-无人机正在启动电机。FLIGHT_READY-无人机已准备好飞行。FLIGHT- 无人机正在飞行。
用法:
drone.get_flight_state()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Report the flight status as the drone takes off
controller.screen.print("Preparing for flight!")
controller.screen.next_row()
drone.take_off(climb_to=800, units=MM, wait=False)
while not drone.get_flight_state() == MOTOR_START:
wait(5, MSEC)
controller.screen.print("Motors starting...")
controller.screen.next_row()
while not drone.get_flight_state() == FLIGHT:
wait(5, MSEC)
controller.screen.print("Take off!")
get_x_position#
get_x_position 返回无人机的 x 坐标,返回值为小数 (float)。
用法:
drone.get_x_position(units)
参数 |
描述 |
|---|---|
|
可选。表示位置的单位:
|
# Move to (200, 0, 500)
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.move_at(angle=90, velocity=50)
while not drone.get_x_position() > 200:
wait(5, MSEC)
drone.hover()
wait(1, SECONDS)
drone.land()
get_y_position#
get_y_position 返回无人机的 y 坐标,返回值为小数 (float)。
用法:
drone.get_y_position(units)
参数 |
描述 |
|---|---|
|
可选。表示位置的单位:
|
# Move to (0, 200, 500)
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.move_at(angle=0, velocity=50)
while not drone.get_y_position() > 200:
wait(5, MSEC)
drone.hover()
wait(1, SECONDS)
drone.land()
get_z_position#
get_y_position 返回无人机的 z 坐标,返回值为小数 (float)。
用法:
drone.get_z_position(units)
参数 |
描述 |
|---|---|
|
可选。表示位置的单位:
|
# Move to (0, 0, 800)
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.climb(UP, 50)
while not drone.get_z_position() > 800:
wait(5, MSEC)
drone.hover()
wait(1, SECONDS)
drone.land()
get_safe_mode#
get_safe_mode 返回一个 Boolean 值,表示无人机的螺旋桨锁定功能是否已启用。
True– 螺旋桨锁定功能已启用。False– 螺旋桨锁定功能未启用。
用法:
drone.get_safe_mode()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Change the sound by enabling the Propeller Lock
while True:
if drone.get_safe_mode():
controller.sound.play(FAULT)
while controller.sound.is_active():
wait(50, MSEC)
else:
controller.sound.play(SUCCESS)
while controller.sound.is_active():
wait(50, MSEC)
wait(5, MSEC)
is_climb_active#
is_climb_active 返回一个 Boolean 值,表示无人机是否正在爬升。
True– 无人机当前正在爬升。False–无人机没有爬升。
用法:
drone.is_climb_active()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# After the drone starts to climb, play a sound and land
drone.take_off(climb_to=500, units=MM)
drone.climb(UP, 50)
wait(3, SECONDS)
if drone.is_climb_active():
controller.sound.play(SUCCESS)
drone.land()
is_move_active#
is_move_active 返回一个 Boolean 值,表示无人机当前是否正在使用移动方法。
True– 无人机当前正在使用移动方法。False– 无人机当前未使用移动方法。
用法:
drone.is_move_active()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# After the drone starts to move, play a sound and land
drone.take_off(climb_to=500, units=MM)
drone.move_at(angle=0, velocity=50)
wait(2, SECONDS)
if drone.is_move_active():
controller.sound.play(SUCCESS)
drone.land()
is_turn_active#
is_turn_active 返回一个 Boolean 值,表示无人机是否正在转向。
True– 无人机当前正在转向。False– 无人机当前未转向。
用法:
drone.is_turn_active()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# After the drone starts to turn, play a sound and land
drone.take_off(climb_to=500, units=MM)
drone.turn(RIGHT)
wait(2, SECONDS)
if drone.is_turn_active():
controller.sound.play(LOOPING)
while controller.sound.is_active():
wait(50, MSEC)
drone.land()
is_hovering#
is_hovering 返回一个 Boolean 值,表示无人机是否正在保持当前位置(悬停)。
True– 无人机当前正在保持当前位置(悬停)。False– 无人机当前正在改变其位置。
用法:
drone.is_hovering()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Play a sound after the drone has finished taking off
drone.take_off(climb_to=700, units=MM)
while not drone.is_hovering():
wait(5, MSEC)
controller.sound.play(PAUSE)
wait(2, SECONDS)
drone.land()
is_taking_off#
is_taking_off 返回一个 Boolean 值,表示无人机是否正在起飞。
True– 无人机当前正在起飞。False– 无人机当前未处于起飞过程中。
用法:
drone.is_taking_off()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Play sounds while the drone is taking off
drone.take_off(climb_to=700, units=MM, wait=False)
wait(1, SECONDS)
while drone.is_taking_off():
controller.sound.play(LOOPING)
wait(5, MSEC)
is_landing#
is_landing 返回一个 Boolean 值,表示无人机是否正在降落。
True– 无人机当前正在降落。False– 无人机当前未处于降落过程中。
用法:
drone.is_landing()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Play sounds while the drone is landing
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.land(wait=False)
wait(1, SECONDS)
while drone.is_landing():
controller.sound.play(LOOPING)
wait(5, MSEC)
is_landed#
is_landed 返回一个 Boolean 值,表示无人机当前是否已着陆。
True– 无人机已着陆。False– 无人机尚未着陆。
用法:
drone.is_landed()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Celebrate a successful landing
drone.take_off(climb_to=500, units=MM)
wait(1, SECONDS)
drone.land()
wait(1, SECONDS)
if drone.is_landed():
controller.sound.play(SUCCESS)