Hi all, I’m having some trouble making my auton run properly.
I have a void statement that I’m trying to run in auton that shoots triballs over for 32 seconds. No, I am not using a continuous loop. I use a void statement that shoots triballs once a distance sensor value is reached.
I’m trying to figure out how have the robot sit in one spot for 32 seconds running the void statement, then once 32 seconds is reached, i want the robot to finish it’s skills run.
I have never used timers, i’ve always just used pros::delay, but that stops the completion of the robot’s functions.
I’m not aware of a standard practice on timers in PROS, but I have always used pros::millis() to run my timers. I define a double, for instance “startTime” as the current time. Then, I say while the current time is less than startTime, perform a function. In your case, it may look like this:
void autonShootTriballs(double time=32000){ //sets parameter time default as 32 seconds
double startTime = pros::millis();
while((pros::millis() - startTime) < time){
shootFunction(); //function that fires and reloads launcher
}
pros::delay(10); //standard delay to not crash while loop
}
I wrote this on the spot, but I believe it works. This should run your shooting function for 32 seconds, and then break the while loop, allowing you to continue your skills run. Reply with any questions, hope this helps.