运动#

介绍#

VEX AIM 编码机器人采用完整的传动系统,使其能够向任何方向移动并独立旋转。Motion 提供了移动、转弯、速度调节和位置跟踪的方法。

圆形罗盘刻度盘,0-315 度,环绕深灰色显示屏,搭配海军蓝色屏幕。机器人正面朝向罗盘刻度盘的 0 度。

以下是可用方法的列表:

动作——移动和转动机器人。

  • move_at – Moves the robot at a specified angle.

  • move_for – Moves the robot at an angle for a specific distance.

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

  • turn – Turns the robot left or right.

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

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

  • stop_all_movement – Stops all movement of the robot.

变异器——设置默认移动和转动速度。

Getters – 返回机器人状态和位置。

行动#

move_at#

move_at moves the robot at a specified angle (from -360 to 360 degrees) and velocity (from 0 to 100 in PERCENT or 0 to 200 in MMPS).

用法:

robot.move_at(angle, velocity, units)

参数

描述

angle

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

velocity

Optional. The velocity as an integer or float number at which the robot will move. If the velocity is not specified, the default velocity is 50%. The range can be:

  • from 0 to 100 in PERCENT.
  • from 0 to 200 in MMPS.

units

Optional. The velocity unit is PERCENT (default) or millimeters per second MMPS.

# Move right, then move forward and stop.
robot.move_at(90)
wait(1,SECONDS)
robot.move_at(0)
wait(1,SECONDS)
robot.stop_all_movement()

# Move right slowly, move in reverse quickly and stop.
robot.move_at(90, 25)
wait(2, SECONDS)
robot.move_at(180, 100, PERCENT)
wait(1, SECONDS)
robot.stop_all_movement()

# Move diagonally to the right and stop.
robot.move_at(45.33)
wait(1,SECONDS)
robot.stop_all_movement()

move_for#

move_for moves the robot at a specific angle for a specified distance.

用法:

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

参数

描述

distance

机器人移动的距离,以整数或浮点数表示,以毫米 (mm) 为单位。

angle

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

velocity

可选。机器人移动的速度,可以是整数或浮点数。如果未指定速度,则默认速度为 50%。

units

Optional. The velocity unit is PERCENT (default) or millimeters per second MMPS.

wait

Optional.

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

# Move right, then move forward.
robot.move_for(50, 90)
robot.move_for(100, 0)

# Move in reverse slowly, then move forward quickly.
robot.move_for(100, 180, 25)
robot.move_for(100, 0, 100, PERCENT)

# Drive forward and blink all LEDs red.
robot.move_for(100, 0, wait=False)
robot.led.on(ALL_LEDS, RED)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, BLACK)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, RED)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, BLACK)

move_with_vectors#

move_with_vectors moves the robot using vector-based motion, combining horizontal (X-axis) and vertical (Y-axis) movement and having the robot rotate at the same time.

用法:

robot.move_with_vectors(forward, rightward, rotation)

参数

描述

forward

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

rightward

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

rotation

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

# Move at 15°
robot.move_with_vectors(48.3, 12.95, 0)
wait(2, SECONDS)
robot.stop_all_movement()

# Move at 45° while turning counterclockwise.
robot.move_with_vectors(50, 50, -30)
wait(2, SECONDS)
robot.stop_all_movement()

turn#

turn turns the robot in a specific direction.

用法:

robot.turn(direction, velocity, units)

参数

描述

direction

The direction in which the robot turns: LEFT or RIGHT.

velocity

可选。机器人转弯的速度,整数或浮点数。如果未指定速度,则默认速度为 50%。

units

Optional. Degrees per second DPS (default) or PERCENT.

# Turn left, then stop.
robot.turn(LEFT)
wait(1, SECONDS)
robot.stop_all_movement()

# Turn left quickly, turn right slowly, then stop.
robot.turn(LEFT, 80)
wait(2, SECONDS)
robot.turn(RIGHT, 20, PERCENT)
wait(3, SECONDS)
robot.stop_all_movement()

turn_for#

turn_for turns the robot in a specified direction for a specified angle relative to its current facing direction.

用法:

robot.turn_for(direction, angle, velocity, units, wait)

参数

描述

direction

The direction in which the robot turns: LEFT or RIGHT.

angle

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

velocity

可选。机器人转弯的速度。如果未指定速度,则默认速度为 50%。

units

Optional. degrees per second PERCENT (default) or DPS.

wait

Optional.

  • wait=True (default) - The robot waits until turn_for is complete before executing the next line of code.
  • wait=False - The robot starts the action and moves to the next command without waiting for turn_for to finish.

# Turn left, then turn around to the right.
robot.turn_for(LEFT, 90)
robot.turn_for(RIGHT, 180)

# Turn left quickly, then turn right slowly.
robot.turn_for(LEFT, 90, 100)
robot.turn_for(RIGHT, 180, 15, PERCENT)

# Turn right and blink all LEDs blue.
robot.turn_for(RIGHT, 180, wait=False)
robot.led.on(ALL_LEDS, BLUE)
wait (0.5, SECONDS)
robot.led.off(ALL_LEDS)
wait (0.5, SECONDS)
robot.led.on(ALL_LEDS, BLUE)
wait (0.5, SECONDS)
robot.led.off(ALL_LEDS)

turn_to#

turn_to is used to turn the robot to face a specific heading.

用法:

robot.turn_to(heading, velocity, units, wait)

参数

描述

heading

机器人将转向的方向,范围是 -360 度到 360 度。

velocity

可选。机器人转弯的速度,可以是整数或浮点数。如果未指定速度,则默认速度为 50%。

units

Optional. Degrees per second PERCENT (default) or DPS.

wait

Optional.

  • wait=True (default) - The robot waits until turn_to is complete before executing the next line of code.
  • wait=False - The robot 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 cardinal directions.
robot.turn_to(90)
wait(2, SECONDS)
robot.turn_to(180)
wait(2, SECONDS)
robot.turn_to(270)
wait(2, SECONDS)
robot.turn_to(0)

# Turn to face backward slowly, then face forward quickly.
robot.turn_to(180, 25)
wait(1, SECONDS)
robot.turn_to(0, 90, PERCENT)

# Turn around quickly and blink all LEDs green.
robot.turn_to(180, 100, wait=False)
robot.led.on(ALL_LEDS, GREEN)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, GREEN)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)

stop_all_movement#

stop_all_movement is used to stop all movement of the robot.

用法:

robot.stop_all_movement()

参数

描述

该方法没有参数。

# Turn right, then stop moving
robot.turn(RIGHT)
wait(1, SECONDS)
robot.stop_all_movement()

修改器#

set_move_velocity#

set_move_velocity overrides the default velocity for all subsequent movement methods in the project. The default move velocity is 50% (100 millimeters per second).

用法:

robot.set_move_velocity(velocity, units)

参数

描述

velocity

设置默认移动速度。

units

Optional. The velocity unit is PERCENT (default) or MMPS.

# Move forward at the default velocity,
robot.set_move_velocity(50)
robot.move_for(100, 0)
wait(1, SECONDS)
# Move slower than the default velocity
robot.set_move_velocity(20)
robot.move_for(100, 0)
wait(1, SECONDS)
# Move faster than the default velocity
robot.set_move_velocity(100)
robot.move_for(100, 0)

set_turn_velocity#

set_turn_velocity overrides the default velocity for all subsequent turn methods in the project. The default turn velocity is 50% (75 degrees per second).

用法:

robot.set_turn_velocity(velocity, units)

参数

描述

velocity

设置默认转弯速度。

units

Optional. degrees per second PERCENT (default) or DPS.

# Turn around at default velocity
robot.set_turn_velocity(50)
robot.turn_for(RIGHT, 180)
wait(1, SECONDS)
# Turn around slower than the default velocity
robot.set_turn_velocity(20)
robot.turn_for(RIGHT, 180)
wait(1, SECONDS)
# Turn around faster than the default velocity
robot.set_turn_velocity(100)
robot.turn_for(RIGHT, 180)

set_xy_position#

set_xy_position sets the robot’s current position to specified values. This updates the robot’s internal coordinates.

用法:

robot.set_xy_position(x, y)

参数

描述

x

新的 x 坐标(以毫米为单位,为整数)。

y

新的 y 坐标(以毫米为单位,为整数)。

# Set the robot's current position
# Move forward and print the new coordinate
robot.set_xy_position(100, 50)
robot.move_for(150, 0)
robot.screen.print("X:", robot.get_x_position())
robot.screen.next_row()
robot.screen.print("Y:", robot.get_y_position())

吸气剂#

get_x_position#

get_x_position returns the robot’s x-coordinate as an integer in millimeters.

用法:

robot.get_x_position()

参数

描述

该方法没有参数。

# Print the start and end x-value 
# of the robot's position after moving
robot.screen.print("Start X:", robot.get_x_position())
robot.move_for(200, 90)
robot.screen.next_row()
robot.screen.print("End X:", robot.get_x_position())

get_y_position#

get_y_position returns the robot’s y-coordinate as an integer in millimeters.

用法:

robot.get_y_position()

参数

描述

该方法没有参数。

# Print the start and end y-value 
# of the robot's position after moving
robot.screen.print("Start Y:", robot.get_y_position())
robot.move_for(200, 0)
robot.screen.next_row()
robot.screen.print("End Y:", robot.get_y_position())

is_move_active#

is_move_active returns a Boolean indicating whether the robot is currently moving.

  • True – The robot is moving.

  • False – The robot is not moving.

用法:

robot.is_move_active()

参数

描述

该方法没有参数。

# Blink all the LEDs when the robot is moving.
robot.move_for(200, 0, wait=False)

while robot.is_move_active():
    robot.led.on(ALL_LEDS, ORANGE)
    wait(0.5, SECONDS)
    robot.led.on(ALL_LEDS, CYAN)
    wait(0.5, SECONDS)

robot.led.off(ALL_LEDS)

is_turn_active#

is_turn_active returns a Boolean indicating whether the robot is currently turning.

  • True – The robot is turning.

  • False – The robot is not turning.

用法:

robot.is_turn_active()

参数

描述

该方法没有参数。

# Blink all the LEDs while the robot is turning
robot.turn_for(RIGHT, 180, wait=False) 

while robot.is_turn_active():
    robot.led.on(ALL_LEDS, GREEN)
    wait(0.5, SECONDS)
    robot.led.on(ALL_LEDS, CYAN)
    wait(0.5, SECONDS)

robot.led.off(ALL_LEDS)

is_stopped#

is_stopped returns a Boolean indicating whether the robot is stopped.

  • True – The robot is completely stopped.

  • False – The robot is currently moving or turning.

用法:

robot.is_stopped()

参数

描述

该方法没有参数。

# Blink all the LEDs while the robot is moving or turning

def light_show():
    # Flash LEDs while the robot is moving or turning
    while not robot.is_stopped():
        robot.led.on(ALL_LEDS, GREEN)
        wait(.5, SECONDS)
        robot.led.on(ALL_LEDS, PURPLE)
        wait(.5, SECONDS)

    robot.led.off(ALL_LEDS)

robot.move_for(200, 0, wait=False)
light_show()

robot.turn_for(RIGHT, 180, wait=False)
light_show()