The programming team on our team is trying to get a timer function where we can run this code every x seconds or something like that.
We’ve searched high and low and have not been able to find a good timer code that works for us. Does anybody have any timer code that works without having a degree in nuclear physics to install and use?
This year, out team is using WPILib. It greatly simplifies the use of most everything, including timers. Read page 53 of the manual for details.
What I love about WPILib is it has simple code for timers, gyros, ultrasonic sensors – just about everything. But it was also easy to switch our code to WPILib, since you don’t have to use their simplified functions if you don’t want to. Instead of using SetPWM(1, 127), you can still say pwm01=127 if you want. I highly recommend using WPILib.
Team 1425 has as schedular function which allows a routine to be run in some amount of time in the future, or set a routine to run every so often, or some amount of time since it last ran.
We do this by having timer 1 keep a time base for us, and a scheduler routine which keeps track of function pointers for routines that are to be run at the specific times.
Getting the function pointers to work was an interesting exercise for the students, but the system works well. It is not as generic as we would have liked due to the limits imposed by the available memory (used to store the info relating to the scheduled events).
A side benefit of this code is a general set of clock routines that allow any part of our code to tell how much time has elapsed. We return ms since the robot started as a long integer.
The timer setup is all based on the timer white paper available at the ifi site.