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);
GEAR_RATIO, vex::rotationUnits::deg, AUTO_DRIVE_PCT, vex::velocityUnits::pct);

(for autonomous drive)

void Intake(int time){

(for intake)

My autonomous consist of:

void autonomous( void ) {

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.

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


I meant

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