Αισθητήρας περιστροφής#

Εισαγωγή#

The rotation class is used to control and access data from an EXP Rotation Sensor.

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

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

Ο αισθητήρας περιστροφής μπορεί να επιστρέψει τη γωνία, τη θέση και την ταχύτητα του άξονα. Η γωνία είναι η απόλυτη θέση του άξονα από 0 έως 359,99 μοίρες. Δεν επαναφέρεται όταν ξεκινά ένα έργο ή όταν το ρομπότ είναι απενεργοποιημένο. Η θέση παρακολουθεί πόσες μοίρες ή στροφές έχει περιστραφεί ο άξονας προς τα εμπρός ή προς τα πίσω κατά τη διάρκεια ενός έργου και μπορεί να επαναφερθεί ανάλογα με τις ανάγκες.

Ο αισθητήρας περιστροφής είναι συμβατός με τυπικούς άξονες VEX 1/8 ίντσας και 1/4 ίντσας.

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

rotation(
    int32_t index,
    bool    reverse = false );

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

Destroys the rotation object and releases associated resources.

virtual ~rotation();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

index

int32_t

The Smart Port that the Rotation Sensor is connected to, written as PORTx, where x is the port number (for example, PORT1).

reverse

bool

Optional. Whether to reverse the Rotation Sensor output:

  • true — Reverses the direction of the reported angle and position values.
  • false (default) — Reports angle and position values in the standard direction.

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

// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);

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

The rotation class includes the following member functions:

  • setPosition — Sets the Rotation Sensor’s current position to a specific value.

  • angle — Returns the shaft’s current angle from 0 to 359.99 degrees.

  • position — Returns how far the shaft has rotated in degrees or turns.

  • velocity — Returns how fast the shaft is rotating.

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

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

// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);

setPosition#

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

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

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

Parameters

Παράμετρος

Τύπος

Περιγραφή

value

double

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

units

rotationUnits

The position unit:

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

Return Values

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

angle#

Επιστρέφει την τρέχουσα γωνία του άξονα.

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

Available Functions
double angle( rotationUnits units = degrees );

Parameters

Παράμετρος

Τύπος

Περιγραφή

units

rotationUnits

Optional. The angle unit:

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

Return Values

Returns a double representing the shaft’s current angle in the specified units.

Examples
// Get the current angle of the shaft
  double angle = Rotation1.angle(degrees);

  // Print the current angle of the shaft to the
  // Brain's screen.
  Brain.Screen.print(angle);

position#

Επιστρέφει την περιστροφή του άξονα.

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

Available Functions
double position( rotationUnits units );

Parameters

Παράμετρος

Τύπος

Περιγραφή

units

rotationUnits

The position unit:

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

Return Values

Returns a double representing how far the shaft has rotated in the specified units.

velocity#

Επιστρέφει την ταχύτητα περιστροφής του άξονα.

Available Functions
double velocity( velocityUnits units );

Parameters

Παράμετρος

Τύπος

Περιγραφή

units

velocityUnits

The velocity unit:

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

Return Values

Returns a double representing how fast the shaft is rotating in the specified units.