运动#

介绍#

VEX AIR 无人机配备四个螺旋桨,可向任意方向飞行并独立旋转。Motion 提供移动、转弯、速度调节和位置跟踪等功能。

圆形罗盘刻度盘,0-360 度,环绕装有 4 个螺旋桨的无人机。无人机前端朝向罗盘刻度盘的 0 度。

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

行动

  • take_off – Lifts the drone to a specified height.

  • land – Lands the drone.

  • hover - Keeps the drone at its position.

  • climb – Moves the drone in a specified vertical direction.

  • climb_for – Moves the drone in a specified vertical direction for a specific distance.

  • climb_to – Moves the drone to a specified altitude.

  • move_at – Moves the drone at a specified heading and velocity.

  • move_for – Moves the drone at a specified heading for a specified distance.

  • move_to – Moves the drone to a specified position while maintaining the same heading.

  • turn – Turns the drone left or right.

  • turn_for – Turns the drone a set number of degrees.

  • turn_to – Turns the drone to face a specific heading.

  • move_with_vectors – Moves the drone using vector-based x, y, z, and rotation values.

修改器

吸气剂

行动#

take_off#

take_off starts the propellers and lifts the drone into the air. This method must be used before other movements can be made.

用法:

drone.take_off(climb_to, units, wait)

参数

描述

climb_to

无人机将飞到的 z 位置。

units

The unit to use:

  • CM - Centimeters
  • MM - Millimeters
  • INCHES

wait

Optional.

  • wait=True (default) – The drone waits until take_off is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for take_off to finish.

# Fly for 1 second
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.land()

land#

land lowers the drone to the ground. The propellers will continue to run until the project is stopped.

用法:

drone.land(wait)

参数

描述

wait

Optional.

  • wait=True (default) – The drone waits until land is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for land to finish.

# Land after 1 second
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.land()

hover#

hover stops the drone from moving in any direction and holds its current position in the air.

Usage:
drone.hover()

参数

描述

该方法没有参数。

# Hold current position for 3 seconds after moving forward
drone.take_off(climb_to=500)
drone.move_at(direction=0, velocity=50)
wait(1, SECONDS)
drone.hover()
wait(3, SECONDS)
drone.land()

climb#

climb moves the drone in a specified vertical direction.

Usage: drone.climb(direction, velocity)

参数

描述

direction

The direction in which the drone will fly:

  • UP
  • DOWN

velocity

无人机爬升的速度百分比。

# Climb upwards for 2 seconds
drone.take_off(climb_to=500)
wait(2, SECONDS)
drone.climb(direction=UP)
wait(2, SECONDS)
drone.land()

climb_for#

climb_for moves the drone in a specified vertical direction for a specific distance.

用法:

drone.climb_for(direction, distance, units, velocity, wait)

参数

描述

direction

The direction in which the drone will fly:

  • UP
  • DOWN

distance

无人机的飞行距离。

units

Optional. The unit that represents the distance:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES

velocity

可选。无人机爬升的速度(以百分比表示)。如果未指定速度,则默认速度为 50%。

wait

Optional.

  • wait=True (default) – The drone waits until climb_for is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for climb_for to finish.

# Lower drone before landing
drone.take_off(climb_to=700)
wait(2, SECONDS)
drone.climb_for(direction=DOWN, distance=300)
wait(2, SECONDS)
drone.land()

climb_to#

climb_to moves the drone to a specific z position.

用法:

drone.climb_to(z, units, velocity, wait)

参数

描述

z

无人机将爬升至的 z 位置(整数或小数)。

units

Optional. The unit that represents the distance:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES

velocity

可选。无人机爬升的速度百分比。

wait

Optional.

  • wait=True (default) – The drone waits until climb_to is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for climb_to to finish.

# Reach 500 mm after takeoff
drone.take_off(climb_to=300)
wait(1, SECONDS)
drone.climb_to(z=500)
wait(1, SECONDS)
drone.land()

move_at#

move_at moves the drone at a specified angle and velocity.

用法:

drone.move_at(angle, velocity)

参数

描述

angle

无人机移动的角度,以整数或小数表示,范围从 0 到 360 度。

velocity

无人机移动的速度(以百分比表示)。

# Move left for 2 seconds
drone.take_off(climb_to=500)
drone.move_at(angle=270)
wait(2, SECONDS)
drone.land()

move_for#

move_for moves the drone in a specific direction for a specific distance using the current set_move_velocity.

用法:

drone.move_for(angle, distance, units, velocity, wait)

参数

描述

angle

无人机移动的角度,以整数或浮点数表示,范围从 0 到 360 度。

distance

无人机移动的距离,以整数或小数表示。

units

Optional. The unit that represents the distance:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES

velocity

可选。无人机移动的速度(百分比)。

wait

Optional.

  • wait=True (default) – The drone waits until move_for is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for move_for to finish.

# Move forward for 200 mm
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.move_for(direction=0, distance=200, velocity=50, units=MM)
wait(1, SECONDS)
drone.land()

move_to#

move_to moves the drone to a specified position in the air while maintaining the same heading.

用法:

drone.move_to(x, y, z, units, move_velocity, climb_velocity, wait)

参数

描述

x

无人机将移动到的 x 坐标。

y

无人机将移动到的 y 坐标。

z

无人机将移动到的 z 坐标。

units

Optional. The unit that represents the distance:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES

move_velocity

可选。无人机移动的速度(百分比)。

climb_velocity

可选。无人机爬升的速度百分比。

wait

Optional.

  • wait=True (default) – The drone waits until move_to is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for move_to to finish.

# Move diagonally to (300, 300, 800)
drone.take_off(climb_to=300)
wait(2, SECONDS)
drone.move_to(x=300, y=300, z=800)
wait(2, SECONDS)
drone.land()

turn#

turn turns the drone in a specific direction using the current set_turn_velocity.

用法:

drone.turn(direction, velocity)

参数

描述

direction

The direction the drone will turn:

  • LEFT
  • RIGHT

velocity

可选。无人机转弯的速度(百分比)。

# Turn to the right for 2 seconds
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.turn(RIGHT, 50)
wait(2, SECONDS)
drone.land()

turn_for#

turn_for turns the drone in a specified direction for a set distance relative to its current facing direction using the current set_turn_velocity.

用法:

drone.turn_for(direction, angle, velocity, wait)

参数

描述

direction

The direction the drone will turn:

  • LEFT
  • RIGHT

angle

无人机旋转的角度,以整数或浮点数表示,范围从 0 到 360 度。

velocity

可选。无人机转弯的速度(百分比)。

wait

Optional.

  • wait=True (default) – The drone waits until turn_for is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for turn_for to finish.

# Turn around, then land
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.turn_for(RIGHT, 180)
wait(1, SECONDS)
drone.land()

turn_to#

turn_to turns the drone to face a specific heading using the current set_turn_velocity.

用法:

drone.turn_to(heading, velocity, wait)

参数

描述

heading

无人机将转向的方向,范围为 0 到 360 度。

velocity

可选。无人机转弯的速度(百分比)。

wait

Optional.

  • wait=True (default) – The drone waits until turn_to is complete before executing the next line of code.
  • wait=False – The drone starts the action and moves on to the next line of code right away, without waiting for turn_to to finish.

# Turn to face each of the cardinal headings
drone.take_off(climb_to=500)
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 moves the drone using vector-based motion, combining movement on the X-axis, Y-axis, and Z-axis while having the drone rotate at the same time.

用法:

drone.move_with_vectors(forward, rightward, upward, rotation)

参数

描述

forward

无人机沿 Y 轴的速度(前后移动)。接受 -100 到 100 之间的百分比值,负值表示向后移动,正值表示向前移动。

rightward

无人机沿 X 轴(左右移动)的速度。接受 -100 到 100 之间的百分比值,负值向左移动,正值向右移动。

upward

无人机沿 Z 轴(上下运动)的速度。接受 -100 到 100 之间的百分比值,负值表示向下移动,正值表示向上移动。

rotation

无人机的旋转速度。接受 -100 到 100 之间的百分比值,其中负值表示逆时针旋转,正值表示顺时针旋转。

# Move with controller
drone.take_off(climb_to=500)
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 sets the viewpoint that is used when steering the drone.

用法:

drone.set_steering_mode(style)

参数

描述

style

Sets the POV that is used to steer the drone.

  • HEADLESS – The drone moves relative to where it was facing at the start of the project.
  • STANDARD (default) – The drone moves relative to where it is facing.

# Steer based on the drone's starting orientation
# until button 7 is pressed
drone.take_off(climb_to=500)
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 sets the drone’s movement style.

这种运动方式用于使用控制器驾驶无人机时。

用法:

drone.set_movement_mode(style)

参数

描述

style

Sets the speed that is used to steer the drone.

  • BALANCED – The drone moves at a medium base speed.
  • PERFORMANCE – The drone moves at a faster base speed.
  • PRECISION (default) – The drone moves at a slower base speed.

# Control the drone with the balanced movement style
drone.take_off(climb_to=500)
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 sets the default climbing speed as a percentage. This will affect any following methods related to climbing. The default climb velocity is 50%.

用法:

drone.set_climb_velocity(velocity)

参数

描述

velocity

无人机爬升的速度百分比。

# Raise the drone quickly before landing
drone.take_off(climb_to=300)
wait(1, SECONDS)
drone.set_climb_velocity(100)
drone.climb_for(direction=UP, distance=500)
wait(1, SECONDS)
drone.land()

set_move_velocity#

set_move_velocity sets the default movement speed as a percentage. This will affect any following methods related to moving. The default move velocity is 50%.

用法:

drone.set_move_velocity(velocity)

参数

描述

velocity

无人机移动的速度(以百分比表示)。

# Move forward quickly, then reverse slowly
drone.take_off(climb_to=500)
drone.set_move_velocity(100)
drone.move_for(direction=0, distance=500)
wait(3, SECONDS)
drone.set_move_velocity(20)
drone.move_for(direction=180, distance=500)
wait(5, SECONDS)
drone.land()

set_turn_velocity#

set_turn_velocity sets the default movement speed as a percentage. This will affect any following methods related to turning. The default turn velocity is 50%.

用法:

drone.set_turn_velocity(velocity)

参数

描述

velocity

无人机转弯的速度(以百分比表示)。

# Turn clockwise quickly, then counterclockwise slowly
drone.take_off(climb_to=500)
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 sets a limit to how high the drone will fly.

用法:

drone.set_max_z_height(z_height, units)

参数

描述

z_height

无人机不会飞过的最大 z 轴值(整数或小数),范围为 1000 至 5000 毫米或 40 至 196 英寸。

units

Optional. The distance units are:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES
# Fly with controller under 1000 mm
drone.set_max_z_height(1000, MM)
drone.take_off(climb_to=500)
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 sets the drone’s current x, y, or z coordinate to a specified value.

用法:

drone.set_xyz_position(x, y, z, units)

Note: All parameters are optional, but at least one (x, y, or z) must be specified.

参数

描述

x

Optional. The x coordinate to set for the drone in units as a float or integer.

y

Optional. The y coordinate to set for the drone in units as a float or integer.

z

Optional. The z coordinate to set for the drone in units as a float or integer.

units

Optional. The unit that represents the distance:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES
# Set a new z position, then fly to z position -300
drone.take_off(climb_to=800)
drone.set_xyz_position(z=0)
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 returns the maximum height that the drone can reach as an integer.

用法:

drone.get_max_z_height(units)

参数

描述

units

Optional. The unit of measurement:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES
# 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)
drone.set_max_z_height(1000)
controller.screen.print(drone.get_max_z_height(MM))
wait(1, SECONDS)
drone.land()

get_flight_state#

get_flight_state returns the drone’s current flying state as a DroneFlightStateType:

  • MOTOR_OFF - No other flight state is true.

  • CALIBRATION - The drone is calibrating its sensors.

  • MOTOR_START - The drone is starting its motors.

  • FLIGHT_READY - The drone is ready to fly.

  • FLIGHT - The drone is in flight.

Usage:
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, 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 returns the drone’s x coordinate as a float.

Usage:
drone.get_x_position(units)

参数

描述

units

Optional. The unit that represents the position:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES
# Move to (200, 0, 500)
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.move_at(direction=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 returns the drone’s y coordinate as a float.

用法:

drone.get_y_position(units)

参数

描述

units

Optional. The unit that represents the position:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES
# Move to (0, 200, 500)
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.move_at(direction=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 returns the drone’s z coordinate as a float.

用法:

drone.get_z_position(units)

参数

描述

units

Optional. The unit that represents the position:

  • CM – Centimeters
  • MM (default) – Millimeters
  • INCHES
# Move to (0, 0, 800)
drone.take_off(climb_to=500)
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 returns a Boolean indicating whether the Propeller Lock is enabled on the drone.

  • True – Propeller Lock is enabled.

  • False – Propeller Lock is not enabled.

用法:

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 returns a Boolean indicating whether the drone is climbing.

  • True – The drone is currently climbing.

  • False – The drone is not climbing.

用法:

drone.is_climb_active()

参数

描述

该方法没有参数。

# After the drone starts to climb, play a sound and land
drone.take_off(climb_to=500)
drone.climb(UP, 50)
wait(3, SECONDS)
if drone.is_climb_active():
    controller.sound.play(SUCCESS)
    drone.land()

is_move_active#

is_move_active returns a Boolean indicating whether the drone is currently using a move method.

  • True – The drone is currently using a move method.

  • False – The drone is not currently using a move method.

用法:

drone.is_move_active()

参数

描述

该方法没有参数。

# After the drone starts to move, play a sound and land
drone.take_off(climb_to=500)
drone.move_at(direction=0, velocity=50)
wait(2, SECONDS)
if drone.is_move_active():
    controller.sound.play(SUCCESS)
    drone.land()

is_turn_active#

is_turn_active returns a Boolean indicating whether the drone is turning.

  • True – The drone is currently turning.

  • False – The drone is not turning.

用法:

drone.is_turn_active()

参数

描述

该方法没有参数。

# After the drone starts to turn, play a sound and land
drone.take_off(climb_to=500)
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 returns a Boolean indicating whether the drone is maintaining its position (hovering).

  • True – The drone is currently maintaining its position (hovering).

  • False – The drone is currently changing its position.

用法:

drone.is_hovering()

参数

描述

该方法没有参数。

# Play a sound after the drone has finished taking off
drone.take_off(climb_to=700)
while not drone.is_hovering():
    wait(5, MSEC)
controller.sound.play(PAUSE)
wait(2, SECONDS)
drone.land()

is_taking_off#

is_taking_off returns a Boolean indicating whether the drone is in the process of taking off.

  • True – The drone is currently in the process of taking off.

  • False – The drone is not in the process of taking off.

用法:

drone.is_taking_off()

参数

描述

该方法没有参数。

# Play sounds while the drone is taking off
drone.take_off(700, wait=False)
wait(1, SECONDS)
while drone.is_taking_off():
    controller.sound.play(LOOPING)
    wait(5, MSEC)

is_landing#

is_landing returns a Boolean indicating whether the drone is in the process of landing.

  • True – The drone is currently in the process of landing.

  • False – The drone is not in the process of landing.

用法:

drone.is_landing()

参数

描述

该方法没有参数。

# Play sounds while the drone is landing
drone.take_off(climb_to=500)
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 returns a Boolean indicating whether the drone is currently landed.

  • True – The drone is landed.

  • False – The drone is not landed.

用法:

drone.is_landed()

参数

描述

该方法没有参数。

# Celebrate a successful landing
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.land()
wait(1, SECONDS)
if drone.is_landed():
    controller.sound.play(SUCCESS)