在 VEXcode Pro V5 中编写一个不带参数的 Void 函数

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 钳爪机器人的配置。

这个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, "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);
}

示例可能给出以下结果:

secs raw 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, percent);
   LeftMotor.spinToPosition(500.0, deg, true);
   reportMotionValues();

   LeftMotor.resetPosition();
   LeftMotor.setVelocity(-50.0, percent);
   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: