So VEX roboteers have 3 categories to compete in. Teamwork challenges, driving skills (when one driver tries to score as high as possible driving the robot) and programming skills (robot is programmed to drive autonomously) and all are given 1:00 minutes. So parents, teachers, teammates are constantly with a timer in their hands trying to time every run right? But a good team will do a million practice runs to get good at it and it’s annoying to time it everytime! But I got good news for the programmers. When you are on an autonomous run, you can put down your timer and let your robot do the work for you and never ever have to say “Hey, stop! Start again, I forgot to start the timer!” How? Here we go:
So here is the explanation.
We are using a touch sensor to start our program. I called this touch sensor “violetHang”. When the program is started the first line of code sets the color to blue violet so we can recognize which sensor we are talking about (usually we use multiple touch sensors).
Set print precision to 0.01 means I want the timer to give me results with 2 decimal places. So instead of a rounded up 16 seconds I want it to say 16.31 seconds.
On the next line I place the cursor (the point where it will start writing stuff on your robot’s brain) to first row, first column. Then I make it write “Run duration:” on the brain and then I reset the timer.
Then the moment “violetHang” sesnsor is pressed code will reset the timer. Code after there is pink instead of blue because we are using “my blocks” usually instead of the standard motor or drivetrain functions, and when the whole code is finished it will type the total time on the brain. So after each run, all you have to do is look at your brain to see how long your run took rather than having to use a stopwatch.
In the photo above my example code took the robot 17.72 seconds to complete and in this example I didn’t add the “print run duration” line.
So one less thing for us lazy programmers to worry about. But isn’t this why we are programmers? So we can do less and have our robots do more of the work, right?
By the way, if you like this method a lot, you could set up a sensor to be your stopwatch even when you are driving. Reset timer when sensor is pressed and print time on the brain when sensor is pressed again. This is a bit similar to dealing with a stopwatch but at least you don’t have to look around for the stopwatch and it will be really accurate!