Time Warning Controller

I am on team 80H and I am trying to make a code where once I run the code in a match at 30 seconds the controller will vibrate and say 30 seconds left, but I cannot figure it out. Can I please get some help?

Which part are you having problems with? What code do you have so far?

This should be pretty easy. Start a new task when driver starts, have it wait 45 seconds or however long you want. Then trigger whatever you want.

What I have is this pseudo code:

Task sleep 9000
Controller Rumble

So do I put a stop at the end of the task, because the rumble stops all other controls from working. What should be at the end so I can still use the controls while and after the rumble occurs

Start a new task. Handle the rumble timing in said new task.

You may be able to use something like the following in the UserControl. The ‘if’ statement prevents your code from locking up waiting for the timer.

void usercontrol( void ) {
Brain.resetTimer();
bool signaled = false;
while (1){
 
  if( Brain.timer(timeUnits::sec) == 75 && !signaled ) {
      Controller1.rumble(".-.-");
      signaled = true;
      }

      vex::task::sleep(20); 
  }
}

I’ve been trying this code and it downloads fine and doesn’t lock the robot but it won’t rumble. I do indent the reset and rumble but I don’t know how to show that in a block quote. Does anyone know why it doesn’t work?

if(Brain.timer(timeUnits::sec) == 10){
Controller1.rumble(".-.-");
Brain.resetTimer();
}

Testing for equality to a particular time will usually fail unless that line happens to be called on the exactly correct fraction of a second. You would instead want to do something that only fires once sometime after the desired time had elapsed, testing with an inequality:

hasRumbled = false
forever:
    if (elapsedTime >= threshold && hasRumbled == false) do:
        rumble
        hasRumbled = true
    end if
loop
1 Like

yes, John is correct, Brain.timer returns a double precision floating point value, testing for equality almost never works. Try this

int main() {
    int count = 0;
    Brain.resetTimer();
    bool signaled = false;

    while(1) {
        if( Brain.timer(timeUnits::sec) > 10 && !signaled ) {
          Controller1.rumble(".-.-");
          signaled = true;
        }

        Brain.Screen.printAt( 10, 50, "Hello V5 %d", count++ );
        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}
1 Like

Is there anyway of making this in Pros 3?

Of course. Just apply the same code but change the API calls. You have all the needed logic from this post, it is not hard to figure out how to apply it to pros.
Hint: pros::millis() will give you time.
Or look into okapi Timer.