Holy hanna montana! I changed a couple of the variables in the code to 32 bit, so that now I have Kp and Ki with a resolution of 0.001 (OK, dcb, 1/1024! hahaha!). I think it's going to be plenty! My first attempt was with Kp = 16/1024, Ki = 16/1024. It was WAY too gentle to a step response on a hill. By step response, I mean I "stepped" on the gas. If I do some sort of bisection method, and then drive super slow up a steep hill each time, I figure I can find the perfect PI variables for this motor quicker than a yeller monkeyturd! (Like Old Yeller, meaning Yellow... He's my dog... I'll do it... Old Yeller is dying of the slobbering fits...) Then I can back off that a bit, and call it good for all motors? I don't know, so back off! Geeze! I want to try to implement some sort of perfect Kp and Ki seeking algorithm, so that the controller can LEARN it's motor. That would be awesome. It would also make use of the EEProm so we could store those values. Not right now, of course! hahaha!
I cleaned up the PI loop. Thank you, JayC! ya...
//////////////////////////////////////////////////////////////////////////////////
errorNew = _throttlePos - _current;
pwmDutyFine += Kp*((int32_t)errorNew) + (Ki - Kp)*((int32_t)errorOld);
errorOld = errorNew;
if (pwmDutyFine > MAX_PWM_FINE)
pwmDutyFine = MAX_PWM_FINE;
else if (pwmDutyFine < 0l)
pwmDutyFine = 0l;
/////////////////////////////////////////////////////////////////////////////
To cut down on shifts and multiplies, I store Kp as scaled by 1000 (1024). hehe
EDIT: 128/1024 < Kp < 1
EDIT: 128/1024 < Kp < 512
Last edited by MPaulHolmes; 05-23-2009 at 12:30 AM..
|