Remove unused parameter and extract branching behaviour

This commit is contained in:
Dr. Dystopia 2024-08-17 22:24:45 +02:00
parent 4ff5ff2772
commit a05798b50a
2 changed files with 17 additions and 13 deletions

View File

@ -133,24 +133,18 @@ bool IMUGyroscope::CanCalibrate() const
return ControlReference::GetInputGate();
}
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState(bool update)
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState()
{
if (!AreInputsBound())
{
if (update)
{
// Set calibration to zero.
m_calibration = {};
RestartCalibration();
}
return std::nullopt;
}
return AreInputsBound() ? GetStateInternal() : Reset();
}
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetStateInternal()
{
auto state = GetRawState();
// Alternatively we could open the control gate around GetRawState() while calibrating,
// but that would imply background input would temporarily be treated differently for our controls
if (update && CanCalibrate())
if (CanCalibrate())
UpdateCalibration(state);
state -= m_calibration;
@ -162,6 +156,14 @@ std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState(bool update)
return state;
}
std::nullopt_t IMUGyroscope::Reset()
{
// Set calibration to zero.
m_calibration = {};
RestartCalibration();
return std::nullopt;
}
ControlState IMUGyroscope::GetDeadzone() const
{
return m_deadzone_setting.GetValue() / 360 * MathUtil::TAU;

View File

@ -23,7 +23,7 @@ public:
StateData GetRawState() const;
// Also updates the state by default
std::optional<StateData> GetState(bool update = true);
std::optional<StateData> GetState();
// Value is in rad/s.
ControlState GetDeadzone() const;
@ -35,6 +35,8 @@ private:
bool AreInputsBound() const;
bool CanCalibrate() const;
std::nullopt_t Reset();
std::optional<StateData> GetStateInternal();
void RestartCalibration();
void UpdateCalibration(const StateData&);