Написание функции 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, 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, "secs rev deg" );
   Brain.Screen.printAt(5,130, "%%.2f: %8.2f %8.2f", 
     Brain.Timer.value(),
     LeftMotor.position(rev), 
     LeftMotor.position(deg)); 
     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():

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

Last Updated: