Remove unused parameter and extract branching behaviour
This commit is contained in:
parent
4ff5ff2772
commit
a05798b50a
|
@ -133,24 +133,18 @@ bool IMUGyroscope::CanCalibrate() const
|
||||||
return ControlReference::GetInputGate();
|
return ControlReference::GetInputGate();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState(bool update)
|
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState()
|
||||||
{
|
{
|
||||||
if (!AreInputsBound())
|
return AreInputsBound() ? GetStateInternal() : Reset();
|
||||||
{
|
|
||||||
if (update)
|
|
||||||
{
|
|
||||||
// Set calibration to zero.
|
|
||||||
m_calibration = {};
|
|
||||||
RestartCalibration();
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetStateInternal()
|
||||||
|
{
|
||||||
auto state = GetRawState();
|
auto state = GetRawState();
|
||||||
|
|
||||||
// Alternatively we could open the control gate around GetRawState() while calibrating,
|
// 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
|
// but that would imply background input would temporarily be treated differently for our controls
|
||||||
if (update && CanCalibrate())
|
if (CanCalibrate())
|
||||||
UpdateCalibration(state);
|
UpdateCalibration(state);
|
||||||
|
|
||||||
state -= m_calibration;
|
state -= m_calibration;
|
||||||
|
@ -162,6 +156,14 @@ std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState(bool update)
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::nullopt_t IMUGyroscope::Reset()
|
||||||
|
{
|
||||||
|
// Set calibration to zero.
|
||||||
|
m_calibration = {};
|
||||||
|
RestartCalibration();
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
ControlState IMUGyroscope::GetDeadzone() const
|
ControlState IMUGyroscope::GetDeadzone() const
|
||||||
{
|
{
|
||||||
return m_deadzone_setting.GetValue() / 360 * MathUtil::TAU;
|
return m_deadzone_setting.GetValue() / 360 * MathUtil::TAU;
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
|
|
||||||
StateData GetRawState() const;
|
StateData GetRawState() const;
|
||||||
// Also updates the state by default
|
// Also updates the state by default
|
||||||
std::optional<StateData> GetState(bool update = true);
|
std::optional<StateData> GetState();
|
||||||
|
|
||||||
// Value is in rad/s.
|
// Value is in rad/s.
|
||||||
ControlState GetDeadzone() const;
|
ControlState GetDeadzone() const;
|
||||||
|
@ -35,6 +35,8 @@ private:
|
||||||
|
|
||||||
bool AreInputsBound() const;
|
bool AreInputsBound() const;
|
||||||
bool CanCalibrate() const;
|
bool CanCalibrate() const;
|
||||||
|
std::nullopt_t Reset();
|
||||||
|
std::optional<StateData> GetStateInternal();
|
||||||
void RestartCalibration();
|
void RestartCalibration();
|
||||||
void UpdateCalibration(const StateData&);
|
void UpdateCalibration(const StateData&);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue