Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PID/PID.h@1:5e2b81f2d0b4, 2013-09-08 (annotated)
- Committer:
- maetugr
- Date:
- Sun Sep 08 20:53:33 2013 +0000
- Revision:
- 1:5e2b81f2d0b4
- Parent:
- 0:12950aa67f2a
- Child:
- 2:03e5f7ab473f
D only with Gyro as source is very stable on one axis;; next changing the PID class to get only gyro input for derivative
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| maetugr | 0:12950aa67f2a | 1 | // by MaEtUgR |
| maetugr | 0:12950aa67f2a | 2 | |
| maetugr | 1:5e2b81f2d0b4 | 3 | #ifndef PID_H |
| maetugr | 1:5e2b81f2d0b4 | 4 | #define PID_H |
| maetugr | 1:5e2b81f2d0b4 | 5 | |
| maetugr | 0:12950aa67f2a | 6 | #include "mbed.h" |
| maetugr | 0:12950aa67f2a | 7 | |
| maetugr | 1:5e2b81f2d0b4 | 8 | #define CONSTRAIN(VAL,LIMIT) ((VAL)<(-LIMIT)?(-LIMIT):((VAL)>(LIMIT)?(LIMIT):(VAL))) |
| maetugr | 0:12950aa67f2a | 9 | |
| maetugr | 0:12950aa67f2a | 10 | class PID { |
| maetugr | 0:12950aa67f2a | 11 | public: |
| maetugr | 0:12950aa67f2a | 12 | PID(float P, float I, float D, float Integral_Max); |
| maetugr | 0:12950aa67f2a | 13 | float compute(float SetPoint, float ProcessValue); |
| maetugr | 0:12950aa67f2a | 14 | void setIntegrate(bool Integrate); |
| maetugr | 0:12950aa67f2a | 15 | void setPID(float P, float I, float D); |
| maetugr | 0:12950aa67f2a | 16 | |
| maetugr | 0:12950aa67f2a | 17 | private: |
| maetugr | 1:5e2b81f2d0b4 | 18 | float P, I, D; // PID Values and limits |
| maetugr | 0:12950aa67f2a | 19 | |
| maetugr | 0:12950aa67f2a | 20 | Timer dtTimer; // Timer to measure time between every compute |
| maetugr | 0:12950aa67f2a | 21 | float LastTime; // Time when last loop was |
| maetugr | 0:12950aa67f2a | 22 | |
| maetugr | 0:12950aa67f2a | 23 | float Integral; // the sum of all errors (constaind so it doesn't get infinite) |
| maetugr | 0:12950aa67f2a | 24 | float Integral_Max; // maximum that the sum of all errors can get (not important: last error not counted) |
| maetugr | 0:12950aa67f2a | 25 | float PreviousError; // the Error of the last computation to get derivative |
| maetugr | 0:12950aa67f2a | 26 | bool Integrate; // if the integral is used / the controller is in use |
| maetugr | 0:12950aa67f2a | 27 | }; |
| maetugr | 0:12950aa67f2a | 28 | |
| maetugr | 0:12950aa67f2a | 29 | #endif |