Skip to content

Commit

Permalink
[sysid] don't crash when null is provided for log
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Apr 12, 2024
1 parent 74f6486 commit e5acd26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ frc2::CommandPtr SysIdRoutine::Quasistatic(Direction direction) {
->Run([this, state, outputSign] {
m_outputVolts = outputSign * timer.Get() * m_config.m_rampRate;
m_mechanism.m_drive(m_outputVolts);
m_mechanism.m_log(this);
m_mechanism.m_log.value()(this);
m_recordState(state);
})
.FinallyDo([this] {
Expand Down Expand Up @@ -52,7 +52,7 @@ frc2::CommandPtr SysIdRoutine::Dynamic(Direction direction) {
->RunOnce([this] { m_outputVolts = m_config.m_stepVoltage; })
.AndThen(m_mechanism.m_subsystem->Run([this, state, outputSign] {
m_mechanism.m_drive(m_outputVolts * outputSign);
m_mechanism.m_log(this);
m_mechanism.m_log.value()(this);
m_recordState(state);
}))
.FinallyDo([this] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <string_view>
#include <utility>
#include <optional>

#include <frc/Timer.h>
#include <frc/sysid/SysIdRoutineLog.h>
Expand Down Expand Up @@ -76,7 +77,7 @@ class Mechanism {

/// Returns measured data (voltages, positions, velocities) of the mechanism
/// motors during test routines.
std::function<void(frc::sysid::SysIdRoutineLog*)> m_log;
std::optional<std::function<void(frc::sysid::SysIdRoutineLog*)>> m_log;

/// The subsystem containing the motor(s) that is (or are) being
/// characterized.
Expand Down Expand Up @@ -106,7 +107,7 @@ class Mechanism {
* left null.
*/
Mechanism(std::function<void(units::volt_t)> drive,
std::function<void(frc::sysid::SysIdRoutineLog*)> log,
std::optional<std::function<void(frc::sysid::SysIdRoutineLog*)>> log,
frc2::Subsystem* subsystem, std::string_view name)
: m_drive{std::move(drive)},
m_log{std::move(log)},
Expand Down

0 comments on commit e5acd26

Please sign in to comment.