Skip to content

Commit

Permalink
period in seconds (but prefer multiply over divide)
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Jan 27, 2025
1 parent e604785 commit 2c1f1ac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions firmware/pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
float Pid::GetOutput(float setpoint, float observation)
{
float error = setpoint - observation;
float periodSec = 1e-3 * m_config->periodMs;

// Integrate error
m_integrator += error * m_config->periodMs * m_config->kI;
m_integrator += error * periodSec * m_config->kI;

// Differentiate error
float errorDelta = error - m_lastError;
float dEdt = errorDelta / m_config->periodMs;
float dEdt = errorDelta / periodSec;
m_lastError = error;

// Clamp to +- 1
Expand Down

0 comments on commit 2c1f1ac

Please sign in to comment.