Vex PROS Blocking Commands

I was wondering how to create blocking commands in PROS. For example, waiting for the chassis to move forward before turning. Originally, we just used delays on between, but we are looking for a more efficient and accurate method of blocking commands. Thanks!

Hi! This code isn’t written by me, but by a moderator on an old post (@jpearman).

void
blockingFunction( bool waitForCompletion ) {
    int32_t _timeout = 500; // some value, this would be 5 seconds
    bool done = false;

    // do something here like start a motor moving
            
    if( waitForCompletion ) {
      // wait for completion or timeout          
      for(int t = _timeout;t >= 0 && !done; t-=10 ) {
        this_thread::sleep_for( 10 );

        // depending on the function, something will determine when it is done
        if( getCompletionCondition() )
          done = true;
      }

      // if we had timeout
      if(!done) {
        // perhaps do something on timeout
      }    
    }
}

I used this a while back and it worked great. Hope this helps!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.