Написання функції Void без параметрів у 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.

Зразок: зразок програми для робота, який проходить прямий шлях

Наступна функція дозволить роботу бігти вперед дляtotalEncкодера. Він використовує конфігурацію V5 Clawbot.

Ця функціяspinToPositionне повернеться до завершення руху. Це називається «синхронізованою» дією – визначається останнім параметромtrue.

Без використання функції, визначеної користувачем:

int main() {
   vexcodeInit();  

   LeftMotor.resetPosition ();
   LeftMotor.setVelocity(100,0, відсоток);
   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)); 
     очікування (1000, мс);

   LeftMotor.resetPosition ();
   LeftMotor.setVelocity(-100,0, відсоток);
   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)); 
     очікування (1000, мс);
}

Зразок може дати наступний результат:

secs raw rev deg
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, deg, true);
   reportMotionValues();

   LeftMotor.resetPosition ();
   LeftMotor.setVelocity(-50,0, відсоток);
   LeftMotor.spinToPosition(-500.0, deg, true);
   reportMotionValues();

}

Тут показано послідовність логічного потоку від викликаючої функції main():

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

Last Updated: