การเขียนฟังก์ชั่นโมฆะโดยไม่มีพารามิเตอร์ใน 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.

ตัวอย่าง: โปรแกรมตัวอย่างสำหรับหุ่นยนต์ที่จะไปเป็นระยะตรง

ฟังก์ชั่นต่อไปนี้จะอนุญาตให้หุ่นยนต์วิ่งไปข้างหน้าสำหรับTotalencencoder มันใช้การกำหนดค่า V5 Clawbot

spintopositionฟังก์ชั่นจะไม่กลับมาจนกว่าการเคลื่อนไหวจะเสร็จสมบูรณ์ สิ่งนี้เรียกว่าการกระทำ "ซิงโครไนซ์" - กำหนดโดยพารามิเตอร์สุดท้ายจริง

โดยไม่ต้องใช้ฟังก์ชันที่ผู้ใช้กำหนด:

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)); 
     รอ (1,000, 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 (),
     leftmotor.position (rev), 
     leftmotor.position (DEG)); 
     รอ (1,000, MSEC);
}

ตัวอย่างอาจให้ผลลัพธ์ต่อไปนี้:

Secs REV 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, จริง);
   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: