Skip to content

Commit 01430b8

Browse files
authored
Minor filter fixes + clang-format rules update (#347)
1 parent d7afc03 commit 01430b8

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ DerivePointerAlignment: false
1212
PointerAlignment: Middle
1313
ReflowComments: false
1414
IncludeBlocks: Preserve
15+
InsertBraces: true
1516
...

control_toolbox/include/control_toolbox/low_pass_filter.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ inline bool LowPassFilter<std::vector<double>>::update(
213213
// This also sets the size of the member variables to match the input data.
214214
if (filtered_value.empty())
215215
{
216+
if (std::any_of(data_in.begin(), data_in.end(), [](double val) { return !std::isfinite(val); }))
217+
{
218+
return false;
219+
}
216220
filtered_value = data_in;
217221
filtered_old_value = data_in;
218222
old_value = data_in;
@@ -230,7 +234,10 @@ inline bool LowPassFilter<std::vector<double>>::update(
230234
{
231235
data_out[i] = b1_ * old_value[i] + a1_ * filtered_old_value[i];
232236
filtered_old_value[i] = data_out[i];
233-
if (std::isfinite(data_in[i])) old_value[i] = data_in[i];
237+
if (std::isfinite(data_in[i]))
238+
{
239+
old_value[i] = data_in[i];
240+
}
234241
}
235242

236243
return true;
@@ -255,7 +262,10 @@ bool LowPassFilter<T>::update(const T & data_in, T & data_out)
255262
// Filter
256263
data_out = b1_ * old_value + a1_ * filtered_old_value;
257264
filtered_old_value = data_out;
258-
if (std::isfinite(data_in)) old_value = data_in;
265+
if (std::isfinite(data_in))
266+
{
267+
old_value = data_in;
268+
}
259269

260270
return true;
261271
}

control_toolbox/src/pid.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ void Pid::reset(bool save_i_term)
9393
cmd_ = 0.0;
9494

9595
// Check to see if we should reset integral error here
96-
if (!save_i_term) clear_saved_iterm();
96+
if (!save_i_term)
97+
{
98+
clear_saved_iterm();
99+
}
97100
}
98101

99102
void Pid::clear_saved_iterm() { i_term_ = 0.0; }

0 commit comments

Comments
 (0)