Αισθητήρας αντικειμένων#

Εισαγωγή#

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();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

port

triport::port &

The 3-Wire Port that the Object Sensor is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

bReverse

bool

An optional boolean to reverse the direction of the Object Sensor:

  • false (default) — Do not reverse the direction
  • true — Reverse the direction

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

// 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 Functions
int32_t reflectivity( 
  percentUnits units = percentUnits::pct );

Parameters

Παράμετροι

Τύπος

Περιγραφή

units

percentUnits

The unit that represents the reflectivity:

  • percent / pct — percent

Return Values

Returns an int32_t representing the reflectivity measured by the Object Detector as a percent in the range 0 - 100%.

Examples
// Display the detected reflectivity on the Brain's screen
int32_t value = ObjectSensorA.reflectivity();
Brain.Screen.print(value);

isObjectDetected#

Επιστρέφει εάν ένα αντικείμενο ανιχνεύεται αυτήν τη στιγμή από τον Ανιχνευτή Αντικειμένων.

Available Functions
bool isObjectDetected();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Επιστρέφει μια λογική τιμή που υποδεικνύει εάν έχει εντοπιστεί ένα αντικείμενο:

  • true — An object is detected.
  • false — No object is detected.

setDetectionThreshold#

Ορίζει το όριο ανίχνευσης για τον Ανιχνευτή Αντικειμένων σε μια συγκεκριμένη τιμή.

Available Functions
void setDetectionThreshold( 
  int32_t      threshold, 
  percentUnits units = percentUnits::pct );

Parameters

Παράμετροι

Τύπος

Περιγραφή

threshold

int32_t

Το όριο ανακλαστικότητας για την ανίχνευση αντικειμένων, στην περιοχή 0 - 100.

units

percentUnits

The unit that represents the new threshold:

  • percent / pct — percent

Return Values

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

Examples
// Set the reflectivity threshold to 50%
ObjectSensorA.setDetectionThreshold(50);

objectDetected#

Καταγράφει μια συνάρτηση επανάκλησης για την ανίχνευση ενός αντικειμένου.

Available Functions
void objectDetected(void (* callback)(void));

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

Η συνάρτηση επανάκλησης που θα κληθεί όταν εντοπιστεί ένα αντικείμενο.

Return Values

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

Examples
void detected() {
  Brain.Screen.print("object detected");
}

// Run detected when the Object Detector detects an object
ObjectSensorA.objectDetected(detected);

objectLost#

Καταχωρεί μια συνάρτηση επανάκλησης για την περίπτωση απώλειας ενός αντικειμένου.

Available Functions
void objectLost(void (* callback)(void));

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

Η συνάρτηση επανάκλησης που θα κληθεί όταν χαθεί ένα αντικείμενο.

Return Values

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

Examples
void lost() {
  Brain.Screen.print("object lost");
}

// Run lost when the Object Detector loses an object
ObjectSensorA.objectLost(lost);