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 di chuyển theo đường thẳng.
Chức năng sau đây sẽ cho phép robot chạy về phía trước với tổng số Enc làvà bộ mã hóa. Nó sử dụng cấu hình V5 Clawbot.
HàmspinToPositionnày sẽ không trả về cho đến khi quá trình chuyển động hoàn tất. Đây được gọi là hành động “đồng bộ” – được xác định bởi tham số cuối cùngđúng.
Không sử dụng hàm do người dùng định nghĩa:
int main() {
vexcodeInit();
LeftMotor.resetPosition();
LeftMotor.setVelocity(100.0, percent);
LeftMotor.spinToPosition(500.0, deg, true);
Brain.Screen.printAt(5, 30, "giây vòng quay độ");
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, "giây, vòng quay, độ" );
Brain.Screen.printAt(5,130, "%%.2f: %8.2f %8.2f",
Brain.Timer.value(),
LeftMotor.position(rev),
LeftMotor.position(deg));
wait(1000, msec);
}
Mẫu thử có thể cho kết quả như sau:
giây thô vòng tua độ
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 chữ số thập phân.
Với một hàm do người dùng định nghĩa:
Mẫu sau đây cho thấy cách thu thập một tập hợp các thao tác thành một lệnh gọi “hàm” có thể tái sử dụng duy nhất.
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();
}
Video dưới đây minh họa trình tự logic diễn ra từ hàm gọi main():