我已经构建了最基本的 vex 机器人,称为“Moby”并对其进行了编码,因此它可以执行一些基本功能,例如举起手臂、前进和后退以及转动,我还构建了一个让它跑得更快的功能,但我不太确定如何查看它是否有效,我关心的是如何改进它?机器人非常基础,因为我已经完成了基础知识,我不确定我应该添加哪些其他功能?
main.cpp(这是在比赛模板内)
void autonomous(void) {
// ..........................................................................
// Insert autonomous user code here.
// ..........................................................................
}
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
int speed(100);
void speedIncrease(float inc){
leftDrive.spin(fwd, inc + leftDrive.velocity(pct), pct);
rightDrive.spin(fwd, inc - rightDrive.velocity(pct), pct);
}
void drive(int speed, int turn){
if(Controller1.ButtonL1.pressing()){
leftDrive.spin(fwd, speed + turn, pct);
rightDrive.spin(fwd, speed - turn, pct);
}
else if(Controller1.ButtonL2.pressing()){
speedIncrease(100);
} else{
leftDrive.stop();
rightDrive.stop();
}
}
void lift(){
if(Controller1.ButtonX.pressing()){
// ARMS.spinToPosition(1000,degrees);
ARMS.spin(forward);
// leftArm.spinToPosition(100,degrees);
// rightArm.spinToPosition(100,degrees);
}
else if(Controller1.ButtonB.pressing()){
// ARMS.spinToPosition(0,degrees);
ARMS.spin(reverse);
// leftArm.spinToPosition(0,degrees);
// rightArm.spinToPosition(0,degrees);
}
else{
leftArm.stop(hold);
rightArm.stop(hold);
ARMS.stop(hold);
}
}
void usercontrol(void) {
// User control code here, inside the loop
leftDrive.setStopping(hold);
rightDrive.setStopping(hold);
while (1) {
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................
drive(Controller1.Axis3.position(pct), Controller1.Axis1.position(percent));
lift();
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
ARMS.setVelocity(90,pct);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}