Kp = 1/4 and Ki = 1/8 give VERY VERY VERY good results on flat ground and on hills for driving with a 6.7" diameter 60 pound motor. It's the best I've had. Yesterday, I was using Ki = 100 or 500 or something ridiculous like that. Needless to say, that caused problems. I was using huge Ki values because a website suggested large Ki values, but that was for a very different situation where they were trying to control the RPM on a tiny motor.
It's optimized for speed, so a little hard to understand.
Here's the code piece (in case like a moron I erase it on accident again):
//////////////////////////////////////////////////////////////////////////////////
errorNew = _throttlePos - _current;
pwmDutyFine += (((int32_t)(errorNew - errorOld)) << 13) + (int32_t)(errorOld << 2);
errorOld = errorNew;
pwmDuty = (int16_t)(pwmDutyFine >> 15);
///////////////////////////////////////////////////////////////////////////////////
The whole thing takes 15 uS, whereas a single floating point multiply takes about 100 microseconds.
EDIT: The multiply isn't as slow as I thought. Oh dang it! I might be able to improve that time a bit. I'm going to try something.
Last edited by MPaulHolmes; 05-25-2009 at 03:01 AM..
|