[commands] Fix C++ SysIdRoutine crashing when passed nullptr or {} (#6508)

Flattens parameter from a `std::optional<std::function<...>>` to just a `std::function<...>`.  This is a breaking change but a trivial one for teams to fix.
This commit is contained in:
Drew Williams
2024-05-01 12:09:15 -04:00
committed by GitHub
parent ae4bcefefc
commit 0afc35f336
4 changed files with 20 additions and 10 deletions

View File

@@ -52,7 +52,8 @@ class Config {
Config(std::optional<ramp_rate_t> rampRate,
std::optional<units::volt_t> stepVoltage,
std::optional<units::second_t> timeout,
std::optional<std::function<void(frc::sysid::State)>> recordState) {
std::function<void(frc::sysid::State)> recordState)
: m_recordState{recordState} {
if (rampRate) {
m_rampRate = rampRate.value();
}
@@ -62,9 +63,6 @@ class Config {
if (timeout) {
m_timeout = timeout.value();
}
if (recordState) {
m_recordState = recordState.value();
}
}
};
@@ -109,7 +107,7 @@ class Mechanism {
std::function<void(frc::sysid::SysIdRoutineLog*)> log,
frc2::Subsystem* subsystem, std::string_view name)
: m_drive{std::move(drive)},
m_log{std::move(log)},
m_log{log ? std::move(log) : [](frc::sysid::SysIdRoutineLog* log) {}},
m_subsystem{subsystem},
m_name{name} {}
@@ -134,7 +132,7 @@ class Mechanism {
std::function<void(frc::sysid::SysIdRoutineLog*)> log,
frc2::Subsystem* subsystem)
: m_drive{std::move(drive)},
m_log{std::move(log)},
m_log{log ? std::move(log) : [](frc::sysid::SysIdRoutineLog* log) {}},
m_subsystem{subsystem},
m_name{m_subsystem->GetName()} {}
};