Library for driving a motor with one PWM and one DIR signal using PI control.
Fork of Motor2 by
Diff: motor.cpp
- Revision:
- 10:b0e6051a6109
- Parent:
- 9:bec5a728405f
- Child:
- 11:87a73d40ce5b
--- a/motor.cpp Sun Sep 22 07:24:15 2013 +0000 +++ b/motor.cpp Sun Nov 03 11:41:40 2013 +0000 @@ -7,15 +7,15 @@ PwmOut pwm(PWMpin); pwm.period_us(pwmPeriod); setPoint = 0; - pMulti = 32; - iDiv = 1; + pMulti = 48; + iMulti = 2; dMulti = 1; error = 0; prevError = 0; P = 0; I = 0; minPwm = 100; - pidMulti = 128; + pidMulti = 256; iMax = 4096 * pidMulti; currentSpeed = 0; @@ -72,7 +72,7 @@ minPwmValue = -minPwm; } - I += error * pidMulti / iDiv; + I += error * pidMulti * iMulti; //constrain integral if (I < -iMax) I = -iMax; if (I > iMax) I = iMax;