运动#
简介#
VEX AIM 编码机器人采用全向驱动系统,可以前进、后退、左转、右转或以一定角度移动,并能独立转向。运动控制方法用于控制机器人的移动和转向方式、移动速度以及其 x 轴和 y 轴位置的跟踪。

以下是可用方法的列表:
Actions — Move and turn the robot.
[
move_at] (#move_at) —以特定角度永久移动机器人。[
move_for] (#move_for) —将机器人以特定角度移动特定距离。[
move_with_vectors] (#move_with_vectors) —使用基于矢量的x、y和旋转值移动机器人。turn— — 向左或向右转机器人。[
turn_for] (#turn_for) —将机器人向左或向右转动特定的度数。[
turn_to] (#turn_to) —将机器人转向特定的方向。[
stop_all_movement] (#stop_all_movement) —停止机器人的所有移动。
Mutators — Set robot movement values.
[
set_move_velocity] (#set_move_velocity) —告诉机器人移动的速度。[
set_turn_velocity] (#set_turn_velocity) —告诉机器人转弯的速度。[
set_xy_position] (#set_xy_position) —将机器人当前的x和y位置更改为新值。
Getters — Return robot state and position.
[
get_x_position] (#get_x_position) —返回机器人当前的x坐标。[
get_y_position] (#get_y_position) —返回机器人当前的y坐标。[
is_move_active] (#is_move_active) —返回机器人是否在移动。[
is_turn_active] (#is_turn_active) —返回机器人是否在转动。[
is_stopped] (#is_stopped) —返回机器人是否既不移动也不转动。
操作#
move_at#
move_at以特定角度永久移动机器人。角度相对于机器人的当前位置。机器人将继续移动,直到它被赋予另一个动作,例如以不同的角度移动、转动或停止。
用法:
robot.move_at(angle, velocity, units)
参数 |
描述 |
|---|---|
|
机器人移动的角度,以度为单位。该值可以是介于 -360 到 360 之间的整数或小数。 |
|
可选。移动速度:使用 |
|
可选。速度单位: |
# 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 之间的整数或小数。 |
|
可选。移动速度:使用 |
|
可选。速度单位: |
|
可选。 |
# 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 使用基于向量的运动来移动机器人。机器人结合向前、向右和旋转速度值来创建平滑的运动。机器人将继续使用此向量移动,直到收到其他动作指令,例如以不同角度移动、转向或停止。
Note: This method sets movement and turn velocity values directly, so it does not use set_move_velocity or set_turn_velocity.
用法:
robot.move_with_vectors(forward, rightward, rotation)
参数 |
描述 |
|---|---|
|
机器人沿y轴方向的速度,范围从-100%到100%。负值使机器人后退,正值使机器人前进。 |
|
机器人沿 x 轴的速度,范围从 -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()
# Scaling movement using the controller joystick
while True:
# Move forward (and backwards) slower than axis1 input
forward = controller.axis1.position() * 0.7
# Move right (and left) faster than axis2 input
rightward = controller.axis2.position() * 1.5
robot.move_with_vectors(forward, rightward, 0)
wait(5, MSEC)
turn#
turn 使机器人持续向左或向右旋转。机器人会一直旋转,直到收到其他动作指令,例如移动或停止。
用法:
robot.turn(direction, velocity, units)
参数 |
描述 |
|---|---|
|
机器人转向: |
|
可选。旋转速度:使用 |
|
可选。速度单位: |
# 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 度。该值可以是整数或十进制数(浮点数)。 |
|
可选。旋转速度:使用 |
|
可选。速度单位: |
|
可选。 |
# 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 将机器人转向特定的方向。机器人将转动最短的方向到达目标航向。
机器人的初始航向角为0度。
程序会等到机器人完成转向后才运行下一行代码。
用法:
robot.turn_to(heading, velocity, units, wait)
参数 |
描述 |
|---|---|
|
机器人应面向的方向,范围从 -360 度到 360 度。 |
|
可选。旋转速度:使用 |
|
可选。速度单位: |
|
可选。 |
# 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% 的移动速度相当于每秒 200 毫米。
用法:
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 将机器人当前的x和y位置更改为新值。
例如,如果机器人已远离其起点,将x设置为 0 ,并将y设置为 0 ,会使机器人的当前位置成为新的 0, 0 位置。然后,机器人可以根据该新值跟踪未来的位置。
用法:
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())
Getters#
get_x_position#
get_x_position 以毫米为单位返回机器人当前的x坐标。
在项目开始时,机器人的x位置设置为0。x位置随着机器人的左右移动而变化,可以使用[set_xy_position] (#set_xy_position)方法进行设置。
用法:
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坐标。
在项目开始时,机器人的y位置设置为0。Y位置随着机器人向前或向后移动而变化,可以使用[set_xy_position] (#set_xy_position)方法进行设置。
用法:
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—机器人没有移动。
此方法与具有 wait 参数的Motion方法一起使用,例如[move_for] (#move_for)。
用法:
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—机器人未转动。
此方法与具有 wait 参数的Motion方法一起使用,例如[turn_for] (#turn_for)和[turn_to] (#turn_to)。
用法:
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()