运动#
介绍#
VEX AIM 编码机器人采用完整的传动系统,使其能够向任何方向移动并独立旋转。Motion 提供了移动、转弯、速度调节和位置跟踪的方法。
以下是可用方法的列表:
动作——移动和转动机器人。
move_at – 以指定角度移动机器人。
move_for – 以特定角度移动机器人特定距离。
move_with_vectors – 使用基于矢量的 x、y 和旋转值移动机器人。
turn – 使机器人向左或向右转动。
turn_for – 将机器人旋转一定的角度。
turn_to – 让机器人转向特定方向。
stop_all_movement – 停止机器人的所有运动。
变异器——设置默认移动和转动速度。
set_move_velocity - 设置默认移动速度。
set_turn_velocity – 设置默认转弯速度。
set_xy_position – 设置机器人的当前位置。
Getters – 返回机器人状态和位置。
get_x_position – 返回机器人的 x 坐标。
get_y_position – 返回机器人的 y 坐标。
is_move_active – 返回机器人当前是否正在移动。
is_turn_active – 返回机器人当前是否正在转弯。
is_stopped – 返回机器人是否停止。
行动#
move_at#
move_at
以指定的角度(从 -360 度到 360 度)和速度(从 0 到 100 的 PERCENT
或 0 到 200 的 MMPS
)移动机器人。
用法:
robot.move_at(angle, velocity, units)
参数 |
描述 |
---|---|
|
机器人移动的角度,以整数或浮点数表示,范围从 -360 度到 360 度。 |
|
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:
|
|
可选。速度单位为 |
# 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 度。 |
|
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:
|
|
可选。速度单位为 |
|
可选
|
# 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
使用基于矢量的运动来移动机器人,结合水平(X 轴)和垂直(Y 轴)运动并同时使机器人旋转。
用法:
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)
参数 |
描述 |
---|---|
|
机器人转动的方向: |
|
Optional. The velocity, as an integer or float, at which the robot turns. If the velocity is not specified, the default velocity is 50%. The range can be:
|
|
可选。每秒度数 |
# 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 度。 |
|
Optional. The velocity at which the robot will turn. If the velocity is not specified, the default velocity is 50%. The range can be:
|
|
可选。每秒度数 |
|
可选。
|
# 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 度。 |
|
Optional. The velocity as an integer or float number at which the robot will turn. If the velocity is not specified, the default velocity is 50%. The range can be:
|
|
可选。每秒度数 |
|
可选
|
# 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()