Αισθητήρας απόστασης#
Εισαγωγή#
The sonar class is used with the VEX IQ Distance Sensor (1st gen). The distance class is used with the VEX IQ Distance Sensor (2nd gen).
Και οι δύο αισθητήρες απόστασης μπορούν να ανιχνεύσουν εάν ένα αντικείμενο βρίσκεται μπροστά από τον αισθητήρα και να επιστρέψουν την απόσταση που βρίσκεται αυτό το αντικείμενο. Ο αισθητήρας απόστασης VEX IQ (2ης γενιάς) μπορεί επίσης να επιστρέψει τη σχετική ταχύτητα του ανιχνευμένου αντικειμένου και να εκτιμήσει εάν το αντικείμενο είναι μικρό, μεσαίο ή μεγάλο.
Κατασκευαστές κλάσεων#
1 — Αυτός ο κατασκευαστής δημιουργεί έναν αισθητήρα απόστασης VEX IQ (1ης γενιάς).
sonar( int32_t index);
2 — Αυτός ο κατασκευαστής δημιουργεί έναν αισθητήρα απόστασης VEX IQ (2ης γενιάς).
distance( int32_t index);
Καταστροφέας κλάσης#
Destroys the distance object and releases associated resources.
1 — Καταστρέφει έναν αισθητήρα απόστασης VEX IQ (1ης γενιάς).
~sonar();
2 — Καταστρέφει έναν αισθητήρα απόστασης VEX IQ (2ης γενιάς).
~distance();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The Smart Port that the Distance Sensor is connected to, written as |
Παραδείγματα#
1 — Δημιουργήστε μια παρουσία του αισθητήρα απόστασης VEX IQ (1ης γενιάς) στη θύρα 1.
sonar Distance1 = sonar(PORT1);
2 — Δημιουργήστε μια παρουσία του VEX IQ Distance Sensor (2ης γενιάς) στη Θύρα 1.
distance Distance1 = distance(PORT1);
Συναρτήσεις Μελών#
The sonar class includes the following member functions:
foundObject— Returns whether the Distance Sensor currently detects an object.distance— Returns the distance between the Distance Sensor and the nearest detected object.
The distance class includes the following member functions:
objectDistance— Returns the distance between the Distance Sensor and the nearest detected object.objectVelocity— Returns how quickly the detected object is moving toward or away from the Distance Sensor.objectSize— Returns the estimated size of the detected object.isObjectDetected— Returns whether the Distance Sensor currently detects an object.changed— Registers a callback function that runs when the detected distance value changes.installed— Returns whether the Distance Sensor is installed and connected.
Before calling any distance or sonar member functions, a distance or sonar instance must be created, as shown below:
/* This constructor is required when using VS Code.
Distance Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a VEX IQ Distance Sensor (2nd gen) instance in Port 1
distance Distance1 = distance(PORT1);
foundObject#
Επιστρέφει εάν ο αισθητήρας απόστασης ανιχνεύει αυτήν τη στιγμή ένα αντικείμενο.
Available Functionsbool foundObject();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΕπιστρέφει μια λογική τιμή που υποδεικνύει εάν ο αισθητήρας απόστασης ανιχνεύει ένα αντικείμενο:
-
true— The Distance Sensor detects an object. -
false— The Distance Sensor does not detect an object.
distance#
Επιστρέφει την απόσταση μεταξύ του αισθητήρα απόστασης και του πλησιέστερου αντικειμένου που ανιχνεύθηκε.
Available Functionsdouble distance( distanceUnits units );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The distance unit:
|
Returns a double representing the distance between the Distance Sensor and the nearest detected object in the specified units.
objectDistance#
Επιστρέφει την απόσταση μεταξύ του αισθητήρα απόστασης και του πλησιέστερου αντικειμένου που ανιχνεύθηκε.
Available Functionsdouble objectDistance( distanceUnits units );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The distance unit:
|
Returns a double representing the distance between the Distance Sensor and the nearest detected object in the specified units.
objectVelocity#
Επιστρέφει τη σχετική ταχύτητα του ανιχνευμένου αντικειμένου.
Η ταχύτητα δείχνει πόσο γρήγορα κινείται το αντικείμενο προς ή μακριά από τον αισθητήρα απόστασης. Μια τιμή κοντά στο 0 σημαίνει ότι το αντικείμενο δεν κινείται πολύ σε σχέση με τον αισθητήρα.
Available Functionsdouble objectVelocity();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesReturns a double representing the relative velocity of the detected object in m/s (meters per second).
objectSize#
Επιστρέφει το εκτιμώμενο μέγεθος του αντικειμένου που ανιχνεύεται από τον αισθητήρα απόστασης.
Ο αισθητήρας απόστασης εκτιμά το μέγεθος του αντικειμένου με βάση το πόσο μεγάλο μέρος της ορατότητας του αισθητήρα καταλαμβάνεται από το ανιχνευόμενο αντικείμενο.
Available FunctionssizeType objectSize();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesReturns a sizeType indicating the estimated size of the detected object:
-
none— No object is detected. -
small— A small object is detected. -
medium— A medium object is detected. -
large— A large object is detected.
isObjectDetected#
Επιστρέφει εάν ο αισθητήρας απόστασης ανιχνεύει αυτήν τη στιγμή ένα αντικείμενο.
Available Functionsbool isObjectDetected();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΕπιστρέφει μια λογική τιμή που υποδεικνύει εάν ο αισθητήρας απόστασης ανιχνεύει ένα αντικείμενο:
-
true— The Distance Sensor detects an object. -
false— The Distance Sensor does not detect an object.
changed#
Καταγράφει μια συνάρτηση επανάκλησης που εκτελείται όταν αλλάζει η τιμή της ανιχνευμένης απόστασης.
Available Functionsvoid changed( void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
A pointer to a function that will be called when the detected distance value changes. The function must take no parameters and return |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
Notes - This is a VEX IQ Distance Sensor (1st gen) or (2nd gen) function.installed#
Επιστρέφει εάν ο αισθητήρας απόστασης είναι εγκατεστημένος και συνδεδεμένος.
Available Functionsbool installed();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΕπιστρέφει μια λογική τιμή που υποδεικνύει εάν ο αισθητήρας απόστασης είναι εγκατεστημένος και συνδεδεμένος:
-
true— The Distance Sensor is installed and connected. -
false— The Distance Sensor is not installed or not connected.