运动#
介绍#
VEX AIM 编码机器人采用完整的传动系统,使其能够向任何方向移动并独立旋转。Motion 提供了移动、转弯、速度调节和位置跟踪的方法。
以下是可用方法的列表:
动作——移动和转动机器人。
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.
变异器——设置默认移动和转动速度。
set_move_velocity – Sets the default movement speed.
set_turn_velocity – Sets the default turn speed.
set_xy_position – Sets the robot’s current position.
Getters – 返回机器人状态和位置。
get_x_position – Returns the robot’s x-coordinate.
get_y_position – Returns the robot’s y-coordinate.
is_move_active – Returns whether the robot is currently moving.
is_turn_active – Returns whether the robot is currently turning.
is_stopped – Returns whether the robot is stopped.
行动#
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)
参数 |
描述 |
---|---|
|
机器人移动的角度,以整数或浮点数表示,范围从 -360 度到 360 度。 |
|
可选。机器人移动的速度,以整数或浮点数表示。如果未指定速度,则默认速度为 50%。范围可以是:
MMPS 为单位,从 0 到 200。4 |
|
可选。速度单位为 |
# 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
使机器人以特定角度移动指定距离。
用法:
robot.move_for(distance, angle, velocity, units, wait)
参数 |
描述 |
---|---|
|
机器人移动的距离,以整数或浮点数表示,以毫米 (mm) 为单位。 |
|
机器人移动的角度,以整数或浮点数表示,范围从 -360 度到 360 度。 |
|
可选。机器人移动的速度,可以是整数或浮点数。如果未指定速度,则默认速度为 50%。 |
|
可选。速度单位为 |
|
可选
|
# 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 to rotate at the same time.
用法:
robot.move_with_vectors(x, y, r)
参数 |
描述 |
---|---|
|
机器人沿 X 轴(左右移动)的速度。接受 -100 到 100 之间的百分比值,负值表示向左移动,正值表示向右移动。 |
|
机器人沿 Y 轴的速度(前后移动)。接受 -100 到 100 之间的百分比值,负值表示向后移动,正值表示向前移动。 |
|
机器人的旋转速度。接受 -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
使机器人转向特定方向。
用法:
robot.turn(direction, velocity, units)
参数 |
描述 |
---|---|
|
机器人转动的方向: |
|
可选。机器人转弯的速度,整数或浮点数。如果未指定速度,则默认速度为 50%。 |
|
可选。每秒度数 |
# 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
使机器人相对于当前面向的方向沿指定方向转动一段设定的距离。
用法:
robot.turn_for(direction, angle, velocity, units, wait)
参数 |
描述 |
---|---|
|
机器人转动的方向: |
|
机器人移动的角度,以整数或浮点数表示,范围从 -360 度到 360 度。 |
|
可选。机器人转弯的速度。如果未指定速度,则默认速度为 50% 或任意速度。 |
|
可选。每秒度数 |
|
可选。
|
# 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
用于使机器人转向特定方向。
用法:
robot.turn_to(heading, velocity, units, wait)
参数 |
描述 |
---|---|
|
机器人将转向的方向,范围是 -360 度到 360 度。 |
|
可选。机器人转弯的速度,可以是整数或浮点数。如果未指定速度,则默认速度为 50%。 |
|
可选。每秒度数 |
|
可选
|
# 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
用于停止机器人的所有运动。
用法:
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
会覆盖项目中所有后续移动方法的默认速度。默认移动速度为 50%(100 毫米/秒)。
用法:
robot.set_move_velocity(velocity, units)
参数 |
描述 |
---|---|
|
设置默认移动速度。 |
|
可选。速度单位为 |
# 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
会覆盖项目中所有后续转弯方法的默认速度。默认转弯速度为 50%(每秒 75 度)。
用法:
robot.set_turn_velocity(velocity, units)
参数 |
描述 |
---|---|
|
设置默认转弯速度。 |
|
可选。每秒度数 |
# 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
将机器人的当前位置设置为指定值。这将更新机器人的内部坐标。
用法:
robot.set_xy_position(x, y)
参数 |
描述 |
---|---|
|
新的 x 坐标(以毫米为单位,为整数)。 |
|
新的 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
以毫米为单位的整数形式返回机器人的 x 坐标。
用法:
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
以毫米为单位的整数形式返回机器人的 y 坐标。
用法:
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
返回一个布尔值,指示机器人当前是否正在移动。
True
——机器人正在移动。False
——机器人没有移动。
用法:
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
返回一个布尔值,指示机器人当前是否正在转弯。
True
——机器人正在转动。False
——机器人没有转动。
用法:
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
返回一个布尔值,表示机器人是否停止。
True
– 机器人完全停止。False
——机器人当前正在移动或转动。
用法:
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()