Wow, that’s a big statement in the title isn’t it? There could be so many mistakes one could make while programming their robot, how can somebody just simplify it to one brave title like this one? Well, I’m 100% confident about one mistake topping every other issue I’ve seen.
I’ve been observing several teams programming their bots for a while and I’ve been noticing this one issue they face time after time. But when I volunteered to be a programming skills judge in North Florida Regional Championships in February this year I got convinced that I had to warn kids about this big DANGER and so many teams made this mistake over and over.
But you may say, “enough already, just tell me what it is!!!”. Yes, yes, yes, here it comes. TIMEOUT!
– “Time out? You’ve been blabbering about the biggest mistake one could make and without revealing it you want a timeout?
– “No, no, no. The biggest mistake is indeed setting a timeout“.
So let’s stay you wrote a code that goes like:
1> Go forward 2 inches
2> Turn left 20 degrees
3> Start the intake
4> Go forward 15 inches and pick up the ball
5> Reverse 8 inches
6> Turn right 40 degrees
7> Go forward 8 inches
8> Turn right 70 degrees
9> Drive backwards 8 inches
10> Shoot the balls
However after step 4 your robot just stops, the intake is running, the ball is picked up but NOTHING ELSE is happening. You wonder what in the world is going on!!! Does it want some coffee? It’s tired and decided to take a nap in the middle of the only job it’s responsible for? Is the robot offended by something you said? Or did you just not write the step 5? You check, make sure that you did and you’re baffled. You try running again but this time it works, and it sometimes does and sometimes doesn’t. You just hope for the best, take your robot to the competition and there it goes, stage fear, indigestion? Who knows, but it just stops there again.
The reason is…….drumroll….you didn’t code a timeout.
What happens is at Step 4 you told the robot to go forward 15 inches but after 14.7 inches of a drive it hit the bar, the wheels can’t turn anymore because the bar is stopping it from moving forward and because it did not complete the directive of going forward 15 inches, it’s not allowed to move on to step 5. That’s the way the code works, each directive has to be completed before the next task can be started. Sometimes it works because these robots are not state of the art, and sometimes, especially depending on the battery performance, it will cover the 15 inches and move on to the next line but your hard work deserves 100% success, not occasional success. I saw this issue time after time while judging maybe 50-60 programs. Their robot would be stopped by an obstacle that didn’t allow a line of code to be completed it just waits there chilling, waiting for a drink, waiting for who knows what, while the hard working roboteers are baffled, sad and annoyed. Don’t let this happen to you and for that you need to setTimeout for your motor to quit trying to do what it is trying to do and move on to the next line.
And by the way timeout needs to be set BEFORE the directive it applies to, not after. So this example will apply the timeout to the direction of spinning the motors in reverse for 2.3 turns.
So say you want to reverse your robot for 2.3 turns but there is a wall there that may possibly stop you and this move takes your robot 1.5 seconds to complete with 40% velocity. If you set a 2 second timeout, in the chance that after doing 2.1 turns your robot hit the wall and it can’t move on to the next line, you’ll loose 0.5 seconds, it will stop trying to complete the line and it will continue to the next line BUT you won’t loose your entire program.
Of course as you know, a simple autonomous routine can take you like “a million” lines already so imagine having to calculate a timeout for each action and adding it to the code, that code will be impossible to read.
And that’s why we LOVE to use “My Blocks”. Check my post about that. So that you can integrate your timeouts to reusable directions instead of making the impossible to follow million lines more impossible to read while making sure your robot never takes a nap or just stop to day dream in the middle of its mission!!!