paper: Digital Filters in C++

Thread created automatically to discuss a document in CD-Media.

Digital Filters in C++
by: Jared Russell

Digital filters can help your robot to achieve new levels of performance. From smoothing a joystick for a better ride, to rejecting high frequency noise from your motor commands, there is so much you can do with these simple but powerful techniques!

Our 2009 machine achieves its traction control abilities in no small part due to digitally filtering both joystick inputs and motor outputs. Without filtering, our traction control code was very jerky - wheels would suddenly change speeds because of the nature of static vs. dynamic friction. With filtering, we glide like butter (and probably save our gearboxes from an early demise!).

Attached is a C++ class that implements digital filtering. I have tested it both on 341’s 2009 robot, and in a simulator in Visual Studio 2003. I make no claims that this software is completely bug free, and there are certainly some more features that would be nice to add later, but hopefully it is useful to someone (even if only as something to skim over and learn some new things).

This class provides a general C++ class for all sorts of digital linear filters. Both FIR and IIR filters of arbitrary topologies are supported. In addition to a free-form constructor, static “factory” methods are provided to help you create commonly used filters (currently these are an FIR moving average filter, a single-pole IIR low pass filter, and a PID controller - yes, a PID controller is just a linear filter!). I plan on adding more advanced filters (Butterworth, Chebyshev, etc.) later, but I hacked this together in a few hours late last night and decided it might be useful to somebody.

Read the documentation in DaisyFilter.h for more on the math of digital filters, along with some of the cool things you can do with them. The test program (FilterTest.cpp) should compile in Visual Studio and most other desktop environments (but do not use it on the cRIO!). It should show some examples of how to use the class.

As far as licensing goes, I’ve gone with the GPL. All that means is please don’t use this code in proprietary software (that you plan on selling), at least not without asking. Also, I am giving the normal disclaimer: this software should not be used for medical or safety-critical applications. I am not responsible for any damage to humans, robots, or small animals caused as a result of this code.

Good luck, and feel free to post your thoughts and/or questions!

DaisyFilter.zip (15.3 KB)