Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Fix sysid crashing when passed nullptr or {} #6508

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -62,9 +63,6 @@ class Config {
if (timeout) {
m_timeout = timeout.value();
}
if (recordState) {
m_recordState = recordState.value();
}
}
};

Expand Down Expand Up @@ -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} {}

Expand All @@ -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()} {}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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();
Expand Down Expand Up @@ -168,3 +177,8 @@ TEST_F(SysIdRoutineTest, OutputCorrectVoltage) {
currentStateList.clear();
sentVoltages.clear();
}

TEST_F(SysIdRoutineTest, EmptyLogFunc) {
RunCommand(std::move(m_emptyRoutineForward));
SUCCEED();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class Drive : public frc2::SubsystemBase {
constants::drive::kRightEncoderReversed};

frc2::sysid::SysIdRoutine m_sysIdRoutine{
frc2::sysid::Config{std::nullopt, std::nullopt, std::nullopt,
std::nullopt},
frc2::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr},
frc2::sysid::Mechanism{
[this](units::volt_t driveVoltage) {
m_leftMotor.SetVoltage(driveVoltage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class Shooter : public frc2::SubsystemBase {
constants::shooter::kEncoderReversed};

frc2::sysid::SysIdRoutine m_sysIdRoutine{
frc2::sysid::Config{std::nullopt, std::nullopt, std::nullopt,
std::nullopt},
frc2::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr},
frc2::sysid::Mechanism{
[this](units::volt_t driveVoltage) {
m_shooterMotor.SetVoltage(driveVoltage);
Expand Down
Loading