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.
サンプル:ロボットが直線距離を移動するためのサンプルプログラム
以下の関数を使用すると、ロボットはtotalEncencoder の間、前進することができます。 V5 Clawbot 構成を使用します。
このspinToPosition関数は、移動が完了するまで戻りません。これは「同期」アクションと呼ばれ、最後のパラメータtrueによって決定されます。
ユーザー定義関数を使用せずに:
int main() {
vexcodeInit();
LeftMotor.resetPosition ();
LeftMotor.setVelocity(100.0, percent);
LeftMotor.spinToPosition(500.0, deg, true);
Brain.Screen.printAt(5,30, "secs rev deg" );
Brain.Screen.printAt(5,60, "%.2f: %8.2f %8.2f",
Brain.Timer.value(),
LeftMotor.position(rev),
LeftMotor.position(deg));
wait(1000, msec);
LeftMotor.resetPosition ();
LeftMotor.setVelocity(-100.0, percent);
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(回転),
LeftMotor.position(角度));
wait(1000 msec);
}
サンプルは以下の結果を示す可能性があります。
秒 生データ 回転数 度
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, percent);
LeftMotor.spinToPosition(500.0, deg, true);
reportMotionValues();
LeftMotor.resetPosition ();
LeftMotor.setVelocity(-50.0, percent);
LeftMotor.spinToPosition(-500.0, deg, true);
reportMotionValues();
}
以下の動画は、呼び出し元の関数 main() から始まる一連のロジックの流れを示しています。