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.
Ukázka: Ukázkový program pro robota, který ujede přímou vzdálenost
Následující funkce umožní robotu běžet vpřed pro kodértotalEnc. Využívá konfiguraci V5 Clawbot.
Tato funkcespinToPositionse nevrátí, dokud není pohyb dokončen. Toto se nazývá „synchronizovaná“ akce – určená posledním parametremtrue.
Bez použití uživatelem definované funkce:
int main() {
vexcodeInit();
LeftMotor.resetPosition ();
LeftMotor.setVelocity(100,0, procent);
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));
čekat(1000, ms);
LeftMotor.resetPosition ();
LeftMotor.setVelocity(-100,0, procent);
LeftMotor.spinToPosition(-1000,0, c, true);
Brain.Screen.printAt(5,100, "secs rev deg" );
Brain.Screen.printAt(5,130, "%%.2f: %8.2f %8.2f",
Brain.Timer.value(),
LeftMotor.position(rev),
LeftMotor.position(deg));
čekat (1000, ms);
}
Vzorek může poskytnout následující výsledek:
s surový otáčkový stupeň 2,06 5445 3,12 1089
Pamatujte, že váš test se bude lišit ve velmi malém rozsahu na desetinných místech.
S uživatelsky definovanou funkcí:
Následující ukázka ukazuje, jak zachytit sadu operací do jediného znovu použitelného volání „funkce“.
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, procent);
LeftMotor.spinToPosition(500,0, deg, true);
reportMotionValues();
LeftMotor.resetPosition ();
LeftMotor.setVelocity(-50,0, procent);
LeftMotor.spinToPosition(-500,0, deg, true);
reportMotionValues();
}
Zde je zobrazena sekvence logického toku z funkce volajícího main():