[wpilibc] Clean up C++ SysId routine (#6160)

This commit is contained in:
Tyler Veness
2024-01-05 15:22:52 -08:00
committed by GitHub
parent 4595f84719
commit 6bed82a18e
3 changed files with 69 additions and 57 deletions

View File

@@ -4,40 +4,43 @@
#include "frc/sysid/SysIdRoutineLog.h"
#include <fmt/format.h>
#include "frc/DataLogManager.h"
using namespace frc::sysid;
SysIdRoutineLog::SysIdRoutineLog(const std::string& logName)
SysIdRoutineLog::SysIdRoutineLog(std::string_view logName)
: m_logName(logName),
m_state(wpi::log::StringLogEntry{frc::DataLogManager::GetLog(),
"sysid-test-state" + logName}) {
m_state(wpi::log::StringLogEntry{
frc::DataLogManager::GetLog(),
fmt::format("sysid-test-state{}", logName)}) {
m_state.Append(StateEnumToString(State::kNone));
}
SysIdRoutineLog::MotorLog::MotorLog(const std::string& motorName,
const std::string& logName,
SysIdRoutineLog::MotorLog::MotorLog(std::string_view motorName,
std::string_view logName,
LogEntries* logEntries)
: m_motorName(motorName), m_logName(logName), m_logEntries(logEntries) {
(*logEntries)[motorName] = MotorEntries();
}
SysIdRoutineLog::MotorLog& SysIdRoutineLog::MotorLog::value(
const std::string& name, double value, const std::string& unit) {
std::string_view name, double value, std::string_view unit) {
auto& motorEntries = (*m_logEntries)[m_motorName];
if (!motorEntries.contains(name)) {
wpi::log::DataLog& log = frc::DataLogManager::GetLog();
motorEntries[name] = wpi::log::DoubleLogEntry(
log, name + "-" + m_motorName + "-" + m_logName, unit);
log, fmt::format("{}-{}-{}", name, m_motorName, m_logName), unit);
}
motorEntries[name].Append(value);
return *this;
}
SysIdRoutineLog::MotorLog SysIdRoutineLog::Motor(const std::string& motorName) {
SysIdRoutineLog::MotorLog SysIdRoutineLog::Motor(std::string_view motorName) {
return MotorLog{motorName, m_logName, &m_logEntries};
}