객체 센서#
소개#
objectdetector 클래스는 반사율을 측정하고 객체 센서의 적외선(IR)을 사용하여 객체를 감지하는 데 사용됩니다.
클래스 생성자#
objectdetector(
triport::port &port,
bool bReverse = false );
클래스 소멸자#
objectdetector 객체를 파괴하고 관련 리소스를 해제합니다.
virtual ~objectdetector();
매개변수#
매개변수 |
유형 |
설명 |
|---|---|---|
|
|
객체 센서가 연결된 3선 포트는 |
|
|
객체 센서의 방향을 반전시킬지 여부를 나타내는 선택적 부울 값:
|
예시#
// 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 Functionsint32_t reflectivity(
percentUnits units = percentUnits::pct );
매개변수 |
유형 |
설명 |
|---|---|---|
|
|
The unit that represents the reflectivity:
|
객체 감지기가 측정한 반사율을 0~100% 범위의 백분율로 나타내는 int32_t 값을 반환합니다.
// 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);