Αξονας#

Εισαγωγή#

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.

Ένα χειριστήριο VEX V5 με τους άξονες γύρω από τα joystick να έχουν επισημανθεί. Οι άξονες 1 και 2 βρίσκονται γύρω από το δεξί joystick και οι άξονες 3 και 4 γύρω από το αριστερό.

Πρόσβαση#

The controller class provides the following axis objects. Each object is an instance of the axis class.

Αντικείμενο άξονα

Παράδειγμα Χρήσης

Περιγραφή

Axis1

Controller.Axis1.position()

Οριζόντιος άξονας δεξιού joystick.

Axis2

Controller.Axis2.position()

Κάθετος άξονας δεξιού joystick.

Axis3

Controller.Axis3.position()

Αριστερό κάθετο άξονα joystick.

Axis4

Controller.Axis4.position()

Οριζόντιος άξονας αριστερού joystick.

Σημειώσεις#

  • Before using an axis member function, create a controller object.

  • position returns a value from -100 to 100.

// 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 returns the position of the joystick axis as a value from -100 to 100.

Διαθέσιμη λειτουργία

int32_t position(percentUnits units = percentUnits::pct) const;

Παράμετρος

Τύπος

Περιγραφή

units

percentUnits

Optional. The unit used for the returned axis value. The default is percentUnits::pct.

Επιστρεφόμενη τιμή

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 runs a function when the joystick’s position changes along that axis.

Διαθέσιμη λειτουργία

void changed(void (* callback)(void)) const;

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

Μια συνάρτηση που εκτελείται κάθε φορά που αλλάζει η θέση του joystick κατά μήκος αυτού του άξονα.

Επιστρεφόμενη τιμή

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

Παράδειγμα

Define the callback function outside of main.

// Rumble when the left joystick moves
void controllerRumble() {
  Controller.rumble(".");
}

Register the callback inside main.

int main() {
  vexcodeInit();

  // Run controllerRumble when the joystick's position changes along Axis4
  Controller.Axis4.changed(controllerRumble);
}