Python ειδικά για ρομπότ#

Εισαγωγή#

Το Hero Bot, Swish, περιλαμβάνει μία επιλογή κινητήρα, μία επιλογή ομάδας κινητήρων και τον Οπτικό Αισθητήρα.

Όλες οι τυπικές μέθοδοι VR VEXcode είναι διαθέσιμες για χρήση στην παιδική χαρά IQ 24-25 Rapid Relay.

Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους ειδικά για ρομπότ:

Σύστημα μετάδοσης κίνησης – Μετακινήστε και περιστρέψτε το ρομπότ.

  • Ενέργειες

    • drive — Moves the robot forward or reverse forever.

    • drive_for — Moves the robot forward or reverse for a specific distance.

    • 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.

    • turn_to_rotation — Turns the robot to a specific rotation.

    • stop — Stops the robot’s movement.

  • Μεταλλαγμένοι

  • Αποκτητές

    • heading — Returns the robot’s current heading from 0 to 359.99 degrees.

    • rotation — Returns the robot’s current rotation.

    • is_done — Returns whether the robot is finished moving, as a Boolean value.

    • is_moving — Returns whether the robot is moving, as a Boolean value.

    • velocity — Returns how fast the robot is driving.

Κίνηση - Μετακίνηση και παρακολούθηση του κινητήρα και της ομάδας κινητήρων του ρομπότ.

  • Ενέργειες

    • spin — Spins a motor or motor group forward or reverse forever.

    • spin_for — Spins a motor or motor group for a specific distance.

    • spin_to_position — Spins a motor or motor group to a specific position.

    • stop — Stops a motor or motor group from spinning.

  • Μεταλλαγμένοι

    • set_position — Changes the motor or motor group’s current position to a new value.

    • set_velocity — Tells a motor or motor group how fast to spin.

    • set_timeout — Sets how much time a motor or motor group will try to finish a movement.

  • Αποκτητές

    • is_done — Returns whether the motor or motor group is finished moving, as a Boolean value.

    • is_spinning — Returns whether the motor or motor group is spinning, as a Boolean value.

    • position — Returns the motor or motor group’s current position.

    • velocity — Returns how fast the motor or motor group is spinning.

Κονσόλα – Εκτύπωση στην Κονσόλα και παρακολούθηση τιμών.

Αισθητήρες - Χρησιμοποιήστε τους διάφορους αισθητήρες του ρομπότ.

  • Οπτικός

    • is_near_object – Returns whether the Optical Sensor detects an object within range.

    • color – Returns the color detected by the Optical Sensor.

    • brightness – Returns the amount of light reflected from the object.

    • hue – Returns the hue detected by the Optical Sensor.

    • object_detected – Registers a function to be called when the Optical Sensor detects an object.

    • object_lost – Registers a function to be called when the Optical Sensor loses an object.

Τα παραδείγματα σε αυτήν τη σελίδα χρησιμοποιούν την προεπιλεγμένη θέση έναρξης της Παιδικής Χαράς.

Σύστημα μετάδοσης κίνησης#

Το σύστημα μετάδοσης κίνησης ελέγχει τον τρόπο με τον οποίο το ρομπότ εικονικής πραγματικότητας (VR) κινείται και στρίβει. Το σύστημα μετάδοσης κίνησης μπορεί να κινείται προς τα εμπρός ή προς τα πίσω, να στρίβει αριστερά ή δεξιά, να στρίβει προς τις κατευθύνσεις και να παρακολουθεί την περιστροφή του.

Ενέργειες#

οδηγώ#

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:
drivetrain.drive(direction)

Παράμετροι

Περιγραφή

direction

The direction the robot moves: FORWARD or REVERSE.

def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

μονάδα_δίσκου#

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:
drivetrain.drive_for(direction, distance, units, wait)

Παράμετροι

Περιγραφή

direction

The direction the robot moves: FORWARD or REVERSE.

distance

The distance the robot drives. This can be an integer or decimal (float).

units

The distance unit: INCHES or MM (millimeters).

wait

Optional. wait=True (default) makes the project wait until the robot is done moving before the next line of code runs. wait=False makes the next line of code run right away.

def main():
    # Drive forward and backward
    drivetrain.drive_for(FORWARD, 200, MM)
    drivetrain.drive_for(REVERSE, 200, MM)

# VR threads — Do not delete
vr_thread(main)

σειρά#

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:
drivetrain.turn(direction)

Παράμετροι

Περιγραφή

direction

The direction the robot turns: LEFT or RIGHT.

def main():
    # Turn right and left, then stop
    drivetrain.turn(RIGHT)
    wait(2, SECONDS)
    drivetrain.turn(LEFT)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

στροφή_για#

turn_for turns the robot left or right for a specific number of degrees. The turn is relative to the current position of the robot. The project will wait until the robot is done turning before the next line of code runs.

Usage:
drivetrain.turn_for(direction, angle, units, wait)

Παράμετροι

Περιγραφή

direction

The direction the robot turns: LEFT or RIGHT.

angle

The number of degrees the robot turns. This can be an integer or decimal (float).

units

The rotation unit: DEGREES.

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

def main():
    # Turn the robot right and left
    drivetrain.turn_for(RIGHT, 90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_for(LEFT, 90, DEGREES)

# VR threads — Do not delete
vr_thread(main)

στροφή_προς_την_κατεύθυνση#

A heading is the direction the robot is facing, measured in degrees. 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:
drivetrain.turn_to_heading(angle, units, wait)

Παράμετροι

Περιγραφή

angle

The direction the robot should face, in degrees. This can be an integer or decimal (float) from -359 to 359.

units

The rotation unit: DEGREES.

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

def main():
    # Turn to face the cardinal directions
    drivetrain.turn_to_heading(90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(180, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(270, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

στροφή_σε_περιστροφή#

turn_to_rotation turns the robot to a specific rotation.

Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. Rotation can also be set using the set_rotation method.

Οι τιμές περιστροφής είναι απόλυτες. Αυτό σημαίνει ότι η κατεύθυνση της στροφής εξαρτάται από την τρέχουσα περιστροφή του ρομπότ. Η στροφή προς τα δεξιά αυξάνει την περιστροφή και η στροφή προς τα αριστερά τη μειώνει.

Για παράδειγμα, αν το ρομπότ ξεκινήσει από 0 μοίρες και στρίψετε σε περιστροφή 720 μοιρών, θα στρίψει δεξιά δύο φορές. Αν στη συνέχεια στρίψετε σε περιστροφή 360 μοιρών, θα στρίψει αριστερά μία φορά, επειδή οι 360 μοίρες είναι μικρότερες από 720 μοίρες.

Το έργο θα περιμένει μέχρι να ολοκληρώσει την περιστροφή του ρομπότ προτού εκτελεστεί η επόμενη γραμμή κώδικα.

Usage:
drivetrain.turn_to_rotation(angle, units, wait)

Παράμετροι

Περιγραφή

angle

The rotation value, in degrees, that the robot will turn to. This can be an integer or decimal (float).

units

The rotation unit: DEGREES.

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

def main():
    # Turn left, then spin in a circle
    # clockwise and face right
    drivetrain.turn_to_rotation(-90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_rotation(450, DEGREES)

# VR threads — Do not delete
vr_thread(main)

στάση#

stop stops the robot’s movement.

Usage:
drivetrain.stop()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

Μεταλλάκτες#

set_heading#

A heading is the direction the robot is facing, measured in degrees. set_heading changes the robot’s current heading to a new heading value.

Για παράδειγμα, εάν το ρομπότ έχει στραφεί προς τα δεξιά, η ρύθμιση της κατεύθυνσης σε 0 μοίρες καθιστά αυτή τη θέση προς τα δεξιά τις νέες 0 μοίρες. Στη συνέχεια, το ρομπότ μπορεί να στραφεί σε άλλες θέσεις με βάση αυτήν τη νέα κατεύθυνση.

Usage:
drivetrain.set_heading(heading, units)

Παράμετροι

Περιγραφή

heading

The heading value, in degrees, to set for the robot. This can be an integer or decimal (float).

units

The heading unit: DEGREES.

def main():
    # Face the new 0 degrees
    drivetrain.set_heading(90, DEGREES)
    drivetrain.turn_to_heading(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

set_rotation#

Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the robot’s current rotation to a new value.

Για παράδειγμα, αν το ρομπότ έχει κάνει δύο πλήρεις στροφές προς τα δεξιά, η τιμή περιστροφής του θα είναι 720 μοίρες. Αν ορίσετε την περιστροφή σε 0 μοίρες, η περιστροφή θα επαναφερθεί από 720 σε 0 μοίρες. Στη συνέχεια, το ρομπότ μπορεί να στραφεί σε περιστροφές με βάση αυτήν τη νέα τιμή.

Usage:
drivetrain.set_rotation(rotation, units)

Παράμετροι

Περιγραφή

rotation

The rotation value, in degrees, to set for the robot. This can be an integer or decimal (float).

units

The rotation unit: DEGREES.

def main():
    # Spin counterclockwise two times
    drivetrain.set_rotation(720, DEGREES)
    drivetrain.turn_to_rotation(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

set_timeout#

set_timeout sets how much time 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:
drivetrain.set_timeout(value, units)

Παράμετροι

Περιγραφή

value

The amount of time the robot can try to finish a movement. This can be a positive integer or decimal (float).

units

The time unit: SECONDS or MSEC (milliseconds).

def main():
    # Turn right after driving forward
    drivetrain.set_timeout(1, SECONDS)
    drivetrain.drive_for(FORWARD, 25, INCHES)
    drivetrain.turn_for(RIGHT, 90)

# VR threads — Do not delete
vr_thread(main)

set_drive_velocity#

set_drive_velocity tells the robot how fast to drive. A higher percentage makes the robot drive faster and a lower percentage makes the robot drive slower.

Κάθε έργο ξεκινά με το ρομπότ να κινείται με ταχύτητα 50% από προεπιλογή.

Σημείωση: Μια υψηλότερη ταχύτητα κάνει το ρομπότ να κινείται πιο γρήγορα, αλλά μπορεί να είναι λιγότερο ακριβές. Μια χαμηλότερη ταχύτητα κάνει το ρομπότ να κινείται πιο αργά, αλλά μπορεί να είναι πιο ακριβές.

Usage:
drivetrain.set_drive_velocity(velocity, units)

Παράμετροι

Περιγραφή

velocity

The velocity to drive with from 0% to 100%. This can be an integer or decimal (float).

units

The velocity unit: PERCENT.

def main():
    # Drive forward at different velocities
    # Default velocity
    drivetrain.drive_for(FORWARD, 150, MM)
    wait(1, SECONDS)
    # Drive slower
    drivetrain.set_drive_velocity(20, PERCENT)
    drivetrain.drive_for(FORWARD, 150, MM)
    wait(1, SECONDS)
    # Drive faster
    drivetrain.set_drive_velocity(100, PERCENT)
    drivetrain.drive_for(FORWARD, 150, MM)

# VR threads — Do not delete
vr_thread(main)

ορισμός_ταχύτητας_στροφής#

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% από προεπιλογή.

Σημείωση: Μια υψηλότερη ταχύτητα κάνει το ρομπότ να περιστρέφεται πιο γρήγορα, αλλά μπορεί να είναι λιγότερο ακριβής. Μια χαμηλότερη ταχύτητα κάνει το ρομπότ να περιστρέφεται πιο αργά, αλλά μπορεί να είναι πιο ακριβής.

Usage:
drivetrain.set_turn_velocity(velocity, units)

Παράμετροι

Περιγραφή

velocity

The velocity to turn with from 0% to 100%. This can be an integer or decimal (float).

units

The velocity unit: PERCENT.

def main():
    # Turn at different velocities
    # Default velocity
    drivetrain.turn_for(RIGHT, 120, DEGREES)
    wait(1, SECONDS)
    # Turn slower
    drivetrain.set_turn_velocity(20, PERCENT)
    drivetrain.turn_for(RIGHT, 120, DEGREES)
    wait(1, SECONDS)
    # Turn faster
    drivetrain.set_turn_velocity(100, PERCENT)
    drivetrain.turn_for(RIGHT, 120, DEGREES)

# VR threads — Do not delete
vr_thread(main)

Αποκτητές#

επικεφαλίδα#

A heading is the direction the robot is facing, measured in degrees. heading returns the robot’s current heading from 0 to 359.99 degrees.

Η αρχική κατεύθυνση του ρομπότ είναι 0 μοίρες.

Usage:
drivetrain.heading(units)

Παράμετροι

Περιγραφή

units

The heading unit: DEGREES.

def main():
    # Display the heading after turning
    drivetrain.turn_for(RIGHT, 450, DEGREES)
    brain.screen.print("Heading: ")
    brain.screen.print(drivetrain.heading(DEGREES))

# VR threads — Do not delete
vr_thread(main)

περιστροφή#

Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the robot’s current rotation.

Η δεξιά στροφή αυξάνει την περιστροφή και η αριστερά τη μειώνει. Για παράδειγμα, κάνοντας δύο πλήρεις στροφές προς τα δεξιά θα επιστρέψει μια περιστροφή 720 μοιρών.

Usage:
drivetrain.rotation(units)

Παράμετροι

Περιγραφή

units

The rotation unit: DEGREES.

def main():
    # Display the rotation after turning
    drivetrain.turn_for(RIGHT, 450, DEGREES)
    brain.screen.print("Rotation: ")
    brain.screen.print(drivetrain.rotation(DEGREES))

# VR threads — Do not delete
vr_thread(main)

είναι_ολοκληρωμένο#

is_done returns whether the robot is finished 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 finished moving.

  • False — The robot is still moving.

This method works together with the following Drivetrain methods that have the wait parameter: drive_for, turn_for, turn_to_heading, and turn_to_rotation.

Usage:
drivetrain.is_done()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

is_moving#

is_moving 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.

Usage:
drivetrain.is_moving()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

ταχύτητα#

velocity returns how fast the robot is driving, as a percentage from -100% to 100%.

Usage:
drivetrain.velocity(units)

Παράμετροι

Περιγραφή

units

The velocity unit: PERCENT.

Παράδειγμα

def main():
    # Display the velocity after driving
    drivetrain.drive_for(FORWARD, 150, MM)
    brain.screen.print("Velocity: ")
    brain.screen.print(drivetrain.velocity(PERCENT))

Κίνηση#

Το Swish χρησιμοποιεί τον κινητήρα εισαγωγής για να συλλέγει Μπάλες και να τις μετακινεί στον καταπέλτη. Η ομάδα κινητήρων καταπέλτη χαμηλώνει και απελευθερώνει τον βραχίονα του καταπέλτη για να εκτοξεύσει Μπάλες.

Κάθε κινητήρας και ομάδα κινητήρων έχει τη δική της συμπεριφορά κατεύθυνσης. Οι περιγραφές κατεύθυνσης εξηγούν πώς κάθε κατεύθυνση κινεί αυτόν τον κινητήρα ή την ομάδα κινητήρων στο Swish.

Ενέργειες#

γνέθω#

spin spins a motor or motor group forward or reverse forever. The motor or motor group will continue to spin until it is given another action, like spinning in a different direction or stopping.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.spin(direction) — Intake Motor

catapult_group

catapult_group.spin(direction) — Catapult Group

Παράμετροι

Περιγραφή

direction

The direction the motor or motor group spins:

  • FORWARD — Spins the Intake Motor in the intake direction or lowers the Catapult Group.
  • REVERSE — Spins the Intake Motor in the outtake direction or releases the Catapult Group.

def main():
    # Spin the Intake Motor to bring a Ball onto the Catapult
    intake_motor.spin(FORWARD)
    wait(2, SECONDS)
    intake_motor.stop()

# VR threads — Do not delete
vr_thread(main)

περιστροφή_για#

spin_for spins a motor or motor group for a specific distance. The spin is relative to the current position of the motor or motor group. The project will wait until the motor or motor group is done spinning before the next line of code runs.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.spin_for(direction, distance, units, wait=True) — Intake Motor

catapult_group

catapult_group.spin_for(direction, distance, units, wait=True) — Catapult Group

Παράμετροι

Περιγραφή

direction

The direction the motor or motor group spins:

  • FORWARD — Spins the Intake Motor in the intake direction or lowers the Catapult Group.
  • REVERSE — Spins the Intake Motor in the outtake direction or releases the Catapult Group.

distance

The distance the motor or motor group spins. DEGREES use integers. TURNS can use integers or decimals.

units

Optional. The distance unit: DEGREES (default) or TURNS.

wait

Optional.

  • wait=True (default) — Makes the project wait until the motor or motor group is done spinning before the next line of code runs.
  • wait=False — Makes the next line of code run right away.

def main():
    # Release the preloaded Ball
    catapult_group.spin_for(REVERSE, 5, DEGREES)
    # Lower the Catapult to prepare to load another Ball
    catapult_group.spin_for(FORWARD, 1350, DEGREES)

# VR threads — Do not delete
vr_thread(main)

περιστροφή_σε_θέση#

spin_to_position spins a motor or motor group to a specific position.

A motor or motor group’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 or motor group position is set to 0 degrees. The motor or motor group position can also be set using the set_position method.

Οι τιμές θέσης είναι απόλυτες. Αυτό σημαίνει ότι η κατεύθυνση της περιστροφής εξαρτάται από την τρέχουσα θέση του κινητήρα ή της ομάδας κινητήρων.

Για παράδειγμα, εάν ο κινητήρας ή η ομάδα κινητήρων ξεκινήσει από τις 0 μοίρες και περιστραφεί σε μια θέση 720 μοιρών, θα περιστραφεί προς τα εμπρός κατά δύο στροφές. Εάν στη συνέχεια περιστραφεί σε μια θέση 360 μοιρών, θα περιστραφεί προς τα πίσω κατά μία στροφή, επειδή οι 360 μοίρες είναι μικρότερες από 720 μοίρες.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.spin_to_position(angle, units, wait=True) — Intake Motor

catapult_group

catapult_group.spin_to_position(angle, units, wait=True) — Catapult Group

Παράμετροι

Περιγραφή

angle

The position value the motor or motor group will spin to. DEGREES use integers. TURNS can use integers or decimals.

units

Optional. The position unit: DEGREES (default) or TURNS.

wait

Optional.

  • wait=True (default) — Makes the project wait until the motor or motor group is done spinning before the next line of code runs.
  • wait=False — Makes the next line of code run right away.

def main():
    # Release the preloaded Ball
    catapult_group.spin_to_position(-90, DEGREES)
    # Lower the Catapult to prepare to load another Ball
    catapult_group.spin_to_position(1260, DEGREES)

# VR threads — Do not delete
vr_thread(main)

κινητήρας διακοπής#

stop stops a motor or motor group from spinning.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.stop() — Intake Motor

catapult_group

catapult_group.stop() — Catapult Group

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Spin the Intake Motor to bring a Ball onto the Catapult
    intake_motor.spin(FORWARD)
    wait(2, SECONDS)
    intake_motor.stop()

# VR threads — Do not delete
vr_thread(main)

Μεταλλάκτες#

ορισμός_θέσης#

A motor or motor group’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 or motor group’s current position to a new value.

Για παράδειγμα, εάν ένας κινητήρας ή μια ομάδα κινητήρων έχει περιστραφεί στις 180 μοίρες, η ρύθμιση της θέσης σε 0 μοίρες θα επαναφέρει αυτήν τη θέση από 180 σε 0 μοίρες. Στη συνέχεια, ο κινητήρας ή η ομάδα κινητήρων μπορεί να περιστραφεί σε θέσεις με βάση αυτήν τη νέα τιμή.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.set_position(position, units) — Intake Motor

catapult_group

catapult_group.set_position(position, units) — Catapult Group

Παράμετροι

Περιγραφή

position

The position value to set for the motor or motor group. DEGREES use integers. TURNS can use integers or decimals.

units

Optional. The position unit: DEGREES (default) or TURNS.

def main():
    # Lower the Catapult to prepare to load another Ball
    catapult_group.spin_to_position(1260, DEGREES)
    # Set the new Catapult position to be 0 degrees
    catapult_group.set_position(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

set_velocity#

set_velocity tells a motor or motor group how fast to spin. A higher percentage makes the motor or motor group spin faster and a lower percentage makes the motor or motor group spin slower.

Κάθε έργο ξεκινά με κάθε κινητήρα ή ομάδα κινητήρων να περιστρέφεται με ταχύτητα 50% από προεπιλογή.

Σημείωση: Μια υψηλότερη ταχύτητα κάνει τον κινητήρα ή την ομάδα κινητήρων να περιστρέφεται πιο γρήγορα, αλλά μπορεί να είναι λιγότερο ακριβής. Μια χαμηλότερη ταχύτητα κάνει τον κινητήρα ή την ομάδα κινητήρων να περιστρέφεται πιο αργά, αλλά μπορεί να είναι πιο ακριβής.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.set_velocity(velocity, units) — Intake Motor

catapult_group

catapult_group.set_velocity(velocity, units) — Catapult Group

Παράμετροι

Περιγραφή

velocity

The velocity to spin with from -100% to 100%. This can be an integer or decimal (float).

units

The velocity unit: PERCENT.

def main():
    # Start spinning the Intake Motor to prepare for picking up a Ball
    intake_motor.set_velocity(100, PERCENT)
    intake_motor.spin(FORWARD)

# VR threads — Do not delete
vr_thread(main)

set_timeout#

set_timeout sets how much time a motor or motor group will try to finish a movement. If the motor or motor group cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the motor or motor group from getting stuck on a movement.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.set_timeout(value, units) — Intake Motor

catapult_group

catapult_group.set_timeout(value, units) — Catapult Group

Παράμετροι

Περιγραφή

value

The amount of time the motor or motor group can try to finish a movement. This can be a positive integer or decimal (float).

units

The time unit: SECONDS or MSEC (milliseconds).

def main():
    # Limit how long the Catapult waits to reach its target
    catapult_group.set_timeout(2, SECONDS)
    catapult_group.spin_for(FORWARD, 2160, DEGREES)

# VR threads — Do not delete
vr_thread(main)

Αποκτητές#

είναι_ολοκληρωμένο#

is_done returns whether the motor or motor group is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the motor or motor group’s movement.

  • True — The motor or motor group is finished moving.

  • False — The motor or motor group is still moving.

This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.is_done() — Intake Motor

catapult_group

catapult_group.is_done() — Catapult Group

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

περιστρέφεται#

is_spinning returns whether the motor or motor group is spinning, as a Boolean value. This can be used to control the timing of other behaviors based on the motor or motor group’s movement.

  • True — The motor or motor group is spinning.

  • False — The motor or motor group is not spinning.

This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.is_spinning() — Intake Motor

catapult_group

catapult_group.is_spinning() — Catapult Group

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

θέση#

A motor or motor group’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. position returns the motor or motor group’s current position.

Στην αρχή ενός έργου, η θέση του κινητήρα ή της ομάδας κινητήρων ορίζεται σε 0 μοίρες. Εάν ο κινητήρας ή η ομάδα κινητήρων περιστραφεί μία πλήρη στροφή προς τα εμπρός, η θέση θα είναι 360 μοίρες ή 1 στροφή. Εάν ο κινητήρας ή η ομάδα κινητήρων περιστραφεί προς την αντίθετη κατεύθυνση, η θέση θα είναι αρνητική.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.position(units) — Intake Motor

catapult_group

catapult_group.position(units) — Catapult Group

Παράμετροι

Περιγραφή

units

The unit to return the motor or motor group position in: DEGREES or TURNS.

def main():
    # Lower the Catapult to prepare to load another Ball
    while not catapult_group.position(DEGREES) == 1260:
        catapult_group.spin(FORWARD)

# VR threads — Do not delete
vr_thread(main)

ταχύτητα#

velocity returns how fast the motor or motor group is spinning.

Μια θετική τιμή σημαίνει ότι ο κινητήρας ή η ομάδα κινητήρων περιστρέφεται προς τα εμπρός. Μια αρνητική τιμή σημαίνει ότι ο κινητήρας ή η ομάδα κινητήρων περιστρέφεται προς τα πίσω.

Χρήση:
Ένα από τα δύο διαθέσιμα αντικείμενα κινητήρα ή ομάδας κινητήρων μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:

μοτέρ

Εντολή

intake_motor

intake_motor.velocity(units) — Intake Motor

catapult_group

catapult_group.velocity(units) — Catapult Group

Παράμετροι

Περιγραφή

units

The velocity unit to return: PERCENT.

def main():
    # Print the current Catapult velocity
    brain.screen.print(catapult_group.velocity(PERCENT))

# VR threads — Do not delete
vr_thread(main)

Κονσόλα#

Η Κονσόλα εμφανίζει κείμενο, αριθμούς και τιμές μεταβλητών ενώ εκτελείται ένα έργο. Οι μέθοδοι κονσόλας μπορούν επίσης να μετακινήσουν τον κέρσορα σε μια νέα γραμμή, να διαγράψουν την Κονσόλα και να προσθέσουν μεταβλητές ή τιμές αισθητήρων στην καρτέλα Παρακολούθηση.

Αποτύπωμα#

εγκέφαλος.οθόνη.εκτύπωση#

brain.screen.print displays text, numbers, or variable values in the Console using the current cursor position. It behaves like print on the Console API page.

Use brain.screen.next_row when you want the next printed value to start on a new row.

Usage:
brain.screen.print(value)

Παράμετροι

Περιγραφή

value

Το κείμενο, ο αριθμός ή η τιμή μεταβλητής που θα εμφανίζεται στην Κονσόλα.

def main():
    # Display a message in the Console
    brain.screen.print("Hello, robot!")

# VR threads — Do not delete
vr_thread(main)

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Γεια σου, ρομπότ!".

brain.screen.next_row#

brain.screen.next_row moves the cursor to column 1 on the next row in the Console. The next value printed will appear on that row.

Usage:
brain.screen.next_row()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Print on two rows
    brain.screen.print("Row 1")
    brain.screen.next_row()
    brain.screen.print("Row 2")

# VR threads — Do not delete
vr_thread(main)

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Row 1" που εμφανίζεται στην πρώτη γραμμή και "Row 2" στη δεύτερη γραμμή.

brain.screen.clear_screen#

brain.screen.clear_screen clears all rows from the Console and moves the cursor back to Row 1.

Usage:
brain.screen.clear_screen()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Display text, then clear it after two seconds
    brain.screen.print("This will disappear...")
    wait(2, SECONDS)
    brain.screen.clear_screen()

# VR threads — Do not delete
vr_thread(main)

Ελεγκτής εκπομπών#

μεταβλητή_παρακολούθησης#

monitor_variable adds one or more predefined variables to the Monitor tab in VEXcode. This lets you watch a variable’s value change while a project is running.

Variables must be global for monitor_variable to monitor them successfully. Provide each variable name as a string.

Usage:
monitor_variable(“variable”)
monitor_variable(“variable1”, “variable2”)

Παράμετροι

Περιγραφή

variable

Το όνομα μιας προκαθορισμένης καθολικής μεταβλητής προς παρακολούθηση, που δίνεται ως συμβολοσειρά. Για να παρακολουθείτε περισσότερες από μία μεταβλητές, διαχωρίστε κάθε όνομα μεταβλητής με κόμμα.

def main():
    # Monitor the amount of loops
    global loops
    monitor_variable("loops")

    # Drive in a square 3 times
    for loops in range(12):
        drivetrain.turn_for(RIGHT, 90, DEGREES)
        drivetrain.drive_for(FORWARD, 150, MM)

# VR threads — Do not delete
vr_thread(main)

αισθητήρας_παρακολούθησης#

monitor_sensor adds one or more sensor values to the Monitor tab in VEXcode. This lets you watch sensor values change while a project is running.

Παρέχετε κάθε τιμή αισθητήρα ως συμβολοσειρά.

Usage:
monitor_sensor(“sensor”)
monitor_sensor(“sensor1”, “sensor2”)

Παράμετροι

Περιγραφή

sensor

The sensor value to monitor, given as a string. To monitor more than one sensor value, separate each sensor value with a comma. Supported sensor identifiers include:

  • Brain
    • brain.timer.time
  • Drivetrain
    • drivetrain.is_done
    • drivetrain.is_moving
    • drivetrain.heading
    • drivetrain.rotation
    • drivetrain.velocity_rpm
    • drivetrain.velocity_percent
  • Arm Motor
    • arm_motor.is_done
    • arm_motor.is_spinning
    • arm_motor.position_degrees
    • arm_motor.position_turns
    • arm_motor.velocity_rpm
    • arm_motor.velocity_percent
  • Arm Motor Group
    • arm_motor_group.is_done
    • arm_motor_group.is_spinning
    • arm_motor_group.position_degrees
    • arm_motor_group.position_turns
    • arm_motor_group.velocity_rpm
    • arm_motor_group.velocity_percent
  • Intake Motor
    • intake_motor.is_done
    • intake_motor.is_spinning
    • intake_motor.position_degrees
    • intake_motor.position_turns
    • intake_motor.velocity_rpm
    • intake_motor.velocity_percent
  • Intake Motor Group
    • intake_motor_group.is_done
    • intake_motor_group.is_spinning
    • intake_motor_group.position_degrees
    • intake_motor_group.position_turns
    • intake_motor_group.velocity_rpm
    • intake_motor_group.velocity_percent
  • Catapult Motor
    • catapult_motor.is_done
    • catapult_motor.is_spinning
    • catapult_motor.position_degrees
    • catapult_motor.position_turns
    • catapult_motor.velocity_rpm
    • catapult_motor.velocity_percent
  • Catapult Tension Motor
    • catapult_tension_motor.is_done
    • catapult_tension_motor.is_spinning
    • catapult_tension_motor.position_degrees
    • catapult_tension_motor.position_turns
    • catapult_tension_motor.velocity_rpm
    • catapult_tension_motor.velocity_percent
  • Bumpers
    • intake_bumper.pressing
    • bumper.pressing
  • Front Distance Sensor
    • front_distance.is_object_detected
    • front_distance.object_distance_mm
    • front_distance.object_distance_inches
  • Front Optical Sensor
    • front_optical.is_near_object
    • front_optical.color
    • front_optical.brightness
    • front_optical.hue
  • Color Sensor
    • color.is_near_object
    • color.color
    • color.brightness
    • color.hue

def main():
    # Monitor the robot's heading
    monitor_sensor("drivetrain.heading")
    drivetrain.turn_for(RIGHT, 450, DEGREES)

# VR threads — Do not delete
vr_thread(main)

Εξεύρεση της φόρας#

Οπτικός#

είναι_κοντά_στο_αντικείμενο#

is_near_object returns a Boolean indicating whether or not the Optical Sensor detects an object within range.

  • True – The Optical Sensor detects an object.

  • False – The Optical Sensor does not detect an object.

Usage:
intake_optical.is_near_object()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Launch a loaded Ball once the Intake Optical Sensor detects a Ball
    if intake_optical.is_near_object():
        catapult_group.spin_for(REVERSE, 5, DEGREES)

# VR threads — Do not delete
vr_thread(main)

χρώμα#

color returns an instance of a Color class, based on the detected hue value. These can be compared to predefined Color objects to create conditional statements.

Πιθανά χρώματα είναι:

  • NONE

  • RED - A hue value between 340° - 20°

  • GREEN - A hue value between 80° - 140°

  • BLUE - A hue value between 200° - 240°

  • YELLOW - A hue value between 40° - 60°

  • ORANGE - A hue value between 20° - 40°

  • PURPLE - A hue value between 240° - 280°

  • CYAN - A hue value between 140° - 200°

Note: The Optical Sensor is looking for hue ranges that match the specified color. For detecting specific hue ranges, see hue.

Usage:
intake_optical.color()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Launch a loaded Ball once yellow is detected in the Intake
    if intake_optical.color() == YELLOW:
        catapult_group.spin_for(REVERSE, 5, DEGREES)

# VR threads — Do not delete
vr_thread(main)

λάμψη#

brightness returns the amount of light reflected from the object as a decimal (float) representing a percent.

Ένα υψηλότερο ποσοστό σημαίνει ότι περισσότερο φως ανακλάται πίσω στον οπτικό αισθητήρα. Ένα χαμηλότερο ποσοστό σημαίνει ότι λιγότερο φως ανακλάται πίσω.

Usage:
intake_optical.brightness()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Launch a loaded Ball once the Intake Optical Sensor sees a Ball
    if intake_optical.brightness() > 0:
        catapult_group.spin_for(REVERSE, 5, DEGREES)

# VR threads — Do not delete
vr_thread(main)

απόχρωση#

hue returns the hue value of the detected color as a decimal (float) from 0 to 359.

Η απόχρωση είναι ένας τρόπος περιγραφής χρώματος χρησιμοποιώντας αριθμούς γύρω από έναν χρωματικό κύκλο.

Ένας κυκλικός χρωματικός τροχός που εμφανίζει ένα πλήρες φάσμα αποχρώσεων με ετικέτες τιμών βαθμών γύρω από την περίμετρο, αυξανόμενες σε βήματα των 30 μοιρών από 0 μοίρες στην κορυφή έως 360 μοίρες.

Usage:
intake_optical.hue()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Launch a loaded Ball once the Intake Optical Sensor reports a hue value
    if intake_optical.hue() > 100:
        catapult_group.spin_for(REVERSE, 5, DEGREES)

# VR threads — Do not delete
vr_thread(main)

ανιχνευμένο_αντικείμενο#

object_detected registers a function to be called whenever the Optical Sensor detects a new object.

Usage:
intake_optical.object_detected(callback, arg)

Παράμετροι

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που εκτελείται όταν ο Οπτικός Αισθητήρας ανιχνεύει ένα νέο αντικείμενο.

arg

Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση Συναρτήσεων με Παραμέτρους για περισσότερες πληροφορίες.

def launch_ball():
    catapult_group.spin_for(REVERSE, 5, DEGREES)

def main():
    # Launch the Ball when the Intake Optical Sensor detects an object
    intake_optical.object_detected(launch_ball)

# VR threads — Do not delete
vr_thread(main)

αντικείμενο_χαμένο#

object_lost registers a function to be called whenever the Optical Sensor loses a detected object.

Usage:
intake_optical.object_lost(callback, arg)

Παράμετροι

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που εκτελείται όταν ο Οπτικός Αισθητήρας χάνει ένα ανιχνευμένο αντικείμενο.

arg

Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση Συναρτήσεων με Παραμέτρους για περισσότερες πληροφορίες.

def lower_catapult():
    catapult_group.spin_to_position(1260, DEGREES)

def main():
    # Lower the Catapult when the Intake Optical Sensor no longer detects an object
    intake_optical.object_lost(lower_catapult)

# VR threads — Do not delete
vr_thread(main)