RobotC Tasks bStopTasksBetweenModes

I am working on teaching some (beginning) students how to utilize tasks so they can do a §roportional loop to control a lift.

If


bStopTasksBetweenModes

is set to false in the


pre_auton()

task will the position information (variable values) in the tasks at the end of the autonomous period remain once the


usercontrol()

starts?

In other words, will the robot remember the current position of the arm when switched to driver control?

//example code
int armDest;
task armControl(){
  // variables, etc...
while(true)
{
  int currPos =  SensorValue[encoder1];
  if(abs(armDest - currPos) > 10)
     {
      motor[port1] = (armDest - currPos);
     }
  wait1Msec(20);
  }
}

One other question - Do I need to start the task in


usercontrol()

if the


autonomous()

is not called? Can I detect if a task is started using


taskStateRunning

?

Edit: code example

Yes. You will need to manually manage all user created tasks if set to false.

A few things.
global variables will always be available while the programming is running, in the code above “armDest” is a global and is available in all tasks.

using bStopTasksBetweenModes is not recommended unless you really understand what it means, your autonomous and usercontrol tasks will not be stopped when the field is disabled, if you do not manage these yourself then they may both end up running together.

This is not really a task.

task armControl(){
  // variables, etc...
  int currPos =  SensorValue[encoder1];
  if(abs(armDest - currPos) > 10)
  {
    motor[port1] = (armDest - currPos);
  }
}

Technically it is but it’s going to act like a function, when started the code will run but, as there is no while statement, it will exit and stop almost straight away, see this.
https://vexforum.com/index.php/conversation/post/122642

Local variables to a task will not be retained when a task is stopped and re-started unless the variable is declared as static.

use “getTaskState” to get the status of a task, bear in mind that only the current task will be in the taskStateRunning state (ie. you have to be running to even be able to make that function call), other tasks will usually be in the taskStateWaitingForTimer state or taskStateStopped if they really are stopped.

Thanks James.

After thinking about it the global variables are all I need to maintain (i.e. If an arm is left in an up position). And I did leave out the while loop and task delay. I will update my example.

That’s a good tip to know.

in simple code I usually just let the system stop any PID tasks etc., for more complex code I don’t use the supplied competition template anyway so the bStopTasksBetweenModes flag becomes meaningless. Just restart any PID tasks at the start of both auton and driver control.