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함수는 이동이 완료될 때까지 반환되지 않습니다. 이것은 마지막 매개변수(참) 또는 에 의해 결정되는 "동기화된" 동작이라고 합니다.
사용자 정의 함수를 사용하지 않고:
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, "초 회전 각도" );
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()에서부터 논리가 어떻게 흐르는지를 보여줍니다.