PID
Fork of QEI by
Revision 1:8100a4a465b0, committed 2017-11-08
- Comitter:
- Joshua_Cheung
- Date:
- Wed Nov 08 02:59:47 2017 +0000
- Parent:
- 0:5c2ad81551aa
- Child:
- 2:61efaab47e47
- Commit message:
- PID control code;
Changed in this revision
PID_control.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PID_control.cpp Wed Nov 08 02:59:47 2017 +0000 @@ -0,0 +1,32 @@ + +int P_controller(int error) { + int correction = Kp*error; + return correction; +} + +int I_Controller(int error) { + integrator += error; + inte correction = Ki*integrator; + integrator /= decayFactor; + + return correction; +} + +int D_Controller(int error) { + int dError = error - prevError; + int dt = time.read_us(); + timer.reset(); + prevError = error; + int correction = Kd*dError/dt; + return correction; +} + +Ticker systicker; +//speed = speed + P_Controller(error) + I_Controller(error) + D_Controller(error); +void systick() { + +} + +int main() { + Systicker.attach_us(&systick, 1000); +} \ No newline at end of file