[Dprglist] Assisting PID odometry with an IMU

Murray Altheim murray18 at altheim.com
Fri Jan 22 15:04:29 PST 2021

Good afternoon,

Part of building a second robot (named the KD01, with "D" for differential)
using much of the same hardware and software as my original KR01 was to
simplify development of the basic motor control, navigation and odometry.

I just finished debugging the hardware and software of the OSEPP motor
encoders (the oscilloscope worked wonders) and now I've got the KD01 able
to drive in a PID-controlled straight line, velocity set by a potentiometer.

Simple stuff.

While taking it on a tour of my lounge its port side wheel goes from
hardwood floor onto the big bump of a rug, the starboard wheel remaining
on wood floor. Once on the rug the PID controllers keep it in a straight
line (yay!) but that bump causes the robot to turn towards the
wheel hitting the bump, so that its heading shifts by say, 30 degrees to

What I'd like to do is have the IMU keep the robot on a straight line, or
at least recover its heading once it has stabilised. I'm not looking for
someone to hold my hand, but a gentle push in the right direction, maybe
a link, an algorithm (or even C/C++/Python code, which I rewrite or port)
would be enormously helpful.

I'd not need or want to use absolute orientation (compass) for this as the
robot is running indoors (and yes, that's a different subject altogether
that we've discussed previously). My guess is to use either the gyroscope
and/or the accelerometer, seems more likely the former than latter, dunno.
I'm at a bit of a loss as to where to start... though David Anderson does
have a very helpful page at:


David outlines either using A. Magnetic Compass; B. Rate Gyro; C. Gyro-
corrected Magnetic Compass; or D. 3-Axis Gyro-Corrected 3-Axis Magnetometer.
Since we'll assume the magnetometer is not reliable indoors, the gyro or
accelerometer will have to suffice. The paper referenced for B. (describing
"gyrodometry) is a bit past my ability to understand with formulae like

    μ′=m(u′) +K∗(u′,U)[K∗(U,U) +σ2∗I]−1(Z−m(U))

and in essence doesn't sound quite like a solution anyway as it refers to
use of "deep learning"; I don't think we'd need that for basic navigation.
Basically I'm thinking there must be a way to take the (relatively simple)
3D coordinates coming from the gyro or accelerometer and use that to note
the axis shift when the robot hits the edge of the rug. Or something like

I'm guessing some of you guys eat this kind of thing for breakfast, but
for me it's a bit indigestible.

Thanks very much in advance,


Murray Altheim <murray18 at altheim dot com>                       = =  ===
http://www.altheim.com/murray/                                     ===  ===
                                                                    = =  ===
     In the evening
     The rice leaves in the garden
     Rustle in the autumn wind
     That blows through my reed hut.
            -- Minamoto no Tsunenobu

More information about the DPRGlist mailing list