18 #ifndef _GAZEBO_FILTER_HH_
19 #define _GAZEBO_FILTER_HH_
44 public:
virtual void SetValue(
const T &_val) { y0 = _val; }
49 public:
virtual void SetFc(
double _fc,
double _fs) = 0;
53 public:
inline virtual const T&
GetValue() {
return y0; }
74 this->SetFc(_fc, _fs);
78 public:
virtual void SetFc(
double _fc,
double _fs)
80 b1 = exp(-2.0 * M_PI * _fc / _fs);
87 public:
inline const T&
Process(
const T &_x)
89 this->y0 = a0 * _x + b1 * this->y0;
157 : a0(0), a1(0), a2(0), b0(0), b1(0), b2(0)
165 : a0(0), a1(0), a2(0), b0(0), b1(0), b2(0)
167 this->SetFc(_fc, _fs);
171 public:
inline void SetFc(
double _fc,
double _fs)
173 this->SetFc(_fc, _fs, 0.5);
180 public:
inline void SetFc(
double _fc,
double _fs,
double _q)
182 double k = tan(M_PI * _fc / _fs);
183 double kQuadDenom = k * k + k / _q + 1.0;
184 this->a0 = k * k/ kQuadDenom;
185 this->a1 = 2 * this->a0;
188 this->b1 = 2 * (k * k - 1.0) / kQuadDenom;
189 this->b2 = (k * k - k / _q + 1.0) / kQuadDenom;
196 this->y0 = this->y1 = this->y2 = this->x1 = this->x2 = _val;
202 public:
inline virtual const T&
process(
const T &_x)
204 this->y0 = this->a0 * _x +
205 this->a1 * this->x1 +
206 this->a2 * this->x2 -
207 this->b1 * this->y1 -
218 protected:
double a0, a1, a2, b0, b1,
b2;
221 protected: T x1, x2, y1,
y2;
OnePoleVector3()
Constructor.
Definition: Filter.hh:134
OnePoleQuaternion(double _fc, double _fs)
Constructor.
Definition: Filter.hh:113
virtual const T & GetValue()
Get the output of the filter.
Definition: Filter.hh:53
BiQuad vector3 filter.
Definition: Filter.hh:226
static Quaternion Slerp(double _fT, const Quaternion &_rkP, const Quaternion &_rkQ, bool _shortestPath=false)
Spherical linear interpolation between 2 quaternions, given the ends and an interpolation parameter b...
One-pole quaternion filter.
Definition: Filter.hh:102
const T & Process(const T &_x)
Update the filter's output.
Definition: Filter.hh:87
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
T y0
Output.
Definition: Filter.hh:56
double b1
Gain of the feedback.
Definition: Filter.hh:97
double a0
Input gain control.
Definition: Filter.hh:94
virtual void SetFc(double _fc, double _fs)
Set the cutoff frequency and sample rate.
Definition: Filter.hh:78
OnePoleVector3(double _fc, double _fs)
Constructor.
Definition: Filter.hh:142
Bi-quad filter base class.
Definition: Filter.hh:153
virtual void SetValue(const T &_val)
Set the current filter's output.
Definition: Filter.hh:194
OnePole()
Constructor.
Definition: Filter.hh:66
BiQuad(double _fc, double _fs)
Constructor.
Definition: Filter.hh:164
A one-pole DSP filter.
Definition: Filter.hh:63
#define GZ_MATH_VISIBLE
Definition: system.hh:134
BiQuadVector3()
Constructor.
Definition: Filter.hh:229
double b2
Definition: Filter.hh:218
virtual const T & process(const T &_x)
Update the filter's output.
Definition: Filter.hh:202
BiQuad()
Constructor.
Definition: Filter.hh:156
One-pole vector3 filter.
Definition: Filter.hh:131
T y2
Definition: Filter.hh:221
A quaternion class.
Definition: Quaternion.hh:42
void SetFc(double _fc, double _fs)
Set the cutoff frequency and sample rate.
Definition: Filter.hh:171
virtual void SetValue(const T &_val)
Set the output of the filter.
Definition: Filter.hh:44
const math::Quaternion & Process(const math::Quaternion &_x)
Update the filter's output.
Definition: Filter.hh:122
virtual ~Filter()
Destructor.
Definition: Filter.hh:40
OnePole(double _fc, double _fs)
Constructor.
Definition: Filter.hh:71
OnePoleQuaternion()
Constructor.
Definition: Filter.hh:105
BiQuadVector3(double _fc, double _fs)
Constructor.
Definition: Filter.hh:237
Filter base class.
Definition: Filter.hh:37
void SetFc(double _fc, double _fs, double _q)
Set the cutoff frequency, sample rate and Q coefficient.
Definition: Filter.hh:180