Compass Heading as Direction for Robot Cart

In a previous post I related how I used the tilt function of the micro:Bit to control the direction a Robot Cart moved. It worked ok although a little inaccurate. But my grandkids had fun with it.

I then wondered if using the compass could be used to turn the Cart. My plan was to detect when the compass had changed direction and command the Cart to turn in that direction. It has not been successful, the following are my findings.

The compass direction can vary by up to 10 degrees just sitting on the bench

Two micro:Bits can have a different idea of where North it. Variation was out by about 20 degrees. But suspect the battery pack being close to one of the micro:Bits affected its calibration.

The calibration animation can be annoying after a few times. Once the calibration is saved it works good. But the message scrolling is the annoying part, especially if you don’t get all the LEDs lit quick enough.

The problem is developing an algorithm that can determine the current rest position and then detect a variation from that position. While ignoring the up to 10 degree variation jitter. And at the same time updating the rest position if the orientation of the micro:Bit is changed. I think it is beyond my programming ability. But it was fun to attempt.

The result of all this; in my opinion; is a joystick or push button interface is a better control mechanism. So I have ordered a Kitronik Game control board to experiment further with the micro:Bit.

Regards
Jim

2 Likes

Hey James,

Awesome project, really cool application of the micro:bits!

Would using a couple of accelerometers work as well?
There are lots of tutorials online coverering many types of digital filters that you could implement.

Keen to see where this takes you!
Liam.

The accelerometers on the micro:Bit provide the tilt function.
There are Make Code functions that can read the accelerometer value directly and others to return a pitch and roll in degrees. With these the board starts in a know position, horizontal returns 0 in X Y axis and full in Z axis because it is essentially measuring the gravitational effect in the X Y Z planes.

The compass is not the same. As the board is moved it changes. If used as a Cart controller the values returned will be constantly changing due to human movement. It would have to be a pretty good algorithm tracking movement over time and determining if the current movement could be translated to a left or right command. It would need to be similar to PID algorithms in drone flight controllers. I really don’t think I have the maths to do that kind of programming.

Anyway, been fun so far.
Jim

3 Likes