+ set_lowpass ( & the_TC_std,
+ current_aircraft.fdm_state->get_Phi_dot ()
+ * SGD_RADIANS_TO_DEGREES / 20.0 +
+ current_aircraft.fdm_state->get_Psi_dot ()
+ * SGD_RADIANS_TO_DEGREES / 3.0 , dt );
+
+ /**************************
+ We want to know the pilot accelerations,
+ to compute the magnetic compass errors.
+ */
+ AccN = current_aircraft.fdm_state->get_V_dot_north();
+ AccE = current_aircraft.fdm_state->get_V_dot_east();
+ AccU = current_aircraft.fdm_state->get_V_dot_down()
+ - 9.81 / 0.3;
+ if ( fabs(the_TC_rad) > 0.2 /* 2.0 */ )
+ { /* Massive sideslip jams it; it stops turning */
+ the_MH_degps = 0.0;
+ the_MH_err = fgGetDouble("/orientation/heading-deg") - the_MH_deg;
+ } else
+ { double MagDip, MagVar, CosDip;
+ double FrcN, FrcE, FrcU, AccTot;
+ double EdgN, EdgE, EdgU;
+ double TrqN, TrqE, TrqU, Torque;
+ /* Find a force vector towards exact magnetic north */
+ MagVar = fgGetDouble("/environment/magnetic-variation-deg")
+ / SGD_RADIANS_TO_DEGREES;
+ MagDip = fgGetDouble("/environment/magnetic-dip-deg")
+ / SGD_RADIANS_TO_DEGREES;
+ CosDip = cos ( MagDip );
+ FrcN = CosDip * cos ( MagVar );
+ FrcE = CosDip * sin ( MagVar );
+ FrcU = sin ( MagDip );
+ /* Rotation occurs around acceleration axis,
+ but axis magnitude is irrelevant. So compute it. */
+ AccTot = AccN*AccN + AccE*AccE + AccU*AccU;
+ if ( AccTot > 1.0 ) AccTot = sqrt ( AccTot );
+ else AccTot = 1.0;
+ /* Force applies to north marking on compass card */
+ EdgN = cos ( the_MH_err / SGD_RADIANS_TO_DEGREES );
+ EdgE = sin ( the_MH_err / SGD_RADIANS_TO_DEGREES );
+ EdgU = 0.0;
+ /* Apply the force to the edge to get torques */
+ TrqN = EdgE * FrcU - EdgU * FrcE;
+ TrqE = EdgU * FrcN - EdgN * FrcU;
+ TrqU = EdgN * FrcE - EdgE * FrcN;
+ /* Select the component parallel to the axis */
+ Torque = ( TrqN * AccN +
+ TrqE * AccE +
+ TrqU * AccU ) * 5.0 / AccTot;
+ /* The magnetic compass has angular momentum,
+ so we apply a torque to it and wait */
+ if ( dt < 1.0 )
+ { the_MH_degps= the_MH_degps * (1.0 - dt) - Torque;
+ the_MH_err += dt * the_MH_degps;
+ }
+ if ( the_MH_err > 180.0 ) the_MH_err -= 360.0; else
+ if ( the_MH_err < -180.0 ) the_MH_err += 360.0;
+ the_MH_deg = fgGetDouble("/orientation/heading-deg") - the_MH_err;
+ }
+
+ /**************************
+ This is not actually correct, but provides a
+ scaling capability for the vacuum pump later on.
+ When we have a real engine model, we can ask it.
+ */
+ the_ENGINE_rpm = globals->get_controls()->get_throttle(0) * 26.0;