リミットスイッチ#

導入#

limit クラスは、物体との物理的な接触を検出する小型デジタルセンサーであるリミットスイッチで使用されます。

VEX V5 リミットスイッチ。

クラスコンストラクタ#

limit(
  triport::port &port);

クラスデストラクタ#

limit オブジェクトを破棄し、関連するリソースを解放します。

virtual ~limit();

パラメータ#

パラメータ

タイプ

説明

port

triport::port &

リミットスイッチが接続されている3線式ポートは、 Brain.ThreeWirePort.X または ExpanderName.Xのように記述され、 X はポート文字です (例: Brain.ThreeWirePort.A または Expander1.A)。

例#

// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);

メンバーの機能#

limit クラスには、以下のメンバ関数が含まれています。

  • pressingを押している – リミットスイッチが押されているかどうかを返します。

  • pressed – リミットスイッチが押されたときに呼び出される関数を登録します。

  • released – リミットスイッチが解放されるたびに呼び出される関数を登録します。

limit を呼び出す前に、以下に示すように limit 作成する必要があります。

/* This constructor is required when using VS Code.
Limit Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);

pressing#

リミットスイッチが現在押されているかどうかを返します。これは、ロボットが他の物体に衝突したかどうかを確認するために使用できます。

Available Functions
int32_t pressing();

Parameters

この関数は引数を受け付けません。

Return Values

リミットスイッチが押されているかどうかを示す int32_t を返します。

  • 1 — リミットスイッチが押されています。

  • 0 — リミットスイッチが押されていません。

pressed#

リミットスイッチが押されたときに呼び出される関数を登録します。

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

Parameters

パラメータ

タイプ

説明

callback

void (*)(void)

リミットスイッチが押されたときに呼び出される関数へのポインタ。

Return Values

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

Examples

コールバック関数を定義します( int main()の外側)

void switchPressed() {
  // The Brain will print that the Limit Switch was pressed
  // on the Brain's screen.
  Brain.Screen.print("switch pressed");
}

コールバックを登録する int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run switchPressed when the Limit Switch is pressed.
  LimitSwitchA.pressed(switchPressed);
}

released#

リミットスイッチが解除されたときに呼び出される関数を登録します。

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

Parameters

パラメータ

タイプ

説明

callback

void (*)(void)

リミットスイッチが解除されたときに呼び出される関数へのポインタ。

Return Values

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

Examples

コールバック関数を定義します( int main()の外側)

void switchReleased() {
  // The Brain will print that the Limit Switch was released
  // on the Brain's screen.
  Brain.Screen.print("switch released");
}

コールバックを登録する int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run switchReleased when the Limit Switch is released.
  LimitSwitchA.released(switchReleased);
}