added wrapping for the magnetometer control algorithm