Libbarrett  1.2.4
include/barrett/math/first_order_filter.h
00001 /*
00002  * first_order_filter.h
00003  *
00004  *  Created on: Apr 1, 2010
00005  *      Author: dc
00006  */
00007 
00008 #ifndef BARRETT_MATH_FIRST_ORDER_FILTER_H_
00009 #define BARRETT_MATH_FIRST_ORDER_FILTER_H_
00010 
00011 
00012 #include <Eigen/Core>
00013 #include <libconfig.h++>
00014 
00015 #include <barrett/detail/ca_macro.h>
00016 #include <barrett/math/traits.h>
00017 
00018 
00019 namespace barrett {
00020 namespace  math {
00021 
00022 
00023 template<typename T, typename MathTraits = math::Traits<T> >
00024 class FirstOrderFilter {
00025 protected:
00026         typedef MathTraits MT;
00027 
00028 public:
00029         explicit FirstOrderFilter(double timeStep = 0.0);
00030         explicit FirstOrderFilter(const libconfig::Setting& setting);
00031 
00032         void setSamplePeriod(double timeStep);
00033         void setFromConfig(const libconfig::Setting& setting);
00034         void setLowPass(const T& omega_p, const T& dcGain = T(1.0));
00035         void setHighPass(const T& omega_p, const T& hfGain = T(1.0));
00036         void setZPK(const T& omega_z, const T& omega_p, const T& dcGain = T(1.0));
00037         void setIntegrator(const T& gain = T(1.0));
00038         void setParameters(const T& a, const T& b, const T& c);
00039 
00040         const T& eval(const T& input);
00041 
00042         typedef const T& result_type;  
00043         result_type operator() (const T& input) {
00044                 return eval(input);
00045         }
00046 
00047 protected:
00048         void updateCoefficients();
00049 
00050         T a, b, c;
00051         double T_s;
00052 
00053         T c1, c2, c3;
00054         T y_0, y_1, x_0, x_1;
00055 
00056 private:
00057         // TODO(dc): write a real copy constructor and assignment operator?
00058         DISALLOW_COPY_AND_ASSIGN(FirstOrderFilter);
00059 
00060 public:
00061         EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(MT::RequiresAlignment)
00062 };
00063 
00064 
00065 }
00066 }
00067 
00068 
00069 // include template definitions
00070 #include <barrett/math/detail/first_order_filter-inl.h>
00071 
00072 
00073 #endif /* BARRETT_MATH_FIRST_ORDER_FILTER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines