Σύστημα μετάδοσης κίνησης#
Εισαγωγή#
Το ρομπότ 123 διαθέτει σύστημα μετάδοσης κίνησης δύο τροχών που του επιτρέπει να κινείται και να στρίβει. Οι μέθοδοι μετάδοσης κίνησης ελέγχουν τον τρόπο με τον οποίο κινείται το ρομπότ.
Το σύστημα μετάδοσης κίνησης μπορεί να μετρήσει την απόσταση με δύο τρόπους: βήματα και mm (χιλιοστά). Ένα βήμα ισούται με ένα τετράγωνο σε ένα πεδίο 123.
Υπάρχουν πολλοί τρόποι για να κωδικοποιήσετε το σύστημα μετάδοσης κίνησης. Παρακάτω είναι μια λίστα με όλες τις μεθόδους συστήματος μετάδοσης κίνησης:
Ενέργειες — Μετακίνηση και περιστροφή του ρομπότ.
drive— Moves the robot forward or reverse forever.drive_for— Moves the robot forward or reverse for a specific distance.drive_until— Moves the robot forward or reverse until it detects an object, crash, or line.turn— Turns the robot left or right forever.turn_for— Turns the robot left or right for a specific number of degrees.turn_to_heading— Turns the robot to face a specific heading from -359 to 359 degrees.stop— Stops the robot’s movement.
Μεταλλαγμένοι — Προσαρμόστε τις ρυθμίσεις του συστήματος μετάδοσης κίνησης.
set_timeout— Sets how long the robot will try to finish a movement.set_heading— Changes the robot’s current heading to a new heading.
Λήψη κωδικών πρόσβασης — Ελέγξτε την κατάσταση της κίνησης.
is_stopped— Returns whether the robot has stopped moving, as a Boolean value.get_heading— Returns the robot’s current heading from 0 to 359 degrees.
Ενέργειες#
drive#
drive moves the robot forward or reverse forever. The robot will continue to move until it is given another action, like turning or stopping.
Usage:
robot.drive(direction)
Παράμετροι |
Περιγραφή |
|---|---|
|
The direction the robot moves: |
# Drive for 2 seconds.
robot.drive(FORWARD)
wait(2, SECONDS)
robot.stop()
drive_for#
drive_for moves the robot forward or reverse for a specific distance. The project will wait until the robot is done moving before the next line of code runs.
Usage:
robot.drive_for(direction, distance, unit)
Παράμετροι |
Περιγραφή |
|---|---|
|
The direction the robot moves: |
|
Η απόσταση που διανύει το ρομπότ. Αυτή μπορεί να είναι ακέραια ή δεκαδική. |
|
The distance unit: |
# Drive back and forth.
robot.drive_for(FORWARD, 3, STEPS)
robot.drive_for(REVERSE, 3, STEPS)
drive_until#
drive_until moves the robot forward or reverse until it detects an object, a crash, or a line.
Usage:
robot.drive_until(direction)
Παράμετροι |
Περιγραφή |
|---|---|
|
The direction the robot moves: |
# Reverse after a crash.
robot.drive_until(FORWARD)
robot.drive_for(REVERSE, 1, STEPS)
turn#
turn turns the robot left or right forever. The robot will continue to turn until it is given another action, like driving or stopping.
Usage:
robot.turn(direction)
Παράμετροι |
Περιγραφή |
|---|---|
|
The direction the robot turns: |
# Turn for 2 seconds.
robot.turn(RIGHT)
wait(2, SECONDS)
robot.stop()
turn_for#
turn_for turns the robot left or right for a specific number of degrees. The project will wait until the robot is done turning before the next line of code runs.
Usage:
robot.turn_for(direction, degrees)
Παράμετροι |
Περιγραφή |
|---|---|
|
The direction the robot turns: |
|
Ο αριθμός των μοιρών που πρέπει να περιστραφεί. Μπορεί να είναι ακέραιος ή δεκαδικός αριθμός. |
# Turn left, then turn around to the right.
robot.turn_for(LEFT, 90)
robot.turn_for(RIGHT, 180)
turn_to_heading#
turn_to_heading turns the robot to face a specific heading from -359 to 359 degrees. The robot will turn the shortest direction to reach the target heading.
Η αρχική κατεύθυνση είναι 0 μοίρες.
Το έργο θα περιμένει μέχρι να ολοκληρώσει την περιστροφή του ρομπότ προτού εκτελεστεί η επόμενη γραμμή κώδικα.
Usage:
robot.turn_to_heading(heading)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η κατεύθυνση προς την οποία πρέπει να είναι στραμμένη το ρομπότ, από -359 έως 359 μοίρες. |
# Turn to face the cardinal directions.
robot.turn_to_heading(90)
wait(2, SECONDS)
robot.turn_to_heading(180)
wait(2, SECONDS)
robot.turn_to_heading(270)
wait(2, SECONDS)
robot.turn_to_heading(0)
wait(2, SECONDS)
stop#
stop stops the robot’s movement.
Usage:
robot.stop()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Stop driving after 4 seconds.
robot.drive(FORWARD)
wait(4, SECONDS)
robot.stop()
Μεταλλάκτες#
set_timeout#
set_timeout sets how many seconds the robot will try to finish a movement. If the robot cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the robot from getting stuck on a movement.
Usage:
robot.set_timeout(time, unit)
Παράμετροι |
Περιγραφή |
|---|---|
|
Ο χρόνος που απαιτείται για μια κίνηση. Μπορεί να είναι ακέραιος ή δεκαδικός αριθμός. |
|
The time unit: |
# Turn right after driving for 1 second.
robot.set_timeout(1, SECONDS)
robot.drive_for(FORWARD, 1000, MM)
robot.turn_for(RIGHT, 90)
set_heading#
set_heading changes the robot’s current heading to a new heading value.
Για παράδειγμα, εάν το ρομπότ έχει στραφεί προς τα δεξιά, η ρύθμιση της κατεύθυνσης σε 0 μοίρες καθιστά αυτή τη θέση προς τα δεξιά τις νέες 0 μοίρες.
Usage:
robot.set_heading(heading)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η τιμή κατεύθυνσης, σε μοίρες, που θα οριστεί για το ρομπότ. |
# Face the new 0 degree heading.
robot.set_heading(90)
robot.turn_to_heading(0)
Αποκτητές#
is_stopped#
is_stopped returns a Boolean that reports whether the robot has stopped moving.
True— The robot is stopped.False— The robot is still moving.
Usage:
robot.is_stopped()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Glow blue after a crash.
robot.drive_until(FORWARD)
while True:
if robot.is_stopped():
robot.led.glow(BLUE)
else:
robot.led.glow(GREEN)
wait(0.05, SECONDS)
get_heading#
get_heading returns the direction the robot is currently facing as a whole number from 0 to 359 degrees.
Η αρχική κατεύθυνση του ρομπότ είναι 0 μοίρες.
Usage:
robot.get_heading()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Display the heading after turning.
robot.turn_for(RIGHT, 450)
console.print(robot.get_heading())