This commit is contained in:
Tygyh 2025-04-23 21:30:01 -04:00 committed by GitHub
commit fd9f560ff1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 13 deletions

View file

@ -132,24 +132,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;
@ -161,6 +155,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;

View file

@ -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&);