物体センサー#
導入#
objectdetector クラスは、反射率を測定し、オブジェクトセンサーによってオブジェクトを検出するために使用されます。
クラスコンストラクタ#
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 の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));
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
オブジェクトが検出されたときに呼び出されるコールバック関数。 |
この関数は値を返しません。
Examplesコールバック関数を定義します(
int main()の外側)// Display a message when an object is detected. void detected() { Brain.Screen.print("object detected"); }コールバックを登録する
int main()int main() { // Run detected when the Object Detector detects an object. ObjectSensorA.objectDetected(detected); }
objectLost#
オブジェクトが失われたときに呼び出されるコールバック関数を登録します。
Available Functionsvoid objectLost(void (* callback)(void));
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
オブジェクトが失われたときに呼び出されるコールバック関数。 |
この関数は値を返しません。
Examplesコールバック関数を定義します(
int main()の外側)// Display a message when an object is lost. void lost() { Brain.Screen.print("object lost"); }コールバックを登録する
int main()int main() { // Run lost when the Object Detector loses an object. ObjectSensorA.objectLost(lost); }