diff options
author | Thomas Gubler <thomasgubler@gmail.com> | 2014-07-18 00:15:16 +0200 |
---|---|---|
committer | Thomas Gubler <thomasgubler@gmail.com> | 2014-07-18 00:15:16 +0200 |
commit | dc612d75c788bc8b2a90c200a13a5a5a0e3a68d9 (patch) | |
tree | 010257aa55f8fd4bcdf105a978651660db9840f5 /src/modules/controllib | |
parent | 213fe0cc20ada8b8581a65f73c68b4efe6508405 (diff) | |
download | px4-firmware-dc612d75c788bc8b2a90c200a13a5a5a0e3a68d9.tar.gz px4-firmware-dc612d75c788bc8b2a90c200a13a5a5a0e3a68d9.tar.bz2 px4-firmware-dc612d75c788bc8b2a90c200a13a5a5a0e3a68d9.zip |
BlockDerivative: initialize in first run
Diffstat (limited to 'src/modules/controllib')
-rw-r--r-- | src/modules/controllib/blocks.cpp | 7 | ||||
-rw-r--r-- | src/modules/controllib/blocks.hpp | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/modules/controllib/blocks.cpp b/src/modules/controllib/blocks.cpp index c6c374300..04cb023a8 100644 --- a/src/modules/controllib/blocks.cpp +++ b/src/modules/controllib/blocks.cpp @@ -293,7 +293,12 @@ int blockIntegralTrapTest() float BlockDerivative::update(float input) { - float output = _lowPass.update((input - getU()) / getDt()); + float output = 0.0f; + if (_initialized) { + output = _lowPass.update((input - getU()) / getDt()); + } else { + _initialized = true; + } setU(input); return output; } diff --git a/src/modules/controllib/blocks.hpp b/src/modules/controllib/blocks.hpp index 66e929038..b0545b60a 100644 --- a/src/modules/controllib/blocks.hpp +++ b/src/modules/controllib/blocks.hpp @@ -238,6 +238,7 @@ public: BlockDerivative(SuperBlock *parent, const char *name) : SuperBlock(parent, name), _u(0), + _initialized(false), _lowPass(this, "LP") {}; virtual ~BlockDerivative() {}; @@ -249,6 +250,7 @@ public: protected: // attributes float _u; /**< previous input */ + bool _initialized; BlockLowPass _lowPass; /**< low pass filter */ }; |