Got IMU? Get "Heading Bot"

Got the DI IMU on your GoPiGo3? Get HEADING BOT!

HEADING ROBOT

heading_robot.py uses the Dexter Industries Inertial Measurement Unit (BNO055 chip)
in IMUPLUS mode (Fusion from Gyros and Accelerometers only, no magnetometers) to
orient the GoPiGo3 robot with respect to the orientation when the program is started as 0 degrees.

heading_robot.py uses three IMU interface layers (modified DI IMU classes)

  • my_safe_inertial_management_unit.py SafeIMUSensor() class
  • my_inertial_management_unit.py InertialMeasurementUnit() class
  • myBNO055.py BNO055() class
     

These classes implement features above the DI IMU standard interface:

  • Initialization of HW in IMUPLUS mode (Fusion using only Gyros and Accels, no mags)
  • Safe “reset and remap axes” method to set heading to 0
  • Tracking of soft I2C exceptions
  • Software Only Interface Object initialization to allow HW access/control without setting mode
  • Multi-process safe program to read values from IMU without knowing current mode
  • verbose options for greater visibility into IMU operations
  • di_i2c mutex protected access to more BNO055 methods

 

heading_robot architecture is based on the superb compass_robot example designed by Robert Lucian Chiriac @RobertLucian

Get The Code:

cd ~ 
curl -LJO https://github.com/slowrunner/Carl/raw/master/Examples/imu/di_BNO055/headingbot/headingbot.tar.gz 
tar -xzvf headingbot.tar.gz
cd headingbot

Usage:

  1. Mount Dexter Industries Inertial Measurement Unit Point-up, chip to front
  2. Connect IMU to GoPiGo3’s AD1 port
  3. Orient GoPiGo3 to some reference such as floor board joints or taped line on floor
  4. ./heading_robot.py

heading_bot_display

  1. Press arrow keys for shortcut to 0, 90, 180, 270
    or enter a direction such as 45, then press return
  2. Watch for robot to complete re-orienting
  3. Check what heading the robot “thinks” it is pointed (IMU heading)
  4. Optionally press “f” key to make robot move forward, press “Space” key to stop
  5. Press ctrl-c to exit

Notes:

1 Like
  1. Bloody Hell!  Right smart job you did there. . .  You do realize that I’ve got my eye on this for after I get my Remote Camera Robot project finished?  I can see that helping hugely with autonomous robot navigation.
     
  2. Is there a way to change the port?  AD1 is already in use by Charlie’s bumper.
     
  3. Is there a way to disable the “direction I’m pointing right now is 0° mode?” What if I want true headings?
     
  4. And did I forget to mention that this is one jaw-dropping piece of work?  I should be a fly on your wall when you’re coding. . .
1 Like

heading_bot.py:

PORT = "AD1"  # Use "AD1" or "AD2" for clock-stretching software I2C

What is true? True North? Not interested. You could use NDOF mode and calibrate, and add your declination - you’re on your own. You could also use DI compass_bot.

Just thought of another way - point him to your true North before you start heading_bot.py

Like I told you before - just bang Charlie into a wall, call safe_resetBNO055(), and that is ZERO! Very stable, doesn’t drift, not influenced by calibration, or clumpy molten magma.

1 Like

In your case, you have a fixed point of reference - Carl’s dock.  Even if Carl’s dock moves, the dock is always his standard 0 - 0 - 0 reference point.

In my case, there is no fixed “zero” point. I just plop Charlie down on the floor, fire him up, and send him on his way. When done, I bring him back, pick him up, turn him off - (or plug him into ground-power for dev work), and put him away so the granddaughters don’t trip over him.

What I was hoping to do was to be able to tell Charlie to “go West” or “turn 90 degrees”, and have that be what happens.  I don’t expect “west” to be exactly 270.00000 degrees true - if I need that kind of accuracy I have a Dexter GPS module I can hook up to him - but then again, I’m not sure he’s ready to go outside just yet.

What I would like to see is “reasonable” accuracy - if I tell him to make four 90° turns, I’d really like him to end up where he started, not in St. Petersburg or Vladivostok. :wink: (or, in a totally different part of the carpet, headed off to who knows where.)  Maybe not decimal accuracy as to absolute direction, but a reasonable repeatability with respect to the four cardinal points and specified turns.  Magnetic variation, deviation, declination, discombobulation and all that? Not so important.  He’s not flying trans-Atlantic. . . .

Then again, maybe I can find a sheet of Mu-metal and make shields for the motor/encoder pairs?  I wonder, do they need to be grounded to provide magnetic shielding?

1 Like

Dexter’s compass_robot.py does exactly that.

Actually, you don’t need compass bot’s complexity. I wish DI had built a layered set of examples, instead of going straight from “read the sensor” to “multiple threads with command and data queues implementing a dynamic stimulus-response feedback loop”.

1 Like

You don’t know how many times I’ve said that with my project!

I’ve gotten to the point where I can read the status of a plugged in joystick, but I haven’t been able to get the dynamic data yet.  All the online examples do this in the context of writing a game - and the actual “read the dynamic data” is buried under layers and layers of game logic.

The on-line spec’s?  Compared to some of those, DOD MIL-883 specifications read like a third-grade story book!

1 Like

Exactly. A simple demo:

  • Ask User: IMUPLUS or NDOF mode?
  • If NDOF, Ask user to perform the calibration aerial maneuver (wobbly fig-8)
  • If NDOF, tell user “put me down now”
  • When heading is constant for 10 seconds, “Announce” current heading
  • Repeat four times:
    • Announce “driving forward two bot lengths in 5 seconds”
    • Drive forward two bot lengths
    • Announce “turning 90 degrees in 5 seconds”
    • turn 90 right by wheel encoders
    • Announce current heading
  • Tell User: “Turning 90 degrees in 5 seconds”
  • Announce current heading
  • Announce "I believe I am pointed +/- x degrees from initial heading
1 Like

Spoken like a true software maven!  As for me, the mechanical adjusters for Carl’s eyes would be infinitely easier - that darned remote robot code is going to be the death of me yet!

1 Like

You can always give up and switch to the “old remote robot” which used two buttons in a phone browser. Left: turn left. Right: turn right, Both: Go Forward.

1 Like

Nevah! (John Adams in 1776)

1 Like