Propeller DCM code

Well here it is, the first DCM propeller code (that I have seen).  This is based on the wealth of work put forth by Bill Premerlani and others on the Ardupilot/matrix pilot side.  I must admit that this is the first enormous coding project that I have undertaken and as such represents a major work in progress.  Consider this V0.0001.



I am using my own custom board with two propeller chips and the following inertial hardware:

1 x Sparkfun 5dof board (The older green one)(analog)

1 x LISY300 gyro for the z-axis (analog)

1 x HMC5843 3-axis magnetometer

1 x MAX1270 ADC

1 x MPXV5004DP Dual pressure sensor (analog)

1 x MPXA6115 Barometric pressure sensor (analog)

I also have a Copernicus GPS mounted but currently unused.  Telemetry is handled by a 900MHz X-bee pro XSC.

So far the largest shortcoming of this code has turned out to be not keeping proper track of axis alignment. This will be the focus of the next release.  For the PI tuning gains I used the AMAZING Viewport software debugging environment.  I would highly recommend that anyone using the propeller look into this package (Free 30 day trial).

My tuning methodology was as follows:

Initialize the DCM matrix with an error in one axis.  The values can be computed via Premerlani's paper.  I chose to offset the matrix by ~10degrees

In the DCMupdate vector, make the off axis gyro signals zero, this will effectively turn your board into 1-dof.  I.E. if you are tuning the x-axis, then make the y and z gyro values zero.  Just make
sure you do not move it around a non-functioning axis.  Turn the kIa gain to zero and adjust the kPa
gain until you are satisfied with the settling time.  Then slowly increase the kIa gain to eliminate the steady-state offset. That's all there is to it!  This completely neglects the countless hours I spent trying to figure that out..

This tuning methodology works equally well for the z compass axis.


Once you have the PI gains set, you can adjust your gyro scaling by placing your board at a known angle (30 degree drafting triangles work well here), waiting for the DCM to stabilize and then rapidly removing the block and making the board level. Overshoot? Reduce the gains. Undershoot? Make them larger.  You can also adjust them analytically if you know the correct scaling signal, mine is a bit funky due to the ADC setup. And my X and Y axis seem to be slightly different. IDG-3200 here I come.


The DCM matrix implementation is done using fixed point arithmetic.  I chose to scale everything by 2^14 so as to reduce the chance of overflow errors when multiplying.  Please feel free to change these values but do so knowing that you may run into overflow issues within the matrix multiplication routine.  I also chose to scale the accelerometer readings to 1g = 2^14 as a legacy decision.  If this is changed, know that the associated kPa and kIa gains will need to be retuned.  

I was hoping that we (me and whoever else) could start working on this in a more distributed fashion.  Once the code is verified we would need to add support for GPS headings, velocity corrections, wind estimation and the lot.  How should we move forward on this?!


You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –


  • Very cool (digging up old thread). Any developments on this over the last year?

  • T3

    Hi Matt,

    Very nice work. It certainly is, as you said, "enormous". I wish you well, and hope that a community grows to help you continue to develop it.

    Could you post a picture of your board? I would like to see it.

    The pressure sensors are a good idea.

    I like the way you are determining the PI drift compensation feedback gains. Very nice.

    Regarding the gyro scaling, what I do with the UAVDevBoard is to run the "roll-pitch-yaw demo" without any yaw reference. (No magnetometer). Recently, we added an "integrate and dump" technique to the sampling, as well as a high rate of sampling, that has lowered the uncompensated drift rate to less than 1 degree per minute, so we can measure the gyro scaling by spinning the board on an old record player that conveniently lets you remove the center spindle. I spin the board 10 or 20 revolutions, and then look at the accumulated yaw error. This lets me estimate the gyro gains to better than 1% accuracy. I revise the gains and repeat until I can spin the board 20 times with zero accumulated error.

    I assume that the gains for the roll and pitch axes are the same, but they could be measured the same way if you are willing to build something to hold your board on its side while you test it.

    Best regards,


This reply was deleted.