Braiteoir Réada#

Réamhrá#

Úsáidtear an rang objectdetector chun frithchaiteacht a thomhas agus réada a bhrath le solas infridhearg (IR) an Braiteora Réad.

Tógálaí Ranga#

objectdetector( 
  triport::port &port, 
  bool           bReverse = false );

Scriostóir Ranga#

Scriosann sé an réad objectdetector agus scaoileann sé acmhainní gaolmhara.

virtual ~objectdetector();

Paraiméadair#

Paraiméadar

Cineál

Cur síos

port

triport::port &

An Port 3-Sreang a bhfuil an Braiteoir Réada ceangailte leis, scríofa mar Brain.ThreeWirePort.X nó ExpanderName.X, áit a seasann X do litir an phoirt (mar shampla, Brain.ThreeWirePort.A nó Expander1.A).

bReverse

bool

Boolean roghnach chun treo an Braiteora Réada a aisiompú:

  • false (réamhshocraithe) — Ná haisiompaigh an treo
  • true — Aisiompaigh an treo

Samplaí#

// Create an objectdetector instance in Port A
objectdetector ObjectSensorA = objectdetector(Brain.ThreeWirePort.A, true);

Feidhmeanna na mBall#

Áirítear leis an rang objectdetector na feidhmeanna ball seo a leanas:

  • reflectivity — Tugann sé seo an fhrithchaiteacht a bhraith an Braiteoir Réada ar ais.

  • isObjectDetected — Tugann sé seo ar ais cibé an mbraitheann an Braiteoir Réada réad.

  • setDetectionThreshold — Socraíonn sé raon braite an Braiteora Réada.

  • objectDetected — Cláraíonn sé feidhm le glaoch uirthi nuair a bhraithfidh an Braiteoir Réada réad.

  • objectLost — Cláraíonn sé feidhm le glaoch uirthi nuair a chailleann an Braiteoir Réada réad.

Sula nglaotar ar aon fheidhmeanna objectdetector ball, ní mór sampla objectdetector a chruthú, mar a thaispeántar thíos:

// Create an objectdetector instance in Port A
objectdetector ObjectSensorA = objectdetector(Brain.ThreeWirePort.A, true);

reflectivity#

Tugann sé seo an fhrithchaiteacht a thomhais an Braiteoir Réada ar ais.

Available Functions
int32_t reflectivity( 
  percentUnits units = percentUnits::pct );

Parameters

Paraiméadair

Cineál

Cur síos

units

percentUnits

An t-aonad a léiríonn an fhrithchaiteacht:

  • percent / pct — faoin gcéad

Return Values

Tugann sé int32_t ar ais a léiríonn an fhrithchaiteacht a thomhais an Brathadóir Réada mar chéatadán sa raon 0 - 100%.

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

isObjectDetected#

Tugann sé seo ar ais an bhfuil réad á bhrath ag an Brathadóir Réad faoi láthair.

Available Functions
bool isObjectDetected();

Parameters

Ní ghlacann an fheidhm seo aon pharaiméadair.

Return Values

Tugann sé seo luach Booleánach ar ais a léiríonn an bhfuil réad braite:

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

setDetectionThreshold#

Socraíonn sé tairseach braite an Bhraiteora Réada go luach sonrach.

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

Parameters

Paraiméadair

Cineál

Cur síos

threshold

int32_t

An tairseach frithchaiteachta le haghaidh braite réad, sa raon 0 - 100.

units

percentUnits

An t-aonad a léiríonn an tairseach nua:

  • percent / pct — faoin gcéad

Return Values

Ní thugann an fheidhm seo luach ar ais.

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

objectDetected#

Cláraíonn sé feidhm athghlaoite nuair a bhraitear réad.

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

Parameters

Paraiméadar

Cineál

Cur síos

callback

void (*)(void)

An fheidhm athghlaoite le glaoch nuair a bhraitear réad.

Return Values

Ní thugann an fheidhm seo luach ar ais.

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

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

objectLost#

Cláraíonn sé feidhm athghlaoite nuair a chailltear réad.

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

Parameters

Paraiméadar

Cineál

Cur síos

callback

void (*)(void)

An fheidhm athghlaoite le glaoch nuair a chailltear réad.

Return Values

Ní thugann an fheidhm seo luach ar ais.

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

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