Skip to content

Commit

Permalink
[bugfix] complete default initialization (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed May 8, 2022
1 parent b27e69f commit 11e62e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
12 changes: 4 additions & 8 deletions include/fcarouge/internal/kalman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,18 @@ struct kalman {
//! @{

//! @brief The state estimate vector x.
state x{};
state x{ 0 * Identity<state>()() };

//! @brief The estimate uncertainty, covariance matrix P.
//!
//! @details The estimate uncertainty, covariance is also known as Σ.
estimate_uncertainty p{ Identity<estimate_uncertainty>()() };

process_uncertainty q{ 0 * Identity<process_uncertainty>()() };
output_uncertainty r{ 0 * Identity<output_uncertainty>()() };
output_model h{ Identity<output_model>()() };

output_uncertainty r{ Identity<output_uncertainty>()() };

state_transition f{ Identity<state_transition>()() };

process_uncertainty q{};

input_control g{};
input_control g{ Identity<input_control>()() };

//! @}

Expand Down
2 changes: 1 addition & 1 deletion sample/dog_position1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace
//! Gaussian.
//!
//! @example dog_position1d.cpp
[[maybe_unused]] auto dog_position{ [] {
[[maybe_unused]] auto dog_position1d{ [] {
using kalman = kalman<double>;
kalman k;

Expand Down
20 changes: 15 additions & 5 deletions test/test.cpp → test/initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,29 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org> */

#include "fcarouge/kalman.hpp"

#include <cassert>

namespace fcarouge::test
{
namespace
{
//! @test Demonstrate the code.
[[maybe_unused]] constexpr auto test = [] {
static_assert(true, "Compile-time check.");
assert(true && "Run-time check.");
//! @test Verify default values are initialized.
[[maybe_unused]] auto defaults{ [] {
using kalman = kalman<double>;
kalman k;

assert(0 == k.x() && "Origin state.");
assert(1 == k.p());
assert(0 == k.q() && "No process noise by default.");
assert(0 == k.r() && "No observation noise by default.");
assert(1 == k.f() && "");
assert(1 == k.h() && "");
assert(1 == k.g() && "");

return 0;
}();
}() };

} // namespace
} // namespace fcarouge::test

0 comments on commit 11e62e9

Please sign in to comment.