Αισθητήρας αντικειμένων#
Εισαγωγή#
The objectdetector class is used to measure reflectivity and detect objects with the Object Sensor’s infrared (IR) light.
Κατασκευαστής κλάσης#
objectdetector(
triport::port &port,
bool bReverse = false );
Καταστροφέας κλάσης#
Destroys the objectdetector object and releases associated resources.
virtual ~objectdetector();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The 3-Wire Port that the Object Sensor is connected to, written as |
|
|
An optional boolean to reverse the direction of the Object Sensor:
|
Παραδείγματα#
// Create an objectdetector instance in Port A
objectdetector ObjectSensorA = objectdetector(Brain.ThreeWirePort.A, true);
Συναρτήσεις Μελών#
The objectdetector class includes the following member functions:
reflectivity— Returns the reflectivity detected by the Object Sensor.isObjectDetected— Returns whether the Object Sensor detects an object.setDetectionThreshold— Sets the detection range of the Object Sensor.objectDetected— Registers a function to be called when the Object Sensor detects an object.objectLost— Registers a function to be called when the Object Sensor loses an object.
Before calling any objectdetector member functions, a objectdetector instance must be created, as shown below:
// Create an objectdetector instance in Port A
objectdetector ObjectSensorA = objectdetector(Brain.ThreeWirePort.A, true);
reflectivity#
Επιστρέφει την ανακλαστικότητα που μετράται από τον αισθητήρα αντικειμένων.
Available Functionsint32_t reflectivity(
percentUnits units = percentUnits::pct );
Παράμετροι |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The unit that represents the reflectivity:
|
Returns an int32_t representing the reflectivity measured by the Object Detector as a percent in the range 0 - 100%.
// Display the detected reflectivity on the Brain's screen
int32_t value = ObjectSensorA.reflectivity();
Brain.Screen.print(value);
isObjectDetected#
Επιστρέφει εάν ένα αντικείμενο ανιχνεύεται αυτήν τη στιγμή από τον Ανιχνευτή Αντικειμένων.
Available Functionsbool isObjectDetected();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΕπιστρέφει μια λογική τιμή που υποδεικνύει εάν έχει εντοπιστεί ένα αντικείμενο:
-
true— An object is detected. -
false— No object is detected.
setDetectionThreshold#
Ορίζει το όριο ανίχνευσης για τον Ανιχνευτή Αντικειμένων σε μια συγκεκριμένη τιμή.
Available Functionsvoid setDetectionThreshold(
int32_t threshold,
percentUnits units = percentUnits::pct );
Παράμετροι |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Το όριο ανακλαστικότητας για την ανίχνευση αντικειμένων, στην περιοχή 0 - 100. |
|
|
The unit that represents the new threshold:
|
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
Examples// Set the reflectivity threshold to 50%
ObjectSensorA.setDetectionThreshold(50);
objectDetected#
Καταγράφει μια συνάρτηση επανάκλησης για την ανίχνευση ενός αντικειμένου.
Available Functionsvoid objectDetected(void (* callback)(void));
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Η συνάρτηση επανάκλησης που θα κληθεί όταν εντοπιστεί ένα αντικείμενο. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
Examplesvoid detected() {
Brain.Screen.print("object detected");
}
// Run detected when the Object Detector detects an object
ObjectSensorA.objectDetected(detected);
objectLost#
Καταχωρεί μια συνάρτηση επανάκλησης για την περίπτωση απώλειας ενός αντικειμένου.
Available Functionsvoid objectLost(void (* callback)(void));
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Η συνάρτηση επανάκλησης που θα κληθεί όταν χαθεί ένα αντικείμενο. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
Examplesvoid lost() {
Brain.Screen.print("object lost");
}
// Run lost when the Object Detector loses an object
ObjectSensorA.objectLost(lost);