[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

@@ -63,6 +63,7 @@ class SysIdRoutineTest : public ::testing::Test {
log->Motor("Mock Motor").position(0_m).velocity(0_mps).voltage(0_V);
},
&m_subsystem}};
frc2::CommandPtr m_quasistaticForward{
m_sysidRoutine.Quasistatic(frc2::sysid::Direction::kForward)};
frc2::CommandPtr m_quasistaticReverse{
@@ -72,6 +73,14 @@ class SysIdRoutineTest : public ::testing::Test {
frc2::CommandPtr m_dynamicReverse{
m_sysidRoutine.Dynamic(frc2::sysid::Direction::kReverse)};
frc2::sysid::SysIdRoutine m_emptySysidRoutine{
frc2::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr},
frc2::sysid::Mechanism{[](units::volt_t driveVoltage) {}, nullptr,
&m_subsystem}};
frc2::CommandPtr m_emptyRoutineForward{
m_emptySysidRoutine.Quasistatic(frc2::sysid::Direction::kForward)};
void RunCommand(frc2::CommandPtr command) {
command.get()->Initialize();
command.get()->Execute();
@@ -168,3 +177,8 @@ TEST_F(SysIdRoutineTest, OutputCorrectVoltage) {
currentStateList.clear();
sentVoltages.clear();
}
TEST_F(SysIdRoutineTest, EmptyLogFunc) {
RunCommand(std::move(m_emptyRoutineForward));
SUCCEED();
}