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.
مثال: برنامج نموذجي لروبوت يقطع مسافة مستقيمة
ستسمح الوظيفة التالية للروبوت بالتحرك للأمام لمدةtotalEncencoder. يستخدم تكوين V5 Clawbot.
لنتكتمل الحركة. يُطلق على هذا اسم الإجراء "المتزامن" - ويتم تحديده بواسطة المعلمة الأخيرةصحيح.
بدون استخدام دالة معرفة من قبل المستخدم:
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():