Autonomous won't work

This is my autonomous code. I am using vexcode text on v5 motors. The program works all the way until the last task with the forward drive. It stops right before it goes forward and I can not figure out why. Any advice on how to fix this?

// START AUTONOMOUS
void autonomous(void) {

 // Display on screen
 Brain.Screen.print("Autonomous has started");

 // Set speeds
 FrontLeftDriveMotor.setVelocity(30, velocityUnits::pct);
 FrontRightDriveMotor.setVelocity(30, velocityUnits::pct);
 BackLeftDriveMotor.setVelocity(30, velocityUnits::pct);
 BackRightDriveMotor.setVelocity(30, velocityUnits::pct);
 ClawMotor1.setVelocity(75, velocityUnits::pct);
 ClawMotor2.setVelocity(75, velocityUnits::pct);
 ArmMotorRight.setVelocity(50, velocityUnits::pct);
 ArmMotorLeft.setVelocity(50, velocityUnits::pct);

 // Move forward
 FrontLeftDriveMotor.rotateFor(1.55, rotationUnits::rev, false);
 FrontRightDriveMotor.rotateFor(1.55, rotationUnits::rev, false);
 BackLeftDriveMotor.rotateFor(1.55, rotationUnits::rev, false);
 BackRightDriveMotor.rotateFor(1.55, rotationUnits::rev);

 // Move left
 FrontLeftDriveMotor.rotateFor(2.8, rotationUnits::rev, false);
 FrontRightDriveMotor.rotateFor(-2.8, rotationUnits::rev, false);
 BackLeftDriveMotor.rotateFor(-2.8, rotationUnits::rev, false);
 BackRightDriveMotor.rotateFor(2.8, rotationUnits::rev);

 // Close claw
 ClawMotor1.rotateFor(1000, rotationUnits::deg, false);
 ClawMotor2.rotateFor(-1000, rotationUnits::deg, false);

 // Pause
 vex::task::sleep(150);

 // Arm up
 ArmMotorRight.rotateFor(-0.2, rotationUnits::rev, false);
 ArmMotorLeft.rotateFor(-0.2, rotationUnits::rev);

 // Pause
 vex::task::sleep(50);

 // Move forward
 FrontLeftDriveMotor.rotateFor(0.7, rotationUnits::rev, false);
 FrontRightDriveMotor.rotateFor(0.7, rotationUnits::rev, false);
 BackLeftDriveMotor.rotateFor(0.7, rotationUnits::rev, false);
 BackRightDriveMotor.rotateFor(0.7, rotationUnits::rev);

 // Pause
 vex::task::sleep(70);

 // Rotate counterclockwise
 FrontLeftDriveMotor.rotateFor(-3.2, rotationUnits::rev, false);
 FrontRightDriveMotor.rotateFor(3.2, rotationUnits::rev, false);
 BackLeftDriveMotor.rotateFor(-3.2, rotationUnits::rev, false);
 BackRightDriveMotor.rotateFor(3.2, rotationUnits::rev);

 // Pause
 vex::task::sleep(70);

 // Move backward
 FrontLeftDriveMotor.rotateFor(-0.55, rotationUnits::rev, false);
 FrontRightDriveMotor.rotateFor(-0.55, rotationUnits::rev, false);
 BackLeftDriveMotor.rotateFor(-0.55, rotationUnits::rev, false);
 BackRightDriveMotor.rotateFor(-0.55, rotationUnits::rev);

 // Arm up
 ArmMotorRight.rotateFor(-2, rotationUnits::rev, false);
 ArmMotorLeft.rotateFor(-2, rotationUnits::rev);

 // Pause
 vex::task::sleep(50);
 
 // Move forward
 FrontLeftDriveMotor.rotateFor(0.7, rotationUnits::rev, false);
 FrontRightDriveMotor.rotateFor(0.7, rotationUnits::rev, false);
 BackLeftDriveMotor.rotateFor(0.7, rotationUnits::rev, false);
 BackRightDriveMotor.rotateFor(0.7, rotationUnits::rev); 

}

Could it be because the autonomous is out of time so it cuts out?

2 Likes

Maybe you should try taking out the pause at the end (even though it probably won’t make a difference). You could also try commenting out sections at a time until you find the thing that won’t work.

Also, here’s a side-tip for cleaner organization: create functions for autonomous, such as moveTiles(2, 70); which would be moving 2 tiles forward at 70 percent speed. Here’s an example for that, taken from my code:

void moveTiles(float tiles, int speed)
{
FLDrive.startRotateFor((tiles * (24 / 12.57)), vex::rotationUnits::rev, speed, vex::velocityUnits::pct);
FRDrive.startRotateFor((-tiles * (24 / 12.57)), vex::rotationUnits::rev, speed, vex::velocityUnits::pct);
BLDrive.startRotateFor((tiles * (24 / 12.57)), vex::rotationUnits::rev, speed, vex::velocityUnits::pct);
BRDrive.rotateFor((-tiles * (24 / 12.57)), vex::rotationUnits::rev, speed, vex::velocityUnits::pct);
}

that way, you can just code in english and you can debug way more quickly, since you’re not randomly searching for specific lines of code. Trust me, this will make your life way easier.
Here’s an example of an auton that uses these kinds of functions:

 movePid(0.3, 80);
 movePid(-0.3, 80);
 foldout();
 vex::task::sleep(300);
 intakeON();
 //eat stack
 movePid(3.5, 60); // 3.6
 vex::task::sleep(700);
 intakeOFF();

hope that helps, and good luck with your auton! :smiley:

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.