Ελεγκτής#
Εισαγωγή#
The controller class represents a VEX V5 Controller connected to the V5 Brain. A controller object can be used to access joystick axis values, read button states, register button or joystick callbacks, make the Controller rumble, write to the Controller screen, and check whether the Controller is connected.
Το VEX V5 είναι συμβατό με τον ελεγκτή EXP. Ανατρέξτε στο EXP Controller API για περισσότερες πληροφορίες.
When one or more Controllers are configured in the Devices window, VEXcode V5 also provides RemoteControlCodeEnabled. This global variable enables or disables Controller actions configured in the Devices menu.
Παράγωγες Κλάσεις#
The controller class provides the following derived classes:
Κατασκευαστές#
1 - Δημιουργεί έναν ελεγκτή χρησιμοποιώντας τον κύριο τύπο ελεγκτή. Συνήθως χρησιμοποιείται όταν είναι συνδεδεμένος ένας μόνο ελεγκτής.
controller();
2 - Δημιουργεί έναν ελεγκτή για τον καθορισμένο τύπο ελεγκτή. Χρησιμοποιείται όταν είναι συνδεδεμένοι δύο ελεγκτές.
controller( controllerType id );
Διαθέσιμες λειτουργίες
controller();
controller(controllerType id);
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Optional. The Controller type to create: |
Σημειώσεις
Only one primary Controller and one partner Controller can be created in a single project.
Παράδειγμα
// Create the primary Controller
controller Controller1 = controller();
// Create a partner Controller
controller Controller2 = controller(partner);
Καταστροφέας#
~ελεγκτής#
~controller destroys the controller object and releases associated resources.
Διαθέσιμη λειτουργία
~controller();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The type of controller being created:
|
Σημειώσεις#
Only one
primaryand onepartnercontroller may exist in a single project.
Παράδειγμα#
// Create a V5 controller instance
controller Controller = controller();
Συναρτήσεις Μελών#
The controller class includes the following member functions:
rumble- Rumbles the controller using a pattern.installed- Checks whether the controller is connected to the brain.
σιγοβροντώ#
rumble makes the Controller vibrate using a pattern. In the pattern string, dots are short vibrations, dashes are long vibrations, and spaces are pauses.
Διαθέσιμη λειτουργία
void rumble(const char *str);
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια χορδή φτιαγμένη από τελείες, παύλες και κενά που αναπαριστούν το μοτίβο βουητού. |
Επιστρεφόμενη τιμή
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
Παράδειγμα
// Rumble with a short-short-long pattern
Controller1.rumble("..-");
Λήπτης#
εγκατεστημένο#
installed returns whether the Controller is connected to the Brain.
Διαθέσιμη λειτουργία
bool installed();
Παράμετροι
Αυτή η συνάρτηση δεν έχει παραμέτρους.
Επιστρεφόμενη τιμή
Επιστρέφει μια λογική τιμή.
true- The controller is installed/connected.false- The controller is not installed/connected.
Καθολικές Μεταβλητές#
Κωδικός Απομακρυσμένου ΕλέγχουΕνεργοποιημένος#
RemoteControlCodeEnabled enables or disables Controller actions configured in the Devices menu. Controller configured actions are enabled by default.
Usage:
RemoteControlCodeEnabled = state;
Αξία |
Περιγραφή |
|---|---|
|
Ενεργοποιεί ενέργειες που έχουν ρυθμιστεί από τον ελεγκτή. |
|
Απενεργοποιεί τις ενέργειες που έχουν ρυθμιστεί από τον ελεγκτή. |
true- Controller-configured actions are enabled.false- Controller-configured actions are disabled.
Οι ενέργειες που διαμορφώνονται από τον ελεγκτή είναι ενεργοποιημένες από προεπιλογή.
// Drive forward or backward using the left joystick
RemoteControlCodeEnabled = false;
while (true) {
if (Controller1.Axis3.position() > 0) {
Drivetrain.drive(forward);
}
else if (Controller1.Axis3.position() < 0) {
Drivetrain.drive(reverse);
}
// Press A to use Controller configured actions again
else if (Controller1.ButtonA.pressing()) {
break;
}
else {
Drivetrain.stop();
}
wait(20, msec);
}
RemoteControlCodeEnabled = true;