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