
Quad X Type Multicopter
Limiter/Limiter.cpp@8:1db19b529b22, 2021-02-21 (annotated)
- Committer:
- komaida424
- Date:
- Sun Feb 21 05:14:57 2021 +0000
- Revision:
- 8:1db19b529b22
- Parent:
- 6:a50e6d3924f1
rev 020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komaida424 | 4:4060309b9cc0 | 1 | #include "mbed.h" |
komaida424 | 4:4060309b9cc0 | 2 | #include "Limiter.h" |
komaida424 | 4:4060309b9cc0 | 3 | |
komaida424 | 8:1db19b529b22 | 4 | Limiter::Limiter(float RATE) |
komaida424 | 4:4060309b9cc0 | 5 | { |
komaida424 | 8:1db19b529b22 | 6 | _rate = RATE; |
komaida424 | 8:1db19b529b22 | 7 | _lastval = 0.0; |
komaida424 | 6:a50e6d3924f1 | 8 | } |
komaida424 | 6:a50e6d3924f1 | 9 | |
komaida424 | 8:1db19b529b22 | 10 | void Limiter::setup(float _cutoffreq,float _interval) |
komaida424 | 6:a50e6d3924f1 | 11 | { |
komaida424 | 8:1db19b529b22 | 12 | _period = 1 / _cutoffreq; |
komaida424 | 8:1db19b529b22 | 13 | _rate = _period / ( _period + _interval ); |
komaida424 | 8:1db19b529b22 | 14 | _lastval = 0.0; |
komaida424 | 6:a50e6d3924f1 | 15 | } |
komaida424 | 6:a50e6d3924f1 | 16 | |
komaida424 | 8:1db19b529b22 | 17 | float Limiter::calc(float _now) |
komaida424 | 4:4060309b9cc0 | 18 | { |
komaida424 | 8:1db19b529b22 | 19 | _lastval = _rate * _lastval + ( 1 - _rate ) * _now; |
komaida424 | 8:1db19b529b22 | 20 | return _lastval; |
komaida424 | 4:4060309b9cc0 | 21 | } |
komaida424 | 4:4060309b9cc0 | 22 | ; |