mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -31,16 +31,16 @@
|
||||
|
||||
namespace gui = wpi::gui;
|
||||
|
||||
static std::unique_ptr<glass::WindowManager> gWindowManager;
|
||||
static std::unique_ptr<wpi::glass::WindowManager> gWindowManager;
|
||||
|
||||
glass::Window* gLogLoaderWindow;
|
||||
glass::Window* gDataSelectorWindow;
|
||||
glass::Window* gAnalyzerWindow;
|
||||
glass::Window* gProgramLogWindow;
|
||||
static glass::MainMenuBar gMainMenu;
|
||||
wpi::glass::Window* gLogLoaderWindow;
|
||||
wpi::glass::Window* gDataSelectorWindow;
|
||||
wpi::glass::Window* gAnalyzerWindow;
|
||||
wpi::glass::Window* gProgramLogWindow;
|
||||
static wpi::glass::MainMenuBar gMainMenu;
|
||||
|
||||
glass::LogData gLog;
|
||||
wpi::Logger gLogger;
|
||||
wpi::glass::LogData gLog;
|
||||
wpi::util::Logger gLogger;
|
||||
|
||||
const char* GetWPILibVersion();
|
||||
|
||||
@@ -57,7 +57,7 @@ std::string_view GetResource_sysid_512_png();
|
||||
void Application(std::string_view saveDir) {
|
||||
// Create the wpigui (along with Dear ImGui) and Glass contexts.
|
||||
gui::CreateContext();
|
||||
glass::CreateContext();
|
||||
wpi::glass::CreateContext();
|
||||
|
||||
// Add icons
|
||||
gui::AddIcon(sysid::GetResource_sysid_16_png());
|
||||
@@ -68,37 +68,37 @@ void Application(std::string_view saveDir) {
|
||||
gui::AddIcon(sysid::GetResource_sysid_256_png());
|
||||
gui::AddIcon(sysid::GetResource_sysid_512_png());
|
||||
|
||||
glass::SetStorageName("sysid");
|
||||
glass::SetStorageDir(saveDir.empty() ? gui::GetPlatformSaveFileDir()
|
||||
wpi::glass::SetStorageName("sysid");
|
||||
wpi::glass::SetStorageDir(saveDir.empty() ? gui::GetPlatformSaveFileDir()
|
||||
: saveDir);
|
||||
|
||||
// Add messages from the global sysid logger into the Log window.
|
||||
gLogger.SetLogger([](unsigned int level, const char* file, unsigned int line,
|
||||
const char* msg) {
|
||||
const char* lvl = "";
|
||||
if (level >= wpi::WPI_LOG_CRITICAL) {
|
||||
if (level >= wpi::util::WPI_LOG_CRITICAL) {
|
||||
lvl = "CRITICAL: ";
|
||||
} else if (level >= wpi::WPI_LOG_ERROR) {
|
||||
} else if (level >= wpi::util::WPI_LOG_ERROR) {
|
||||
lvl = "ERROR: ";
|
||||
} else if (level >= wpi::WPI_LOG_WARNING) {
|
||||
} else if (level >= wpi::util::WPI_LOG_WARNING) {
|
||||
lvl = "WARNING: ";
|
||||
} else if (level >= wpi::WPI_LOG_INFO) {
|
||||
} else if (level >= wpi::util::WPI_LOG_INFO) {
|
||||
lvl = "INFO: ";
|
||||
} else if (level >= wpi::WPI_LOG_DEBUG) {
|
||||
} else if (level >= wpi::util::WPI_LOG_DEBUG) {
|
||||
lvl = "DEBUG: ";
|
||||
}
|
||||
std::string filename = std::filesystem::path{file}.filename().string();
|
||||
gLog.Append(fmt::format("{}{} ({}:{})\n", lvl, msg, filename, line));
|
||||
#ifndef NDEBUG
|
||||
wpi::print(stderr, "{}{} ({}:{})\n", lvl, msg, filename, line);
|
||||
wpi::util::print(stderr, "{}{} ({}:{})\n", lvl, msg, filename, line);
|
||||
#endif
|
||||
});
|
||||
|
||||
gLogger.set_min_level(wpi::WPI_LOG_DEBUG);
|
||||
gLogger.set_min_level(wpi::util::WPI_LOG_DEBUG);
|
||||
|
||||
// Initialize window manager and add views.
|
||||
auto& storage = glass::GetStorageRoot().GetChild("SysId");
|
||||
gWindowManager = std::make_unique<glass::WindowManager>(storage);
|
||||
auto& storage = wpi::glass::GetStorageRoot().GetChild("SysId");
|
||||
gWindowManager = std::make_unique<wpi::glass::WindowManager>(storage);
|
||||
gWindowManager->GlobalInit();
|
||||
|
||||
auto logLoader = std::make_unique<sysid::LogLoader>(storage, gLogger);
|
||||
@@ -122,7 +122,7 @@ void Application(std::string_view saveDir) {
|
||||
gAnalyzerWindow = gWindowManager->AddWindow("Analyzer", std::move(analyzer));
|
||||
|
||||
gProgramLogWindow = gWindowManager->AddWindow(
|
||||
"Program Log", std::make_unique<glass::LogView>(&gLog));
|
||||
"Program Log", std::make_unique<wpi::glass::LogView>(&gLog));
|
||||
|
||||
// Set default positions and sizes for windows.
|
||||
|
||||
@@ -194,7 +194,7 @@ void Application(std::string_view saveDir) {
|
||||
ImGui::Separator();
|
||||
ImGui::Text("v%s", GetWPILibVersion());
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Save location: %s", glass::GetStorageDir().c_str());
|
||||
ImGui::Text("Save location: %s", wpi::glass::GetStorageDir().c_str());
|
||||
if (ImGui::Button("Close")) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
@@ -206,7 +206,7 @@ void Application(std::string_view saveDir) {
|
||||
sysid::kAppWindowSize.y);
|
||||
gui::Main();
|
||||
|
||||
glass::DestroyContext();
|
||||
wpi::glass::DestroyContext();
|
||||
gui::DestroyContext();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ void sysid::SaveFile(std::string_view contents,
|
||||
// Open a fd_ostream to write to file.
|
||||
std::error_code ec;
|
||||
// NOLINTNEXTLINE(build/include_what_you_use)
|
||||
wpi::raw_fd_ostream ostream{path.string(), ec};
|
||||
wpi::util::raw_fd_ostream ostream{path.string(), ec};
|
||||
|
||||
// Check error code.
|
||||
if (ec) {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
using namespace sysid;
|
||||
|
||||
static double Lerp(units::second_t time,
|
||||
static double Lerp(wpi::units::second_t time,
|
||||
std::vector<MotorData::Run::Sample<double>>& data) {
|
||||
auto next = std::find_if(data.begin(), data.end(), [&](const auto& entry) {
|
||||
return entry.time > time;
|
||||
@@ -36,7 +36,7 @@ static double Lerp(units::second_t time,
|
||||
|
||||
const auto prev = next - 1;
|
||||
|
||||
return wpi::Lerp(prev->measurement, next->measurement,
|
||||
return wpi::util::Lerp(prev->measurement, next->measurement,
|
||||
(time - prev->time) / (next->time - prev->time));
|
||||
}
|
||||
|
||||
@@ -79,21 +79,21 @@ static std::vector<PreparedData> ConvertToPrepared(const MotorData& data) {
|
||||
|
||||
/**
|
||||
* To preserve a raw copy of the data, this method saves a raw version
|
||||
* in the dataset StringMap where the key of the raw data starts with "raw-"
|
||||
* in the dataset wpi::util::StringMap where the key of the raw data starts with "raw-"
|
||||
* before the name of the original data.
|
||||
*
|
||||
* @tparam S The size of the array data that's being used
|
||||
*
|
||||
* @param dataset A reference to the dataset being used
|
||||
*/
|
||||
static void CopyRawData(wpi::StringMap<MotorData>* dataset) {
|
||||
static void CopyRawData(wpi::util::StringMap<MotorData>* dataset) {
|
||||
auto& data = *dataset;
|
||||
// Loads the Raw Data
|
||||
for (auto& it : data) {
|
||||
auto& key = it.first;
|
||||
auto& motorData = it.second;
|
||||
|
||||
if (!wpi::contains(key, "raw")) {
|
||||
if (!wpi::util::contains(key, "raw")) {
|
||||
data[fmt::format("raw-{}", key)] = motorData;
|
||||
data[fmt::format("original-raw-{}", key)] = motorData;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ static Storage CombineDatasets(const std::vector<PreparedData>& slowForward,
|
||||
}
|
||||
|
||||
void AnalysisManager::PrepareGeneralData() {
|
||||
wpi::StringMap<std::vector<PreparedData>> preparedData;
|
||||
wpi::util::StringMap<std::vector<PreparedData>> preparedData;
|
||||
|
||||
WPI_INFO(m_logger, "{}", "Preprocessing raw data.");
|
||||
|
||||
@@ -167,11 +167,11 @@ void AnalysisManager::PrepareGeneralData() {
|
||||
preparedData["raw-dynamic-reverse"][0].timestamp};
|
||||
}
|
||||
|
||||
AnalysisManager::AnalysisManager(Settings& settings, wpi::Logger& logger)
|
||||
AnalysisManager::AnalysisManager(Settings& settings, wpi::util::Logger& logger)
|
||||
: m_logger{logger}, m_settings{settings} {}
|
||||
|
||||
AnalysisManager::AnalysisManager(TestData data, Settings& settings,
|
||||
wpi::Logger& logger)
|
||||
wpi::util::Logger& logger)
|
||||
: m_data{std::move(data)}, m_logger{logger}, m_settings{settings} {
|
||||
// Reset settings for Dynamic Test Limits
|
||||
m_settings.stepTestDuration = 0_s;
|
||||
|
||||
@@ -27,13 +27,13 @@ ArmSim::ArmSim(double Ks, double Kv, double Ka, double Kg, double offset,
|
||||
Reset(initialPosition, initialVelocity);
|
||||
}
|
||||
|
||||
void ArmSim::Update(units::volt_t voltage, units::second_t dt) {
|
||||
void ArmSim::Update(wpi::units::volt_t voltage, wpi::units::second_t dt) {
|
||||
// Returns arm acceleration under gravity
|
||||
auto f = [=, this](
|
||||
const Eigen::Vector<double, 2>& x,
|
||||
const Eigen::Vector<double, 1>& u) -> Eigen::Vector<double, 2> {
|
||||
return Eigen::Vector<double, 2>{
|
||||
x(1), (m_A * x.block<1, 1>(1, 0) + m_B * u + m_c * wpi::sgn(x(1)) +
|
||||
x(1), (m_A * x.block<1, 1>(1, 0) + m_B * u + m_c * wpi::util::sgn(x(1)) +
|
||||
m_d * std::cos(x(0) + m_offset))(0)};
|
||||
};
|
||||
|
||||
@@ -42,7 +42,7 @@ void ArmSim::Update(units::volt_t voltage, units::second_t dt) {
|
||||
// small for ill-conditioned data (e.g., high velocities with sharp spikes in
|
||||
// acceleration).
|
||||
Eigen::Vector<double, 1> u{voltage.value()};
|
||||
m_x = frc::RKDP(f, m_x, u, dt, 0.25);
|
||||
m_x = wpi::math::RKDP(f, m_x, u, dt, 0.25);
|
||||
}
|
||||
|
||||
double ArmSim::GetPosition() const {
|
||||
@@ -53,10 +53,10 @@ double ArmSim::GetVelocity() const {
|
||||
return m_x(1);
|
||||
}
|
||||
|
||||
double ArmSim::GetAcceleration(units::volt_t voltage) const {
|
||||
double ArmSim::GetAcceleration(wpi::units::volt_t voltage) const {
|
||||
Eigen::Vector<double, 1> u{voltage.value()};
|
||||
return (m_A * m_x.block<1, 1>(1, 0) + m_B * u +
|
||||
m_c * wpi::sgn(GetVelocity()) + m_d * std::cos(m_x(0) + m_offset))(0);
|
||||
m_c * wpi::util::sgn(GetVelocity()) + m_d * std::cos(m_x(0) + m_offset))(0);
|
||||
}
|
||||
|
||||
void ArmSim::Reset(double position, double velocity) {
|
||||
|
||||
@@ -20,16 +20,16 @@ ElevatorSim::ElevatorSim(double Ks, double Kv, double Ka, double Kg,
|
||||
Reset(initialPosition, initialVelocity);
|
||||
}
|
||||
|
||||
void ElevatorSim::Update(units::volt_t voltage, units::second_t dt) {
|
||||
void ElevatorSim::Update(wpi::units::volt_t voltage, wpi::units::second_t dt) {
|
||||
Eigen::Vector<double, 1> u{voltage.value()};
|
||||
|
||||
// Given dx/dt = Ax + Bu + c sgn(x) + d,
|
||||
// x_k+1 = e^(AT) x_k + A^-1 (e^(AT) - 1) (Bu + c sgn(x) + d)
|
||||
Eigen::Matrix<double, 2, 2> Ad;
|
||||
Eigen::Matrix<double, 2, 1> Bd;
|
||||
frc::DiscretizeAB<2, 1>(m_A, m_B, dt, &Ad, &Bd);
|
||||
wpi::math::DiscretizeAB<2, 1>(m_A, m_B, dt, &Ad, &Bd);
|
||||
m_x = Ad * m_x + Bd * u +
|
||||
Bd * m_B.householderQr().solve(m_c * wpi::sgn(GetVelocity()) + m_d);
|
||||
Bd * m_B.householderQr().solve(m_c * wpi::util::sgn(GetVelocity()) + m_d);
|
||||
}
|
||||
|
||||
double ElevatorSim::GetPosition() const {
|
||||
@@ -40,9 +40,9 @@ double ElevatorSim::GetVelocity() const {
|
||||
return m_x(1);
|
||||
}
|
||||
|
||||
double ElevatorSim::GetAcceleration(units::volt_t voltage) const {
|
||||
double ElevatorSim::GetAcceleration(wpi::units::volt_t voltage) const {
|
||||
Eigen::Vector<double, 1> u{voltage.value()};
|
||||
return (m_A * m_x + m_B * u + m_c * wpi::sgn(GetVelocity()) + m_d)(1);
|
||||
return (m_A * m_x + m_B * u + m_c * wpi::util::sgn(GetVelocity()) + m_d)(1);
|
||||
}
|
||||
|
||||
void ElevatorSim::Reset(double position, double velocity) {
|
||||
|
||||
@@ -32,10 +32,10 @@ FeedbackGains sysid::CalculatePositionFeedbackGains(
|
||||
// instabilities in the LQR.
|
||||
if (std::abs(Ka) < 1e-7) {
|
||||
// System has position state and velocity input
|
||||
frc::LinearSystem<1, 1, 1> system{Matrix1d{0.0}, Matrix1d{1.0},
|
||||
wpi::math::LinearSystem<1, 1, 1> system{Matrix1d{0.0}, Matrix1d{1.0},
|
||||
Matrix1d{1.0}, Matrix1d{0.0}};
|
||||
|
||||
frc::LinearQuadraticRegulator<1, 1> controller{
|
||||
wpi::math::LinearQuadraticRegulator<1, 1> controller{
|
||||
system, {params.qp}, {params.r}, preset.period};
|
||||
controller.LatencyCompensate(system, preset.period,
|
||||
preset.measurementDelay);
|
||||
@@ -43,16 +43,16 @@ FeedbackGains sysid::CalculatePositionFeedbackGains(
|
||||
return {Kv * controller.K(0, 0) * preset.outputConversionFactor, 0.0};
|
||||
}
|
||||
|
||||
auto system = frc::LinearSystemId::IdentifyPositionSystem<units::meters>(
|
||||
auto system = wpi::math::LinearSystemId::IdentifyPositionSystem<wpi::units::meters>(
|
||||
Kv_t{Kv}, Ka_t{Ka});
|
||||
|
||||
frc::LinearQuadraticRegulator<2, 1> controller{
|
||||
wpi::math::LinearQuadraticRegulator<2, 1> controller{
|
||||
system, {params.qp, params.qv}, {params.r}, preset.period};
|
||||
controller.LatencyCompensate(system, preset.period, preset.measurementDelay);
|
||||
|
||||
return {controller.K(0, 0) * preset.outputConversionFactor,
|
||||
controller.K(0, 1) * preset.outputConversionFactor /
|
||||
(preset.normalized ? 1 : units::second_t{preset.period}.value())};
|
||||
(preset.normalized ? 1 : wpi::units::second_t{preset.period}.value())};
|
||||
}
|
||||
|
||||
FeedbackGains sysid::CalculateVelocityFeedbackGains(
|
||||
@@ -69,9 +69,9 @@ FeedbackGains sysid::CalculateVelocityFeedbackGains(
|
||||
return {0.0, 0.0};
|
||||
}
|
||||
|
||||
auto system = frc::LinearSystemId::IdentifyVelocitySystem<units::meters>(
|
||||
auto system = wpi::math::LinearSystemId::IdentifyVelocitySystem<wpi::units::meters>(
|
||||
Kv_t{Kv}, Ka_t{Ka});
|
||||
frc::LinearQuadraticRegulator<1, 1> controller{
|
||||
wpi::math::LinearQuadraticRegulator<1, 1> controller{
|
||||
system, {params.qv}, {params.r}, preset.period};
|
||||
controller.LatencyCompensate(system, preset.period, preset.measurementDelay);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ static void CheckSize(const std::vector<PreparedData>& data, size_t window,
|
||||
* @return True, if the key corresponds to a raw dataset.
|
||||
*/
|
||||
static bool IsRaw(std::string_view key) {
|
||||
return wpi::contains(key, "raw") && !wpi::contains(key, "original");
|
||||
return wpi::util::contains(key, "raw") && !wpi::util::contains(key, "original");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ static bool IsRaw(std::string_view key) {
|
||||
* @return True, if the key corresponds to a filtered dataset.
|
||||
*/
|
||||
static bool IsFiltered(std::string_view key) {
|
||||
return !wpi::contains(key, "raw") && !wpi::contains(key, "original");
|
||||
return !wpi::util::contains(key, "raw") && !wpi::util::contains(key, "original");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,16 +116,16 @@ static void PrepareMechData(std::vector<PreparedData>* data,
|
||||
}
|
||||
}
|
||||
|
||||
std::tuple<units::second_t, units::second_t, units::second_t>
|
||||
std::tuple<wpi::units::second_t, wpi::units::second_t, wpi::units::second_t>
|
||||
sysid::TrimStepVoltageData(std::vector<PreparedData>* data,
|
||||
AnalysisManager::Settings* settings,
|
||||
units::second_t minStepTime,
|
||||
units::second_t maxStepTime) {
|
||||
wpi::units::second_t minStepTime,
|
||||
wpi::units::second_t maxStepTime) {
|
||||
auto voltageBegins =
|
||||
std::find_if(data->begin(), data->end(),
|
||||
[](auto& datum) { return std::abs(datum.voltage) > 0; });
|
||||
|
||||
units::second_t firstTimestamp = voltageBegins->timestamp;
|
||||
wpi::units::second_t firstTimestamp = voltageBegins->timestamp;
|
||||
double firstPosition = voltageBegins->position;
|
||||
|
||||
auto motionBegins = std::find_if(
|
||||
@@ -134,7 +134,7 @@ sysid::TrimStepVoltageData(std::vector<PreparedData>* data,
|
||||
(settings->velocityThreshold * datum.dt.value());
|
||||
});
|
||||
|
||||
units::second_t positionDelay;
|
||||
wpi::units::second_t positionDelay;
|
||||
if (motionBegins != data->end()) {
|
||||
positionDelay = motionBegins->timestamp - firstTimestamp;
|
||||
} else {
|
||||
@@ -146,8 +146,8 @@ sysid::TrimStepVoltageData(std::vector<PreparedData>* data,
|
||||
// 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;
|
||||
return wpi::util::sgn(a.velocity) * a.acceleration <
|
||||
wpi::util::sgn(b.velocity) * b.acceleration;
|
||||
});
|
||||
|
||||
// Current limiting can delay onset of the peak acceleration, so we need to
|
||||
@@ -155,11 +155,11 @@ sysid::TrimStepVoltageData(std::vector<PreparedData>* data,
|
||||
// because this whole file is tech debt already
|
||||
auto accelBegins = std::find_if(
|
||||
data->begin(), data->end(), [&maxAccel](const auto& measurement) {
|
||||
return wpi::sgn(measurement.velocity) * measurement.acceleration >
|
||||
0.8 * wpi::sgn(maxAccel->velocity) * maxAccel->acceleration;
|
||||
return wpi::util::sgn(measurement.velocity) * measurement.acceleration >
|
||||
0.8 * wpi::util::sgn(maxAccel->velocity) * maxAccel->acceleration;
|
||||
});
|
||||
|
||||
units::second_t velocityDelay;
|
||||
wpi::units::second_t velocityDelay;
|
||||
if (accelBegins != data->end()) {
|
||||
velocityDelay = accelBegins->timestamp - firstTimestamp;
|
||||
|
||||
@@ -209,7 +209,7 @@ double sysid::GetNoiseFloor(
|
||||
std::function<double(const PreparedData&)> accessorFunction) {
|
||||
double sum = 0.0;
|
||||
size_t step = window / 2;
|
||||
auto averageFilter = frc::LinearFilter<double>::MovingAverage(window);
|
||||
auto averageFilter = wpi::math::LinearFilter<double>::MovingAverage(window);
|
||||
for (size_t i = 0; i < data.size(); i++) {
|
||||
double mean = averageFilter.Calculate(accessorFunction(data[i]));
|
||||
if (i >= step) {
|
||||
@@ -229,8 +229,8 @@ double sysid::GetMaxSpeed(
|
||||
return max;
|
||||
}
|
||||
|
||||
units::second_t sysid::GetMeanTimeDelta(const std::vector<PreparedData>& data) {
|
||||
std::vector<units::second_t> dts;
|
||||
wpi::units::second_t sysid::GetMeanTimeDelta(const std::vector<PreparedData>& data) {
|
||||
std::vector<wpi::units::second_t> dts;
|
||||
|
||||
for (const auto& pt : data) {
|
||||
if (pt.dt > 0_s && pt.dt < 500_ms) {
|
||||
@@ -241,8 +241,8 @@ units::second_t sysid::GetMeanTimeDelta(const std::vector<PreparedData>& data) {
|
||||
return std::accumulate(dts.begin(), dts.end(), 0_s) / dts.size();
|
||||
}
|
||||
|
||||
units::second_t sysid::GetMeanTimeDelta(const Storage& data) {
|
||||
std::vector<units::second_t> dts;
|
||||
wpi::units::second_t sysid::GetMeanTimeDelta(const Storage& data) {
|
||||
std::vector<wpi::units::second_t> dts;
|
||||
|
||||
for (const auto& pt : data.slowForward) {
|
||||
if (pt.dt > 0_s && pt.dt < 500_ms) {
|
||||
@@ -274,7 +274,7 @@ units::second_t sysid::GetMeanTimeDelta(const Storage& data) {
|
||||
void sysid::ApplyMedianFilter(std::vector<PreparedData>* data, int window) {
|
||||
CheckSize(*data, window, "Median Filter");
|
||||
|
||||
frc::MedianFilter<double> medianFilter(window);
|
||||
wpi::math::MedianFilter<double> medianFilter(window);
|
||||
|
||||
// Load the median filter with the first value for accurate initial behavior
|
||||
for (int i = 0; i < window; i++) {
|
||||
@@ -319,14 +319,14 @@ static std::string RemoveStr(std::string_view str, std::string_view removeStr) {
|
||||
*
|
||||
* @return The maximum duration of the Dynamic Tests
|
||||
*/
|
||||
static units::second_t GetMaxStepTime(
|
||||
wpi::StringMap<std::vector<PreparedData>>& data) {
|
||||
static wpi::units::second_t GetMaxStepTime(
|
||||
wpi::util::StringMap<std::vector<PreparedData>>& data) {
|
||||
auto maxStepTime = 0_s;
|
||||
for (auto& it : data) {
|
||||
auto& key = it.first;
|
||||
auto& dataset = it.second;
|
||||
|
||||
if (IsRaw(key) && wpi::contains(key, "dynamic")) {
|
||||
if (IsRaw(key) && wpi::util::contains(key, "dynamic")) {
|
||||
if (!dataset.empty()) {
|
||||
auto duration = dataset.back().timestamp - dataset.front().timestamp;
|
||||
if (duration > maxStepTime) {
|
||||
@@ -339,11 +339,11 @@ static units::second_t GetMaxStepTime(
|
||||
}
|
||||
|
||||
void sysid::InitialTrimAndFilter(
|
||||
wpi::StringMap<std::vector<PreparedData>>* data,
|
||||
wpi::util::StringMap<std::vector<PreparedData>>* data,
|
||||
AnalysisManager::Settings* settings,
|
||||
std::vector<units::second_t>& positionDelays,
|
||||
std::vector<units::second_t>& velocityDelays, units::second_t& minStepTime,
|
||||
units::second_t& maxStepTime, std::string_view unit) {
|
||||
std::vector<wpi::units::second_t>& positionDelays,
|
||||
std::vector<wpi::units::second_t>& velocityDelays, wpi::units::second_t& minStepTime,
|
||||
wpi::units::second_t& maxStepTime, std::string_view unit) {
|
||||
auto& preparedData = *data;
|
||||
|
||||
// Find the maximum Step Test Duration of the dynamic tests
|
||||
@@ -354,7 +354,7 @@ void sysid::InitialTrimAndFilter(
|
||||
for (auto& it : preparedData) {
|
||||
auto& key = it.first;
|
||||
auto& dataset = it.second;
|
||||
if (wpi::contains(key, "quasistatic")) {
|
||||
if (wpi::util::contains(key, "quasistatic")) {
|
||||
settings->velocityThreshold =
|
||||
std::min(settings->velocityThreshold,
|
||||
GetNoiseFloor(dataset, kNoiseMeanWindow,
|
||||
@@ -369,7 +369,7 @@ void sysid::InitialTrimAndFilter(
|
||||
|
||||
// Trim quasistatic test data to remove all points where voltage is zero or
|
||||
// velocity < velocity threshold.
|
||||
if (wpi::contains(key, "quasistatic")) {
|
||||
if (wpi::util::contains(key, "quasistatic")) {
|
||||
dataset.erase(std::remove_if(dataset.begin(), dataset.end(),
|
||||
[&](const auto& pt) {
|
||||
return std::abs(pt.voltage) <= 0 ||
|
||||
@@ -393,7 +393,7 @@ void sysid::InitialTrimAndFilter(
|
||||
PrepareMechData(&dataset, unit);
|
||||
|
||||
// Trims filtered Dynamic Test Data
|
||||
if (IsFiltered(key) && wpi::contains(key, "dynamic")) {
|
||||
if (IsFiltered(key) && wpi::util::contains(key, "dynamic")) {
|
||||
// Get the filtered dataset name
|
||||
auto filteredKey = RemoveStr(key, "raw-");
|
||||
|
||||
@@ -420,7 +420,7 @@ void sysid::InitialTrimAndFilter(
|
||||
}
|
||||
}
|
||||
|
||||
void sysid::AccelFilter(wpi::StringMap<std::vector<PreparedData>>* data) {
|
||||
void sysid::AccelFilter(wpi::util::StringMap<std::vector<PreparedData>>* data) {
|
||||
auto& preparedData = *data;
|
||||
|
||||
// Remove points with acceleration = 0
|
||||
|
||||
@@ -17,16 +17,16 @@ SimpleMotorSim::SimpleMotorSim(double Ks, double Kv, double Ka,
|
||||
Reset(initialPosition, initialVelocity);
|
||||
}
|
||||
|
||||
void SimpleMotorSim::Update(units::volt_t voltage, units::second_t dt) {
|
||||
void SimpleMotorSim::Update(wpi::units::volt_t voltage, wpi::units::second_t dt) {
|
||||
Eigen::Vector<double, 1> u{voltage.value()};
|
||||
|
||||
// Given dx/dt = Ax + Bu + c sgn(x),
|
||||
// x_k+1 = e^(AT) x_k + A^-1 (e^(AT) - 1) (Bu + c sgn(x))
|
||||
Eigen::Matrix<double, 2, 2> Ad;
|
||||
Eigen::Matrix<double, 2, 1> Bd;
|
||||
frc::DiscretizeAB<2, 1>(m_A, m_B, dt, &Ad, &Bd);
|
||||
wpi::math::DiscretizeAB<2, 1>(m_A, m_B, dt, &Ad, &Bd);
|
||||
m_x = Ad * m_x + Bd * u +
|
||||
Bd * m_B.householderQr().solve(m_c * wpi::sgn(GetVelocity()));
|
||||
Bd * m_B.householderQr().solve(m_c * wpi::util::sgn(GetVelocity()));
|
||||
}
|
||||
|
||||
double SimpleMotorSim::GetPosition() const {
|
||||
@@ -37,9 +37,9 @@ double SimpleMotorSim::GetVelocity() const {
|
||||
return m_x(1);
|
||||
}
|
||||
|
||||
double SimpleMotorSim::GetAcceleration(units::volt_t voltage) const {
|
||||
double SimpleMotorSim::GetAcceleration(wpi::units::volt_t voltage) const {
|
||||
Eigen::Vector<double, 1> u{voltage.value()};
|
||||
return (m_A * m_x + m_B * u + m_c * wpi::sgn(GetVelocity()))(1);
|
||||
return (m_A * m_x + m_B * u + m_c * wpi::util::sgn(GetVelocity()))(1);
|
||||
}
|
||||
|
||||
void SimpleMotorSim::Reset(double position, double velocity) {
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
|
||||
using namespace sysid;
|
||||
|
||||
Analyzer::Analyzer(glass::Storage& storage, wpi::Logger& logger)
|
||||
Analyzer::Analyzer(wpi::glass::Storage& storage, wpi::util::Logger& logger)
|
||||
: m_logger(logger) {
|
||||
// Fill the StringMap with preset values.
|
||||
// Fill the wpi::util::StringMap with preset values.
|
||||
m_presets["Default"] = presets::kDefault;
|
||||
m_presets["WPILib"] = presets::kWPILib;
|
||||
m_presets["CTRE Phoenix 5"] = presets::kCTREv5;
|
||||
@@ -55,8 +55,8 @@ void Analyzer::UpdateFeedforwardGains() {
|
||||
m_settings.preset.measurementDelay =
|
||||
m_settings.type == FeedbackControllerLoopType::kPosition
|
||||
// Clamp feedback measurement delay to ≥ 0
|
||||
? units::math::max(0_s, m_manager->GetPositionDelay())
|
||||
: units::math::max(0_s, m_manager->GetVelocityDelay());
|
||||
? wpi::units::math::max(0_s, m_manager->GetPositionDelay())
|
||||
: wpi::units::math::max(0_s, m_manager->GetVelocityDelay());
|
||||
PrepareGraphs();
|
||||
} catch (const sysid::InvalidDataError& e) {
|
||||
m_state = AnalyzerState::kGeneralDataError;
|
||||
@@ -70,7 +70,7 @@ void Analyzer::UpdateFeedforwardGains() {
|
||||
} catch (const AnalysisManager::FileReadingError& e) {
|
||||
m_state = AnalyzerState::kFileError;
|
||||
HandleError(e.what());
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
m_state = AnalyzerState::kFileError;
|
||||
HandleError(e.what());
|
||||
} catch (const std::exception& e) {
|
||||
@@ -86,7 +86,7 @@ void Analyzer::UpdateFeedbackGains() {
|
||||
const auto& Ka = m_feedforwardGains.Ka;
|
||||
if (Kv.isValidGain && Ka.isValidGain) {
|
||||
const auto& fb = m_manager->CalculateFeedback(Kv, Ka);
|
||||
m_timescale = units::second_t{Ka.gain / Kv.gain};
|
||||
m_timescale = wpi::units::second_t{Ka.gain / Kv.gain};
|
||||
m_timescaleValid = true;
|
||||
m_Kp = fb.Kp;
|
||||
m_Kd = fb.Kd;
|
||||
@@ -298,7 +298,7 @@ void Analyzer::PrepareData() {
|
||||
} catch (const AnalysisManager::FileReadingError& e) {
|
||||
m_state = AnalyzerState::kFileError;
|
||||
HandleError(e.what());
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
m_state = AnalyzerState::kFileError;
|
||||
HandleError(e.what());
|
||||
} catch (const std::exception& e) {
|
||||
@@ -475,7 +475,7 @@ void Analyzer::DisplayFeedforwardParameters(float beginX, float beginY) {
|
||||
if (ImGui::SliderFloat("Test Duration", &m_stepTestDuration,
|
||||
m_manager->GetMinStepTime().value(),
|
||||
m_manager->GetMaxStepTime().value(), "%.2f")) {
|
||||
m_settings.stepTestDuration = units::second_t{m_stepTestDuration};
|
||||
m_settings.stepTestDuration = wpi::units::second_t{m_stepTestDuration};
|
||||
PrepareData();
|
||||
}
|
||||
}
|
||||
@@ -612,9 +612,9 @@ void Analyzer::DisplayFeedbackGains() {
|
||||
sysid::CreateTooltip(
|
||||
"Gain presets represent how feedback gains are calculated for your "
|
||||
"specific feedback controller:\n\n"
|
||||
"Default, WPILib (2020-): For use with the new WPILib PIDController "
|
||||
"Default, WPILib (2020-): For use with the new WPILib wpi::math::PIDController "
|
||||
"class.\n"
|
||||
"WPILib (Pre-2020): For use with the old WPILib PIDController class.\n"
|
||||
"WPILib (Pre-2020): For use with the old WPILib wpi::math::PIDController class.\n"
|
||||
"CTRE: For use with CTRE units. These are the default units that ship "
|
||||
"with CTRE motor controllers.\n"
|
||||
"REV (Brushless): For use with NEO and NEO 550 motors on a SPARK MAX.\n"
|
||||
|
||||
@@ -30,7 +30,7 @@ static ImPlotPoint Getter(int idx, void* data) {
|
||||
template <typename Model>
|
||||
static std::vector<std::vector<ImPlotPoint>> PopulateTimeDomainSim(
|
||||
const std::vector<PreparedData>& data,
|
||||
const std::array<units::second_t, 4>& startTimes, size_t step, Model model,
|
||||
const std::array<wpi::units::second_t, 4>& startTimes, size_t step, Model model,
|
||||
double* simSquaredErrorSum, double* squaredVariationSum,
|
||||
int* timeSeriesPoints) {
|
||||
// Create the vector of ImPlotPoints that will contain our simulated data.
|
||||
@@ -42,7 +42,7 @@ static std::vector<std::vector<ImPlotPoint>> PopulateTimeDomainSim(
|
||||
tmp.emplace_back(startTime.value(), data[0].velocity);
|
||||
|
||||
model.Reset(data[0].position, data[0].velocity);
|
||||
units::second_t t = 0_s;
|
||||
wpi::units::second_t t = 0_s;
|
||||
|
||||
for (size_t i = 1; i < data.size(); ++i) {
|
||||
const auto& now = data[i];
|
||||
@@ -60,7 +60,7 @@ static std::vector<std::vector<ImPlotPoint>> PopulateTimeDomainSim(
|
||||
continue;
|
||||
}
|
||||
|
||||
model.Update(units::volt_t{pre.voltage}, now.timestamp - pre.timestamp);
|
||||
model.Update(wpi::units::volt_t{pre.voltage}, now.timestamp - pre.timestamp);
|
||||
tmp.emplace_back((startTime + t).value(), model.GetVelocity());
|
||||
*simSquaredErrorSum += std::pow(now.velocity - model.GetVelocity(), 2);
|
||||
*squaredVariationSum += std::pow(now.velocity, 2);
|
||||
@@ -71,7 +71,7 @@ static std::vector<std::vector<ImPlotPoint>> PopulateTimeDomainSim(
|
||||
return pts;
|
||||
}
|
||||
|
||||
AnalyzerPlot::AnalyzerPlot(wpi::Logger& logger) : m_logger(logger) {}
|
||||
AnalyzerPlot::AnalyzerPlot(wpi::util::Logger& logger) : m_logger(logger) {}
|
||||
|
||||
void AnalyzerPlot::SetRawTimeData(const std::vector<PreparedData>& rawSlow,
|
||||
const std::vector<PreparedData>& rawFast,
|
||||
@@ -131,7 +131,7 @@ void AnalyzerPlot::SetRawData(const Storage& data, std::string_view unit,
|
||||
void AnalyzerPlot::SetData(const Storage& rawData, const Storage& filteredData,
|
||||
std::string_view unit,
|
||||
const AnalysisManager::FeedforwardGains& ffGains,
|
||||
const std::array<units::second_t, 4>& startTimes,
|
||||
const std::array<wpi::units::second_t, 4>& startTimes,
|
||||
AnalysisType type, std::atomic<bool>& abort) {
|
||||
double simSquaredErrorSum = 0;
|
||||
double squaredVariationSum = 0;
|
||||
@@ -163,7 +163,7 @@ void AnalyzerPlot::SetData(const Storage& rawData, const Storage& filteredData,
|
||||
auto slowStep = std::ceil(slow.size() * 1.0 / kMaxSize * 4);
|
||||
auto fastStep = std::ceil(fast.size() * 1.0 / kMaxSize * 4);
|
||||
|
||||
units::second_t dtMean = GetMeanTimeDelta(filteredData);
|
||||
wpi::units::second_t dtMean = GetMeanTimeDelta(filteredData);
|
||||
|
||||
// Velocity-vs-time plots
|
||||
{
|
||||
@@ -192,7 +192,7 @@ void AnalyzerPlot::SetData(const Storage& rawData, const Storage& filteredData,
|
||||
slow[i].timestamp) == startTimes.end()) {
|
||||
m_timestepData.data.emplace_back(
|
||||
(slow[i].timestamp).value(),
|
||||
units::millisecond_t{slow[i].dt}.value());
|
||||
wpi::units::millisecond_t{slow[i].dt}.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,7 +217,7 @@ void AnalyzerPlot::SetData(const Storage& rawData, const Storage& filteredData,
|
||||
fast[i].timestamp) == startTimes.end()) {
|
||||
m_timestepData.data.emplace_back(
|
||||
(fast[i].timestamp).value(),
|
||||
units::millisecond_t{fast[i].dt}.value());
|
||||
wpi::units::millisecond_t{fast[i].dt}.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ void AnalyzerPlot::SetData(const Storage& rawData, const Storage& filteredData,
|
||||
startTimes.end()) {
|
||||
m_timestepData.data.emplace_back(
|
||||
(slow[i].timestamp).value(),
|
||||
units::millisecond_t{slow[i].dt}.value());
|
||||
wpi::units::millisecond_t{slow[i].dt}.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,19 +351,19 @@ void AnalyzerPlot::SetData(const Storage& rawData, const Storage& filteredData,
|
||||
startTimes.end()) {
|
||||
m_timestepData.data.emplace_back(
|
||||
(fast[i].timestamp).value(),
|
||||
units::millisecond_t{fast[i].dt}.value());
|
||||
wpi::units::millisecond_t{fast[i].dt}.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto minTime =
|
||||
units::math::min(slow.front().timestamp, fast.front().timestamp);
|
||||
wpi::units::math::min(slow.front().timestamp, fast.front().timestamp);
|
||||
m_timestepData.fitLine[0] =
|
||||
ImPlotPoint{minTime.value(), units::millisecond_t{dtMean}.value()};
|
||||
ImPlotPoint{minTime.value(), wpi::units::millisecond_t{dtMean}.value()};
|
||||
|
||||
auto maxTime = units::math::max(slow.back().timestamp, fast.back().timestamp);
|
||||
auto maxTime = wpi::units::math::max(slow.back().timestamp, fast.back().timestamp);
|
||||
m_timestepData.fitLine[1] =
|
||||
ImPlotPoint{maxTime.value(), units::millisecond_t{dtMean}.value()};
|
||||
ImPlotPoint{maxTime.value(), wpi::units::millisecond_t{dtMean}.value()};
|
||||
|
||||
// RMSE = std::sqrt(sum((x_i - x^_i)^2) / N) where sum represents the sum of
|
||||
// all time series points, x_i represents the velocity at a timestep, x^_i
|
||||
|
||||
@@ -105,7 +105,7 @@ void DataSelector::Display() {
|
||||
continue;
|
||||
}
|
||||
for (auto it2 = it->second.begin(); it2 != it->second.end();) {
|
||||
auto direction = wpi::rsplit(it2->first, '-').second;
|
||||
auto direction = wpi::util::rsplit(it2->first, '-').second;
|
||||
if (direction != "forward" && direction != "reverse") {
|
||||
WPI_WARNING(m_logger, "Unrecognized direction {}, removing",
|
||||
direction);
|
||||
@@ -220,7 +220,7 @@ DataSelector::Tests DataSelector::LoadTests(
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [testName, direction] = wpi::rsplit(testState, '-');
|
||||
auto [testName, direction] = wpi::util::rsplit(testState, '-');
|
||||
auto testIt = tests.find(testName);
|
||||
if (testIt == tests.end()) {
|
||||
testIt = tests.emplace(std::string{testName}, State{}).first;
|
||||
@@ -252,7 +252,7 @@ static void AddSamples(std::vector<MotorData::Run::Sample<T>>& samples,
|
||||
[](const auto& datapoint, double val) { return datapoint.first < val; });
|
||||
|
||||
for (auto it = begin; it != end; ++it) {
|
||||
samples.emplace_back(units::second_t{it->first * 1.0e-6}, T{it->second});
|
||||
samples.emplace_back(wpi::units::second_t{it->first * 1.0e-6}, T{it->second});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
using namespace sysid;
|
||||
|
||||
LogLoader::LogLoader(glass::Storage& storage, wpi::Logger& logger) {}
|
||||
LogLoader::LogLoader(wpi::glass::Storage& storage, wpi::util::Logger& logger) {}
|
||||
|
||||
LogLoader::~LogLoader() = default;
|
||||
|
||||
@@ -40,7 +40,7 @@ void LogLoader::Display() {
|
||||
if (!m_opener->result().empty()) {
|
||||
m_filename = m_opener->result()[0];
|
||||
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(m_filename);
|
||||
auto fileBuffer = wpi::util::MemoryBuffer::GetFile(m_filename);
|
||||
if (!fileBuffer) {
|
||||
ImGui::OpenPopup("Error");
|
||||
m_error = fmt::format("Could not open file: {}",
|
||||
@@ -108,7 +108,7 @@ void LogLoader::Display() {
|
||||
|
||||
void LogLoader::RebuildEntryTree() {
|
||||
m_entryTree.clear();
|
||||
wpi::SmallVector<std::string_view, 16> parts;
|
||||
wpi::util::SmallVector<std::string_view, 16> parts;
|
||||
m_reader->ForEachEntryName([&](const wpi::log::DataLogReaderEntry& entry) {
|
||||
// only show double/float/string entries (TODO: support struct/protobuf)
|
||||
if (entry.type != "double" && entry.type != "float" &&
|
||||
@@ -117,19 +117,19 @@ void LogLoader::RebuildEntryTree() {
|
||||
}
|
||||
|
||||
// filter on name
|
||||
if (!m_filter.empty() && !wpi::contains_lower(entry.name, m_filter)) {
|
||||
if (!m_filter.empty() && !wpi::util::contains_lower(entry.name, m_filter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
parts.clear();
|
||||
// split on first : if one is present
|
||||
auto [prefix, mainpart] = wpi::split(entry.name, ':');
|
||||
if (mainpart.empty() || wpi::contains(prefix, '/')) {
|
||||
auto [prefix, mainpart] = wpi::util::split(entry.name, ':');
|
||||
if (mainpart.empty() || wpi::util::contains(prefix, '/')) {
|
||||
mainpart = entry.name;
|
||||
} else {
|
||||
parts.emplace_back(prefix);
|
||||
}
|
||||
wpi::split(mainpart, '/', -1, false,
|
||||
wpi::util::split(mainpart, '/', -1, false,
|
||||
[&](auto part) { parts.emplace_back(part); });
|
||||
|
||||
// ignore a raw "/" key
|
||||
@@ -139,7 +139,7 @@ void LogLoader::RebuildEntryTree() {
|
||||
|
||||
// get to leaf
|
||||
auto nodes = &m_entryTree;
|
||||
for (auto part : wpi::drop_back(std::span{parts.begin(), parts.end()})) {
|
||||
for (auto part : wpi::util::drop_back(std::span{parts.begin(), parts.end()})) {
|
||||
auto it =
|
||||
std::find_if(nodes->begin(), nodes->end(),
|
||||
[&](const auto& node) { return node.name == part; });
|
||||
|
||||
@@ -70,7 +70,7 @@ class AnalysisManager {
|
||||
* The duration of the dynamic test that should be considered. A value of
|
||||
* zero indicates it needs to be set to the default.
|
||||
*/
|
||||
units::second_t stepTestDuration = 0_s;
|
||||
wpi::units::second_t stepTestDuration = 0_s;
|
||||
};
|
||||
|
||||
struct FeedforwardGain {
|
||||
@@ -189,7 +189,7 @@ class AnalysisManager {
|
||||
* @param settings The settings for this instance of the analysis manager.
|
||||
* @param logger The logger instance to use for log data.
|
||||
*/
|
||||
AnalysisManager(Settings& settings, wpi::Logger& logger);
|
||||
AnalysisManager(Settings& settings, wpi::util::Logger& logger);
|
||||
|
||||
/**
|
||||
* Constructs an instance of the analysis manager with the given path (to the
|
||||
@@ -199,7 +199,7 @@ class AnalysisManager {
|
||||
* @param settings The settings for this instance of the analysis manager.
|
||||
* @param logger The logger instance to use for log data.
|
||||
*/
|
||||
AnalysisManager(TestData data, Settings& settings, wpi::Logger& logger);
|
||||
AnalysisManager(TestData data, Settings& settings, wpi::util::Logger& logger);
|
||||
|
||||
/**
|
||||
* Prepares data from the JSON and stores the output in Storage member
|
||||
@@ -281,7 +281,7 @@ class AnalysisManager {
|
||||
*
|
||||
* @return The minimum step test duration.
|
||||
*/
|
||||
units::second_t GetMinStepTime() const { return m_minStepTime; }
|
||||
wpi::units::second_t GetMinStepTime() const { return m_minStepTime; }
|
||||
|
||||
/**
|
||||
* Returns the maximum duration of the Step Voltage Test of the currently
|
||||
@@ -289,7 +289,7 @@ class AnalysisManager {
|
||||
*
|
||||
* @return Maximum step test duration
|
||||
*/
|
||||
units::second_t GetMaxStepTime() const { return m_maxStepTime; }
|
||||
wpi::units::second_t GetMaxStepTime() const { return m_maxStepTime; }
|
||||
|
||||
/**
|
||||
* Returns the estimated time delay of the measured position, including
|
||||
@@ -297,7 +297,7 @@ class AnalysisManager {
|
||||
*
|
||||
* @return Position delay in milliseconds
|
||||
*/
|
||||
units::millisecond_t GetPositionDelay() const {
|
||||
wpi::units::millisecond_t GetPositionDelay() const {
|
||||
return std::accumulate(m_positionDelays.begin(), m_positionDelays.end(),
|
||||
0_s) /
|
||||
m_positionDelays.size();
|
||||
@@ -309,7 +309,7 @@ class AnalysisManager {
|
||||
*
|
||||
* @return Velocity delay in milliseconds
|
||||
*/
|
||||
units::millisecond_t GetVelocityDelay() const {
|
||||
wpi::units::millisecond_t GetVelocityDelay() const {
|
||||
return std::accumulate(m_velocityDelays.begin(), m_velocityDelays.end(),
|
||||
0_s) /
|
||||
m_positionDelays.size();
|
||||
@@ -320,30 +320,30 @@ class AnalysisManager {
|
||||
*
|
||||
* @return The start times for each test
|
||||
*/
|
||||
const std::array<units::second_t, 4>& GetStartTimes() const {
|
||||
const std::array<wpi::units::second_t, 4>& GetStartTimes() const {
|
||||
return m_startTimes;
|
||||
}
|
||||
|
||||
bool HasData() const { return !m_originalDataset.empty(); }
|
||||
|
||||
private:
|
||||
wpi::Logger& m_logger;
|
||||
wpi::util::Logger& m_logger;
|
||||
|
||||
Storage m_originalDataset;
|
||||
Storage m_rawDataset;
|
||||
Storage m_filteredDataset;
|
||||
|
||||
// Stores the various start times of the different tests.
|
||||
std::array<units::second_t, 4> m_startTimes;
|
||||
std::array<wpi::units::second_t, 4> m_startTimes;
|
||||
|
||||
// The settings for this instance. This contains pointers to the feedback
|
||||
// controller preset, LQR parameters, acceleration window size, etc.
|
||||
Settings& m_settings;
|
||||
|
||||
units::second_t m_minStepTime{0};
|
||||
units::second_t m_maxStepTime{std::numeric_limits<double>::infinity()};
|
||||
std::vector<units::second_t> m_positionDelays;
|
||||
std::vector<units::second_t> m_velocityDelays;
|
||||
wpi::units::second_t m_minStepTime{0};
|
||||
wpi::units::second_t m_maxStepTime{std::numeric_limits<double>::infinity()};
|
||||
std::vector<wpi::units::second_t> m_positionDelays;
|
||||
std::vector<wpi::units::second_t> m_velocityDelays;
|
||||
|
||||
void PrepareGeneralData();
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ class ArmSim {
|
||||
* @param voltage Voltage to apply over the timestep.
|
||||
* @param dt Sample period.
|
||||
*/
|
||||
void Update(units::volt_t voltage, units::second_t dt);
|
||||
void Update(wpi::units::volt_t voltage, wpi::units::second_t dt);
|
||||
|
||||
/**
|
||||
* Returns the position.
|
||||
@@ -58,7 +58,7 @@ class ArmSim {
|
||||
* @param voltage The voltage that is being applied to the mechanism / input
|
||||
* @return The acceleration given the state and input
|
||||
*/
|
||||
double GetAcceleration(units::volt_t voltage) const;
|
||||
double GetAcceleration(wpi::units::volt_t voltage) const;
|
||||
|
||||
/**
|
||||
* Resets model position and velocity.
|
||||
|
||||
@@ -34,7 +34,7 @@ class ElevatorSim {
|
||||
* @param voltage Voltage to apply over the timestep.
|
||||
* @param dt Sample period.
|
||||
*/
|
||||
void Update(units::volt_t voltage, units::second_t dt);
|
||||
void Update(wpi::units::volt_t voltage, wpi::units::second_t dt);
|
||||
|
||||
/**
|
||||
* Returns the position.
|
||||
@@ -56,7 +56,7 @@ class ElevatorSim {
|
||||
* @param voltage The voltage that is being applied to the mechanism / input
|
||||
* @return The acceleration given the state and input
|
||||
*/
|
||||
double GetAcceleration(units::volt_t voltage) const;
|
||||
double GetAcceleration(wpi::units::volt_t voltage) const;
|
||||
|
||||
/**
|
||||
* Resets model position and velocity.
|
||||
|
||||
@@ -29,7 +29,7 @@ struct FeedbackControllerPreset {
|
||||
/**
|
||||
* The period at which the controller runs.
|
||||
*/
|
||||
units::millisecond_t period;
|
||||
wpi::units::millisecond_t period;
|
||||
|
||||
/**
|
||||
* Whether the controller gains are time-normalized.
|
||||
@@ -39,7 +39,7 @@ struct FeedbackControllerPreset {
|
||||
/**
|
||||
* The measurement delay in the encoder measurements.
|
||||
*/
|
||||
units::millisecond_t measurementDelay;
|
||||
wpi::units::millisecond_t measurementDelay;
|
||||
|
||||
/**
|
||||
* Checks equality between two feedback controller presets.
|
||||
|
||||
@@ -145,10 +145,10 @@ void ApplyMedianFilter(std::vector<PreparedData>* data, int window);
|
||||
* @param maxStepTime The maximum step test duration.
|
||||
* @return The updated minimum step test duration.
|
||||
*/
|
||||
std::tuple<units::second_t, units::second_t, units::second_t>
|
||||
std::tuple<wpi::units::second_t, wpi::units::second_t, wpi::units::second_t>
|
||||
TrimStepVoltageData(std::vector<PreparedData>* data,
|
||||
AnalysisManager::Settings* settings,
|
||||
units::second_t minStepTime, units::second_t maxStepTime);
|
||||
wpi::units::second_t minStepTime, wpi::units::second_t maxStepTime);
|
||||
|
||||
/**
|
||||
* Compute the mean time delta of the given data.
|
||||
@@ -156,7 +156,7 @@ TrimStepVoltageData(std::vector<PreparedData>* data,
|
||||
* @param data A reference to all of the collected PreparedData
|
||||
* @return The mean time delta for all the data points
|
||||
*/
|
||||
units::second_t GetMeanTimeDelta(const std::vector<PreparedData>& data);
|
||||
wpi::units::second_t GetMeanTimeDelta(const std::vector<PreparedData>& data);
|
||||
|
||||
/**
|
||||
* Compute the mean time delta of the given data.
|
||||
@@ -164,7 +164,7 @@ units::second_t GetMeanTimeDelta(const std::vector<PreparedData>& data);
|
||||
* @param data A reference to all of the collected PreparedData
|
||||
* @return The mean time delta for all the data points
|
||||
*/
|
||||
units::second_t GetMeanTimeDelta(const Storage& data);
|
||||
wpi::units::second_t GetMeanTimeDelta(const Storage& data);
|
||||
|
||||
/**
|
||||
* Creates a central finite difference filter that computes the nth
|
||||
@@ -187,16 +187,16 @@ units::second_t GetMeanTimeDelta(const Storage& data);
|
||||
* @param period The period in seconds between samples taken by the user.
|
||||
*/
|
||||
template <int Derivative, int Samples>
|
||||
frc::LinearFilter<double> CentralFiniteDifference(units::second_t period) {
|
||||
wpi::math::LinearFilter<double> CentralFiniteDifference(wpi::units::second_t period) {
|
||||
static_assert(Samples % 2 != 0, "Number of samples must be odd.");
|
||||
|
||||
// Generate stencil points from -(samples - 1)/2 to (samples - 1)/2
|
||||
wpi::array<int, Samples> stencil{wpi::empty_array};
|
||||
wpi::util::array<int, Samples> stencil{wpi::util::empty_array};
|
||||
for (int i = 0; i < Samples; ++i) {
|
||||
stencil[i] = -(Samples - 1) / 2 + i;
|
||||
}
|
||||
|
||||
return frc::LinearFilter<double>::FiniteDifference<Derivative, Samples>(
|
||||
return wpi::math::LinearFilter<double>::FiniteDifference<Derivative, Samples>(
|
||||
stencil, period);
|
||||
}
|
||||
|
||||
@@ -219,12 +219,12 @@ frc::LinearFilter<double> CentralFiniteDifference(units::second_t period) {
|
||||
* @param unit The angular unit that the arm test is in (only for calculating
|
||||
* cosine data)
|
||||
*/
|
||||
void InitialTrimAndFilter(wpi::StringMap<std::vector<PreparedData>>* data,
|
||||
void InitialTrimAndFilter(wpi::util::StringMap<std::vector<PreparedData>>* data,
|
||||
AnalysisManager::Settings* settings,
|
||||
std::vector<units::second_t>& positionDelays,
|
||||
std::vector<units::second_t>& velocityDelays,
|
||||
units::second_t& minStepTime,
|
||||
units::second_t& maxStepTime,
|
||||
std::vector<wpi::units::second_t>& positionDelays,
|
||||
std::vector<wpi::units::second_t>& velocityDelays,
|
||||
wpi::units::second_t& minStepTime,
|
||||
wpi::units::second_t& maxStepTime,
|
||||
std::string_view unit = "");
|
||||
|
||||
/**
|
||||
@@ -232,6 +232,6 @@ void InitialTrimAndFilter(wpi::StringMap<std::vector<PreparedData>>* data,
|
||||
*
|
||||
* @param data A pointer to a PreparedData vector
|
||||
*/
|
||||
void AccelFilter(wpi::StringMap<std::vector<PreparedData>>* data);
|
||||
void AccelFilter(wpi::util::StringMap<std::vector<PreparedData>>* data);
|
||||
|
||||
} // namespace sysid
|
||||
|
||||
@@ -34,7 +34,7 @@ class SimpleMotorSim {
|
||||
* @param voltage Voltage to apply over the timestep.
|
||||
* @param dt Sample period.
|
||||
*/
|
||||
void Update(units::volt_t voltage, units::second_t dt);
|
||||
void Update(wpi::units::volt_t voltage, wpi::units::second_t dt);
|
||||
|
||||
/**
|
||||
* Returns the position.
|
||||
@@ -56,7 +56,7 @@ class SimpleMotorSim {
|
||||
* @param voltage The voltage that is being applied to the mechanism / input
|
||||
* @return The acceleration given the state and input
|
||||
*/
|
||||
double GetAcceleration(units::volt_t voltage) const;
|
||||
double GetAcceleration(wpi::units::volt_t voltage) const;
|
||||
|
||||
/**
|
||||
* Resets model position and velocity.
|
||||
|
||||
@@ -22,14 +22,14 @@ struct MotorData {
|
||||
// Timestamps are not necessarily aligned!
|
||||
struct Run {
|
||||
template <typename T>
|
||||
requires std::is_arithmetic_v<T> || units::traits::is_unit_t_v<T>
|
||||
requires std::is_arithmetic_v<T> || wpi::units::traits::is_unit_t_v<T>
|
||||
struct Sample {
|
||||
Sample(units::second_t time, T measurement)
|
||||
Sample(wpi::units::second_t time, T measurement)
|
||||
: time{time}, measurement{measurement} {}
|
||||
units::second_t time;
|
||||
wpi::units::second_t time;
|
||||
T measurement;
|
||||
};
|
||||
std::vector<Sample<units::volt_t>> voltage;
|
||||
std::vector<Sample<wpi::units::volt_t>> voltage;
|
||||
std::vector<Sample<double>> position;
|
||||
std::vector<Sample<double>> velocity;
|
||||
};
|
||||
@@ -40,7 +40,7 @@ struct MotorData {
|
||||
struct TestData {
|
||||
std::string distanceUnit;
|
||||
AnalysisType mechanismType;
|
||||
wpi::StringMap<MotorData> motorData;
|
||||
wpi::util::StringMap<MotorData> motorData;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ struct PreparedData {
|
||||
/**
|
||||
* The timestamp of the data point.
|
||||
*/
|
||||
units::second_t timestamp;
|
||||
wpi::units::second_t timestamp;
|
||||
|
||||
/**
|
||||
* The voltage of the data point.
|
||||
@@ -71,7 +71,7 @@ struct PreparedData {
|
||||
/**
|
||||
* The difference in timestamps between this point and the next point.
|
||||
*/
|
||||
units::second_t dt = 0_s;
|
||||
wpi::units::second_t dt = 0_s;
|
||||
|
||||
/**
|
||||
* The acceleration of the data point
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace sysid {
|
||||
* @param accum The accumulated gyro angle.
|
||||
*/
|
||||
constexpr double CalculateTrackwidth(double l, double r,
|
||||
units::radian_t accum) {
|
||||
wpi::units::radian_t accum) {
|
||||
// The below comes from solving ω = (vr − vl) / 2r for 2r.
|
||||
return (gcem::abs(r) + gcem::abs(l)) / gcem::abs(accum.value());
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
struct ImPlotPoint;
|
||||
|
||||
namespace glass {
|
||||
namespace wpi::glass {
|
||||
class Storage;
|
||||
} // namespace glass
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace sysid {
|
||||
* load their data, visualize the data, adjust certain variables, and then view
|
||||
* the calculated gains.
|
||||
*/
|
||||
class Analyzer : public glass::View {
|
||||
class Analyzer : public wpi::glass::View {
|
||||
public:
|
||||
TestData m_data;
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ class Analyzer : public glass::View {
|
||||
* @param storage Glass Storage
|
||||
* @param logger The program logger
|
||||
*/
|
||||
Analyzer(glass::Storage& storage, wpi::Logger& logger);
|
||||
Analyzer(wpi::glass::Storage& storage, wpi::util::Logger& logger);
|
||||
|
||||
/**
|
||||
* Displays the analyzer widget
|
||||
@@ -212,7 +212,7 @@ class Analyzer : public glass::View {
|
||||
|
||||
// Everything related to feedback controller calculations.
|
||||
AnalysisManager::Settings m_settings;
|
||||
wpi::StringMap<FeedbackControllerPreset> m_presets;
|
||||
wpi::util::StringMap<FeedbackControllerPreset> m_presets;
|
||||
|
||||
int m_selectedLoopType = 1;
|
||||
int m_selectedPreset = 0;
|
||||
@@ -223,7 +223,7 @@ class Analyzer : public glass::View {
|
||||
double m_accelRMSE;
|
||||
double m_Kp;
|
||||
double m_Kd;
|
||||
units::millisecond_t m_timescale;
|
||||
wpi::units::millisecond_t m_timescale;
|
||||
bool m_timescaleValid = false;
|
||||
|
||||
// Units
|
||||
@@ -235,7 +235,7 @@ class Analyzer : public glass::View {
|
||||
float m_stepTestDuration = 0;
|
||||
|
||||
// Logger
|
||||
wpi::Logger& m_logger;
|
||||
wpi::util::Logger& m_logger;
|
||||
|
||||
// Plot
|
||||
AnalyzerPlot m_plot{m_logger};
|
||||
|
||||
@@ -37,7 +37,7 @@ class AnalyzerPlot {
|
||||
*
|
||||
* @param logger The program logger
|
||||
*/
|
||||
explicit AnalyzerPlot(wpi::Logger& logger);
|
||||
explicit AnalyzerPlot(wpi::util::Logger& logger);
|
||||
|
||||
/**
|
||||
* Sets the data to be displayed on the plots.
|
||||
@@ -55,7 +55,7 @@ class AnalyzerPlot {
|
||||
void SetData(const Storage& rawData, const Storage& filteredData,
|
||||
std::string_view unit,
|
||||
const AnalysisManager::FeedforwardGains& ff,
|
||||
const std::array<units::second_t, 4>& startTimes,
|
||||
const std::array<wpi::units::second_t, 4>& startTimes,
|
||||
AnalysisType type, std::atomic<bool>& abort);
|
||||
|
||||
/**
|
||||
@@ -189,10 +189,10 @@ class AnalyzerPlot {
|
||||
std::string m_velPortionAccelLabel;
|
||||
|
||||
// Thread safety
|
||||
wpi::spinlock m_mutex;
|
||||
wpi::util::spinlock m_mutex;
|
||||
|
||||
// Logger
|
||||
wpi::Logger& m_logger;
|
||||
wpi::util::Logger& m_logger;
|
||||
|
||||
FilteredDataVsTimePlot m_quasistaticData;
|
||||
FilteredDataVsTimePlot m_dynamicData;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "wpi/sysid/analysis/Storage.hpp"
|
||||
#include "wpi/util/StringMap.hpp"
|
||||
|
||||
namespace glass {
|
||||
namespace wpi::glass {
|
||||
class Storage;
|
||||
} // namespace glass
|
||||
|
||||
@@ -25,21 +25,21 @@ namespace wpi {
|
||||
namespace log {
|
||||
class DataLogReaderEntry;
|
||||
} // namespace log
|
||||
class Logger;
|
||||
class wpi::util::Logger;
|
||||
} // namespace wpi
|
||||
|
||||
namespace sysid {
|
||||
/**
|
||||
* Helps with loading datalog files.
|
||||
*/
|
||||
class DataSelector : public glass::View {
|
||||
class DataSelector : public wpi::glass::View {
|
||||
public:
|
||||
/**
|
||||
* Creates a data selector widget
|
||||
*
|
||||
* @param logger The program logger
|
||||
*/
|
||||
explicit DataSelector(glass::Storage& storage, wpi::Logger& logger)
|
||||
explicit DataSelector(wpi::glass::Storage& storage, wpi::util::Logger& logger)
|
||||
: m_logger{logger} {}
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ class DataSelector : public glass::View {
|
||||
std::vector<std::string> m_missingTests;
|
||||
|
||||
private:
|
||||
wpi::Logger& m_logger;
|
||||
wpi::util::Logger& m_logger;
|
||||
using Runs = std::vector<std::pair<int64_t, int64_t>>;
|
||||
using State = std::map<std::string, Runs, std::less<>>; // full name
|
||||
using Tests = std::map<std::string, State, std::less<>>; // e.g. "dynamic"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "wpi/glass/View.hpp"
|
||||
#include "wpi/util/Signal.h"
|
||||
|
||||
namespace glass {
|
||||
namespace wpi::glass {
|
||||
class Storage;
|
||||
} // namespace glass
|
||||
|
||||
@@ -25,21 +25,21 @@ namespace log {
|
||||
class DataLogReaderEntry;
|
||||
class DataLogReaderThread;
|
||||
} // namespace log
|
||||
class Logger;
|
||||
class wpi::util::Logger;
|
||||
} // namespace wpi
|
||||
|
||||
namespace sysid {
|
||||
/**
|
||||
* Helps with loading datalog files.
|
||||
*/
|
||||
class LogLoader : public glass::View {
|
||||
class LogLoader : public wpi::glass::View {
|
||||
public:
|
||||
/**
|
||||
* Creates a log loader widget
|
||||
*
|
||||
* @param logger The program logger
|
||||
*/
|
||||
explicit LogLoader(glass::Storage& storage, wpi::Logger& logger);
|
||||
explicit LogLoader(wpi::glass::Storage& storage, wpi::util::Logger& logger);
|
||||
|
||||
~LogLoader() override;
|
||||
|
||||
@@ -52,10 +52,10 @@ class LogLoader : public glass::View {
|
||||
* Signal called when the current file is unloaded (invalidates any
|
||||
* LogEntry*).
|
||||
*/
|
||||
wpi::sig::Signal<> unload;
|
||||
wpi::util::sig::Signal<> unload;
|
||||
|
||||
private:
|
||||
// wpi::Logger& m_logger;
|
||||
// Logger& m_logger;
|
||||
|
||||
std::string m_filename;
|
||||
std::unique_ptr<pfd::open_file> m_opener;
|
||||
|
||||
Reference in New Issue
Block a user