I am trying to include vex::task::sleep(25); inside the while loop to multi-task during driver skills. I thought it is a default function just like the delay function. However, when I build it, it says that it is not defined within the scope. How can I fix this problem?
If you are doing this in a multi-threaded enviroment, then use this_thread::sleep() opposed to vex::task::sleep
Do I have to set up anything with this? Or it is just a default function?
You mention PROS in the topic title, are you using PROS or VEXcode ?
If VEXcode, then to add a delay use either
this_thread::sleep_for(10); // 10mS delay
or
task::sleep(10); // 10mS delay
they do exactly the same thing.
I am using pros. When I use task::sleep, it says that it is not defined within the scope.
well, yes, that’s because task::sleep is not a PROS API. A delay in PROS is
pros::delay(10); // 10mS delay
Oh, then I might want to find another way through the problem that I am having now.
I have a nested while loop in the driver loop for manipulating the flywheel velocity. During skills run, it would take approx 4-6 sec to exit the loop (during this time the robot doesn’t move) and we want to eliminate this. Do you have any suggestions?
post the code so we can see what you are doing.
void opcontrol() {
int intakestate = 0;
int flywheelstate = 0;
int revintakestate = 0;
int expansion = 0;
pusharm.set_value(0);
while (true) {
if(master.get_digital_new_press(DIGITAL_L1) == 1){
if (flywheelstate == 0) {
flywheelstate = 1;
flywheelControl2 (160,1.7);
}
else if(flywheelstate == 1) {
flywheelstate = 0;
flywheelmtr = 0;
}
}
}
the code for flywheelControl2
void flywheelControl2 (int targetSpeed, double skp) {
float sensitivity = 0.5;
float tolerance = 2;
double currentSpeed = fabs(flywheelmtr.get_actual_velocity());
double motorPower = 0;
while (fabs(currentSpeed) > (targetSpeed + tolerance) || fabs(currentSpeed) < (targetSpeed - tolerance)) {
//task_delay_until(20)
if (currentSpeed > (targetSpeed + tolerance)) {
motorPower = fabs(motorPower)/skp;
}
if (currentSpeed < (targetSpeed - tolerance)){
motorPower = fabs(motorPower) + sensitivity;
}
currentSpeed = fabs(flywheelmtr.get_actual_velocity());
flywheelmtr.move_velocity(-motorPower);
delay(20);
}
}
you are not spawning a new thread anywhere in the code you have provided.
if multi-tasking is your end goal, have a look at the docs i have linked below.
https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html