Αδρανειακό#
Εισαγωγή#
Ένας αδρανειακός αισθητήρας μετρά τον τρόπο που κινείται και περιστρέφεται το ρομπότ.
Ο Αισθητήρας Αδράνειας χρησιμοποιεί δύο μέρη για να το κάνει αυτό. Το γυροσκόπιο μετρά την στροφή, όπως την κατεύθυνση, την περιστροφή, τον ρυθμό γυροσκοπίου και τον προσανατολισμό. Το επιταχυνσιόμετρο μετρά τις αλλαγές στην κίνηση, όπως την επιτάχυνση ή την επιβράδυνση κατά μήκος των αξόνων x, y και z.
Για να εμφανιστούν οι αδρανειακές εντολές στο VEXcode V5, πρέπει να διαμορφωθεί ένας αδρανειακός αισθητήρας στο παράθυρο Συσκευές.
Παρακάτω είναι μια λίστα με τις διαθέσιμες μεθόδους:
Προσανατολισμός — Ανάγνωση και έλεγχος κατεύθυνσης, περιστροφής και βαθμονόμησης αισθητήρα.
heading— Returns the direction the sensor is facing, from 0 to 359.99 degrees.rotation— Returns how far the sensor has turned.gyro_rate— Returns how fast the sensor is rotating on the selected axis.orientation— Returns the Inertial Sensor’s roll, pitch, or yaw angle.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.calibrate— Calibrates the Inertial Sensor.reset_heading— Resets the Inertial Sensor’s current heading to 0 degrees.reset_rotation— Resets the Inertial Sensor’s current rotation to 0 degrees.is_calibrating— Returns whether the Inertial Sensor is currently calibrating.changed— Registers a function to run when the Inertial Sensor’s value changes.installed— Checks if the Inertial Sensor is installed.
Κίνηση — Μετρήστε την επιτάχυνση, τις συγκρούσεις και τη συμπεριφορά κατεύθυνσης στροφής.
acceleration— Returns how quickly the sensor is speeding up or slowing down on the selected axis.collision— Registers a function to run when the Inertial Sensor detects a collision.set_turn_type— Sets which turn direction returns positive heading values.get_turn_type— Returns which turn direction returns positive heading values.
Κατασκευαστής
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 as a float.
Η αρχική κατεύθυνση είναι 0 μοίρες. Εάν ο αισθητήρας περιστραφεί πέραν των 359,99 μοιρών, η κατεύθυνση επιστρέφει στις 0 μοίρες.
Usage:
inertial_1.heading(units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Optional. The heading unit: |
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.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 as a float.
Η δεξιά στροφή αυξάνει την περιστροφή και η αριστερά στροφή μειώνει την περιστροφή. Για παράδειγμα, κάνοντας δύο πλήρεις στροφές προς τα δεξιά θα επιστρέψει μια περιστροφή 720 μοιρών. Η περιστροφή μίας πλήρους στροφής προς τα αριστερά από 0 μοίρες θα επιστρέψει μια περιστροφή -360 μοιρών.
Usage:
inertial_1.rotation(units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Optional. The rotation unit: |
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(inertial_1.rotation())
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 as a float.
Η τιμή μπορεί να είναι θετική ή αρνητική ανάλογα με την κατεύθυνση περιστροφής του αισθητήρα σε αυτόν τον άξονα.
Usage:
inertial_1.gyro_rate(axis, units)
Παράμετροι |
Περιγραφή |
|---|---|
|
The axis to return the gyro rate from:
|
|
Optional. The gyro rate unit:
|
# Display the rate of change of
# rotation while turning
drivetrain.turn(RIGHT)
wait(1, SECONDS)
brain.screen.print(inertial_1.gyro_rate(AxisType.ZAXIS, VelocityUnits.DPS))
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, from -180.00 to 180.00 degrees, as a float.
Οι όροι κύλιση, κλίση και εκτροπή περιγράφουν διαφορετικούς τρόπους με τους οποίους ο αισθητήρας μπορεί να γέρνει ή να περιστρέφεται.
Usage:
inertial_1.orientation(type, units)
Παράμετροι |
Περιγραφή |
|---|---|
|
The orientation angle to return:
|
|
Optional. The orientation unit:
|
# Display the roll, pitch, and yaw of the Brain as it
# is rotated by hand
while True:
brain.screen.clear_screen()
brain.screen.print(inertial_1.orientation(AxisType.ROLL, DEGREES))
brain.screen.next_row()
brain.screen.print(inertial_1.orientation(AxisType.PITCH, DEGREES))
brain.screen.next_row()
brain.screen.print(inertial_1.orientation(AxisType.YAW, DEGREES))
brain.screen.next_row()
brain.screen.set_cursor(1, 1)
wait(0.1, SECONDS)
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:
inertial_1.set_heading(value, units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η τιμή κατεύθυνσης, σε μοίρες, που θα οριστεί για τον αισθητήρα. Αυτή μπορεί να είναι μια τιμή από 0 έως 359,99. |
|
Optional. The heading unit: |
# Turn the robot around
inertial_1.set_heading(180, DEGREES)
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:
inertial_1.set_rotation(value, units)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η τιμή περιστροφής, σε μοίρες, που θα οριστεί για τον αισθητήρα. Αυτή μπορεί να είναι ακέραιος ή δεκαδικός αριθμός (float). |
|
Optional. The rotation unit: |
# Turn the robot around
inertial_1.set_rotation(-180, DEGREES)
drivetrain.turn_to_rotation(0)
calibrate#
calibrate calibrates the Inertial Sensor.
Η βαθμονόμηση βοηθά τον αισθητήρα να μετρά σωστά τις στροφές. Διατηρήστε τον αισθητήρα ακίνητο κατά τη βαθμονόμηση. Εάν ο αισθητήρας κινηθεί κατά τη βαθμονόμηση, οι τιμές κατεύθυνσης, περιστροφής, γυροσκοπικού ρυθμού και προσανατολισμού ενδέχεται να μην μετρώνται σωστά.
Το έργο θα περιμένει μέχρι να ολοκληρωθεί η βαθμονόμηση πριν εκτελεστεί η επόμενη γραμμή κώδικα.
Usage:
inertial_1.calibrate()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Start calibration.
inertial_1.calibrate()
# Print that the Inertial Sensor is calibrating while
# waiting for it to finish calibrating.
while inertial_1.is_calibrating():
brain.screen.clear()
brain.screen.print("Inertial Sensor Calibrating")
wait(50, MSEC)
reset_heading#
reset_heading resets the Inertial Sensor’s current heading to 0 degrees.
Αφού χρησιμοποιηθεί αυτή η μέθοδος, η τρέχουσα κατεύθυνση του αισθητήρα γίνεται η νέα κατεύθυνση 0 μοιρών.
Usage:
inertial_1.reset_heading()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
reset_rotation#
reset_rotation resets the Inertial Sensor’s current rotation to 0 degrees.
Αφού χρησιμοποιηθεί αυτή η μέθοδος, ο αισθητήρας παρακολουθεί τις μελλοντικές στροφές από τη νέα τιμή περιστροφής 0 μοιρών.
Usage:
inertial_1.reset_rotation()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
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:
inertial_1.is_calibrating()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
changed#
changed registers a function to be called whenever the Inertial Sensor’s value changes.
Usage:
inertial_1.changed(callback, arg)
Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως ορισμένη συνάρτηση που εκτελείται όταν αλλάζει η τιμή του Αδρανειακού Αισθητήρα. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση Συναρτήσεων με Παραμέτρους για περισσότερες πληροφορίες. |
def my_function():
brain.screen.print("Value changed!!")
# Call my_function whenever inertial_1's value changes
inertial_1.changed(my_function)
installed#
installed checks if the Inertial Sensor is installed.
True— The Inertial Sensor is installed.False— The Inertial Sensor is not installed.
Usage:
inertial_1.installed()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
Κίνηση#
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 AxisType.XAXIS, AxisType.YAXIS, and AxisType.ZAXIS.
Usage:
inertial_1.acceleration(type)
Παράμετροι |
Περιγραφή |
|---|---|
|
The axis to measure acceleration on:
|
# Return the acceleration for the Z axis of the Inertial Sensor
zaccel = inertial_1.acceleration(AxisType.ZAXIS)
collision#
collision registers a function to be called whenever the Inertial Sensor detects a sudden impact or collision.
Usage:
inertial_1.collision(callback, arg)
Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως ορισμένη συνάρτηση που εκτελείται όταν ανιχνεύεται σύγκρουση. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση Συναρτήσεων με Παραμέτρους για περισσότερες πληροφορίες. |
def my_function():
brain.screen.print("Collision!")
# Call my_function whenever a collision is detected
inertial_1.collision(my_function)
set_turn_type#
set_turn_type sets which turn direction returns positive heading values.
Usage:
inertial_1.set_turn_type(turntype)
Παράμετροι |
Περιγραφή |
|---|---|
|
The turn type to set:
|
get_turn_type#
get_turn_type returns which turn direction returns positive heading values.
LEFT— Left turns return positive heading values.RIGHT— Right turns return positive heading values.
Usage:
inertial_1.get_turn_type()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
Κατασκευαστές#
Inertial#
Inertial creates an Inertial Sensor.
Usage:
Inertial(port)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η Έξυπνη Θύρα στην οποία είναι συνδεδεμένος ο Αδρανειακός Αισθητήρας, από 1 έως 21. |
# Create a new object "inertial_1" with the Inertial class.
inertial_1 = Inertial(Ports.PORT1)