2024-01-05 14:50:23 -05:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
|
|
|
|
#include "frc/sysid/SysIdRoutineLog.h"
|
|
|
|
|
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <string>
|
|
|
|
|
|
2024-01-05 15:22:52 -08:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
2024-01-05 14:50:23 -05:00
|
|
|
#include "frc/DataLogManager.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc::sysid;
|
|
|
|
|
|
2024-01-05 15:22:52 -08:00
|
|
|
SysIdRoutineLog::SysIdRoutineLog(std::string_view logName)
|
2024-01-19 20:43:18 -05:00
|
|
|
: m_logName(logName) {}
|
2024-01-05 14:50:23 -05:00
|
|
|
|
2024-01-05 15:22:52 -08:00
|
|
|
SysIdRoutineLog::MotorLog::MotorLog(std::string_view motorName,
|
|
|
|
|
std::string_view logName,
|
2024-01-05 14:50:23 -05:00
|
|
|
LogEntries* logEntries)
|
|
|
|
|
: m_motorName(motorName), m_logName(logName), m_logEntries(logEntries) {
|
|
|
|
|
(*logEntries)[motorName] = MotorEntries();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SysIdRoutineLog::MotorLog& SysIdRoutineLog::MotorLog::value(
|
2024-01-05 15:22:52 -08:00
|
|
|
std::string_view name, double value, std::string_view unit) {
|
2024-01-05 14:50:23 -05:00
|
|
|
auto& motorEntries = (*m_logEntries)[m_motorName];
|
|
|
|
|
|
|
|
|
|
if (!motorEntries.contains(name)) {
|
|
|
|
|
wpi::log::DataLog& log = frc::DataLogManager::GetLog();
|
|
|
|
|
|
|
|
|
|
motorEntries[name] = wpi::log::DoubleLogEntry(
|
2024-01-05 15:22:52 -08:00
|
|
|
log, fmt::format("{}-{}-{}", name, m_motorName, m_logName), unit);
|
2024-01-05 14:50:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
motorEntries[name].Append(value);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-05 15:22:52 -08:00
|
|
|
SysIdRoutineLog::MotorLog SysIdRoutineLog::Motor(std::string_view motorName) {
|
2024-01-05 14:50:23 -05:00
|
|
|
return MotorLog{motorName, m_logName, &m_logEntries};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SysIdRoutineLog::RecordState(State state) {
|
2024-01-19 20:43:18 -05:00
|
|
|
if (!m_stateInitialized) {
|
|
|
|
|
m_state =
|
|
|
|
|
wpi::log::StringLogEntry{frc::DataLogManager::GetLog(),
|
2024-01-20 15:42:57 +11:00
|
|
|
fmt::format("sysid-test-state-{}", m_logName)};
|
2024-01-19 20:43:18 -05:00
|
|
|
m_stateInitialized = true;
|
|
|
|
|
}
|
2024-01-05 14:50:23 -05:00
|
|
|
m_state.Append(StateEnumToString(state));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SysIdRoutineLog::StateEnumToString(State state) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case State::kQuasistaticForward:
|
|
|
|
|
return "quasistatic-forward";
|
|
|
|
|
case State::kQuasistaticReverse:
|
|
|
|
|
return "quasistatic-reverse";
|
|
|
|
|
case State::kDynamicForward:
|
|
|
|
|
return "dynamic-forward";
|
|
|
|
|
case State::kDynamicReverse:
|
|
|
|
|
return "dynamic-reverse";
|
|
|
|
|
case State::kNone:
|
|
|
|
|
return "none";
|
|
|
|
|
default:
|
|
|
|
|
return "none";
|
|
|
|
|
}
|
|
|
|
|
}
|