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.
Dependencies: MODSERIAL mbed EMG_Input QEI biquadFilter
Motor/motor.h@9:19dafcb4a098, 2016-10-27 (annotated)
- Committer:
- kbruil
- Date:
- Thu Oct 27 19:36:12 2016 +0000
- Revision:
- 9:19dafcb4a098
- Child:
- 10:27fdd43f3b85
Robot PID cleaned up a bit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kbruil | 9:19dafcb4a098 | 1 | #include "mbed.h" |
| kbruil | 9:19dafcb4a098 | 2 | #include "QEI.h" |
| kbruil | 9:19dafcb4a098 | 3 | #include "BiQuad.h" |
| kbruil | 9:19dafcb4a098 | 4 | #ifndef M_PI |
| kbruil | 9:19dafcb4a098 | 5 | #define M_PI 3.141592653589793238462643383279502884L // Pi |
| kbruil | 9:19dafcb4a098 | 6 | #endif |
| kbruil | 9:19dafcb4a098 | 7 | |
| kbruil | 9:19dafcb4a098 | 8 | class motor { |
| kbruil | 9:19dafcb4a098 | 9 | private: |
| kbruil | 9:19dafcb4a098 | 10 | DigitalOut pwm; // pwm port |
| kbruil | 9:19dafcb4a098 | 11 | DigitalOut dir; // direction port |
| kbruil | 9:19dafcb4a098 | 12 | QEI sense; // encoder |
| kbruil | 9:19dafcb4a098 | 13 | |
| kbruil | 9:19dafcb4a098 | 14 | BiQuad bq1, bq2; // Declare biquads for filtering D |
| kbruil | 9:19dafcb4a098 | 15 | BiQuadChain bqc; // Declare biquad chains for filtering D |
| kbruil | 9:19dafcb4a098 | 16 | |
| kbruil | 9:19dafcb4a098 | 17 | double position; |
| kbruil | 9:19dafcb4a098 | 18 | double integral; |
| kbruil | 9:19dafcb4a098 | 19 | double olderr; |
| kbruil | 9:19dafcb4a098 | 20 | double P, I, D; |
| kbruil | 9:19dafcb4a098 | 21 | bool flip; |
| kbruil | 9:19dafcb4a098 | 22 | |
| kbruil | 9:19dafcb4a098 | 23 | |
| kbruil | 9:19dafcb4a098 | 24 | public: |
| kbruil | 9:19dafcb4a098 | 25 | motor(PinName p_pwm, PinName p_dir, PinName p_senseA, PinName p_senseB, double p, double i, double d, bool flipped); |
| kbruil | 9:19dafcb4a098 | 26 | void setSpeed(float val); |
| kbruil | 9:19dafcb4a098 | 27 | double getPosition(void); |
| kbruil | 9:19dafcb4a098 | 28 | void PID(double setpoint, double dt); |
| kbruil | 9:19dafcb4a098 | 29 | ~motor(); |
| kbruil | 9:19dafcb4a098 | 30 | |
| kbruil | 9:19dafcb4a098 | 31 | }; |