脳#

導入#

VEX V5 C++では、脳は brain クラスで表されます。Brainオブジェクトを作成するか(またはプロジェクトにデフォルトで用意されているものを使用)、そのメンバオブジェクトを介してBrainの機能にアクセスします。

派生クラス#

brain クラスは、以下の派生クラスの基底クラスとして機能します。

  • Screen - このクラスは、Brain の内蔵カラータッチスクリーンへのアクセスを提供し、プログラムがテキストやグラフィックを表示したり、タッチ入力を受け取ったりできるようにします。

  • Timer - このクラスは、プログラム内の経過時間を計測し、時間ベースの動作を制御するための高解像度タイミングユーティリティを提供します。

  • Battery - このクラスを使用すると、プログラムは電圧、電流、容量、温度など、Brain のバッテリーの状態を監視できます。

  • ThreeWirePort (triport / 3-Wire Port) - このクラスは、Brain の 3-Wire ポートへのアクセスを提供し、リミットスイッチ、ポテンショメータ、LED などの従来のセンサーやデバイスを接続および制御します。

  • SDcard - このクラスは、ファイルの保存、データロギング、外部リソースの読み込みのために、Brain の SD カードからの読み書きを可能にします。

クラスコンストラクタ#

brain();

パラメータ#

brain コンストラクタはパラメータを使用しません。

注記#

  • プロジェクト内で作成できる brain オブジェクトは1つだけです。

例#

// Create the V5 Brain
brain Brain = brain();

メンバーの機能#

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

  • programStop - V5 Brain 上で現在実行中のプロジェクトを停止します。

  • timer - Brain の内部タイマーの現在の値を指定された単位で返します。

  • resetTimer - Brain の内部タイマーをゼロにリセットし、タイミングを再開します。

  • setTimer - Brain の内部タイマーを、指定された値と時間単位に設定します。

brain メンバー関数を呼び出す前に、以下に示すように brain インスタンスを作成する必要があります。

// Create the V5 Brain
brain Brain = brain();

プログラム停止#

V5 Brain上で現在実行中のプロジェクトを停止します。

Available Functions
void programStop();

Parameters

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

Return Values

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

Examples
// Stop the project when the Brain screen is pressed
while (true) {
  if (Brain.Screen.pressing()) {
    Brain.programStop();
  }
  wait(20, msec);
}

タイマー#

Brainの内部タイマーの現在の値を、指定された単位で返します。

Available Functions
double timer(
  timeUnits units );

Parameters

パラメータ

タイプ

説明

units

timeUnits

The unit of time to return:

  • seconds / sec - seconds
  • msec - milliseconds

Return Values

プログラム開始からの経過時間を、指定された単位で表す double 倍精度浮動小数点数を返します。

Examples
  • プロジェクトが開始されると、タイマーは自動的に作動します。

  • タイマーは resetTimer を使用してリセットできます。

Examples
// Stop the project after 3 seconds
while (Brain.timer(seconds) < 3) {
  wait(20, msec);
}

Brain.programStop();

リセットタイマー#

脳の内部タイマーをゼロにリセットします。その後、タイマーは直ちにゼロから再びカウントアップを開始します。

Available Functions
void resetTimer();

Parameters

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

Return Values

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

Notes
  • タイマーはリセットされるとすぐに再びカウントを開始します。

  • resetTimer を呼び出すと、timer への後続の呼び出しによって返される値に影響します。

Examples
// Reset the timer and measure elapsed time
Brain.resetTimer();

while (Brain.timer(sec) < 5) {
  wait(20, msec);
}

// 5 seconds have elapsed since reset
Brain.Screen.print("5 seconds passed");

setTimer#

Brainの内部タイマーを、指定された値と時間単位に設定します。

Available Functions
void setTimer(
  double value,
  timeUnits units );

Parameters

パラメータ

タイプ

説明

value

double

タイマーを設定する時間。これは、 units パラメータで指定された timeUnits に基づいて決定されます。

units

timeUnits

value パラメータを解釈するために使用される単位:

  • seconds / sec - 秒
  • msec - ミリ秒

Return Values

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

Notes
  • タイマーは設定後もカウントダウンを続けます。

  • setTimer を呼び出すと、timer によって返される値がすぐに変更されます。

Examples
// Set the timer to start at 10 seconds
Brain.setTimer(10, sec);

// Wait until the timer is at 3 seconds
while (Brain.timer(sec) < 3) {
  wait(20, msec);
}

// 5 seconds have elapsed since setTimer was called
Brain.Screen.print("5 seconds passed");