Κίνηση#
Εισαγωγή#
Το ρομπότ κωδικοποίησης VEX AIM χρησιμοποιεί ένα ολονομικό σύστημα μετάδοσης κίνησης για να κινείται προς τα εμπρός, προς τα πίσω, αριστερά, δεξιά ή υπό γωνία, ενώ παράλληλα μπορεί να στρίβει ανεξάρτητα. Οι μέθοδοι κίνησης ελέγχουν τον τρόπο με τον οποίο το ρομπότ κινείται και στρίβει, την ταχύτητα με την οποία κινείται και τον τρόπο με τον οποίο παρακολουθείται η θέση x και y του.

Παρακάτω είναι μια λίστα με τις διαθέσιμες μεθόδους:
Ενέργειες — Μετακίνηση και περιστροφή του ρομπότ.
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.
Μεταλλαγμένοι — Ορίστε τιμές κίνησης ρομπότ.
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.
Getters — Επιστρέφει την κατάσταση και τη θέση του ρομπότ.
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 angle is relative to the current position of the robot. 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)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η γωνία, σε μοίρες, κατά την οποία κινείται το ρομπότ. Αυτή μπορεί να είναι ακέραιος ή δεκαδικός αριθμός από -360 έως 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 angle is relative to the current position of the robot. 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)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η απόσταση που κινείται το ρομπότ, σε χιλιοστά (mm). Αυτή μπορεί να είναι ακέραια ή δεκαδική (float). |
|
Η γωνία, σε μοίρες, κατά την οποία κινείται το ρομπότ. Αυτή μπορεί να είναι ακέραιος ή δεκαδικός αριθμός από -360 έως 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#
A vector is a way to describe how fast something moves, and what direction it moves in. move_with_vectors moves the robot using vector-based motion. The robot combines forward, rightward, and rotation velocity values to create on smooth movement. The robot will continue to move using this vector until it is given another action, like moving at a different angle, turning, or stopping.
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 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: |
|
Ο αριθμός των μοιρών που περιστρέφεται το ρομπότ, που κυμαίνεται από -360 έως 360 μοίρες. Αυτός μπορεί να είναι ακέραιος ή δεκαδικός αριθμός (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.
Η αρχική κατεύθυνση του ρομπότ είναι 0 μοίρες.
Το έργο θα περιμένει μέχρι να ολοκληρώσει την περιστροφή του ρομπότ προτού εκτελεστεί η επόμενη γραμμή κώδικα.
Χρήση:
robot.turn_to(heading, velocity, units, wait)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η κατεύθυνση προς την οποία πρέπει να είναι στραμμένη το ρομπότ, από -360 έως 360 μοίρες. |
|
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.
Κάθε έργο ξεκινά με το ρομπότ να κινείται με ταχύτητα 50% από προεπιλογή.
Μια ταχύτητα κίνησης 100% ισοδυναμεί με 200 χιλιοστά ανά δευτερόλεπτο.
Χρήση:
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.
Κάθε έργο ξεκινά με το ρομπότ να περιστρέφεται με ταχύτητα 50% (75 μοίρες ανά δευτερόλεπτο) από προεπιλογή.
Χρήση:
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.
Για παράδειγμα, εάν το ρομπότ έχει απομακρυνθεί από το σημείο εκκίνησής του, ορίζοντας το x σε 0 και το y σε 0, η τρέχουσα θέση του ρομπότ γίνεται η νέα θέση 0, 0. Στη συνέχεια, το ρομπότ μπορεί να παρακολουθήσει μελλοντικές θέσεις με βάση αυτήν τη νέα τιμή.
Χρήση:
robot.set_xy_position(x, y)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η τιμή θέσης x που θα οριστεί για το ρομπότ, σε mm. Αυτή μπορεί να είναι ακέραιος ή δεκαδικός αριθμός (float). |
|
Η τιμή θέσης y που θα οριστεί για το ρομπότ, σε mm. Αυτή μπορεί να είναι ακέραιος ή δεκαδικός αριθμός (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()