1. 4 days ago

    When multitasking in robotc are you able to stop a task within itself? For example, for the code below would this task stop if the sensor touchtest is pressed? Thanks in advance for any help!

    task Check()
    {
    	while( true )
     	{
     		if( SensorValue( TouchTest ) == 1)
     		{
     			SensorValue( LiftEncoder ) = 0;
     			startTask( LiftpController );
     			stopTask( Check );
    		}
      	else if( SensorValue( TouchTest ) == 0)
      	{
    			motorReq[ TRLift ] = (-30);
      	 	motorReq[ TLAndBLLift ] = (-30);
      	 	motorReq[ BRLift ] = (-30);
      	}
      }
    }
  2. Barin

    Dec 31 Arizona 6030B

    @DavidChandler When multitasking in robotc are you able to stop a task within itself? For example, for the code below would this task stop if the sensor touchtest is pressed? Thanks in advance for any help!
    task Check() { while( true ) { if( SensorValue( TouchTest ) == 1) { SensorValue( LiftEncoder ) = 0; startTask( LiftpController ); stopTask( Check ); } else if( SensorValue( TouchTest ) == 0) { motorReq[ TRLift ] = (-30); motorReq[ TLAndBLLift ] = (-30); motorReq[ BRLift ] = (-30); } } }

    If I recall correctly, you are able to stop tasks within themselves.

  3. Okay cool. Thank you!

  4. jpearman

    Dec 31 Moderator, ROBOTC Tech Support Rockstar, Los Angeles 8888

    Yes, a task can stop itself. You can also just return from the task and that will have the same effect.

    task Check() {
      while( true ) {
        if( SensorValue( TouchTest ) == 1) {
          SensorValue( LiftEncoder ) = 0;
          startTask( LiftpController );
          return;
        }
        else if( SensorValue( TouchTest ) == 0) {
          motorReq[ TRLift ] = (-30);
          motorReq[ TLAndBLLift ] = (-30);
          motorReq[ BRLift ] = (-30);
        }
      }
    }
 

or Sign Up to reply!