I have come across a problem in task scheduling in the V5 Text code. I found out that I do not have to use tasks to do driving while doing other things so I took it out. I finally realized what is going wrong and want to confirm my thoughts.
It turns out that when I use the DriveRobot function shown below within a spawned task, it never gets control back after doing the wait(xx,msec) and the motors keep running forever.
The autonomous code spawns the drive task to drive for 2500 msec and does other things, then waits for the drive to be complete by using the bool AutoDriveDone = true to signify completion which never happens since the drive robot function never gets control back to stop the motors.
I am using the code “while(!AutoDriveDone){}” to wait for completion. Nothing in this loop causes a wait so that the only way the AutoDrive task can get control is for the time slice interruption to occur an have the task scheduler make the AutoDrive task active which never seems to happen. It seems that the time slice interruption is not happening or the task scheduler is not selecting the proper task to run after the interruption and goes back to the while loop rather than the wait in the DriveRobot function.
I could probably get around this by putting a short wait inside the while braces and hope that the task scheduler switches tasks correctly. I may try this after State unless I get some time to play before that.
Right now I do not need this to work as I have gotten autonomous routines to run in less than 15 seconds but would like to report this to someone as I believe that this uncovers an error in the task scheduler code inside the V5 Text program. It may not be scheduling correctly the tasks in other situations.
Any ideas on who to report this to? I will try to use their feedback procedure and see if anything turns up.
Dennis Team VEX 1102X
Here is a snapshot of the code I am using:
bool AutoDriveDone = true;
int AutoDrive1(void){ AutoDriveDone = false; DriveRobot(80,0,2500.0);return 1;}
////
// Drive robot using the data passed to it //
////
void DriveRobot(int Forward, int Turn, double DriveTime) {
int RightPower = Forward - Turn; //* Right Drive //
int LeftPower = Forward + Turn; // Left Drive //
// Now go set the motors as desired *//
LeftDrive.setVelocity(LeftPower, percent);
RightDrive.setVelocity(RightPower, percent);
LeftDrive.setMaxTorque(100, percent);
RightDrive.setMaxTorque(100, percent);
LeftDrive.spin(forward);
RightDrive.spin(forward);
if (DriveTime == 0.0) { AutoDriveDone = true; return; }
// wait before stopping the motors
wait(DriveTime, msec);
LeftDrive.stop(brake);
RightDrive.stop(brake);
AutoDriveDone = true;
}
void AutonomousBlueLeft(){
MoveCubeAway();
AwakenStepOne();
StartIntake(100);
task AutoDrive11(AutoDrive1); //* Go Forward 40 inches NEVER STOPS DRIVING***
AwakenStepTwo();
while (!AutoDriveDone) {}
StopIntake();
…More Code
}