I remember when I first saw Steadicam stabilized recording and I was completely amazed by the soft camera movements. It looked so good like it was flying. Of couse it was only a mechanical filter. Since then everyone has gimbals because of the phones and action cameras. They all use active stabilization.
I also bought an action cam and I thought it would be fun the build a gimbal.
InvenSense MPU-9250
Previously we used the InvenSense MPU9250 9 axis sensor on the RobonAUT so I chose it for this project as well.
The chip itself contains an MPU6xxx accelerometer/gyroscope and they glued an Asahi Kase AK8963 compass ontop of it. The compass is accessible over an internal I2C bus, so my MCU writes the MPU9250 registers over SPI and it triggers an internal I2C transaction. As a kind move of the manufacturer the two internal modules’ coordinate system is different.
While I was developing the driver I only found one tricky bit that I need to set. We I read the I2C result registers sometimes it gave me zero value for everything. The bit I mentioned above turns on buffering so I am able to read the register while there’s an internal I2C transaction in progress.
Compass calibration

Ideally if we turn the compass around a vertical axis the two changing value should draw a circle with it’s center in the origin. In practive we get some strange shape.
There’s two effect that cause us problem. The first is the hard iron effect which caused by nearby magnetic materials (i.e. magnet in the motor) and it moves the center of the circle. It’s easy to fix this problem, we only need to get the minimal and maximal value on each axis and create an average from them as an offset value.
The other effect is the soft iron effect an it’s due the materials diverting the Earth’s magnetic field (ferromagnetic materials). This makes our circle to look like an ellipse and it also turns it around the origin. We need to get a coefficient on each axis and also an angle for each axis pairs. This can be calculated from the axes of the ellipse. As a summary we have three bias values, three scale values and three 2×2 rotation matrices. These values can result an offset vector and a 3×3 matrix or a 4×4 transformation matrix.
Using the data
At this point we have precise values of all 9 axes but we need three angles on each axis in order to control the gimbal. I used Sebastian Madgwick’s filter because it worked really we previously.
Motorcontroller
I used a motor I got from an optical drive at the beginning. This is an 18 pole brushless motor. I did not use the Hall-sensors because we can get the position from the MPU. As a motor driver I chose a very simple STL293B chip. During my tests it was a bit complicated to control the motor for absolute position due to the 18 pole setup but I solved this problem as you can see on the video below.
The frame
I desinged a frame in Fusion 360 to make me able to use the whole thing with my camera. It’s a two piece frame that lets the oppotunity to use a different motor.
My colleague 3D printed it with his machine which I’m very thankful for
Further tasks
- Bigger motor with larger torque
- Mechanics for the other axes
- Control interface