DPRG List  

[DPRG] Balancing robot difficulties

Subject: [DPRG] Balancing robot difficulties
From: dpa dpa at io.isem.smu.edu
Date: Wed Jul 4 00:19:44 CDT 2007


Kenneth wrote:
> Noted the comment on Harmonic drives. 

Great link, thanks.  I'd not understood that the outer
gear is *flexible*.  Very interesting.  Where to get
such a motor?  

Luke wrote:

I dug back through some code for the nBot balancing
robot and found the following comment:

; 28 Jun 03 dpa         Added code to remove backlash

Hmmm, what do you know?  

This was in the header of the assembly code that
handles the two quad encoders on the motors.

Looks like it tries to ignore the encoder ticks in a
sort of dead zone around zero that depends on which
direction the motor is going.  It's been awhile since
I worked with this code... ;)

The encoder is mounted on the motor itself so the
interrupt is ignoring counts that happen when the
motor changes directions and goes through 0, for 9
counts in either direction.

The file is HC11 assembly code so I tried to rewrite it
in C, as a fragment of the interrupt routine that
maintains the counts for the quad encoders mounted on
the drive motors.  There are actually two of these,
left and right, but only one is shown here:

//  measured backlash at the wheels == 9 ticks

#define BACKLASH 9

// backlash counter

int backlash;

// quad encoder interrupt, maintains encoder count

void quadencoder_interrupt()

    // ...
    // standard quad encoder interrupt stuff
    // ...

    if (encoder tick direction is forward) {

        if (backlash >= BACKLASH) encoder_count++;
        else backlash++;

    else { // encoder tick direction is backward

        if (backlash <= 0) encoder_count--;
        else backlash--;

    // ...

So the wheel encoder count is not incremented/decremented during
the time in which the motor is taking up the backlash, as it passes
through zero.  This in turn prevents the balance algorithm from
reacting to the quick burst of counts as the motor, now unloaded,
winds the backlash in the opposite direction.  That looks to the
balance algorithm as it the robot has suddenly jerked when it has

I still think this is a second order tweak that requires getting
as much mechanical backlash out of the system as possible first.

best regards,

More information about the DPRG mailing list