Κίνηση#
Εισαγωγή#
Οι κινητήρες ελέγχουν τον τρόπο με τον οποίο κινούνται τα μέρη ενός ρομπότ. Οι κινητήρες μπορούν να χρησιμοποιηθούν για την ανύψωση ενός βραχίονα, την περιστροφή ενός νυχιού, την περιστροφή ενός τροχού ή την κίνηση ενός άλλου μέρους μιας κατασκευής. Δύο κινητήρες μπορούν να συνεργαστούν ως σύστημα μετάδοσης κίνησης για να κινούν και να περιστρέφουν ολόκληρο το ρομπότ.
Each motor is configured in the Devices window. Depending on the build, motor names can change. For example, the Competition Advanced 2.0 build has a motor named arm_motor. A custom robot may use different motor names.
By default, FORWARD spins a motor counterclockwise, and REVERSE spins a motor clockwise. If a motor is set to reverse in the Devices window, those directions will be switched.
Υπάρχουν πολλοί τρόποι κωδικοποίησης κινητήρων. Παρακάτω είναι μια λίστα με όλες τις μεθόδους κίνησης:
Ενέργειες — Σταματήστε και περιστρέψτε τους κινητήρες.
spin— Spins a motor forward or reverse forever.spin_for— Spins a motor for a specific distance.spin_to_position— Spins a motor to a specific position.stop— Stops a motor from spinning.
Μεταλλαγμένοι — Προσαρμόστε τις ρυθμίσεις του κινητήρα.
set_velocity— Tells a motor how fast to spin.set_max_torque— Sets how hard a motor is allowed to push while spinning.set_position— Changes the motor’s current position to a new value.set_stopping— Sets how a motor will stop moving: by braking, coasting, or holding.set_timeout— Sets how much time a motor will try to finish a movement.
Λήψη ελεγκτών — Έλεγχος κατάστασης κινητήρα.
get_position— Returns the motor’s current position.get_velocity— Returns how fast the motor is spinning, as a percentage from -100% to 100%.get_current— Returns how much power the motor is using from the battery, as a percentage from 0% to 100%.is_stopped— Returns whether the motor is finished moving, as a Boolean value.is_moving— Returns whether the motor is spinning, as a Boolean value.
Ενέργειες#
spin#
spin spins a motor forward or reverse forever. The motor will continue to spin until it is given another action, like spinning in a different direction or stopping.
Usage:
arm_motor.spin(direction)
Παράμετροι |
Περιγραφή |
|---|---|
|
The direction the motor spins: |
# Build Used: Competition Advanced 2.0
def main():
# Raise the ArmMotor, then stop
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
spin_for#
spin_for spins a motor for a specific distance. The spin is relative to the current position of the motor. The project will wait until the motor is done spinning before the next line of code runs.
Usage:
arm_motor.spin_for(direction, angle, units, wait)
Παράμετροι |
Περιγραφή |
|---|---|
|
The direction the motor spins: |
|
The distance the motor spins. |
|
Optional. The distance unit: |
|
Optional. |
# Build Used: Competition Advanced 2.0
def main():
# Raise and lower the ArmMotor
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
arm_motor.spin_for(FORWARD, 180, DEGREES)
# Start threads — Do not delete
start_thread(main)
spin_to_position#
spin_to_position spins a motor to a specific position.
A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. At the beginning of a project, the motor position is set to 0 degrees. The motor position can also be set using the set_position method.
Οι τιμές θέσης είναι απόλυτες. Αυτό σημαίνει ότι η κατεύθυνση της περιστροφής εξαρτάται από την τρέχουσα θέση του κινητήρα.
Για παράδειγμα, αν ο κινητήρας ξεκινήσει στις 0 μοίρες και περιστραφεί σε μια θέση 720 μοιρών, θα περιστραφεί προς τα εμπρός κατά δύο στροφές. Αν στη συνέχεια περιστραφεί σε μια θέση 360 μοιρών, θα περιστραφεί προς τα πίσω κατά μία στροφή, επειδή οι 360 μοίρες είναι μικρότερες από τις 720.
Usage:
arm_motor.spin_to_position(angle, units, wait)
Παράμετροι |
Περιγραφή |
|---|---|
|
The position value the motor will spin to. |
|
Optional. The position unit: |
|
Optional. |
# Build Used: Competition Advanced 2.0
def main():
# Return ArmMotor to 0 degrees after raising
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
arm_motor.spin_to_position(0, DEGREES)
# Start threads — Do not delete
start_thread(main)
stop#
stop stops a motor from spinning.
Usage:
arm_motor.stop()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Competition Advanced 2.0
def main():
# Raise the ArmMotor
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
Μεταλλάκτες#
set_velocity#
set_velocity tells a motor how fast to spin. A higher percentage makes the motor spin faster and a lower percentage makes the motor spin slower.
Κάθε έργο ξεκινά με κάθε κινητήρα να περιστρέφεται με ταχύτητα 50% από προεπιλογή.
Σημείωση: Μια υψηλότερη ταχύτητα κάνει τον κινητήρα να περιστρέφεται πιο γρήγορα, αλλά μπορεί να είναι λιγότερο ακριβής. Μια χαμηλότερη ταχύτητα κάνει τον κινητήρα να περιστρέφεται πιο αργά, αλλά μπορεί να είναι πιο ακριβής.
Usage:
arm_motor.set_velocity(velocity)
Παράμετροι |
Περιγραφή |
|---|---|
|
The velocity to spin with from 0% to 100%. This can be an |
# Build Used: Competition Advanced 2.0
def main():
# Move the ArmMotor at different velocities
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
# Move slow
arm_motor.set_velocity(20)
arm_motor.spin_for(FORWARD, 180, DEGREES)
wait(1, SECONDS)
# Move fast
arm_motor.set_velocity(100)
arm_motor.spin_for(REVERSE, 180, DEGREES)
# Start threads — Do not delete
start_thread(main)
set_max_torque#
Η ροπή είναι μια δύναμη περιστροφής. Δείχνει πόσο δυνατά μπορεί να σπρώξει ή να τραβήξει ένας κινητήρας όταν περιστρέφεται.
set_max_torque sets the most torque a motor is allowed to use.
Ένα υψηλότερο ποσοστό επιτρέπει στον κινητήρα να πιέζει πιο δυνατά, όπως όταν σηκώνεται ένα βαρύ αντικείμενο. Ένα χαμηλότερο ποσοστό περιορίζει την ισχύ που μπορεί να πιέσει ο κινητήρας. Αυτό μπορεί να βοηθήσει στην προστασία του ρομπότ εάν ο κινητήρας κολλήσει ή φτάσει στο όριο της απόστασης που μπορεί να κινηθεί.
Κάθε έργο ξεκινά με τη ροπή κάθε κινητήρα στο 50% από προεπιλογή.
Usage:
arm_motor.set_max_torque(value)
Παράμετροι |
Περιγραφή |
|---|---|
|
The max torque the motor can use from 0% to 100%. This can be an |
# Build Used: Competition Advanced 2.0
def main():
# Move the ArmMotor at different torques
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
# Move with less torque
arm_motor.set_max_torque(20)
arm_motor.spin_for(FORWARD, 180, DEGREES)
wait(1, SECONDS)
# Move with maximum torque
arm_motor.set_max_torque(100)
arm_motor.spin_for(REVERSE, 180, DEGREES)
# Start threads — Do not delete
start_thread(main)
set_position#
A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. set_position changes the motor’s current position to a new value.
Για παράδειγμα, εάν ένας κινητήρας έχει περιστραφεί στις 180 μοίρες, η ρύθμιση της θέσης σε 0 μοίρες θα επαναφέρει αυτήν τη θέση από 180 σε 0 μοίρες. Στη συνέχεια, ο κινητήρας μπορεί να περιστραφεί σε θέσεις με βάση αυτήν τη νέα τιμή.
Usage:
arm_motor.set_position(position, units)
Παράμετροι |
Περιγραφή |
|---|---|
|
The position value to set for the motor. |
|
Optional. The position unit: |
# Build Used: Competition Advanced 2.0
def main():
# Return ArmMotor to 0 degrees after raising
arm_motor.set_position(0, DEGREES)
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
arm_motor.spin_to_position(0, DEGREES)
# Start threads — Do not delete
start_thread(main)
set_stopping#
set_stopping sets how a motor will stop moving: by braking, coasting, or holding.
Usage:
arm_motor.set_stopping(mode)
Παράμετροι |
Περιγραφή |
|---|---|
|
How the motor will stop:
|
For example, if a Competition Advanced 2.0 build is used and arm_motor is set to HOLD, the motor will hold the arm at its current position until another arm movement happens. This means the motor will work against gravity to keep the arm in the air if the motor was stopped with the arm raised.
If this method is not used, the motor will use BRAKE when stopping.
# Build Used: Competition Advanced 2.0
def main():
# Move the ArmMotor, then coast to a stop
arm_motor.set_velocity(20)
arm_motor.set_stopping(COAST)
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
set_timeout#
set_timeout sets how much time a motor will try to finish a movement. If the motor cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the motor from getting stuck on a movement.
Usage:
arm_motor.set_timeout(value, units)
Παράμετροι |
Περιγραφή |
|---|---|
|
The amount of time the motor can try to finish a movement. This can be a positive |
|
Optional. The unit of time: |
# Build Used: Competition Advanced 2.0
def main():
# Move ArmMotor as far as possible for 1 second before resetting
arm_motor.set_position(0, DEGREES)
arm_motor.set_timeout(1, SECONDS)
arm_motor.spin_for(REVERSE, 180, DEGREES)
arm_motor.spin_to_position(0, DEGREES)
# Start threads — Do not delete
start_thread(main)
Αποκτητές#
get_position#
A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. get_position returns the motor’s current position.
Στην αρχή ενός έργου, η θέση του κινητήρα ορίζεται στις 0 μοίρες. Εάν ο κινητήρας περιστραφεί μία στροφή προς τα εμπρός, η θέση θα είναι 360 μοίρες ή 1 στροφή. Εάν ο κινητήρας περιστραφεί προς την αντίθετη κατεύθυνση, η θέση θα είναι αρνητική.
Usage:
arm_motor.get_position(units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Optional. The unit to return the motor position in: |
# Build Used: Competition Advanced 2.0
def main():
# Display how far the ArmMotor moves after one second
arm_motor.set_position(0, DEGREES)
console.print("Start: ")
console.print(arm_motor.get_position(DEGREES))
console.new_line()
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
console.print("After: ")
console.print(arm_motor.get_position(DEGREES))
# Start threads — Do not delete
start_thread(main)
get_velocity#
get_velocity returns how fast the motor is spinning, as a percentage from -100% to 100%.
Μια θετική τιμή σημαίνει ότι ο κινητήρας περιστρέφεται προς τα εμπρός. Μια αρνητική τιμή σημαίνει ότι ο κινητήρας περιστρέφεται προς τα πίσω.
Usage:
arm_motor.get_velocity()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Competition Advanced 2.0
def main():
# Display the ArmMotor's velocity when it moves
console.print("Resting: ")
console.print(arm_motor.get_velocity())
console.new_line()
arm_motor.spin(REVERSE)
wait(1, SECONDS)
console.print("Moving: ")
console.print(arm_motor.get_velocity())
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
get_current#
get_current returns how much power the motor is using from the battery, as a percentage from 0% to 100%.
Μια υψηλότερη τιμή ρεύματος σημαίνει ότι ο κινητήρας χρησιμοποιεί περισσότερη ισχύ. Αυτό μπορεί να συμβεί όταν ο κινητήρας σηκώνει κάτι βαρύ, πιέζει ένα αντικείμενο ή προσπαθεί να κινηθεί όταν αυτό έχει κολλήσει.
Usage:
arm_motor.get_current()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Competition Advanced 2.0
def main():
# Display the motor's current when it moves
console.print("Resting: ")
console.print(arm_motor.get_current())
console.new_line()
arm_motor.spin(REVERSE)
wait(1, SECONDS)
console.print("Moving: ")
console.print(arm_motor.get_current())
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
is_stopped#
is_stopped returns whether the motor is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the motor’s movement.
True— The motor is finished moving.False— The motor is still moving.
This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.
Usage:
arm_motor.is_stopped()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Competition Advanced 2.0
def main():
# Turn the Eye Sensor's light on while ArmMotor is moving
arm_motor.spin_for(REVERSE, 180, DEGREES, wait=False)
wait(0.1, SECONDS)
while True:
if arm_motor.is_stopped():
eye.set_light(OFF)
else:
eye.set_light(ON)
# Start threads — Do not delete
start_thread(main)
is_moving#
is_moving returns whether the motor is spinning, as a Boolean value. This can be used to control the timing of other behaviors based on the motor’s movement.
True— The motor is spinning.False— The motor is not spinning.
This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.
Usage:
arm_motor.is_moving()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Competition Advanced 2.0
def main():
# Turn the Eye Sensor's light on while ArmMotor is moving
arm_motor.spin_for(REVERSE, 180, DEGREES, wait=False)
wait(0.1, SECONDS)
while True:
if arm_motor.is_moving():
eye.set_light(ON)
else:
eye.set_light(OFF)
# Start threads — Do not delete
start_thread(main)