运动#
介绍#
The VEX AIM Coding Robot uses a holonomic drivetrain to move forward, reverse, left, right, or at an angle while also being able to turn independently. Motion methods control how the robot moves and turns, how fast it moves, and how its x and y position are tracked.

以下是可用方法的列表:
动作——移动和转向机器人。
move_at— Moves the robot at a specific angle forever.move_for— Moves the robot at a specific 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 forever.turn_for— Turns the robot left or right for a specific number of degrees.turn_to— Turns the robot to face a specific heading.stop_all_movement— Stops all movement of the robot.
Mutators — Set robot movement values.
set_move_velocity— Tells the robot how fast to move.set_turn_velocity— Tells the robot how fast to turn.set_xy_position— Changes the robot’s current x and y position to new values.
获取器 — 返回机器人状态和位置。
get_x_position— Returns the robot’s current x-coordinate.get_y_position— Returns the robot’s current y-coordinate.is_move_active— Returns whether the robot is moving.is_turn_active— Returns whether the robot is turning.is_stopped— Returns whether the robot is neither moving nor turning.
行动#
move_at#
move_at moves the robot forever at a specific angle. The robot will continue to move until it is given another action, like moving at a different angle, turning, or stopping.
用法:
robot.move_at(angle, velocity, units)
参数 |
描述 |
|---|---|
|
The angle, in degrees, that the robot moves. This can be an integer or decimal from -360 to 360. |
|
Optional. The velocity to move with from 0% to 100% when using |
|
Optional. The velocity unit: |
# 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 specific distance. The project will wait until the robot is done moving before the next line of code runs.
用法:
robot.move_for(distance, angle, velocity, units, wait)
参数 |
描述 |
|---|---|
|
The distance the robot moves, in millimeters (mm). This can be an integer or decimal (float). |
|
The angle, in degrees, that the robot moves. This can be an integer or decimal from -360 to 360. |
|
Optional. The velocity to move with from 0% to 100% when using |
|
Optional. The velocity unit: |
|
Optional. |
# 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 movement along the x-axis (horizontal) and y-axis (vertical) while also rotating the robot.
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)
参数 |
描述 |
|---|---|
|
The robot’s velocity along the y-axis, from -100% to 100%. Negative values move the robot backward and positive values move it forward. |
|
The robot’s velocity along the x-axis, from -100% to 100%. Negative values move the robot left and positive values move it right. |
|
The robot’s turn velocity, from -100% to 100%. Negative values turn the robot counterclockwise and positive values turn it clockwise. |
# 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 turns the robot left or right forever. The robot will continue to turn until it is given another action, like moving or stopping.
用法:
robot.turn(direction, velocity, units)
参数 |
描述 |
|---|---|
|
The direction the robot turns: |
|
Optional. The velocity to turn with from 0% to 100% when using |
|
Optional. The velocity unit: |
# 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 left or right for a specific number of degrees. The turn is relative to the current direction the robot is facing. The project will wait until the robot is done turning before the next line of code runs.
用法:
robot.turn_for(direction, angle, velocity, units, wait)
参数 |
描述 |
|---|---|
|
The direction the robot turns: |
|
The number of degrees the robot turns, ranging from -360 to 360 degrees. This can be an integer or decimal (float). |
|
Optional. The velocity to turn with from 0% to 100% when using |
|
Optional. The velocity unit: |
|
Optional. |
# 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#
A heading is the direction the robot is facing, measured in degrees. turn_to turns the robot to face a specific heading. The robot will turn the shortest direction to reach the target heading.
The robot’s starting heading is 0 degrees.
The project will wait until the robot is done turning before the next line of code runs.
用法:
robot.turn_to(heading, velocity, units, wait)
参数 |
描述 |
|---|---|
|
The heading the robot should face, from -360 to 360 degrees. |
|
Optional. The velocity to turn with from 0% to 100% when using |
|
Optional. The velocity unit: |
|
Optional. |
# 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 stops 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 tells the robot how fast to move. A higher percentage makes the robot move faster and a lower percentage makes the robot move slower.
Every project begins with the robot moving at 50% velocity by default.
A move velocity of 100% is equivalent to 200 millimeters per second.
用法:
robot.set_move_velocity(velocity, units)
参数 |
描述 |
|---|---|
|
The velocity to move with from 0% to 100% when using |
|
Optional. The velocity unit: |
# 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 tells the robot how fast to turn. A higher percentage makes the robot turn faster and a lower percentage makes the robot turn slower.
Every project begins with the robot turning at 50% velocity (75 degrees per second) by default.
用法:
robot.set_turn_velocity(velocity, units)
参数 |
描述 |
|---|---|
|
The velocity to turn with from 0% to 100% when using |
|
Optional. The velocity unit: |
# 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 changes the robot’s current x and y position to new values.
For example, if the robot has moved away from its starting point, setting x to 0 and y to 0 makes the robot’s current location the new 0, 0 position. Then the robot can track future positions based on that new value.
用法:
robot.set_xy_position(x, y)
参数 |
描述 |
|---|---|
|
The x-position value to set for the robot, in mm. This can be an integer or decimal (float). |
|
The y-position value to set for the robot, in mm. This can be an integer or decimal (float). |
# 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 current x-coordinate in millimeters.
At the beginning of a project, the robot’s x-position is set to 0. The x-position changes as the robot moves left or right and can be set using the set_xy_position method.
用法:
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 current y-coordinate in millimeters.
At the beginning of a project, the robot’s y-position is set to 0. The y-position changes as the robot moves forward or reverse and can be set using the set_xy_position method.
用法:
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 whether the robot is moving, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.
True— The robot is moving.False— The robot is not moving.
This method works together with Motion methods that have the wait parameter, such as 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 returns whether the robot is turning, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.
True— The robot is turning.False— The robot is not turning.
This method works together with Motion methods that have the wait parameter, such as turn_for and 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 returns whether the robot is neither moving nor turning, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.
True— The robot is not moving or turning.False— The robot is 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()