Velocity Calculation

Does anyone know of a way to get velocity from a simple wheel encoder using WPILib. I know how to do it using timer interrupts but since they are disabled I have not found a simple solution to getting the velocity of a wheel.

Any help would be greatly appreciated.

The velocity is basically the number of ticks / time. If you are taking readings over time, you can use deltaTicks / deltaTime. deltaTicks is the number of ticks between readings, and deltaTime is the amount of time between readings.

To get the time there are a few functions, GetMsClock() to return the running time in millisecods. Alternatively you can use StartTimer(), StopTimer(), GetTimer(), and PresetTimer() to return time in milliseconds.

To improve the accuracy, try to make the time between samples as long as you can, since very short sample times will compound the errors in reading the timers and reading the encoders. Longer sample time will have the same errors, but only once over a much longer time. If you only do the velocity calculation every 200ms it should be pretty accurate.

With the timer functions, you can Preset a timer to 0 each time you do the calculation, and wait until it gets to 200 then calculate again.

Does this solve the problem?

Yes this does help. It is one solution I was thinking of but did not know how to implement it easily but I think I got it know.

Thank you for the advice.