Autonomous Coding Help!

How would I change the units in my autonomous functions from revolutions to degrees, and how would I change my parameters from rotations to seconds? And how would I make two autonomous functions run at the same time?

Here is my code:
void driving(double rotations, int speed)
{
leftFront.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false); //deg vs rev
leftBack.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
rightFront.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
rightBack.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct);
}
void turnRight(double turnDistance, int speed) {
leftFront.rotateFor(-(turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
leftBack.rotateFor(-(turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
rightFront.rotateFor(turnDistance, rotationUnits::rev, speed, velocityUnits::pct, false);
rightBack.rotateFor((turnDistance), rotationUnits::rev, speed, velocityUnits::pct, true);
}
void turnLeft(double turnDistance, int speed) {
leftFront.rotateFor((turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
leftBack.rotateFor(turnDistance, rotationUnits::rev, speed, velocityUnits::pct, false);
rightFront.rotateFor(-(turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
rightBack.rotateFor(-turnDistance, rotationUnits::rev, speed, velocityUnits::pct, true);
}
void spin(double rotations, int speed) //seconds?
{
rolltake.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
}
void flywheel(double rotations, int speed) //seconds?
{
flywheel1.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
flywheel2.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
}

Here how would I make these two lines of code run at the same time given the information above?
flywheel(400, 90);
spin(400, 90);

For future reference, format your code with ``` [code goes here] and add three more ‘`’ at the end, like this

void driving(double rotations, int speed)
{
leftFront.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false); //deg vs rev
leftBack.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
rightFront.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
rightBack.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct);
}
void turnRight(double turnDistance, int speed) {
leftFront.rotateFor(-(turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
leftBack.rotateFor(-(turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
rightFront.rotateFor(turnDistance, rotationUnits::rev, speed, velocityUnits::pct, false);
rightBack.rotateFor((turnDistance), rotationUnits::rev, speed, velocityUnits::pct, true);
}
void turnLeft(double turnDistance, int speed) {
leftFront.rotateFor((turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
leftBack.rotateFor(turnDistance, rotationUnits::rev, speed, velocityUnits::pct, false);
rightFront.rotateFor(-(turnDistance), rotationUnits::rev, speed, velocityUnits::pct, false);
rightBack.rotateFor(-turnDistance, rotationUnits::rev, speed, velocityUnits::pct, true);
}
void spin(double rotations, int speed) //seconds?
{
rolltake.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
}
void flywheel(double rotations, int speed) //seconds?
{
flywheel1.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
flywheel2.rotateFor(rotations, rotationUnits::rev, speed, velocityUnits::pct, false);
}

For changing the units from revolutions to degrees, you would use rotationUnits::deg, instead of rotationUnits::rev. For time units, you’d just use rotateFor with different parameters.

// This would set the units to degrees.
rightBack.rotateFor(rotations, rotationUnits::deg, speed, velocityUnits::pct);
// This would rotate the motor for 5 seconds.
rightBack.rotateFor(5.0, timeUnits::sec)

If by running flywheel(400, 90) and spin(400, 90) at the same time you mean having both of the motors going at once, then that alone would work since by adding false at the end of rotateFor, you’re telling the program to continue executing and not wait for the motor to complete its movement, so they’d both just run. However, if you want to run two functions performing different tasks at the same time in auton, then you’d want to use tasks. There’s lots of good info about using them in other threads.

1 Like