I have been experimenting with the multitasking functions in RobotC but ran into some trouble. I know that it is probably very common this year to be using this method, so I was hoping I could get some help.
I ran into an issue where the task (I think) is not being executed enough or not using as much of the CPU as I think it should be. It runs with a sort of sputtering motion, pausing for very short intervals, just enough to slow down the process. I have tried to use the
hogCPU()
command, but to be honest, I think I’m really just guessing around at this point. I also cannot find a definite answer for the difference between the
endTimeSlice()
and
abortTimeSlice()
commands.
For my specific usage, I am attempting to load balls into both of my separate launchers. At the same time, I want to have full capability of everything else on the robot (which is located in my main task along with drive code as well). This means that I wouldn’t need to take the extra few seconds on the alliance tile to load, but instead, will be loading on the go. Sort of like a run and gun sort of deal. This is far to difficult to do manually (Unless I had an extra hand, literally or figuratively) so I was thinking that multiple tasks would be an excellent place to start.
Here is the code for the one with sputtering issues
task ludicrousFire(){
while(true){
if(vexRT[Btn6U]){
motor[port2] = 127;
motor[port3] = -127;
motor[port4] = 127;
if(SensorValue(touchLeft) && ballInQueue){
motor[scoopEnd] = 127;
wait1Msec(600);
}
}
EndTimeSlice();
}
}
And another bit of code I have been messing around with.
task ludicrousLoad()
{
leftIsReady = true;
rightIsReady = false;
while(true){
if(vexRT[Btn6D]){
const int trackerThreshold=800;
if(SensorValue(lineTracker1)>trackerThreshold){
while(SensorValue(lineTracker1)>trackerThreshold){
motor[scoop]=-127;
}
if(leftIsReady){
motor[scoopEnd]=127;
}
}
else if(SensorValue(lineTracker1)<trackerThreshold){
if(leftIsReady){
motor[scoopEnd]=127;
}
else if(rightIsReady){
motor[scoopEnd]=-127;
}
}
}
EndTimeSlice();
}
}
For this last task, I was trying to use a line sensor to sense whether or not a ball was ready to be loaded, and then load the ball into the corresponding launcher. Unfortunately, only the first part of the if statement seemed to be getting executed. The intake would turn until the ball was in the right spot, shut off, and then nothing would happen. As you can see, I even defined the booleans for each subsequent statement, so that seemed not to be the problem.
Here is my full main task
task usercontrol()
{
int threshold = 10;
while(true){
if(abs(vexRT[Ch2]) > threshold || abs(vexRT[Ch4]) > threshold){
motor[frontleft] = (vexRT[Ch2] + vexRT[Ch4]); // (y + x)/2
motor[backleft] = (vexRT[Ch2] + vexRT[Ch4]); // (y + x)/2
motor[frontright] = (vexRT[Ch2] - vexRT[Ch4]); // (y - x)/2
motor[backright] = (vexRT[Ch2] - vexRT[Ch4]); // (y - x)/2
}
else{
motor[frontright] = 0;
motor[frontleft] = 0;
motor[backright] = 0;
motor[backleft] = 0;
}
//////////////////////////////////////////////////////////////////////
if(SensorValue(lineTracker1)<600){
ballInQueue = true;
}
else{
ballInQueue = false;
}
startTask(ludicrousLoad);
startTask(ludicrousFire);
if(vexRT[Btn8L]==1){
motor[scoopEnd]=127;
}
if(vexRT[Btn8R]==1){
motor[scoopEnd]=-127;
}
else if(vexRT[Btn8L]==0 && vexRT[Btn8R]==0){
motor[scoopEnd] = 0;
}
if(vexRT[Btn5U]==1){
motor[scoop]=127;
}
if(vexRT[Btn5D]==1){
motor[scoop]=-127;
}
else if(vexRT[Btn5U]==0 && vexRT[Btn5D]==0){
motor[scoop] = 0;
}
if (vexRT[Btn7R] == 1){
motor[port2] = -127;
motor[port3] = 127;
motor[port4] = -127;
}
else if (vexRT[Btn7L] == 1){
motor[port2] = 127;
motor[port3] = -127;
motor[port4] = 127;
}
else if (vexRT[Btn7L] == 0 && vexRT[Btn7L] == 0){
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
}
if(vexRT[Btn7U] == 1){
motor[scoop] = -127;
motor[scoopEnd] = -127;
wait1Msec(500);
motor[scoopEnd] = 0;
wait1Msec(300);
motor[scoopEnd] = 127;
motor[scoop] = 0;
motor[port2] = 127;
motor[port3] = -127;
motor[port4] = 127;
wait1Msec(700);
wait1Msec(550);
}
if(vexRT[Btn7D] == 1){
motor[port2] = 127;
motor[port3] = -127;
motor[port4] = 127;
wait1Msec(700);
//motor[scoopEnd] = -127;
wait1Msec(550);
}
EndTimeSlice();
}
}
I believe very well that my problem lies in the
EndTimeSlice()
and
abortTimeSlice()
commands and where I put them for each case. In the main task, I have the
EndTimeSlice()
command in the last line before the while loop is closed off. So, for clarification, it is inside the while loop.
Thanks for reading this and/or helping if you decided to do so.
1390 Omicron Theta, Galactic ltd.