add 2nd order low pass block

This commit is contained in:
Thomas Gubler
2015-09-06 15:46:59 +02:00
parent b7847e13a6
commit 040d1da8a1
2 changed files with 36 additions and 0 deletions
+8
View File
@@ -198,6 +198,14 @@ int blockHighPassTest()
return 0;
}
float BlockLowPass2::update(float input)
{
if (_lp.get_cutoff_freq() != getFCutParam()) {
_lp.set_cutoff_frequency(_fs, getFCutParam());
}
return _lp.apply(input);
}
float BlockIntegral::update(float input)
{
// trapezoidal integration
+28
View File
@@ -45,6 +45,7 @@
#include <stdlib.h>
#include <math.h>
#include <mathlib/math/test/test.hpp>
#include <mathlib/math/filter/LowPassFilter2p.hpp>
#include "block/Block.hpp"
#include "block/BlockParam.hpp"
@@ -163,6 +164,33 @@ protected:
int __EXPORT blockHighPassTest();
/**
* A 2nd order low pass filter block which uses the 2nd order low pass filter used by px4
*/
class __EXPORT BlockLowPass2 : public Block
{
public:
// methods
BlockLowPass2(SuperBlock *parent, const char *name, float sample_freq) :
Block(parent, name),
_fCut(this, ""), // only one parameter, no need to name
_fs(sample_freq),
_lp(_fs, _fCut.get())
{};
virtual ~BlockLowPass2() {};
float update(float input);
// accessors
float getFCutParam() { return _fCut.get(); }
void setState(float state) { _lp.reset(state); }
protected:
// attributes
control::BlockParamFloat _fCut;
float _fs;
math::LowPassFilter2p _lp;
};
// XXX missing test function for BlockLowPass2
/**
* A rectangular integrator.
* A limiter is built into the class to bound the