[sysid] Fix peak acceleration filtering behavior in dynamic velocity test (#6207)

This commit is contained in:
HarryXChen
2024-01-12 20:05:50 -05:00
committed by GitHub
parent b482321c0d
commit 84e3a22baa
2 changed files with 92 additions and 16 deletions

View File

@@ -14,6 +14,7 @@
#include <frc/filter/LinearFilter.h>
#include <frc/filter/MedianFilter.h>
#include <units/math.h>
#include <wpi/MathExtras.h>
#include <wpi/StringExtras.h>
using namespace sysid;
@@ -138,7 +139,11 @@ sysid::TrimStepVoltageData(std::vector<PreparedData>* data,
auto maxAccel = std::max_element(
data->begin(), data->end(), [](const auto& a, const auto& b) {
return std::abs(a.acceleration) < std::abs(b.acceleration);
// Since we don't know if its a forward or backwards test here, we use
// the sign of each point's velocity to determine how to compare their
// accelerations.
return wpi::sgn(a.velocity) * a.acceleration <
wpi::sgn(b.velocity) * b.acceleration;
});
units::second_t velocityDelay;