Viết hàm Void không có tham số trong 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.

Ví dụ: Một chương trình mẫu cho robot đi một quãng đường thẳng

Chức năng sau đây sẽ cho phép rô-bốt chạy về phía trước bộ mã hóa totalEnc . Nó sử dụng cấu hình V5 Clawbot.

Cái này spinToPositionChức năng sẽ không trở lại cho đến khi chuyển động hoàn tất. Đây được gọi là hành động “đồng bộ hóa” – được xác định bởi tham số cuối cùng true.

Không sử dụng chức năng do người dùng xác định:

int main() {
   vexcodeInit();  

   LeftMotor.resetPosition ();
   LeftMotor.setVelocity(100,0, phần trăm);
   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)); 
     chờ (1000, mili giây);

   LeftMotor.resetPosition ();
   LeftMotor.setVelocity(-100.0, phần trăm);
   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)); 
     chờ (1000, msec);
}

Mẫu có thể cho kết quả như sau:

giây tốc độ quay thô deg
2,06 5445 3,12 1089

Xin lưu ý rằng bài kiểm tra của bạn sẽ thay đổi trong một biên độ rất nhỏ ở các vị trí thập phân.

Với chức năng do người dùng xác định:

Mẫu sau đây cho biết cách nắm bắt một tập hợp các hoạt động thành một lệnh gọi "hàm" có thể sử dụng lại.

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, phần trăm);
   LeftMotor.spinToPosition(500.0, deg, true);
   reportMotionValues();

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(-50,0, phần trăm);
   LeftMotor.spinToPosition(-500.0, deg, true);
   reportMotionValues();

}

Ở đây hiển thị trình tự luồng logic từ hàm gọi hàm main():

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

Last Updated: