Att skriva en Void-funktion utan parametrar i VEXcode Pro V5

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.

Exempel: Ett exempelprogram för en robot som ska röra sig en rak sträcka

Följande funktion tillåter roboten att köra framåt förtotalEnckodare. Den använder V5 Clawbot-konfigurationen.

DennaspinToPosition-funktion återgår inte förrän rörelsen är klar. Detta kallas "synkroniserad" åtgärd – bestäms av den sista parameterntrue.

Utan att använda en användardefinierad funktion:

int main() {
   vexcodeInit();  

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(100.0, procent);
   LeftMotor.spinToPosition(500.0, deg, true);


   Brain.Screen.printAt(5,30, "sek varv grader");
   Brain.Screen.printAt(5,60, "%.2f: %8.2f %8.2f", 
     Brain.Timer.value(), 
     LeftMotor.position(varv), 
     LeftMotor.position(deg)); 
     wait(1000, msec);

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(-100.0, procent);
   LeftMotor.spinToPosition(-1000.0, c, true);

   Brain.Screen.printAt(5,100, "sek varv grader");
   Brain.Screen.printAt(5,130, "%%.2f: %8.2f %8.2f", 
     Brain.Timer.value(),
     LeftMotor.position(varv), 
     LeftMotor.position(grader)); 
     wait(1000, ms);
}

Provet kan ge följande resultat:

sek rå varv grader
2,06 5445 3,12 1089

Observera att ditt test kommer att variera inom en mycket liten marginal i decimaler.

Med en användardefinierad funktion:

Följande exempel visar hur man samlar in en uppsättning operationer i ett enda återanvändbart "funktionsanrop".

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();

}

Här visas sekvensen av logikflödet från anroparfunktionen main():

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

Last Updated: