mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
@@ -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()} {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user