Αδρανειακό#

Εισαγωγή#

Το IQ (2ης γενιάς) Brain περιλαμβάνει έναν ενσωματωμένο αδρανειακό αισθητήρα. Αυτός ο αισθητήρας μετρά τον τρόπο με τον οποίο κινείται και περιστρέφεται ο εγκέφαλος.

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

This page uses brain_inertial as the example Inertial Sensor name. Replace it with your own configured name as needed.

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

Προσανατολισμός — Ανάγνωση και έλεγχος κατεύθυνσης, περιστροφής και βαθμονόμησης αισθητήρα.

  • heading — Returns the direction the sensor is facing, from 0 to 359.99 degrees.

  • rotation — Returns how far the sensor has turned.

  • calibrate — Calibrates the Inertial Sensor.

  • set_heading — Sets the Inertial Sensor’s current heading to a new heading value.

  • set_rotation — Sets the Inertial Sensor’s current rotation to a new rotation value.

  • is_calibrating — Returns whether the Inertial Sensor is currently calibrating.

  • reset_heading — Resets the Inertial Sensor’s current heading to 0 degrees.

  • reset_rotation — Resets the Inertial Sensor’s current rotation to 0 degrees.

  • changed — Registers a function to run when the Inertial Sensor’s heading changes.

Κίνηση — Μετρήστε την επιτάχυνση, την ταχύτητα περιστροφής και την κλίση.

  • acceleration — Returns how quickly the sensor is speeding up or slowing down on the selected axis.

  • gyro_rate — Returns how fast the sensor is rotating on the selected axis.

  • orientation — Returns the Inertial Sensor’s roll, pitch, or yaw angle.

Κατασκευαστές — Μη αυτόματη αρχικοποίηση και διαμόρφωση ενός αδρανειακού αισθητήρα.

  • Inertial — Creates an Inertial Sensor.

Προσανατολισμός#

heading#

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

Η αρχική κατεύθυνση είναι 0 μοίρες. Εάν ο αισθητήρας περιστραφεί πέραν των 359,99 μοιρών, η κατεύθυνση επιστρέφει στις 0 μοίρες.

Usage:
brain_inertial.heading(units)

Παράμετροι

Περιγραφή

units

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

# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(brain_inertial.heading())

rotation#

Rotation is how much the sensor has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the Inertial Sensor’s current rotation.

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

Usage:
brain_inertial.rotation(units)

Παράμετροι

Περιγραφή

units

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

# Display the rotation value after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(brain_inertial.rotation())

calibrate#

calibrate calibrates the Inertial Sensor. All subsequent lines will wait for calibration to complete before running. Calibration helps the sensor measure turns correctly by measuring and compensating for sensor noise and drift over a specified period. During this time, the Brain must remain completely still on a stable surface. Movement during calibration can produce inaccurate results.

Ο εγκέφαλος IQ με την οθόνη σε γωνία προς τα δεξιά, με τους άξονες x, y και z να αντιπροσωπεύονται από βέλη που ξεκινούν από το κέντρο της οθόνης και εκτείνονται προς τα έξω. Ένα κόκκινο βέλος με την ένδειξη x δείχνει προς τα δεξιά, ένα πράσινο βέλος με την ένδειξη y εκτείνεται προς τα εμπρός και ένα μπλε βέλος με την ένδειξη z δείχνει προς τα κάτω.Η ίδια εικόνα με την προηγούμενη, τώρα με την οθόνη του εγκεφάλου στραμμένη προς τα αριστερά και τα βέλη x, y, z να διατηρούν τον προσανατολισμό τους.Η ίδια εικόνα με την προηγούμενη, τώρα με την οθόνη του εγκεφάλου στραμμένη προς τα πάνω, σαν να είναι επίπεδη σε μια επιφάνεια. Ο προσανατολισμός x, y, z είναι ο ίδιος.

Το VEX Brain επιχειρεί αυτόματα να βαθμονομήσει τον ενσωματωμένο Αδρανειακό Αισθητήρα στην αρχή κάθε έργου. Ωστόσο, εάν το ρομπότ μεταφέρεται ή μετακινείται κατά την έναρξη του έργου, ο αισθητήρας ενδέχεται να μην βαθμονομηθεί σωστά ή να δώσει λανθασμένη βαθμονόμηση.

Usage:
brain_inertial.calibrate()

Παράμετρος

Περιγραφή

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

# Start calibration
brain_inertial.calibrate()
# Print after calibration
while brain_inertial.is_calibrating():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Inertial Sensor")
    brain.screen.next_row()
    brain.screen.print("Calibrating")
    wait(50, MSEC)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")

set_heading#

A heading is the direction the sensor is facing, measured in degrees from 0 to 359.99. set_heading() changes the Inertial Sensor’s current heading to a new heading value.

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

Usage:
brain_inertial.set_heading(value, units)

Παράμετροι

Περιγραφή

value

Η τιμή κατεύθυνσης, σε μοίρες, που θα οριστεί για τον αισθητήρα. Αυτή μπορεί να είναι μια τιμή από 0 έως 359,99.

units

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

# Turn the robot around
brain_inertial.set_heading(180)
drivetrain.turn_to_heading(0)

set_rotation#

Rotation is how much the sensor has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation() changes the Inertial Sensor’s current rotation to a new value.

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

Usage:
brain_inertial.set_rotation(value, units)

Παράμετροι

Περιγραφή

value

Η τιμή περιστροφής, σε μοίρες, που θα οριστεί για τον αισθητήρα. Αυτή μπορεί να είναι ακέραιος ή δεκαδικός αριθμός (float).

units

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

# Turn the robot around
brain_inertial.set_rotation(-180)
drivetrain.turn_to_rotation(0)

is_calibrating#

is_calibrating returns whether the Inertial Sensor is currently calibrating.

  • True — The Inertial Sensor is calibrating.

  • False — The Inertial Sensor is not calibrating.

Usage:
brain_inertial.is_calibrating()

Παράμετρος

Περιγραφή

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

# Start calibration
brain_inertial.calibrate()
# Print while waiting for calibration
while brain_inertial.is_calibrating():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Inertial Sensor")
    brain.screen.next_row()
    brain.screen.print("Calibrating")
    wait(50, MSEC)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")

reset_heading#

reset_heading resets the Inertial Sensor’s current heading to 0 degrees.

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

Usage:
brain_inertial.reset_heading()

Παράμετροι

Περιγραφή

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

# Turn the robot before and after resetting the heading
drivetrain.turn_to_heading(90, DEGREES)
wait(0.5, SECONDS)
brain_inertial.reset_heading()
drivetrain.turn_to_heading(90, DEGREES)

reset_rotation#

reset_rotation resets the Inertial Sensor’s current rotation to 0 degrees.

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

Usage:
brain_inertial.reset_rotation()

Παράμετροι

Περιγραφή

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

# Turn the robot before and after resetting the rotation
drivetrain.turn_to_rotation(-90, DEGREES)
wait(0.5, SECONDS)
brain_inertial.reset_rotation()
drivetrain.turn_to_rotation(-90, DEGREES)

changed#

changed registers a function to be called when the Inertial Sensor’s heading changes.

Usage:
brain_inertial.changed(callback, arg)

Παράμετροι

Περιγραφή

callback

Μια συνάρτηση που εκτελείται όταν αλλάζει η επικεφαλίδα του Αδρανειακού Αισθητήρα.

arg

Προαιρετικό. Μια πλειάδα ορισμάτων που θα διαβιβαστεί στη συνάρτηση επανάκλησης.

def heading_changed():
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_screen()
    brain.screen.print("my heading ")
    brain.screen.next_row()
    brain.screen.print("has changed!")
    wait(0.1, SECONDS)
# Call the function when the inertial heading is changed
wait(1, SECONDS)
drivetrain.turn_for(RIGHT, 90, DEGREES, wait=False)
brain_inertial.changed(heading_changed)
wait(15, MSEC)

Κίνηση#

acceleration#

Acceleration is how quickly the sensor is speeding up or slowing down. acceleration returns the acceleration of the Inertial Sensor on the selected axis, from -4.0 G to 4.0 G, as a float.

A G is a unit used to measure acceleration. 1 G is about the acceleration you feel from gravity while sitting still.

The value can be positive or negative depending on the direction of acceleration on the selected axis. The axis options are XAXIS, YAXIS, and ZAXIS.

Usage:
brain_inertial.acceleration(axis)

Παράμετροι

Περιγραφή

άξονας

The axis to measure acceleration on:

  • XAXIS
  • YAXIS
  • ZAXIS

# Display acceleration after moving
vexcode_brain_precision = 2
drivetrain.set_drive_velocity(100, PERCENT)
brain.screen.print("Resting: ")
brain.screen.next_row()
brain.screen.print(brain_inertial.acceleration(XAXIS))
brain.screen.next_row()
wait(1, SECONDS)
drivetrain.drive_for(FORWARD, 500, MM, wait=False)
wait(0.01, SECONDS)
brain.screen.print("Startup: ")
brain.screen.next_row()
brain.screen.print(brain_inertial.acceleration(XAXIS))

gyro_rate#

Gyro rate is how fast the Inertial Sensor is rotating. gyro_rate returns the current rotation speed of the Inertial Sensor on the selected axis.

Η τιμή μπορεί να είναι θετική ή αρνητική ανάλογα με την κατεύθυνση περιστροφής του αισθητήρα σε αυτόν τον άξονα.

Usage:
brain_inertial.gyro_rate(axis, units)

Παράμετροι

Περιγραφή

axis

The axis to return the gyro rate from:

  • XAXIS
  • YAXIS
  • ZAXIS

units

Optional. The gyro rate unit:

  • DPS (default) — degrees per second
  • RPM — rotations per minute
  • PERCENT

# Display the z-axis gyro rate
drivetrain.turn(RIGHT)
wait(1, SECONDS)
brain.screen.print(brain_inertial.gyro_rate(ZAXIS, RPM))
drivetrain.stop()

orientation#

Orientation is the Inertial Sensor’s current angle on a selected turning axis. orientation returns the roll, pitch, or yaw of the Inertial Sensor.

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

Usage:
brain_inertial.orientation(axis, units)

Παράμετροι

Περιγραφή

axis

The orientation angle to return:

  • ROLL
  • PITCH
  • YAW

units

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

# Display the roll, pitch, and yaw of the Brain as it
# is rotated by hand
while True:
    brain.screen.clear_screen()
    brain.screen.print(brain_inertial.orientation(OrientationType.ROLL))
    brain.screen.next_row()
    brain.screen.print(brain_inertial.orientation(OrientationType.PITCH))
    brain.screen.next_row()
    brain.screen.print(brain_inertial.orientation(OrientationType.YAW))
    brain.screen.next_row()
    brain.screen.set_cursor(1, 1)
    wait(0.1, SECONDS)

Κατασκευαστές#

Constructors are used to manually create Inertial objects, such as when configuring an Inertial Sensor outside of VEXcode.

Inertial#

Inertial creates an Inertial Sensor.

Usage:
Inertial(smartport)

Παράμετρος

Περιγραφή

smartport

Optional. If using the IQ (2nd gen) Brain’s built-in Inertial Sensor, a Smart Port is not needed. If connecting an external Inertial Sensor, specify the Smart Port that the Inertial Sensor is connected to, written as PORTx, where x is the port number.

# Create a new object "brain_inertial" with the
# Inertial class
brain_inertial = Inertial()
left_drive_smart = Motor(Ports.PORT1, 1.0, False)
right_drive_smart = Motor(Ports.PORT6, 1.0, True)

drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)

brain_inertial.set_heading(180)
drivetrain.turn_to_heading(0)