dT as zero crash prevention
Should not happen, but just in case.
This commit is contained in:
parent
e1de1ac99f
commit
d9ce797cae
@ -26,7 +26,7 @@ controllerPD::controllerPD(float kP, float kD, float saturation)
|
|||||||
, m_kD(kD)
|
, m_kD(kD)
|
||||||
, m_saturation(saturation)
|
, m_saturation(saturation)
|
||||||
, m_lastError(0)
|
, m_lastError(0)
|
||||||
, m_pt1FilterApply4(10.0f)
|
, m_pt1FilterApply4(100.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ float controllerPD::run(float dT, float input, float setPoint)
|
|||||||
|
|
||||||
float pTerm(m_kP*error);
|
float pTerm(m_kP*error);
|
||||||
|
|
||||||
float dTerm(m_kD*((error-m_lastError)/dT));
|
float dTerm((dT != 0.0f) ? m_kD*((error-m_lastError)/dT) : 0.0f);
|
||||||
|
|
||||||
// Store error for next iteration
|
// Store error for next iteration
|
||||||
m_lastError = error;
|
m_lastError = error;
|
||||||
|
@ -25,7 +25,12 @@ pt1FilterApply4::pt1FilterApply4(float freqCut)
|
|||||||
|
|
||||||
float pt1FilterApply4::filter(float input, float dT)
|
float pt1FilterApply4::filter(float input, float dT)
|
||||||
{
|
{
|
||||||
m_filtered = m_filtered + dT / (m_RC + dT) * (input - m_filtered);
|
if (dT != 0.0f && m_RC + dT != 0.0f)
|
||||||
|
{
|
||||||
|
float gain(dT / (m_RC + dT));
|
||||||
|
|
||||||
|
m_filtered += gain * (input - m_filtered);
|
||||||
|
}
|
||||||
|
|
||||||
return m_filtered;
|
return m_filtered;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user