Skip to content

Commit a919b8e

Browse files
[tidy] tighten rules
1 parent 9358a3d commit a919b8e

File tree

8 files changed

+177
-299
lines changed

8 files changed

+177
-299
lines changed

.clang-tidy

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Checks: '*,
2-
-fuchsia-overloaded-operator,
3-
-misc-non-private-member-variables-in-classes,
4-
-llvmlibc-*,
5-
-modernize-use-trailing-return-type,
62
-altera-struct-pack-align,
7-
-fuchsia-trailing-return'
3+
-fuchsia-overloaded-operator,
4+
-fuchsia-trailing-return,
5+
-llvmlibc-implementation-in-namespace,
6+
-llvmlibc-restrict-system-libc-headers,
7+
-portability-simd-intrinsics'
8+
9+
CheckOptions:
10+
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
11+
value: 1

.github/workflows/verify_code_static_analysis_tidy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
run: sudo apt update
1717
- name: Install
1818
run: |
19-
sudo apt install clang-tidy-12
19+
sudo apt install clang-tidy-13
2020
( cd /tmp ; mkdir eigen ;
2121
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
2222
( cd eigen ;
@@ -28,6 +28,6 @@ jobs:
2828
- name: Tidy
2929
run: |
3030
FILES=`find . -iname *.hpp`
31-
clang-tidy-12 ${FILES} \
31+
clang-tidy-13 ${FILES} \
3232
--warnings-as-errors=* \
3333
-- -x c++ -Wall -Wextra -pedantic -std=c++2b -Iinclude -I/usr/local/include/eigen3

include/fcarouge/internal/kalman.hpp

+39-10
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,14 @@ For more information, please refer to <https://unlicense.org> */
4242
//! @file
4343
//! @brief The main Kalman filter class.
4444

45-
#include "kalman_equation.hpp"
46-
#include "kalman_operator.hpp"
47-
4845
#include <functional>
4946
#include <type_traits>
5047

5148
namespace fcarouge::internal
5249
{
5350
template <typename State, typename Output, typename Input, typename Transpose,
5451
typename Symmetrize, typename Divide, typename Identity,
55-
typename... PredictionArguments>
52+
typename Multiply, typename... PredictionArguments>
5653
struct kalman {
5754
//! @name Public Member Types
5855
//! @{
@@ -94,12 +91,18 @@ struct kalman {
9491
//! @details Also known as B.
9592
using input_control = std::invoke_result_t<Divide, State, Input>;
9693

94+
using innovation = output;
95+
using innovation_uncertainty = output_uncertainty;
96+
using gain = std::invoke_result_t<Transpose, output_model>;
97+
9798
//! @}
9899

99100
//! @name Public Member Variables
100101
//! @{
101102

102103
//! @brief The state estimate vector x.
104+
//!
105+
//! @todo Is there a simpler, more portable way to get a zero initialization?
103106
state x{ 0 * Identity().template operator()<state>() };
104107

105108
//! @brief The estimate uncertainty, covariance matrix P.
@@ -167,38 +170,64 @@ struct kalman {
167170
//! @details
168171
// Add prediction arguments?
169172
std::function<state(const state &, const state_transition &)> predict_state =
170-
[](const state &x, const state_transition &f) { return state{ f * x }; };
173+
[this](const state &x, const state_transition &f) {
174+
return state{ multiply(f, x) };
175+
};
176+
177+
Transpose transpose;
178+
Divide divide;
179+
Symmetrize symmetrize;
180+
Identity identity;
181+
Multiply multiply;
171182

172183
//! @}
173184

174185
//! @name Public Member Functions
175186
//! @{
176187

188+
//! @todo Do we want to allow the client to view the gain k? And the residual
189+
//! y?
190+
//! @todo Do we want to store i - k * h in a temporary result for reuse?
177191
inline constexpr void update(const auto &...output_z)
178192
{
193+
const auto z{ output{ output_z... } };
194+
179195
h = transition_observation_h();
180196
r = noise_observation_r();
181-
const auto z{ output{ output_z... } };
182-
internal::update<Transpose, Symmetrize, Divide, Identity>(x, p, h, r, z);
197+
198+
const innovation_uncertainty s{ h * p * transpose(h) + r };
199+
const gain k{ divide(p * transpose(h), s) };
200+
const innovation y{ z - h * x };
201+
const auto i{ identity.template operator()<estimate_uncertainty>() };
202+
203+
x = state{ x + k * y };
204+
p = symmetrize(estimate_uncertainty{
205+
(i - k * h) * p * transpose(i - k * h) + k * r * transpose(k) });
183206
}
184207

185208
inline constexpr void predict(const PredictionArguments &...arguments,
186209
const auto &...input_u)
187210
{
188211
const auto ff{ predict_state };
212+
const auto u{ input{ input_u... } };
213+
189214
f = transition_state_f(arguments...);
190215
q = noise_process_q(arguments...);
191216
g = transition_control_g(arguments...);
192-
const auto u{ input{ input_u... } };
193-
internal::predict<Transpose, Symmetrize>(x, p, ff, f, q, g, u);
217+
218+
x = state{ ff(x, f) + g * u };
219+
p = symmetrize(estimate_uncertainty{ f * p * transpose(f) + q });
194220
}
195221

196222
inline constexpr void predict(const PredictionArguments &...arguments)
197223
{
198224
const auto ff{ predict_state };
225+
199226
f = transition_state_f(arguments...);
200227
q = noise_process_q(arguments...);
201-
internal::predict<Transpose, Symmetrize>(x, p, ff, f, q);
228+
229+
x = state{ ff(x, f) };
230+
p = symmetrize(estimate_uncertainty{ f * p * transpose(f) + q });
202231
}
203232

204233
//! @}

include/fcarouge/internal/kalman_equation.hpp

-165
This file was deleted.

include/fcarouge/internal/kalman_operator.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ For more information, please refer to <https://unlicense.org> */
4444

4545
namespace fcarouge::internal
4646
{
47-
//! @brief Function object for providing an identy matrix.
47+
//! @brief Function object for providing an identity matrix.
4848
//!
4949
//! @note This function object template should be a variable template. Proposed
5050
//! in paper P2008R0 entitled "Enabling variable template template parameters".
@@ -55,9 +55,9 @@ struct identity {
5555
//!
5656
//! @return The identity matrix `diag(1, 1, ..., 1)`.
5757
template <typename Type>
58-
[[nodiscard]] inline constexpr Type operator()() const noexcept
58+
[[nodiscard]] inline constexpr auto operator()() const noexcept
5959
{
60-
return 1;
60+
return Type{ 1 };
6161
}
6262
};
6363

0 commit comments

Comments
 (0)