物体センサー#

導入#

objectdetector クラスは、反射率を測定し、オブジェクトセンサーによってオブジェクトを検出するために使用されます。

クラスコンストラクタ#

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

コールバック関数を定義します( 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 Functions
void objectLost(void (* callback)(void));

Parameters

パラメータ

タイプ

説明

callback

void (*)(void)

オブジェクトが失われたときに呼び出されるコールバック関数。

Return Values

この関数は値を返しません。

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