SCRIPT namespace replacements

This commit is contained in:
PJ Reiniger
2025-11-07 20:00:05 -05:00
committed by Peter Johnson
parent ae6c043632
commit 9aca8e0fd6
2622 changed files with 22275 additions and 22275 deletions

View File

@@ -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();
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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

View File

@@ -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) {

View File

@@ -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"

View File

@@ -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

View File

@@ -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});
}
}

View File

@@ -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; });