Pan/Tilt Head Tracker Camera Control - Pitch,Yaw,Roll Angle Reference Point

Hello guyz,

I have been working on a pan-tilt head tracking servo actuated camera control project. So far, I have my Altimu 10 v4 9 DOF sensor working. I used the AHRS for minimu9 in this link: GitHub - pololu/minimu-9-ahrs-arduino: Arduino program for building an AHRS with a Pololu MinIMU-9

and I can get the 3d model correctly working. I also calibrated my yaw angle by choosing proper libraries in Arduino lib. But my problem is that the yaw angle of the sensor is the not exactly what I want.

First of all, when I wear my sensor, while I rotate my head in terms of yaw, motor should also rotate as the same angle as my head. But the code I use, which is on upper link, gives the values changing from 0-360. Secondly, yaw angle reference point used in calibration, generally speaking for magnetometers, is that the ACTUAL NORTH of the Earth. But I don't want my 0 yaw angle to be that direction. Whenever I wear my sensor, before it starts reading and processing it should take my heading direction as the reference zero yaw angle. By default, it always reads the value referencing as the north of earth. F.e, when I am heading to the exact south, the value proccessed to servo should be 180 degrees. But what I want is that, apart from the N S E W, magnetic directions, the value goes to servos initially should be chosen as zero. Even if I am heading 30 degrees away from actual N, this 30 degrees should be my reference point so I can put my camera regardless of the directions. Otherwise, I have to put the camera looking at the actual North before I control it which is basically lame.

Much help and questions appreciated!

Regards.

You need an external input of some sort (e.g. a button) which when pressed alerts the program that "the direction I am pointing at now is the reference direction".

Save the angle and add or subtract as required.

Note that the order of rotations matters.