VEXcode Pro V5'te Parametreler Olmadan Bir Void Fonksiyonu Yazma

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.

Örnek: Bir robotun düz bir mesafeyi kat etmesi için örnek bir program.

Aşağıdaki fonksiyon, robotuntotalEncenkoder değeriyle ileri yönde hareket etmesini sağlayacaktır. V5 Clawbot yapılandırmasını kullanır.

Bufonksiyonu, hareket tamamlanana kadar geri dönmeyecektir. Bu, son parametretrue tarafından belirlenen “senkronize” eylem olarak adlandırılır.

Kullanıcı tanımlı bir fonksiyon kullanmadan:

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, "sn devir derece" );
   Brain.Screen.printAt(5,130, "%%.2f: %8.2f %8.2f", 
     Brain.Timer.value(),
     LeftMotor.position(rev), 
     LeftMotor.position(deg)); 
     wait(1000, msec);
}

Örneklem aşağıdaki sonucu verebilir:

saniye ham devir derece
2.06 5445 3.12 1089

Testinizin ondalık basamaklarda çok küçük bir farkla değişeceğini unutmayın.

Kullanıcı tanımlı bir fonksiyonla:

Aşağıdaki örnek, bir dizi işlemin tek bir yeniden kullanılabilir "işlev" çağrısında nasıl yakalanacağını gösterir.

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

}

Aşağıdaki video, çağıran fonksiyon olan main() fonksiyonundan başlayarak mantıksal akışın nasıl ilerlediğini göstermektedir:

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

Last Updated: