Κωδικοποιητής#

Εισαγωγή#

The encoder class is used with the Optical Shaft Encoder, which measures the rotational position and speed of a shaft. It uses internal optical sensors to detect how far and how fast the shaft turns, making it useful for tracking wheel rotation, arm position, or other mechanisms.

Ο κωδικοποιητής οπτικού άξονα VEX.

Κατασκευαστής κλάσης#

encoder(
  triport::port &port );

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

Destroys the encoder object and releases associated resources.

virtual ~encoder();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

port

triport::port &

The first 3-Wire Port of a required two-port group used by the Optical Shaft Encoder. The encoder occupies two adjacent ports (A–B, C–D, E–F, or G–H) on either the Brain or a 3-Wire Expander. Specify the first port in the pair (A, C, E, or G), written as Brain.ThreeWirePort.X or ExpanderName.X where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.C).

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

// Create an encoder instance in Ports A and B
encoder EncoderA = encoder(Brain.ThreeWirePort.A);

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

The encoder class includes the following member functions:

  • setPosition — Sets the encoder’s current position to a specified value.

  • position — Returns how far the encoder has rotated.

  • velocity — Returns the current rotational velocity of the encoder.

Before calling any encoder member functions, a encoder instance must be created, as shown below:

/* This constructor is required when using VS Code.
Encoder configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create an encoder instance in Ports A and B
encoder EncoderA = encoder(Brain.ThreeWirePort.A);

setPosition#

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

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

Parameters

Παράμετροι

Τύπος

Περιγραφή

value

double

Η περιστροφική θέση που θα οριστεί.

units

rotationUnits

The unit that represents the position:

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

Return Values

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

position#

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

Available Functions
double position(
  rotationUnits units );

Parameters

Παράμετροι

Τύπος

Περιγραφή

units

rotationUnits

The unit that represents the position:

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

Return Values

Returns a double representing the rotation in the specified units.

velocity#

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

Available Functions
double velocity(
  velocityUnits units );

Parameters

Παράμετροι

Τύπος

Περιγραφή

units

velocityUnits

The unit used to represent the velocity:

  • percent / pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

Return Values

Returns a double representing the velocity in the specified units.