Αξονας#
Εισαγωγή#
The axis class is a derived class of the controller class. It provides access to controller joystick axis values and joystick axis change callbacks.
An axis object is accessed through a controller object. It is not constructed directly.

Πρόσβαση#
The controller class provides the following axis objects. Each object is an instance of the axis class.
Αντικείμενο άξονα |
Παράδειγμα Χρήσης |
Περιγραφή |
|---|---|---|
|
|
Οριζόντιος άξονας δεξιού joystick. |
|
|
Κάθετος άξονας δεξιού joystick. |
|
|
Αριστερό κάθετο άξονα joystick. |
|
|
Οριζόντιος άξονας αριστερού joystick. |
Σημειώσεις#
Before using an
axismember function, create acontrollerobject.positionreturns a value from-100to100.
// Create a controller object
controller Controller = controller();
Συναρτήσεις Μελών#
The axis class includes the following member functions:
Getter — Ανάγνωση της θέσης του άξονα του joystick.
position— Returns the position of the joystick axis.
Επανάκληση — Εκτέλεση συνάρτησης όταν αλλάζει η θέση του joystick κατά μήκος ενός άξονα.
changed— Runs a function when the joystick’s position changes along that axis.
Λήπτης#
position#
position returns the position of the joystick axis as a value from -100 to 100.
Διαθέσιμη λειτουργία
int32_t position(percentUnits units = percentUnits::pct) const;
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Optional. The unit used for the returned axis value. The default is |
Επιστρεφόμενη τιμή
Returns an int32_t value from -100 to 100.
100— The joystick axis is fully moved in the positive direction.0— The joystick axis is centered.-100— The joystick axis is fully moved in the negative direction.
Παράδειγμα
// Turn with the left joystick
while (true) {
if (Controller.Axis4.position() > 10) {
Drivetrain.turn(right);
}
else if (Controller.Axis4.position() < -10) {
Drivetrain.turn(left);
}
else {
Drivetrain.stop();
}
wait(20, msec);
}
Επανάκληση#
changed#
changed runs a function when the joystick’s position changes along that axis.
Διαθέσιμη λειτουργία
void changed(void (* callback)(void)) const;
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια συνάρτηση που εκτελείται κάθε φορά που αλλάζει η θέση του joystick κατά μήκος αυτού του άξονα. |
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια προηγουμένως καθορισμένη συνάρτηση επανάκλησης που καλείται αυτόματα όταν αλλάζει η τιμή του άξονα. Η συνάρτηση πρέπει να ταιριάζει με την απαιτούμενη υπογραφή επανάκλησης. Ανατρέξτε στην ενότητα Συναρτήσεις επανάκλησης για περισσότερες πληροφορίες. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
Παράδειγμα
Define the callback function outside of main.
Define the callback function (outside of
int main())// Play a sound when the left joystick moves void sounds() { Brain.playSound(siren); wait(1, seconds); }Register the callback inside
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Call the function when the left joystick moves Controller.Axis4.changed(sounds); }