Making two void controls work at the same time

I’m currently trying to program autonomous, I’m struggling to find a way to make our robot move at the same time as it’s intake is running. My problem is that the programs runs separately (I want it to move and intake but it either just moves or just intakes and does the other). Here’s the program I have it at:

void DriveFoward(float inches) {
float inchesPerDegree=WHEEL_CIRCUM/360;
float degree=inches/inchesPerDegree;
FrontLeftDrive.startRotateFor(degreeGEAR_RATIO, vex::rotationUnits::deg, AUTO_DRIVE_PCT, vex::velocityUnits::pct);
FrontRightDrive.rotateFor(degree
GEAR_RATIO, vex::rotationUnits::deg, AUTO_DRIVE_PCT, vex::velocityUnits::pct);
}

(for autonomous drive)

void Intake(int time){
LeftClaw.spin(directionType::fwd,60,percentUnits::pct);
RightClaw.spin(directionType::fwd,60,percentUnits::pct);
task::sleep(uint32_t(time));
LeftClaw.stop(brakeType::hold);
RightClaw.stop(hold);

(for intake)

My autonomous consist of:

void autonomous( void ) {
DriveFoward(100);
Intake(5000);

I’d really appreciate some help on this.

You’d need to make one into a task or use thread(functionname).detach

Check this link out

Also some parts of your code isn’t right like task::sleep() should have a number between the parenthesis not uint32_t(time));

1 Like

That looks fine to me, time is a parameter passed to the function that line is in, uint_32(time) casts time to an unsigned 32-bit integer. I don’t think that’s strictly necessary but it shouldn’t break anything either.

1 Like

void Intake(int time){
LeftClaw.rotateFor(fwd, time, sec, 60, pct);
RightClaw.rotateFor(fwd, time, sec, 60, pct);
//Rotate without yielding your current thread
}

void autonomous( void ) {
Intake(5); // Start the intake before the drive since the drive yields.
DriveFoward(100);
}

That code spins one side for 5, the other for 5, and then continues with autonomous. i think you forgot the ‘false’ param

Yes

I meant

LeftClaw.rotateFor(fwd, time, sec, 60, pct, false);
RightClaw.rotateFor(fwd, time, sec, 60, pct, false);