Derivative fix: Comments and code style

This commit is contained in:
Lorenz Meier
2014-07-18 07:28:49 +02:00
parent dc612d75c7
commit 6c50e510a5
2 changed files with 22 additions and 1 deletions

View File

@@ -293,10 +293,16 @@ int blockIntegralTrapTest()
float BlockDerivative::update(float input)
{
float output = 0.0f;
float output;
if (_initialized) {
output = _lowPass.update((input - getU()) / getDt());
} else {
// if this is the first call to update
// we have no valid derivative
// and so we use the assumption the
// input value is not changing much,
// which is the best we can do here.
output = 0.0f;
_initialized = true;
}
setU(input);

View File

@@ -242,6 +242,21 @@ public:
_lowPass(this, "LP")
{};
virtual ~BlockDerivative() {};
/**
* Update the state and get current derivative
*
* This call updates the state and gets the current
* derivative. As the derivative is only valid
* on the second call to update, it will return
* no change (0) on the first. To get a closer
* estimate of the derivative on the first call,
* call setU() one time step before using the
* return value of update().
*
* @param input the variable to calculate the derivative of
* @return the current derivative
*/
float update(float input);
// accessors
void setU(float u) {_u = u;}