VEXcode Pro V5 でパラメーターなしで Void 関数を作成する

The VEX Visual Studio Code Extension has replaced VEXcode Pro V5, which is now end-of-life.

VEXcode Blocks and VEXcode Text remain actively developed and supported for all VEX platforms.

サンプル:ロボットが直線距離を移動するサンプルプログラム

次の関数により、ロボットはtotalEncエンコーダに向かって前進することができます。 V5 Clawbot 構成を使用します。

このpinToPosition関数は、移動が完了するまで戻りません。 これは「同期」アクションと呼ばれ、最後のパラメータtrueによって決定されます。

ユーザー定義関数を使用しない場合:

int main() {
   vexcodeInit();  

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(100.0, パーセント);
   LeftMotor.spinToPosition(500.0, 度, true);


   Brain.Screen.printAt(5,30, "秒回転度" );
   Brain.Screen.printAt(5,60, "%.2f: %8.2f %8.2f", 
     Brain.Timer.value(), 
     LeftMotor.position(rev), 
     LeftMotor.position(deg)); 
     wait(1000, ミリ秒);

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(-100.0, パーセント);
   LeftMotor.spinToPosition(-1000.0, c, true);

   Brain.Screen.printAt(5,100, "秒回転度" );
   Brain.Screen.printAt(5,130, "%%.2f: %8.2f %8.2f", 
     Brain.Timer.value(),
     LeftMotor.position(rev), 
     LeftMotor.position(deg)); 
     待機(1000, ミリ秒);
}

サンプルでは次の結果が得られる場合があります。

秒生回転度
2.06 5445 3.12 1089

テストでは、小数点以下の桁が非常にわずかな誤差内で変化することに注意してください。

ユーザー定義関数を使用する場合:

次のサンプルは、一連の操作を単一の再利用可能な「関数」呼び出しにキャプチャする方法を示しています。

void reportMotionValues() {

  Brain.Screen.printAt(5, 60, "%.2f: %8.2f %8.2f",
    Brain.Timer.value(), 
    LeftMotor.position(rev),
    LeftMotor.position(deg)); 
}


int main() {
   vexcodeInit();  

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(50.0, パーセント);
   LeftMotor.spinToPosition(500.0, 度, true);
   レポートモーション値();

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(-50.0, パーセント);
   LeftMotor.spinToPosition(-500.0, 度, true);
   レポートモーション値();

}

ここでは、呼び出し元関数 main() からのロジック フローのシーケンスを示します。

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: