How to calibrate VTOL heading for mission mode

Greetings,
I am attempting automated missions with a tailsitter that include a VTOL transition. I am finding that the heading goes wrong during the transition. In fact, It appears to flip backwards or even spin erratically in QGC. This looks like a symptom of the heading axis getting rotated down 90 degrees as the aircraft moves through transition; it approaches a singularity.
Is there a specific way to calibrate tailsitters so that their heading is correct after transitioning? It seems that missions will not be possible until this is fixed. Perhaps there is a parameter or piece of code that I am missing? Can someone show me the section of code that should switch the axis during transition so that it remains correct in fixed-wing mode?

Thank you