Αισθητήρας GPS#
Εισαγωγή#
The gps class is used to control and access data from the V5 GPS (Game Positioning System™) Sensor. This sensor provides accurate position and orientation tracking for a robot on the VEX Field. It uses the GPS Field Code around the Field’s perimeter to calculate the robot’s X and Y coordinates and heading in real time.
Ο αισθητήρας GPS επιστρέφει τη θέση του ρομπότ χρησιμοποιώντας ένα σημείο αναφοράς που υπολογίζεται αυτόματα από τις μετατοπίσεις που εισάγονται κατά τη διαμόρφωση του αισθητήρα GPS στο παράθυρο Συσκευές.
Για περισσότερες πληροφορίες σχετικά με τον αισθητήρα GPS, διαβάστε την ενότητα Χρήση του αισθητήρα GPS με το VEX V5 στη βιβλιοθήκη VEX.
Το σημείο αναφοράς λειτουργεί ως η θέση (0, 0) του αισθητήρα GPS, όπου όλες οι συντεταγμένες, οι κατευθύνσεις και οι κινήσεις που επιστρέφονται από τις μεθόδους GPS είναι σχετικές με αυτό το διαμορφωμένο σημείο.

Κατασκευαστές κλάσεων#
1 — Creates a
gpsobject on the specified Smart Port using the default origin (0, 0).gps( int32_t index, double heading_offset = 0, turnType dir = right );
2 — Creates a
gpsobject on the specified Smart Port and defines a custom origin position.gps( int32_t index, double ox, double oy, distanceUnits units = mm, double heading_offset = 0, turnType dir = right );
Καταστροφέας κλάσης#
Destroys the gps object and releases associated resources.
~gps();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The Smart Port that the GPS Sensor is connected to, written as |
|
|
Η συντεταγμένη Χ της αρχικής θέσης. |
|
|
Η συντεταγμένη Y της αρχικής θέσης. |
|
|
The unit of measurement used for
|
|
|
Η περιστροφική μετατόπιση του αισθητήρα GPS σε μοίρες, από 0,00 έως 359,99. Η προεπιλογή είναι 0. |
|
|
The direction that will return positive heading values:
|
Παραδείγματα#
// Create the gps instance
gps GPS1 = gps(
PORT1, // Smart Port 1
180); // heading_offset
// Create the gps instance
gps GPS1 = gps(
PORT1, // Smart Port 1
50.00, // ox
100.00, // oy
mm, // units
180 ); // heading_offset
Συναρτήσεις Μελών#
The gps class includes the following member functions:
calibrate— Calibrates the GPS Sensor.setOrigin— Sets the origin position for the GPS coordinate system.setLocation— Sets the current location and heading of the GPS Sensor.xPosition— Returns the current X position.yPosition— Returns the current Y position.heading— Returns the current heading.acceleration— Returns linear acceleration along the specified axis.gyroRate— Returns the angular velocity for the specified axis.orientation— Returns the orientation for the specified axis.quality— Returns the current GPS signal quality.changed— Registers a callback function that runs when GPS data changes.
Before calling any gps member functions, a gps instance must be created, as shown below:
/* This constructor is required when using VS Code.
GPS Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the gps instance in Smart Port 1
gps GPS1 = gps(PORT1);
Μέθοδοι Κλάσης#
calibrate#
Βαθμονομεί τον αισθητήρα GPS. Αυτό θα ορίσει την κατεύθυνση που έχει ρυθμιστεί από το GPS (σύμφωνα με τη γωνία μετατόπισής του) ως την τρέχουσα κατεύθυνση του συστήματος μετάδοσης κίνησης.
Ο αισθητήρας GPS πρέπει να παραμένει ακίνητος κατά τη διάρκεια της διαδικασίας βαθμονόμησης.
Available Functionsvoid calibrate();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΑυτή η συνάρτηση δεν επιστρέφει τιμή.
Examples// Turn to face the lower Field wall using data from the GPS Sensor.
GPS1.calibrate();
Drivetrain.turnToHeading(180, degrees)
setOrigin#
Ορίζει την αρχή του συστήματος συντεταγμένων GPS.
Available Functions1 — Ορίζει την αρχή των αξόνων στην καθορισμένη θέση X και Y.
void setOrigin( double x, double y, distanceUnits units = mm );
Parameters2 — Ορίζει την προέλευση στην τρέχουσα θέση του αισθητήρα.
void setOrigin();
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Η συντεταγμένη Χ της νέας αρχικής θέσης. |
|
|
Η συντεταγμένη Y της νέας αρχικής θέσης. |
|
|
The unit of measurement used for
|
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
NotessetLocation#
Ορίζει την τρέχουσα θέση και κατεύθυνση GPS.
Available Functions1 — Ορίζει την τρέχουσα τοποθεσία χρησιμοποιώντας καθορισμένες μονάδες απόστασης και περιστροφής.
void setLocation( double x, double y, distanceUnits units = mm, double angle = 0, rotationUnits units_r = degrees );
Parameters2 — Ορίζει την τρέχουσα τοποθεσία χρησιμοποιώντας χιλιοστά και μοίρες.
void setLocation( double x, double y, double angle );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Η συντεταγμένη Χ της τρέχουσας τοποθεσίας. |
|
|
Η συντεταγμένη Y της τρέχουσας τοποθεσίας. |
|
|
The unit of measurement used for
|
|
|
Η τιμή κατεύθυνσης για την τρέχουσα τοποθεσία. |
|
|
The unit of measurement used for
|
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
NotesxPosition#
Επιστρέφει την τρέχουσα θέση X του αισθητήρα GPS.
Available Functionsdouble xPosition( distanceUnits units = distanceUnits::mm );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The unit of measurement for the returned X position:
|
Returns a double representing the x positional offset from the origin in the specified units.
Η θέση X μετριέται σε σχέση με την τρέχουσα αρχή.
The origin may be changed using
setOrigin.
// Drive slowly towards the center of the Field
Drivetrain.setDriveVelocity(20.0, percent);
Drivetrain.drive(forward);
// Stop driving when the GPS returns an x position
// near the center of the Field
waitUntil((GPS1.xPosition(mm) < 0.0));
Drivetrain.stop();
yPosition#
Επιστρέφει την τρέχουσα θέση Y του αισθητήρα GPS.
Available Functionsdouble yPosition( distanceUnits units = distanceUnits::mm );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The unit of measurement for the returned Y position:
|
Returns a double representing the Y positional offset from the origin in the specified units.
Η θέση Y μετριέται σε σχέση με την τρέχουσα αρχή.
The origin may be changed using
setOrigin().
// Drive slowly towards the center of the Field
Drivetrain.setDriveVelocity(20.0, percent);
Drivetrain.drive(forward);
// Stop driving when the GPS reports an y position
// near the center of the Field
waitUntil((GPS1.yPosition(mm) < 0.0));
Drivetrain.stop();
heading#
Επιστρέφει την τρέχουσα κατεύθυνση (γωνία εκτροπής) του αισθητήρα GPS.
Available Functionsdouble heading( rotationUnits units = rotationUnits::deg );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The unit of measurement for the returned heading value:
|
Returns a double representing the current heading in the specified units.
Η τιμή επικεφαλίδας περιλαμβάνεται μεταξύ 0 και 360 μοιρών.
The positive rotation direction is determined by the
dirparameter specified during construction.
// Turn slowly to face the right wall
Drivetrain.setTurnVelocity(20.0, percent);
Drivetrain.turn(right);
// Stop turning when the GPS reports a heading
// greater than 90 degrees
waitUntil((GPS1.heading() > 90.0));
Drivetrain.stop();
acceleration#
Επιστρέφει τη γραμμική επιτάχυνση που μετράται από τον αισθητήρα GPS κατά μήκος του καθορισμένου άξονα.
Available Functionsdouble acceleration(
axisType axis );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The axis for which acceleration will be returned:
|
Returns a double representing the acceleration along the specified axis in G (gravitational units).
Οι τιμές επιτάχυνσης αναφέρονται σε μονάδες G, όπου 1 G ισούται με την επιτάχυνση λόγω της βαρύτητας στην επιφάνεια της Γης.
gyroRate#
Επιστρέφει τη γωνιακή ταχύτητα που μετράται από τον αισθητήρα GPS κατά μήκος του καθορισμένου άξονα.
Available Functionsdouble gyroRate(
axisType axis,
velocityUnits units );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The axis for which angular velocity will be returned:
|
|
|
The unit of measurement for the returned angular velocity:
|
Returns a double representing the angular velocity along the specified axis in the selected units.
orientation#
Επιστρέφει τη γωνία προσανατολισμού του αισθητήρα GPS για τον καθορισμένο άξονα.
Available Functionsdouble orientation(
orientationType axis,
rotationUnits units );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The orientation axis to retrieve:
|
|
|
The unit of measurement for the returned orientation value:
|
Returns a double representing the orientation of the specified axis in the selected units.
quality#
Επιστρέφει την αντιληπτή ποιότητα σήματος GPS.
Available Functionsint32_t quality();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesReturns an int32_t representing the GPS signal quality as a percentage:
Πιθανές τιμές |
Περιγραφή |
|---|---|
|
Όλα τα αναφερόμενα δεδομένα θέσης και κατεύθυνσης από τον αισθητήρα GPS είναι έγκυρα. |
|
Τα δεδομένα θέσης δεν υπολογίζονται πλέον απευθείας από τον Κώδικα Πεδίου GPS και αντ’ αυτού εκτιμώνται μέσω εναλλακτικών μέσων. |
|
Only heading values are valid. As time passes without sufficient scanning of the GPS Field Code, signal quality continues to decrease until |
changed#
Καταγράφει μια συνάρτηση επανάκλησης που εκτελείται όταν αλλάζει η τιμή κατεύθυνσης GPS.
Available Functionsvoid changed(
void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
A pointer to a function that will be called when the GPS heading value changes. The function must take no parameters and return |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.