Need help with making void functions in autonomous

Hi, I’m having errors in the autonomous and pre-auton segment of my code for my team. I’ve attached it in a link for anyone to look at. What happens is the pre-auton function (which I’m not really sure I’ve done correctly), it gives me the error code “incorrect use of void type” or “Function Definition Is not Allowed here”. I’ve tried fixing the errors to no avail, and I was wondering if someone could explain how to properly make a function/void command. [https://ufile.io/b16afxwj](Upload files for free - Code for 8878B.zip - ufile.io)

cleaning up the formatting of the code would help you see the errors, however it’s pretty close.

remove the semi-colons from your function definitions.

This

void goLeft (float deg, int spd); {
  MDriveL.startRotateFor(deg, rotationUnits::deg);
  MDriveR.rotateFor(deg, rotationUnits::deg);
}

should be

void goLeft (float deg, int spd) {
  MDriveL.startRotateFor(deg, rotationUnits::deg);
  MDriveR.rotateFor(deg, rotationUnits::deg);
}

no need to call with void in front. so instead of

void stop ();

just call

stop();

and there are one or two extra braces in the code, again formatting will help.

(and I assume you do not have spaces in the project name, was that just to attach the project ? I had to rename it and remove the spaces.)

here are the cleaned up functions.

code

void goForward (float deg, int spd) {
  MDriveL.startRotateFor(deg, rotationUnits::deg);
  MDriveR.rotateFor(deg, rotationUnits::deg);
} 
void goLeft (float deg, int spd) {
  MDriveL.startRotateFor(deg, rotationUnits::deg);
  MDriveR.rotateFor(deg, rotationUnits::deg);
}
void goRight (float deg, int spd) {
  MDriveL.startRotateFor(deg, rotationUnits::deg);
  MDriveR.rotateFor(deg, rotationUnits::deg);
}
void goBackward (float deg, int spd) {
  MDriveL.startRotateFor(directionType::rev, 720, rotationUnits::deg);
  MDriveR.rotateFor(directionType::rev, 720, rotationUnits::deg);
}
void spinForward (float deg, int spd) {
  MDriveL.startRotateFor(directionType::fwd, 1080, rotationUnits::deg);
  MDriveR.startRotateFor(directionType::fwd, 1080, rotationUnits::deg);
  MUpperIntake.startRotateFor(directionType::rev, 1080, rotationUnits::deg);
  MLowerIntake.rotateFor(directionType::rev, 1080, rotationUnits::deg);
}
void spinBackward (float deg, int spd) {
  MDriveL.startRotateFor(directionType::fwd, 1080, rotationUnits::deg);
  MDriveR.startRotateFor(directionType::fwd, 1080, rotationUnits::deg);
  MUpperIntake.spin(directionType::rev, 100, velocityUnits::pct);
  MLowerIntake.spin(directionType::rev, 100, velocityUnits::pct);
}

void stop () {
  MDriveL.stop(brakeType::hold);
  MDriveR.stop(brakeType::hold);
  MUpperIntake.stop(brakeType::hold);
  MLowerIntake.stop(brakeType::hold);
}
5 Likes

sorry for the late response. This helped a lot, thanks so much! We haven’t gotten to testing the autonomous yet but there are no errors in the code, so the problem seems to be fixed. Also, yeah the name was just to attach the project to an uploading site.