كتابة وظيفة فارغة بدون معلمات في 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)); 
     wait(1000, msec);

   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(),
     المحرك الأيسر .position(rev), 
     LeftMotor.position(deg)); 
     wait(1000, msec);
}

قد تعطي العينة النتيجة التالية:

secs raw rev deg
2.06 5445 3.12 1089

لاحظ أن اختبارك سيختلف ضمن هامش صغير جدًا في المنازل العشرية.

مع وظيفة محددة من قبل المستخدم:

يوضح النموذج التالي كيفية التقاط مجموعة من العمليات في استدعاء "وظيفة" واحد قابل لإعادة الاستخدام.

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: