Encoder Velocity: A Common Miscalculation

Encoders are commonly used to track the position, velocity, and acceleration of motors and other mechanical objects. If you are new to the operation of encoders, please refer to the Phidgets Encoder Primer for information that may help in understanding this document.

When working with Phidget Encoders, a tempting method to calculate their velocity is to simply divide the number of pulses (or edges) by the elapsed time given by an event. However, problems arise with this method when the encoder starts and stops, or moves slowly enough that it’s hard to tell the difference.

Phidget Encoder adapters report the elapsed time between the previously reported time and the latest recorded edge. This works well for calculating the speed of encoders moving quickly enough to make one or more edges per interval. However, if the encoder adapter reports a span of time without an edge, it will begin reporting time since the last interval. In this way, blindly dividing the number of edges by the elapsed time becomes a dangerous proposition, as seen in the following diagram.

Calculating Velocity with Reported Elapsed Time

Calculating Velocity with Reported Elapsed Time

From this example, in the interval between 5-6s, the time reported by the event will only be 0.1s (the time between the start of the interval and the last edge in said interval). This results in a large spike in velocity if calculated as edges per reported time.

In order to mitigate the resulting spike in calculated velocity, it is advised to keep a record of the time since the last edge to calculate velocity, instead of directly using the elapsed time provided by the event. This can be done simply by adding the elapsed time of all intervals with zero counts to that of the first interval with a nonzero count.

As an example, the time change for velocity in the interval 5s-6s from the diagram could be calculated as:

1.7s + 1s + 0.1s = 2.8s

Which results in a calculated velocity of pulseeq

While this method is still not perfect, it is safer than doing calculations with a velocity that is potentially many orders of magnitude too large.

—James Decoux, Phidgets Inc.

Was this information helpful? Have a better solution? Please leave your thoughts in the comments below.

About

Phidgets make your ideas real. Reliable sensors, motor controllers, relays and more connect computers and technology to the real world. Applications include robotics, data acquisition, monitoring, automation, testing, teaching, art and interactive design. Simply plug in the device and write a program with the help of our robust API. Applications can be developed on Windows, OS X, Linux (including Raspberry Pi), iOS and Android. It's easy for programmers to get started using their favourite language: Android Java, Applescript, C/C++, C#, Cocoa, Delphi, Flash AS3, Java, LabVIEW, MATLAB, Max/MSP, Python, Ruby, Visual Basic.NET, Visual Basic 6.0, Visual Basic for Applications, Visual Basic Script, Visual C/C++/Borland.NET and Flowstone. Phidgets is an established company with an excellent reputation for making reliable products that last, at a very reasonable price, that get the job done. There's always stock, so you won't have to wait to get started on your project. Plus, you'll always be able to get support from a team of knowledgable engineers. With Phidgets, you'll get your project up and running in no time!

Tagged with: , , , ,
Posted in How-Tos

Leave a comment