객체 센서#

소개#

objectdetector 클래스는 반사율을 측정하고 객체 센서의 적외선(IR)을 사용하여 객체를 감지하는 데 사용됩니다.

클래스 생성자#

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

클래스 소멸자#

objectdetector 객체를 파괴하고 관련 리소스를 해제합니다.

virtual ~objectdetector();

매개변수#

매개변수

유형

설명

port

triport::port &

객체 센서가 연결된 3선 포트는 Brain.ThreeWirePort.X 또는 ExpanderName.X형식으로 표기되며, 여기서 X 는 포트 문자입니다(예: Brain.ThreeWirePort.A 또는 Expander1.A).

bReverse

bool

객체 센서의 방향을 반전시킬지 여부를 나타내는 선택적 부울 값:

  • false (기본값) — 방향 반전 안 함
  • true — 방향 반전

예시#

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

회원 기능#

objectdetector 클래스는 다음과 같은 멤버 함수를 포함합니다.

  • reflectivity — 객체 센서에 의해 감지된 반사율을 반환합니다.

  • isObjectDetected — 객체 센서가 객체를 감지했는지 여부를 반환합니다.

  • setDetectionThreshold — 객체 센서의 감지 범위를 설정합니다.

  • objectDetected — 객체 센서가 객체를 감지할 때 호출될 함수를 등록합니다.

  • objectLost — 객체 센서가 객체를 잃어버렸을 때 호출될 함수를 등록합니다.

objectdetector 멤버 함수를 호출하기 전에 아래와 같이 objectdetector 인스턴스를 생성해야 합니다.

// 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

객체 감지기가 측정한 반사율을 0~100% 범위의 백분율로 나타내는 int32_t 값을 반환합니다.

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