You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a class that functions as a PID controller. Its constructor should take 3 arguments, one for each constant: P, I, and D. It should have a function, getCorrection(), that takes an error as an argument, and returns a correction. Here is more specifically what the function needs to do, not necessarily in this order:
Calculate deltaTime (the time since the last getCorrection() was called)
Add error * deltaTime to a variable (like errorSum), used to calculate I
Calculate the proportional error: P * error
Calculate the integral error: I * errorSum
Calculate the derivative error: D * (error - previousError) / deltaTime
Cache the current error as previousError for the next time getCorrection() is called
Return the sum of the three errors
Since deltaTime and the derivative correction both need some information from the previous call to getCorrection(), it would be a good idea to include some kind of start() function, that doesn't return a correction, but does cache the time and an initial error.
Create a class that functions as a PID controller. Its constructor should take 3 arguments, one for each constant: P, I, and D. It should have a function, getCorrection(), that takes an error as an argument, and returns a correction. Here is more specifically what the function needs to do, not necessarily in this order:
Since deltaTime and the derivative correction both need some information from the previous call to getCorrection(), it would be a good idea to include some kind of start() function, that doesn't return a correction, but does cache the time and an initial error.
Needed Arduino functions:
micros()
The text was updated successfully, but these errors were encountered: