mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilibc] Clean up C++ SysId routine (#6160)
This commit is contained in:
@@ -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};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user