DPRG
DPRG List  



[DPRG] Re:

Subject: [DPRG] Re:
From: Chuck McManis cmcmanis at mcmanis.com
Date: Sat Dec 27 18:40:01 CST 2003

Hi Dave,

I took your ascii drawing and augmented it with a current feedback system:
<http://www.mcmanis.com/chuck/robotics/balance.html>

If you were to implement this on the 68HC11, I would expect it would go 
something like:

#define IK ?? /* current loop "P" constant */

void pwm(int torque) {
     int direction, magnitude, duty_cycle;
     int ms, i;

     if (torque < 0) {
         direction = 1;
         magnitude = -torque;
     } else {
         direction = 0;
         magnitude = torque;
     }
     for (ms = 0; ms < 40; ms++) {
         i = get_current();
         duty_cycle = pwm_convert(magnitude + (i1 - magnitude)*IK);
         SET_DUTY_CYCLE(duty_cycle)'
         msleep(1);
     }
}

What this would do, is create another control loop within your initial loop 
that changes the pwm() function from shipping a constant value, to actually 
setting the "desired current through the motor" value. You would eliminate 
the msleep(40) in the main loop because this would run for 40mS by itself.

The function pwm_convert() takes an absolute current value desired, and 
converts it into a PWM duty cycle necessary to achieve that current. Under 
ideal conditions the sensed current value and the actual current value will 
match and the duty_cycle will remain unchanged, however as the sensed 
current becomes less than the desired current (because of battery sag) the 
"P" term will start to increase the actual duty cycle sent to compensate. 
Further, if you're batteries were REALLY full, then you would get _more_ 
current than you wanted and the P term would back off the duty cycle to 
compensate.

What this has accomplished is to switch the system from controlling the 
motors through voltage, and thus indirectly the current, to one that 
controls the current directly and is thus immune to changes in battery voltage.

--Chuck



More information about the DPRG mailing list