Αδρανειακός αισθητήρας#

Εισαγωγή#

The inertial class is used to control and access data from the IQ (2nd gen) Brain’s built-in Inertial Sensor. This sensor measures how the Brain is moving and turning.

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

Κατασκευαστές κλάσεων#

inertial(
  turnType dir = turnType::right );

Καταστροφέας κλάσης#

Destroys the inertial object and releases associated resources.

~inertial();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

dir

turnType

Optional. The direction that returns positive values:

  • right (default) — Right turns return positive values.
  • left — Left turns return positive values.

Παραδείγματα#

// Create the inertial instance
inertial myInertial = inertial(
    right);     // dir

Συναρτήσεις Μελών#

The inertial class includes the following member functions:

  • heading — Returns the direction the sensor is facing.

  • rotation — Returns how far the sensor has turned.

  • setHeading — Sets the sensor’s current heading to a new heading value.

  • setRotation — Sets the sensor’s current rotation to a new rotation value.

  • calibrate — Calibrates the Inertial Sensor.

  • resetHeading — Resets the sensor’s current heading to 0 degrees.

  • resetRotation — Resets the sensor’s current rotation to 0 degrees.

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

  • changed — Registers a callback function that runs when the heading changes.

  • installed — Returns whether the Inertial Sensor is installed.

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

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

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

  • collision — Registers a callback function that runs when a collision is detected.

  • setTurnType — Sets which turn direction returns positive heading values.

  • getTurnType — Returns which turn direction produces positive values.

Before calling any inertial member functions, an inertial instance must be created, as shown below:

/* This constructor is required when using VS Code.
Inertial Sensor configuration is generated automatically
in VEXcode with the IQ (2nd gen) Brain. Replace the values
as needed. */

// Create the inertial instance
inertial myInertial = inertial();

heading#

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

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

Available Functions
double heading( rotationUnits units = degrees );

Parameters

Παράμετρος

Τύπος

Περιγραφή

units

rotationUnits

The heading unit:

  • deg / degrees (default) — degrees
  • turns / rev — revolutions

Return Values

Returns a double representing the current heading of the sensor in the specified units.

Notes
  • The heading value is wrapped between 0 and 359.99 degrees. Use rotation to access the continuous rotation value.

Examples
// Turn, then show the current heading
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", myInertial.heading(degrees));

rotation#

Επιστρέφει την τρέχουσα περιστροφή του αδρανειακού αισθητήρα.

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

Available Functions
double rotation( rotationUnits units = degrees );

Parameters

Παράμετρος

Τύπος

Περιγραφή

units

rotationUnits

The rotation unit:

  • deg / degrees (default) — degrees
  • turns / rev — revolutions

Return Values

Returns a double representing the current rotation in the specified units.

Notes
  • The rotation value is continuous and does not wrap between 0 and 359.99 degrees. Use heading to access the wrapped heading value.

Examples
// Turn, then show the current rotation
Drivetrain.turnFor(right, 450, degrees);
Brain.Screen.print("%f", myInertial.rotation(degrees));

setHeading#

Μια κατεύθυνση είναι η κατεύθυνση προς την οποία είναι στραμμένος ο αισθητήρας, μετρούμενη σε μοίρες από 0 έως 359,99. Αυτή η συνάρτηση αλλάζει την τρέχουσα κατεύθυνση του αδρανειακού αισθητήρα σε μια νέα τιμή κατεύθυνσης.

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

Available Functions
void setHeading( double        value,
                 rotationUnits units );

Parameters

Παράμετρος

Τύπος

Περιγραφή

value

double

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

units

rotationUnits

The heading unit:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Examples
// Turn the robot around
myInertial.setHeading(180, degrees);
Drivetrain.turnToHeading(0, degrees);

setRotation#

Ορίζει την τρέχουσα περιστροφή του αδρανειακού αισθητήρα σε μια καθορισμένη τιμή.

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

Available Functions
void setRotation( double        value,
                  rotationUnits units );

Parameters

Παράμετρος

Τύπος

Περιγραφή

value

double

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

units

rotationUnits

The rotation unit:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Examples
// Turn the robot around
myInertial.setRotation(-180, degrees);
Drivetrain.turnToRotation(0, degrees);

calibrate#

Βαθμονομεί τον αδρανειακό αισθητήρα.

Η βαθμονόμηση βοηθά τον αισθητήρα να μετρά σωστά τις στροφές. Διατηρήστε τον αισθητήρα ακίνητο κατά τη βαθμονόμηση. Εάν ο αισθητήρας κινηθεί κατά τη βαθμονόμηση, οι τιμές κατεύθυνσης, περιστροφής, γυροσκοπικού ρυθμού και προσανατολισμού ενδέχεται να μην μετρώνται σωστά.

Available Functions
void calibrate( );

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Notes
  • Ο αισθητήρας θα πρέπει να παραμένει ακίνητος κατά τη διάρκεια της βαθμονόμησης.

  • Use isCalibrating to determine when calibration has completed.

resetHeading#

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

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

Available Functions
void resetHeading();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

resetRotation#

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

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

Available Functions
void resetRotation();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

isCalibrating#

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

Available Functions
bool isCalibrating();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Επιστρέφει μια λογική τιμή που υποδεικνύει εάν ο Αισθητήρας Αδράνειας βαθμονομείται:

  • true — The sensor is currently calibrating.
  • false — The sensor is not currently calibrating.

changed#

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

Available Functions
void changed( void (* callback)(void) );

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

A pointer to a function that will be called when the heading value changes. The function must take no parameters and return void.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Examples

Define the callback function (outside of int main())

// Display the heading when the Inertial Sensor's heading value changes.
void onHeadingChanged() {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Heading: %.2f", myInertial.heading());
}

Register the callback inside int main()

int main() {
  // Run onHeadingChanged when the Inertial Sensor's heading value changes.
  myInertial.changed(onHeadingChanged);
}

installed#

Επιστρέφει εάν ο Αισθητήρας Αδράνειας είναι εγκατεστημένος και συνδεδεμένος.

Available Functions
bool installed();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

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

  • true — The sensor is connected and responding.
  • false — The sensor is not connected or not detected.

acceleration#

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

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.

Available Functions
double acceleration( axisType axis );

Parameters

Παράμετρος

Τύπος

Περιγραφή

axis

axisType

The axis to measure acceleration on:

  • xaxis
  • yaxis
  • zaxis

Return Values

Returns a double representing the acceleration along the specified axis in G (gravitational units).

Notes
  • Acceleration values are reported in units of G.

gyroRate#

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

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

Available Functions
double gyroRate( axisType      axis,
                 velocityUnits units );

Parameters

Παράμετρος

Τύπος

Περιγραφή

axis

axisType

The axis to return the gyro rate from:

  • xaxis
  • yaxis
  • zaxis

units

velocityUnits

The gyro rate unit:

  • dps — degrees per second
  • rpm — revolutions per minute

Return Values

Returns a double representing the current rotation speed along the specified axis in the selected units.

Examples
// Display the rate of change of rotation while turning in dps
Drivetrain.turn(right);
wait(1, seconds);

Brain.Screen.print(myInertial.gyroRate(zaxis, dps));

Drivetrain.stop();

orientation#

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

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

Available Functions
double orientation(
  orientationType type,
  rotationUnits   units );

Parameters

Παράμετρος

Τύπος

Περιγραφή

type

orientationType

The orientation angle to return:

  • pitch
  • roll
  • yaw

units

rotationUnits

The orientation unit:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

Returns a double representing the selected orientation angle in the specified units.

Examples
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  // Show the Inertial Sensor's orientation value
  // for roll in degrees
  double orient = myInertial.orientation(roll, deg);
  Brain.Screen.print("%f", orient);
  wait(0.1, seconds);
}

collision#

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

Available Functions
void collision( void (* callback)(axisType, double, double, double) );

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(axisType, double, double, double)

A pointer to a function that will be called when a collision is detected. The callback function must accept the following parameters:

  • axisType — The axis on which the collision was detected.
  • Acceleration values at the time of impact, in order:
    • double — Acceleration along the x-axis (in G).
    • double — Acceleration along the y-axis (in G).
    • double — Acceleration along the z-axis (in G).
The function must return void.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Examples

Define the callback function (outside of int main())

// Display a message when the Inertial Sensor detects a collision.
void onCollision(axisType axis, double x, double y, double z) {
  Brain.Screen.print("Collision detected!");
}

Register the callback inside int main()

int main() {
  // Run onCollision when the Inertial Sensor detects a collision.
  myInertial.collision(onCollision);
}

setTurnType#

Ορίζει ποια κατεύθυνση στροφής επιστρέφει θετικές τιμές.

Available Functions
void setTurnType( turnType dir );

Parameters

Παράμετρος

Τύπος

Περιγραφή

dir

turnType

The direction that returns positive values:

  • right
  • left

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Notes

getTurnType#

Επιστρέφει τις τιμές των οποίων η κατεύθυνση στροφής παράγει θετικές τιμές.

Available Functions
turnType getTurnType();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Returns a turnType indicating which direction produces positive values:

  • right — Clockwise rotation returns positive values.
  • left — Counterclockwise rotation returns positive values.
Notes