diff --git a/src/Aircraft/aircraft.cxx b/src/Aircraft/aircraft.cxx index e48aefbb6..a6ce9e11e 100644 --- a/src/Aircraft/aircraft.cxx +++ b/src/Aircraft/aircraft.cxx @@ -36,7 +36,7 @@ fgAIRCRAFT current_aircraft; void fgAircraftInit( void ) { FG_LOG( FG_AIRCRAFT, FG_INFO, "Initializing Aircraft structure" ); - current_aircraft.fdm_state = &cur_fdm_state; + current_aircraft.fdm_state = cur_fdm_state; current_aircraft.controls = &controls; } diff --git a/src/Autopilot/autopilot.cxx b/src/Autopilot/autopilot.cxx index 2226f5e19..40efd1634 100644 --- a/src/Autopilot/autopilot.cxx +++ b/src/Autopilot/autopilot.cxx @@ -142,7 +142,7 @@ extern char *coord_format_lon(float); static inline double get_ground_speed( void ) { // starts in ft/s so we convert to kts - double ft_s = current_aircraft.fdm_state->get_V_ground_speed() + double ft_s = cur_fdm_state->get_V_ground_speed() * current_options.get_speed_up();; double kts = ft_s * FEET_TO_METER * 3600 * METER_TO_NM; return kts; @@ -209,50 +209,50 @@ static inline void MakeTargetLatLonStr( fgAPDataPtr APData, double lat, double l } static inline double get_speed( void ) { - return( current_aircraft.fdm_state->get_V_equiv_kts() ); + return( cur_fdm_state->get_V_equiv_kts() ); } static inline double get_aoa( void ) { - return( current_aircraft.fdm_state->get_Gamma_vert_rad() * RAD_TO_DEG ); + return( cur_fdm_state->get_Gamma_vert_rad() * RAD_TO_DEG ); } static inline double fgAPget_latitude( void ) { - return( current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG ); + return( cur_fdm_state->get_Latitude() * RAD_TO_DEG ); } static inline double fgAPget_longitude( void ) { - return( current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG ); + return( cur_fdm_state->get_Longitude() * RAD_TO_DEG ); } static inline double fgAPget_roll( void ) { - return( current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG ); + return( cur_fdm_state->get_Phi() * RAD_TO_DEG ); } static inline double get_pitch( void ) { - return( current_aircraft.fdm_state->get_Theta() ); + return( cur_fdm_state->get_Theta() ); } double fgAPget_heading( void ) { - return( current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG ); + return( cur_fdm_state->get_Psi() * RAD_TO_DEG ); } static inline double fgAPget_altitude( void ) { - return( current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER ); + return( cur_fdm_state->get_Altitude() * FEET_TO_METER ); } static inline double fgAPget_climb( void ) { // return in meters per minute - return( current_aircraft.fdm_state->get_Climb_Rate() * FEET_TO_METER * 60 ); + return( cur_fdm_state->get_Climb_Rate() * FEET_TO_METER * 60 ); } static inline double get_sideslip( void ) { - return( current_aircraft.fdm_state->get_Beta() ); + return( cur_fdm_state->get_Beta() ); } static inline double fgAPget_agl( void ) { double agl; - agl = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER + agl = cur_fdm_state->get_Altitude() * FEET_TO_METER - scenery.cur_elev; return( agl ); @@ -607,7 +607,7 @@ void NewAltitudeInit(void) char NewAltitudeLabel[] = "Enter New Altitude"; char *s; - float alt = current_aircraft.fdm_state->get_Altitude(); + float alt = cur_fdm_state->get_Altitude(); if ( current_options.get_units() == fgOPTIONS::FG_UNITS_METERS) { alt *= FEET_TO_METER; diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index ed2794f39..d2e52dbf8 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -48,14 +48,10 @@ #include "JSBsim.hxx" -// The default aircraft -FGFDMExec FDMExec; - - // Initialize the JSBsim flight model, dt is the time increment for // each subsequent iteration through the EOM -int fgJSBsimInit(double dt, FGInterface& f) { - FG_LOG( FG_FLIGHT, FG_INFO, "Starting initializing JSBsim" ); +int FGJSBsim::init( double dt ) { + FG_LOG( FG_FLIGHT, FG_INFO, "Starting and initializing JSBsim" ); FG_LOG( FG_FLIGHT, FG_INFO, " created FDMExec" ); @@ -75,12 +71,12 @@ int fgJSBsimInit(double dt, FGInterface& f) { current_options.get_uBody(), current_options.get_vBody(), current_options.get_wBody(), - f.get_Phi(), - f.get_Theta(), - f.get_Psi(), - f.get_Latitude(), - f.get_Longitude(), - f.get_Altitude() + get_Phi(), + get_Theta(), + get_Psi(), + get_Latitude(), + get_Longitude(), + get_Altitude() ); // FDMExec.GetState()->Setlatitude(f.get_Latitude()); @@ -92,23 +88,27 @@ int fgJSBsimInit(double dt, FGInterface& f) { FG_LOG( FG_FLIGHT, FG_INFO, " loaded initial conditions" ); - FDMExec.GetState()->Setdt(dt); + FDMExec.GetState()->Setdt( dt ); FG_LOG( FG_FLIGHT, FG_INFO, " set dt" ); FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing JSBsim" ); + copy_from_JSBsim(); + return 1; } // Run an iteration of the EOM (equations of motion) -int fgJSBsimUpdate(FGInterface& f, int multiloop) { +int FGJSBsim::update( int multiloop ) { double save_alt = 0.0; + double time_step = (1.0 / current_options.get_model_hz()) * multiloop; + double start_elev = get_Altitude(); // lets try to avoid really screwing up the JSBsim model - if ( f.get_Altitude() < -9000 ) { - save_alt = f.get_Altitude(); - f.set_Altitude( 0.0 ); + if ( get_Altitude() < -9000 ) { + save_alt = get_Altitude(); + set_Altitude( 0.0 ); } // copy control positions into the JSBsim structure @@ -123,7 +123,7 @@ int fgJSBsimUpdate(FGInterface& f, int multiloop) { // FCS->SetBrake( controls.get_brake( 0 ) ); // Inform JSBsim of the local terrain altitude - // Runway_altitude = f.get_Runway_altitude(); + // Runway_altitude = get_Runway_altitude(); // old -- FGInterface_2_JSBsim() not needed except for Init() // translate FG to JSBsim structure @@ -146,11 +146,17 @@ int fgJSBsimUpdate(FGInterface& f, int multiloop) { // autopilot (and the rest of the sim can use the updated // values - fgJSBsim_2_FGInterface(f); + copy_from_JSBsim(); // but lets restore our original bogus altitude when we are done if ( save_alt < -9000.0 ) { - f.set_Altitude( save_alt ); + set_Altitude( save_alt ); + } + + double end_elev = get_Altitude(); + if ( time_step > 0.0 ) { + // feet per second + set_Climb_Rate( (end_elev - start_elev) / time_step ); } return 1; @@ -158,47 +164,46 @@ int fgJSBsimUpdate(FGInterface& f, int multiloop) { // Convert from the FGInterface struct to the JSBsim generic_ struct -int FGInterface_2_JSBsim (FGInterface& f) { - +int FGJSBsim::copy_to_JSBsim() { return 1; } // Convert from the JSBsim generic_ struct to the FGInterface struct -int fgJSBsim_2_FGInterface (FGInterface& f) { +int FGJSBsim::copy_from_JSBsim() { // Velocities - f.set_Velocities_Local( FDMExec.GetPosition()->GetVn(), + set_Velocities_Local( FDMExec.GetPosition()->GetVn(), FDMExec.GetPosition()->GetVe(), FDMExec.GetPosition()->GetVd() ); - // f.set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground, + // set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground, // V_down_rel_ground ); - // f.set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass, + // set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass, // V_down_airmass ); - // f.set_Velocities_Local_Rel_Airmass( V_north_rel_airmass, + // set_Velocities_Local_Rel_Airmass( V_north_rel_airmass, // V_east_rel_airmass, V_down_rel_airmass ); - // f.set_Velocities_Gust( U_gust, V_gust, W_gust ); - // f.set_Velocities_Wind_Body( U_body, V_body, W_body ); + // set_Velocities_Gust( U_gust, V_gust, W_gust ); + // set_Velocities_Wind_Body( U_body, V_body, W_body ); - // f.set_V_rel_wind( V_rel_wind ); - // f.set_V_true_kts( V_true_kts ); - // f.set_V_rel_ground( V_rel_ground ); - // f.set_V_inertial( V_inertial ); - // f.set_V_ground_speed( V_ground_speed ); - // f.set_V_equiv( V_equiv ); + // set_V_rel_wind( V_rel_wind ); + // set_V_true_kts( V_true_kts ); + // set_V_rel_ground( V_rel_ground ); + // set_V_inertial( V_inertial ); + // set_V_ground_speed( V_ground_speed ); + // set_V_equiv( V_equiv ); - /* ***FIXME*** */ f.set_V_equiv_kts( FDMExec.GetState()->GetVt() ); - // f.set_V_calibrated( V_calibrated ); - // f.set_V_calibrated_kts( V_calibrated_kts ); + /* ***FIXME*** */ set_V_equiv_kts( FDMExec.GetState()->GetVt() ); + // set_V_calibrated( V_calibrated ); + // set_V_calibrated_kts( V_calibrated_kts ); - f.set_Omega_Body( FDMExec.GetRotation()->GetP(), + set_Omega_Body( FDMExec.GetRotation()->GetP(), FDMExec.GetRotation()->GetQ(), FDMExec.GetRotation()->GetR() ); - // f.set_Omega_Local( P_local, Q_local, R_local ); - // f.set_Omega_Total( P_total, Q_total, R_total ); + // set_Omega_Local( P_local, Q_local, R_local ); + // set_Omega_Total( P_total, Q_total, R_total ); - // f.set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot ); - // ***FIXME*** f.set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot ); + // set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot ); + // ***FIXME*** set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot ); // Positions double lat_geoc = FDMExec.GetState()->Getlatitude(); @@ -216,72 +221,72 @@ int fgJSBsim_2_FGInterface (FGInterface& f) { << " sl_radius2 = " << sl_radius2 * METER_TO_FEET << " Equator = " << EQUATORIAL_RADIUS_FT ); - f.set_Geocentric_Position( lat_geoc, lon, + set_Geocentric_Position( lat_geoc, lon, sl_radius2 * METER_TO_FEET + alt ); - f.set_Geodetic_Position( lat_geod, lon, alt ); - f.set_Euler_Angles( FDMExec.GetRotation()->Getphi(), + set_Geodetic_Position( lat_geod, lon, alt ); + set_Euler_Angles( FDMExec.GetRotation()->Getphi(), FDMExec.GetRotation()->Gettht(), FDMExec.GetRotation()->Getpsi() ); // Miscellaneous quantities - // f.set_T_Local_to_Body(T_local_to_body_m); - // f.set_Gravity( Gravity ); - // f.set_Centrifugal_relief( Centrifugal_relief ); + // set_T_Local_to_Body(T_local_to_body_m); + // set_Gravity( Gravity ); + // set_Centrifugal_relief( Centrifugal_relief ); - f.set_Alpha( FDMExec.GetTranslation()->Getalpha() ); - f.set_Beta( FDMExec.GetTranslation()->Getbeta() ); - // f.set_Alpha_dot( Alpha_dot ); - // f.set_Beta_dot( Beta_dot ); + set_Alpha( FDMExec.GetTranslation()->Getalpha() ); + set_Beta( FDMExec.GetTranslation()->Getbeta() ); + // set_Alpha_dot( Alpha_dot ); + // set_Beta_dot( Beta_dot ); - // f.set_Cos_alpha( Cos_alpha ); - // f.set_Sin_alpha( Sin_alpha ); - // f.set_Cos_beta( Cos_beta ); - // f.set_Sin_beta( Sin_beta ); + // set_Cos_alpha( Cos_alpha ); + // set_Sin_alpha( Sin_alpha ); + // set_Cos_beta( Cos_beta ); + // set_Sin_beta( Sin_beta ); - // f.set_Cos_phi( Cos_phi ); - // f.set_Sin_phi( Sin_phi ); - // f.set_Cos_theta( Cos_theta ); - // f.set_Sin_theta( Sin_theta ); - // f.set_Cos_psi( Cos_psi ); - // f.set_Sin_psi( Sin_psi ); + // set_Cos_phi( Cos_phi ); + // set_Sin_phi( Sin_phi ); + // set_Cos_theta( Cos_theta ); + // set_Sin_theta( Sin_theta ); + // set_Cos_psi( Cos_psi ); + // set_Sin_psi( Sin_psi ); - // ***ATTENDTOME*** f.set_Gamma_vert_rad( Gamma_vert_rad ); - // f.set_Gamma_horiz_rad( Gamma_horiz_rad ); + // ***ATTENDTOME*** set_Gamma_vert_rad( Gamma_vert_rad ); + // set_Gamma_horiz_rad( Gamma_horiz_rad ); - // f.set_Sigma( Sigma ); - // f.set_Density( Density ); - // f.set_V_sound( V_sound ); - // f.set_Mach_number( Mach_number ); + // set_Sigma( Sigma ); + // set_Density( Density ); + // set_V_sound( V_sound ); + // set_Mach_number( Mach_number ); - // f.set_Static_pressure( Static_pressure ); - // f.set_Total_pressure( Total_pressure ); - // f.set_Impact_pressure( Impact_pressure ); - // f.set_Dynamic_pressure( Dynamic_pressure ); + // set_Static_pressure( Static_pressure ); + // set_Total_pressure( Total_pressure ); + // set_Impact_pressure( Impact_pressure ); + // set_Dynamic_pressure( Dynamic_pressure ); - // f.set_Static_temperature( Static_temperature ); - // f.set_Total_temperature( Total_temperature ); + // set_Static_temperature( Static_temperature ); + // set_Total_temperature( Total_temperature ); - /* **FIXME*** */ f.set_Sea_level_radius( sl_radius2 * METER_TO_FEET ); - /* **FIXME*** */ f.set_Earth_position_angle( 0.0 ); + /* **FIXME*** */ set_Sea_level_radius( sl_radius2 * METER_TO_FEET ); + /* **FIXME*** */ set_Earth_position_angle( 0.0 ); - /* ***FIXME*** */ f.set_Runway_altitude( 0.0 ); - // f.set_Runway_latitude( Runway_latitude ); - // f.set_Runway_longitude( Runway_longitude ); - // f.set_Runway_heading( Runway_heading ); - // f.set_Radius_to_rwy( Radius_to_rwy ); + /* ***FIXME*** */ set_Runway_altitude( 0.0 ); + // set_Runway_latitude( Runway_latitude ); + // set_Runway_longitude( Runway_longitude ); + // set_Runway_heading( Runway_heading ); + // set_Radius_to_rwy( Radius_to_rwy ); - // f.set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy); - // f.set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy ); - // f.set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy, + // set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy); + // set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy ); + // set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy, // D_pilot_above_rwy ); - // f.set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy ); + // set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy ); - f.set_sin_lat_geocentric( lat_geoc ); - f.set_cos_lat_geocentric( lat_geoc ); - f.set_sin_cos_longitude( lon ); - f.set_sin_cos_latitude( lat_geod ); + set_sin_lat_geocentric( lat_geoc ); + set_cos_lat_geocentric( lat_geoc ); + set_sin_cos_longitude( lon ); + set_sin_cos_latitude( lat_geod ); - return 0; + return 1; } diff --git a/src/FDM/JSBSim.hxx b/src/FDM/JSBSim.hxx index 8f416abaf..7b34a1a47 100644 --- a/src/FDM/JSBSim.hxx +++ b/src/FDM/JSBSim.hxx @@ -30,17 +30,25 @@ #include -// reset flight params to a specific position -int fgJSBsimInit(double dt, FGInterface& f); +class FGJSBsim: public FGInterface { -// update position based on inputs, positions, velocities, etc. -int fgJSBsimUpdate(FGInterface& f, int multiloop); + // The aircraft for this instance + FGFDMExec FDMExec; -// Convert from the FGInterface struct to the JSBsim generic_ struct -int FGInterface_2_JSBsim (FGInterface& f); +public: -// Convert from the JSBsim generic_ struct to the FGInterface struct -int fgJSBsim_2_FGInterface (FGInterface& f); + // copy FDM state to LaRCsim structures + int copy_to_JSBsim(); + + // copy FDM state from LaRCsim structures + int copy_from_JSBsim(); + + // reset flight params to a specific position + int init( double dt ); + + // update position based on inputs, positions, velocities, etc. + int update( int multiloop ); +}; #endif // _JSBSIM_HXX diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx index f731e6d70..6d33ac7c7 100644 --- a/src/FDM/LaRCsim.cxx +++ b/src/FDM/LaRCsim.cxx @@ -36,21 +36,52 @@ // Initialize the LaRCsim flight model, dt is the time increment for // each subsequent iteration through the EOM -int fgLaRCsimInit(double dt) { - ls_toplevel_init(dt); +int FGLaRCsim::init( double dt ) { + // cout << "FGLaRCsim::init()" << endl; - return(1); + double save_alt = 0.0; + + if ( get_Altitude() < -9000.0 ) { + save_alt = get_Altitude(); + set_Altitude( 0.0 ); + } + + // translate FG to LaRCsim structure + copy_to_LaRCsim(); + + // actual LaRCsim top level init + ls_toplevel_init( dt ); + + FG_LOG( FG_FLIGHT, FG_INFO, "FG pos = " << + get_Latitude() ); + + // translate LaRCsim back to FG structure + copy_from_LaRCsim(); + + // but lets restore our original bogus altitude when we are done + if ( save_alt < -9000.0 ) { + set_Altitude( save_alt ); + } + + // set valid time for this record + stamp_time(); + + return 1; } // Run an iteration of the EOM (equations of motion) -int fgLaRCsimUpdate(FGInterface& f, int multiloop) { +int FGLaRCsim::update( int multiloop ) { + // cout << "FGLaRCsim::update()" << endl; + double save_alt = 0.0; + double time_step = (1.0 / current_options.get_model_hz()) * multiloop; + double start_elev = get_Altitude(); // lets try to avoid really screwing up the LaRCsim model - if ( f.get_Altitude() < -9000.0 ) { - save_alt = f.get_Altitude(); - f.set_Altitude( 0.0 ); + if ( get_Altitude() < -9000.0 ) { + save_alt = get_Altitude(); + set_Altitude( 0.0 ); } // copy control positions into the LaRCsim structure @@ -62,7 +93,7 @@ int fgLaRCsimUpdate(FGInterface& f, int multiloop) { Brake_pct = controls.get_brake( 0 ); // Inform LaRCsim of the local terrain altitude - Runway_altitude = f.get_Runway_altitude(); + Runway_altitude = get_Runway_altitude(); // old -- FGInterface_2_LaRCsim() not needed except for Init() // translate FG to LaRCsim structure @@ -79,11 +110,17 @@ int fgLaRCsimUpdate(FGInterface& f, int multiloop) { // translate LaRCsim back to FG structure so that the // autopilot (and the rest of the sim can use the updated // values - fgLaRCsim_2_FGInterface(f); + copy_from_LaRCsim(); // but lets restore our original bogus altitude when we are done if ( save_alt < -9000.0 ) { - f.set_Altitude( save_alt ); + set_Altitude( save_alt ); + } + + double end_elev = get_Altitude(); + if ( time_step > 0.0 ) { + // feet per second + set_Climb_Rate( (end_elev - start_elev) / time_step ); } return 1; @@ -91,240 +128,239 @@ int fgLaRCsimUpdate(FGInterface& f, int multiloop) { // Convert from the FGInterface struct to the LaRCsim generic_ struct -int FGInterface_2_LaRCsim (FGInterface& f) { +int FGLaRCsim::copy_to_LaRCsim () { + Mass = get_Mass(); + I_xx = get_I_xx(); + I_yy = get_I_yy(); + I_zz = get_I_zz(); + I_xz = get_I_xz(); + // Dx_pilot = get_Dx_pilot(); + // Dy_pilot = get_Dy_pilot(); + // Dz_pilot = get_Dz_pilot(); + Dx_cg = get_Dx_cg(); + Dy_cg = get_Dy_cg(); + Dz_cg = get_Dz_cg(); + // F_X = get_F_X(); + // F_Y = get_F_Y(); + // F_Z = get_F_Z(); + // F_north = get_F_north(); + // F_east = get_F_east(); + // F_down = get_F_down(); + // F_X_aero = get_F_X_aero(); + // F_Y_aero = get_F_Y_aero(); + // F_Z_aero = get_F_Z_aero(); + // F_X_engine = get_F_X_engine(); + // F_Y_engine = get_F_Y_engine(); + // F_Z_engine = get_F_Z_engine(); + // F_X_gear = get_F_X_gear(); + // F_Y_gear = get_F_Y_gear(); + // F_Z_gear = get_F_Z_gear(); + // M_l_rp = get_M_l_rp(); + // M_m_rp = get_M_m_rp(); + // M_n_rp = get_M_n_rp(); + // M_l_cg = get_M_l_cg(); + // M_m_cg = get_M_m_cg(); + // M_n_cg = get_M_n_cg(); + // M_l_aero = get_M_l_aero(); + // M_m_aero = get_M_m_aero(); + // M_n_aero = get_M_n_aero(); + // M_l_engine = get_M_l_engine(); + // M_m_engine = get_M_m_engine(); + // M_n_engine = get_M_n_engine(); + // M_l_gear = get_M_l_gear(); + // M_m_gear = get_M_m_gear(); + // M_n_gear = get_M_n_gear(); + // V_dot_north = get_V_dot_north(); + // V_dot_east = get_V_dot_east(); + // V_dot_down = get_V_dot_down(); + // U_dot_body = get_U_dot_body(); + // V_dot_body = get_V_dot_body(); + // W_dot_body = get_W_dot_body(); + // A_X_cg = get_A_X_cg(); + // A_Y_cg = get_A_Y_cg(); + // A_Z_cg = get_A_Z_cg(); + // A_X_pilot = get_A_X_pilot(); + // A_Y_pilot = get_A_Y_pilot(); + // A_Z_pilot = get_A_Z_pilot(); + // N_X_cg = get_N_X_cg(); + // N_Y_cg = get_N_Y_cg(); + // N_Z_cg = get_N_Z_cg(); + // N_X_pilot = get_N_X_pilot(); + // N_Y_pilot = get_N_Y_pilot(); + // N_Z_pilot = get_N_Z_pilot(); + // P_dot_body = get_P_dot_body(); + // Q_dot_body = get_Q_dot_body(); + // R_dot_body = get_R_dot_body(); + V_north = get_V_north(); + V_east = get_V_east(); + V_down = get_V_down(); + // V_north_rel_ground = get_V_north_rel_ground(); + // V_east_rel_ground = get_V_east_rel_ground(); + // V_down_rel_ground = get_V_down_rel_ground(); + // V_north_airmass = get_V_north_airmass(); + // V_east_airmass = get_V_east_airmass(); + // V_down_airmass = get_V_down_airmass(); + // V_north_rel_airmass = get_V_north_rel_airmass(); + // V_east_rel_airmass = get_V_east_rel_airmass(); + // V_down_rel_airmass = get_V_down_rel_airmass(); + // U_gust = get_U_gust(); + // V_gust = get_V_gust(); + // W_gust = get_W_gust(); + // U_body = get_U_body(); + // V_body = get_V_body(); + // W_body = get_W_body(); + // V_rel_wind = get_V_rel_wind(); + // V_true_kts = get_V_true_kts(); + // V_rel_ground = get_V_rel_ground(); + // V_inertial = get_V_inertial(); + // V_ground_speed = get_V_ground_speed(); + // V_equiv = get_V_equiv(); + // V_equiv_kts = get_V_equiv_kts(); + // V_calibrated = get_V_calibrated(); + // V_calibrated_kts = get_V_calibrated_kts(); + P_body = get_P_body(); + Q_body = get_Q_body(); + R_body = get_R_body(); + // P_local = get_P_local(); + // Q_local = get_Q_local(); + // R_local = get_R_local(); + // P_total = get_P_total(); + // Q_total = get_Q_total(); + // R_total = get_R_total(); + // Phi_dot = get_Phi_dot(); + // Theta_dot = get_Theta_dot(); + // Psi_dot = get_Psi_dot(); + // Latitude_dot = get_Latitude_dot(); + // Longitude_dot = get_Longitude_dot(); + // Radius_dot = get_Radius_dot(); + Lat_geocentric = get_Lat_geocentric(); + Lon_geocentric = get_Lon_geocentric(); + Radius_to_vehicle = get_Radius_to_vehicle(); + Latitude = get_Latitude(); + Longitude = get_Longitude(); + Altitude = get_Altitude(); + Phi = get_Phi(); + Theta = get_Theta(); + Psi = get_Psi(); + // T_local_to_body_11 = get_T_local_to_body_11(); + // T_local_to_body_12 = get_T_local_to_body_12(); + // T_local_to_body_13 = get_T_local_to_body_13(); + // T_local_to_body_21 = get_T_local_to_body_21(); + // T_local_to_body_22 = get_T_local_to_body_22(); + // T_local_to_body_23 = get_T_local_to_body_23(); + // T_local_to_body_31 = get_T_local_to_body_31(); + // T_local_to_body_32 = get_T_local_to_body_32(); + // T_local_to_body_33 = get_T_local_to_body_33(); + // Gravity = get_Gravity(); + // Centrifugal_relief = get_Centrifugal_relief(); + // Alpha = get_Alpha(); + // Beta = get_Beta(); + // Alpha_dot = get_Alpha_dot(); + // Beta_dot = get_Beta_dot(); + // Cos_alpha = get_Cos_alpha(); + // Sin_alpha = get_Sin_alpha(); + // Cos_beta = get_Cos_beta(); + // Sin_beta = get_Sin_beta(); + // Cos_phi = get_Cos_phi(); + // Sin_phi = get_Sin_phi(); + // Cos_theta = get_Cos_theta(); + // Sin_theta = get_Sin_theta(); + // Cos_psi = get_Cos_psi(); + // Sin_psi = get_Sin_psi(); + // Gamma_vert_rad = get_Gamma_vert_rad(); + // Gamma_horiz_rad = get_Gamma_horiz_rad(); + // Sigma = get_Sigma(); + // Density = get_Density(); + // V_sound = get_V_sound(); + // Mach_number = get_Mach_number(); + // Static_pressure = get_Static_pressure(); + // Total_pressure = get_Total_pressure(); + // Impact_pressure = get_Impact_pressure(); + // Dynamic_pressure = get_Dynamic_pressure(); + // Static_temperature = get_Static_temperature(); + // Total_temperature = get_Total_temperature(); + Sea_level_radius = get_Sea_level_radius(); + Earth_position_angle = get_Earth_position_angle(); + Runway_altitude = get_Runway_altitude(); + // Runway_latitude = get_Runway_latitude(); + // Runway_longitude = get_Runway_longitude(); + // Runway_heading = get_Runway_heading(); + // Radius_to_rwy = get_Radius_to_rwy(); + // D_cg_north_of_rwy = get_D_cg_north_of_rwy(); + // D_cg_east_of_rwy = get_D_cg_east_of_rwy(); + // D_cg_above_rwy = get_D_cg_above_rwy(); + // X_cg_rwy = get_X_cg_rwy(); + // Y_cg_rwy = get_Y_cg_rwy(); + // H_cg_rwy = get_H_cg_rwy(); + // D_pilot_north_of_rwy = get_D_pilot_north_of_rwy(); + // D_pilot_east_of_rwy = get_D_pilot_east_of_rwy(); + // D_pilot_above_rwy = get_D_pilot_above_rwy(); + // X_pilot_rwy = get_X_pilot_rwy(); + // Y_pilot_rwy = get_Y_pilot_rwy(); + // H_pilot_rwy = get_H_pilot_rwy(); - Mass = f.get_Mass(); - I_xx = f.get_I_xx(); - I_yy = f.get_I_yy(); - I_zz = f.get_I_zz(); - I_xz = f.get_I_xz(); - // Dx_pilot = f.get_Dx_pilot(); - // Dy_pilot = f.get_Dy_pilot(); - // Dz_pilot = f.get_Dz_pilot(); - Dx_cg = f.get_Dx_cg(); - Dy_cg = f.get_Dy_cg(); - Dz_cg = f.get_Dz_cg(); - // F_X = f.get_F_X(); - // F_Y = f.get_F_Y(); - // F_Z = f.get_F_Z(); - // F_north = f.get_F_north(); - // F_east = f.get_F_east(); - // F_down = f.get_F_down(); - // F_X_aero = f.get_F_X_aero(); - // F_Y_aero = f.get_F_Y_aero(); - // F_Z_aero = f.get_F_Z_aero(); - // F_X_engine = f.get_F_X_engine(); - // F_Y_engine = f.get_F_Y_engine(); - // F_Z_engine = f.get_F_Z_engine(); - // F_X_gear = f.get_F_X_gear(); - // F_Y_gear = f.get_F_Y_gear(); - // F_Z_gear = f.get_F_Z_gear(); - // M_l_rp = f.get_M_l_rp(); - // M_m_rp = f.get_M_m_rp(); - // M_n_rp = f.get_M_n_rp(); - // M_l_cg = f.get_M_l_cg(); - // M_m_cg = f.get_M_m_cg(); - // M_n_cg = f.get_M_n_cg(); - // M_l_aero = f.get_M_l_aero(); - // M_m_aero = f.get_M_m_aero(); - // M_n_aero = f.get_M_n_aero(); - // M_l_engine = f.get_M_l_engine(); - // M_m_engine = f.get_M_m_engine(); - // M_n_engine = f.get_M_n_engine(); - // M_l_gear = f.get_M_l_gear(); - // M_m_gear = f.get_M_m_gear(); - // M_n_gear = f.get_M_n_gear(); - // V_dot_north = f.get_V_dot_north(); - // V_dot_east = f.get_V_dot_east(); - // V_dot_down = f.get_V_dot_down(); - // U_dot_body = f.get_U_dot_body(); - // V_dot_body = f.get_V_dot_body(); - // W_dot_body = f.get_W_dot_body(); - // A_X_cg = f.get_A_X_cg(); - // A_Y_cg = f.get_A_Y_cg(); - // A_Z_cg = f.get_A_Z_cg(); - // A_X_pilot = f.get_A_X_pilot(); - // A_Y_pilot = f.get_A_Y_pilot(); - // A_Z_pilot = f.get_A_Z_pilot(); - // N_X_cg = f.get_N_X_cg(); - // N_Y_cg = f.get_N_Y_cg(); - // N_Z_cg = f.get_N_Z_cg(); - // N_X_pilot = f.get_N_X_pilot(); - // N_Y_pilot = f.get_N_Y_pilot(); - // N_Z_pilot = f.get_N_Z_pilot(); - // P_dot_body = f.get_P_dot_body(); - // Q_dot_body = f.get_Q_dot_body(); - // R_dot_body = f.get_R_dot_body(); - V_north = f.get_V_north(); - V_east = f.get_V_east(); - V_down = f.get_V_down(); - // V_north_rel_ground = f.get_V_north_rel_ground(); - // V_east_rel_ground = f.get_V_east_rel_ground(); - // V_down_rel_ground = f.get_V_down_rel_ground(); - // V_north_airmass = f.get_V_north_airmass(); - // V_east_airmass = f.get_V_east_airmass(); - // V_down_airmass = f.get_V_down_airmass(); - // V_north_rel_airmass = f.get_V_north_rel_airmass(); - // V_east_rel_airmass = f.get_V_east_rel_airmass(); - // V_down_rel_airmass = f.get_V_down_rel_airmass(); - // U_gust = f.get_U_gust(); - // V_gust = f.get_V_gust(); - // W_gust = f.get_W_gust(); - // U_body = f.get_U_body(); - // V_body = f.get_V_body(); - // W_body = f.get_W_body(); - // V_rel_wind = f.get_V_rel_wind(); - // V_true_kts = f.get_V_true_kts(); - // V_rel_ground = f.get_V_rel_ground(); - // V_inertial = f.get_V_inertial(); - // V_ground_speed = f.get_V_ground_speed(); - // V_equiv = f.get_V_equiv(); - // V_equiv_kts = f.get_V_equiv_kts(); - // V_calibrated = f.get_V_calibrated(); - // V_calibrated_kts = f.get_V_calibrated_kts(); - P_body = f.get_P_body(); - Q_body = f.get_Q_body(); - R_body = f.get_R_body(); - // P_local = f.get_P_local(); - // Q_local = f.get_Q_local(); - // R_local = f.get_R_local(); - // P_total = f.get_P_total(); - // Q_total = f.get_Q_total(); - // R_total = f.get_R_total(); - // Phi_dot = f.get_Phi_dot(); - // Theta_dot = f.get_Theta_dot(); - // Psi_dot = f.get_Psi_dot(); - // Latitude_dot = f.get_Latitude_dot(); - // Longitude_dot = f.get_Longitude_dot(); - // Radius_dot = f.get_Radius_dot(); - Lat_geocentric = f.get_Lat_geocentric(); - Lon_geocentric = f.get_Lon_geocentric(); - Radius_to_vehicle = f.get_Radius_to_vehicle(); - Latitude = f.get_Latitude(); - Longitude = f.get_Longitude(); - Altitude = f.get_Altitude(); - Phi = f.get_Phi(); - Theta = f.get_Theta(); - Psi = f.get_Psi(); - // T_local_to_body_11 = f.get_T_local_to_body_11(); - // T_local_to_body_12 = f.get_T_local_to_body_12(); - // T_local_to_body_13 = f.get_T_local_to_body_13(); - // T_local_to_body_21 = f.get_T_local_to_body_21(); - // T_local_to_body_22 = f.get_T_local_to_body_22(); - // T_local_to_body_23 = f.get_T_local_to_body_23(); - // T_local_to_body_31 = f.get_T_local_to_body_31(); - // T_local_to_body_32 = f.get_T_local_to_body_32(); - // T_local_to_body_33 = f.get_T_local_to_body_33(); - // Gravity = f.get_Gravity(); - // Centrifugal_relief = f.get_Centrifugal_relief(); - // Alpha = f.get_Alpha(); - // Beta = f.get_Beta(); - // Alpha_dot = f.get_Alpha_dot(); - // Beta_dot = f.get_Beta_dot(); - // Cos_alpha = f.get_Cos_alpha(); - // Sin_alpha = f.get_Sin_alpha(); - // Cos_beta = f.get_Cos_beta(); - // Sin_beta = f.get_Sin_beta(); - // Cos_phi = f.get_Cos_phi(); - // Sin_phi = f.get_Sin_phi(); - // Cos_theta = f.get_Cos_theta(); - // Sin_theta = f.get_Sin_theta(); - // Cos_psi = f.get_Cos_psi(); - // Sin_psi = f.get_Sin_psi(); - // Gamma_vert_rad = f.get_Gamma_vert_rad(); - // Gamma_horiz_rad = f.get_Gamma_horiz_rad(); - // Sigma = f.get_Sigma(); - // Density = f.get_Density(); - // V_sound = f.get_V_sound(); - // Mach_number = f.get_Mach_number(); - // Static_pressure = f.get_Static_pressure(); - // Total_pressure = f.get_Total_pressure(); - // Impact_pressure = f.get_Impact_pressure(); - // Dynamic_pressure = f.get_Dynamic_pressure(); - // Static_temperature = f.get_Static_temperature(); - // Total_temperature = f.get_Total_temperature(); - Sea_level_radius = f.get_Sea_level_radius(); - Earth_position_angle = f.get_Earth_position_angle(); - Runway_altitude = f.get_Runway_altitude(); - // Runway_latitude = f.get_Runway_latitude(); - // Runway_longitude = f.get_Runway_longitude(); - // Runway_heading = f.get_Runway_heading(); - // Radius_to_rwy = f.get_Radius_to_rwy(); - // D_cg_north_of_rwy = f.get_D_cg_north_of_rwy(); - // D_cg_east_of_rwy = f.get_D_cg_east_of_rwy(); - // D_cg_above_rwy = f.get_D_cg_above_rwy(); - // X_cg_rwy = f.get_X_cg_rwy(); - // Y_cg_rwy = f.get_Y_cg_rwy(); - // H_cg_rwy = f.get_H_cg_rwy(); - // D_pilot_north_of_rwy = f.get_D_pilot_north_of_rwy(); - // D_pilot_east_of_rwy = f.get_D_pilot_east_of_rwy(); - // D_pilot_above_rwy = f.get_D_pilot_above_rwy(); - // X_pilot_rwy = f.get_X_pilot_rwy(); - // Y_pilot_rwy = f.get_Y_pilot_rwy(); - // H_pilot_rwy = f.get_H_pilot_rwy(); - - return( 0 ); + return 1; } // Convert from the LaRCsim generic_ struct to the FGInterface struct -int fgLaRCsim_2_FGInterface (FGInterface& f) { +int FGLaRCsim::copy_from_LaRCsim() { // Mass properties and geometry values - f.set_Inertias( Mass, I_xx, I_yy, I_zz, I_xz ); - // f.set_Pilot_Location( Dx_pilot, Dy_pilot, Dz_pilot ); - f.set_CG_Position( Dx_cg, Dy_cg, Dz_cg ); + set_Inertias( Mass, I_xx, I_yy, I_zz, I_xz ); + // set_Pilot_Location( Dx_pilot, Dy_pilot, Dz_pilot ); + set_CG_Position( Dx_cg, Dy_cg, Dz_cg ); // Forces - // f.set_Forces_Body_Total( F_X, F_Y, F_Z ); - // f.set_Forces_Local_Total( F_north, F_east, F_down ); - // f.set_Forces_Aero( F_X_aero, F_Y_aero, F_Z_aero ); - // f.set_Forces_Engine( F_X_engine, F_Y_engine, F_Z_engine ); - // f.set_Forces_Gear( F_X_gear, F_Y_gear, F_Z_gear ); + // set_Forces_Body_Total( F_X, F_Y, F_Z ); + // set_Forces_Local_Total( F_north, F_east, F_down ); + // set_Forces_Aero( F_X_aero, F_Y_aero, F_Z_aero ); + // set_Forces_Engine( F_X_engine, F_Y_engine, F_Z_engine ); + // set_Forces_Gear( F_X_gear, F_Y_gear, F_Z_gear ); // Moments - // f.set_Moments_Total_RP( M_l_rp, M_m_rp, M_n_rp ); - // f.set_Moments_Total_CG( M_l_cg, M_m_cg, M_n_cg ); - // f.set_Moments_Aero( M_l_aero, M_m_aero, M_n_aero ); - // f.set_Moments_Engine( M_l_engine, M_m_engine, M_n_engine ); - // f.set_Moments_Gear( M_l_gear, M_m_gear, M_n_gear ); + // set_Moments_Total_RP( M_l_rp, M_m_rp, M_n_rp ); + // set_Moments_Total_CG( M_l_cg, M_m_cg, M_n_cg ); + // set_Moments_Aero( M_l_aero, M_m_aero, M_n_aero ); + // set_Moments_Engine( M_l_engine, M_m_engine, M_n_engine ); + // set_Moments_Gear( M_l_gear, M_m_gear, M_n_gear ); // Accelerations - // f.set_Accels_Local( V_dot_north, V_dot_east, V_dot_down ); - f.set_Accels_Body( U_dot_body, V_dot_body, W_dot_body ); - f.set_Accels_CG_Body( A_X_cg, A_Y_cg, A_Z_cg ); - f.set_Accels_Pilot_Body( A_X_pilot, A_Y_pilot, A_Z_pilot ); - // f.set_Accels_CG_Body_N( N_X_cg, N_Y_cg, N_Z_cg ); - // f.set_Accels_Pilot_Body_N( N_X_pilot, N_Y_pilot, N_Z_pilot ); - // f.set_Accels_Omega( P_dot_body, Q_dot_body, R_dot_body ); + // set_Accels_Local( V_dot_north, V_dot_east, V_dot_down ); + set_Accels_Body( U_dot_body, V_dot_body, W_dot_body ); + set_Accels_CG_Body( A_X_cg, A_Y_cg, A_Z_cg ); + set_Accels_Pilot_Body( A_X_pilot, A_Y_pilot, A_Z_pilot ); + // set_Accels_CG_Body_N( N_X_cg, N_Y_cg, N_Z_cg ); + // set_Accels_Pilot_Body_N( N_X_pilot, N_Y_pilot, N_Z_pilot ); + // set_Accels_Omega( P_dot_body, Q_dot_body, R_dot_body ); // Velocities - f.set_Velocities_Local( V_north, V_east, V_down ); - // f.set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground, + set_Velocities_Local( V_north, V_east, V_down ); + // set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground, // V_down_rel_ground ); - // f.set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass, + // set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass, // V_down_airmass ); - // f.set_Velocities_Local_Rel_Airmass( V_north_rel_airmass, + // set_Velocities_Local_Rel_Airmass( V_north_rel_airmass, // V_east_rel_airmass, V_down_rel_airmass ); - // f.set_Velocities_Gust( U_gust, V_gust, W_gust ); - f.set_Velocities_Wind_Body( U_body, V_body, W_body ); + // set_Velocities_Gust( U_gust, V_gust, W_gust ); + set_Velocities_Wind_Body( U_body, V_body, W_body ); - // f.set_V_rel_wind( V_rel_wind ); - // f.set_V_true_kts( V_true_kts ); - // f.set_V_rel_ground( V_rel_ground ); - // f.set_V_inertial( V_inertial ); - f.set_V_ground_speed( V_ground_speed ); - // f.set_V_equiv( V_equiv ); - f.set_V_equiv_kts( V_equiv_kts ); - // f.set_V_calibrated( V_calibrated ); - // f.set_V_calibrated_kts( V_calibrated_kts ); + // set_V_rel_wind( V_rel_wind ); + // set_V_true_kts( V_true_kts ); + // set_V_rel_ground( V_rel_ground ); + // set_V_inertial( V_inertial ); + set_V_ground_speed( V_ground_speed ); + // set_V_equiv( V_equiv ); + set_V_equiv_kts( V_equiv_kts ); + // set_V_calibrated( V_calibrated ); + // set_V_calibrated_kts( V_calibrated_kts ); - f.set_Omega_Body( P_body, Q_body, R_body ); - // f.set_Omega_Local( P_local, Q_local, R_local ); - // f.set_Omega_Total( P_total, Q_total, R_total ); + set_Omega_Body( P_body, Q_body, R_body ); + // set_Omega_Local( P_local, Q_local, R_local ); + // set_Omega_Total( P_total, Q_total, R_total ); - // f.set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot ); - f.set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot ); + // set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot ); + set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot ); FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << Longitude << " lat_geoc = " << Lat_geocentric << " lat_geod = " << Latitude @@ -340,76 +376,76 @@ int fgLaRCsim_2_FGInterface (FGInterface& f) { while ( tmp_lon > FG_PI ) { tmp_lon -= FG_2PI; } // Positions - f.set_Geocentric_Position( Lat_geocentric, tmp_lon_geoc, + set_Geocentric_Position( Lat_geocentric, tmp_lon_geoc, Radius_to_vehicle ); - f.set_Geodetic_Position( Latitude, tmp_lon, Altitude ); - f.set_Euler_Angles( Phi, Theta, Psi ); + set_Geodetic_Position( Latitude, tmp_lon, Altitude ); + set_Euler_Angles( Phi, Theta, Psi ); // Miscellaneous quantities - f.set_T_Local_to_Body(T_local_to_body_m); - // f.set_Gravity( Gravity ); - // f.set_Centrifugal_relief( Centrifugal_relief ); + set_T_Local_to_Body(T_local_to_body_m); + // set_Gravity( Gravity ); + // set_Centrifugal_relief( Centrifugal_relief ); - f.set_Alpha( Alpha ); - f.set_Beta( Beta ); - // f.set_Alpha_dot( Alpha_dot ); - // f.set_Beta_dot( Beta_dot ); + set_Alpha( Alpha ); + set_Beta( Beta ); + // set_Alpha_dot( Alpha_dot ); + // set_Beta_dot( Beta_dot ); - // f.set_Cos_alpha( Cos_alpha ); - // f.set_Sin_alpha( Sin_alpha ); - // f.set_Cos_beta( Cos_beta ); - // f.set_Sin_beta( Sin_beta ); + // set_Cos_alpha( Cos_alpha ); + // set_Sin_alpha( Sin_alpha ); + // set_Cos_beta( Cos_beta ); + // set_Sin_beta( Sin_beta ); - f.set_Cos_phi( Cos_phi ); - // f.set_Sin_phi( Sin_phi ); - f.set_Cos_theta( Cos_theta ); - // f.set_Sin_theta( Sin_theta ); - // f.set_Cos_psi( Cos_psi ); - // f.set_Sin_psi( Sin_psi ); + set_Cos_phi( Cos_phi ); + // set_Sin_phi( Sin_phi ); + set_Cos_theta( Cos_theta ); + // set_Sin_theta( Sin_theta ); + // set_Cos_psi( Cos_psi ); + // set_Sin_psi( Sin_psi ); - f.set_Gamma_vert_rad( Gamma_vert_rad ); - // f.set_Gamma_horiz_rad( Gamma_horiz_rad ); + set_Gamma_vert_rad( Gamma_vert_rad ); + // set_Gamma_horiz_rad( Gamma_horiz_rad ); - // f.set_Sigma( Sigma ); - // f.set_Density( Density ); - // f.set_V_sound( V_sound ); - // f.set_Mach_number( Mach_number ); + // set_Sigma( Sigma ); + // set_Density( Density ); + // set_V_sound( V_sound ); + // set_Mach_number( Mach_number ); - // f.set_Static_pressure( Static_pressure ); - // f.set_Total_pressure( Total_pressure ); - // f.set_Impact_pressure( Impact_pressure ); - // f.set_Dynamic_pressure( Dynamic_pressure ); + // set_Static_pressure( Static_pressure ); + // set_Total_pressure( Total_pressure ); + // set_Impact_pressure( Impact_pressure ); + // set_Dynamic_pressure( Dynamic_pressure ); - // f.set_Static_temperature( Static_temperature ); - // f.set_Total_temperature( Total_temperature ); + // set_Static_temperature( Static_temperature ); + // set_Total_temperature( Total_temperature ); - f.set_Sea_level_radius( Sea_level_radius ); - f.set_Earth_position_angle( Earth_position_angle ); + set_Sea_level_radius( Sea_level_radius ); + set_Earth_position_angle( Earth_position_angle ); - f.set_Runway_altitude( Runway_altitude ); - // f.set_Runway_latitude( Runway_latitude ); - // f.set_Runway_longitude( Runway_longitude ); - // f.set_Runway_heading( Runway_heading ); - // f.set_Radius_to_rwy( Radius_to_rwy ); + set_Runway_altitude( Runway_altitude ); + // set_Runway_latitude( Runway_latitude ); + // set_Runway_longitude( Runway_longitude ); + // set_Runway_heading( Runway_heading ); + // set_Radius_to_rwy( Radius_to_rwy ); - // f.set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy); - // f.set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy ); - // f.set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy, + // set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy); + // set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy ); + // set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy, // D_pilot_above_rwy ); - // f.set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy ); + // set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy ); - f.set_sin_lat_geocentric(Lat_geocentric); - f.set_cos_lat_geocentric(Lat_geocentric); - f.set_sin_cos_longitude(Longitude); - f.set_sin_cos_latitude(Latitude); + set_sin_lat_geocentric(Lat_geocentric); + set_cos_lat_geocentric(Lat_geocentric); + set_sin_cos_longitude(Longitude); + set_sin_cos_latitude(Latitude); // printf("sin_lat_geo %f cos_lat_geo %f\n", sin_Lat_geoc, cos_Lat_geoc); // printf("sin_lat %f cos_lat %f\n", - // f.get_sin_latitude(), f.get_cos_latitude()); + // get_sin_latitude(), get_cos_latitude()); // printf("sin_lon %f cos_lon %f\n", - // f.get_sin_longitude(), f.get_cos_longitude()); + // get_sin_longitude(), get_cos_longitude()); - return 0; + return 1; } diff --git a/src/FDM/LaRCsim.hxx b/src/FDM/LaRCsim.hxx index 884cfd85f..d08db68b3 100644 --- a/src/FDM/LaRCsim.hxx +++ b/src/FDM/LaRCsim.hxx @@ -30,17 +30,22 @@ #include "flight.hxx" -// reset flight params to a specific position -int fgLaRCsimInit(double dt); +class FGLaRCsim: public FGInterface { -// update position based on inputs, positions, velocities, etc. -int fgLaRCsimUpdate(FGInterface& f, int multiloop); +public: -// Convert from the FGInterface struct to the LaRCsim generic_ struct -int FGInterface_2_LaRCsim (FGInterface& f); + // copy FDM state to LaRCsim structures + int copy_to_LaRCsim(); -// Convert from the LaRCsim generic_ struct to the FGInterface struct -int fgLaRCsim_2_FGInterface (FGInterface& f); + // copy FDM state from LaRCsim structures + int copy_from_LaRCsim(); + + // reset flight params to a specific position + int init( double dt ); + + // update position based on inputs, positions, velocities, etc. + int update( int multiloop ); +}; #endif // _LARCSIM_HXX diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 6bb94eec4..3f98f3bb7 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -41,10 +41,23 @@ // world time, so we introduce cur_fdm_state which is extrapolated by // the difference between sim time and real world time -FGInterface cur_fdm_state; +FGInterface * cur_fdm_state; FGInterface base_fdm_state; +int FGInterface::init( double dt ) { + cout << "dummy init() ... SHOULDN'T BE CALLED!" << endl; + return 0; +} + +int FGInterface::update( int multi_loop ) { + cout << "dummy update() ... SHOULDN'T BE CALLED!" << endl; + return 0; +} + +FGInterface::~FGInterface() { +} + // Extrapolate fdm based on time_offset (in usec) void FGInterface::extrapolate( int time_offset ) { double dt = time_offset / 1000000.0; @@ -75,6 +88,7 @@ void FGInterface::extrapolate( int time_offset ) { } +#if 0 // Initialize the flight model parameters int fgFDMInit(int model, FGInterface& f, double dt) { double save_alt = 0.0; @@ -127,8 +141,10 @@ int fgFDMInit(int model, FGInterface& f, double dt) { return 1; } +#endif +#if 0 // Run multiloop iterations of the flight model int fgFDMUpdate(int model, FGInterface& f, int multiloop, int time_offset) { double time_step, start_elev, end_elev; @@ -173,6 +189,7 @@ int fgFDMUpdate(int model, FGInterface& f, int multiloop, int time_offset) { return 1; } +#endif // Set the altitude (force) @@ -199,7 +216,7 @@ void fgFDMForceAltitude(int model, double alt_meters) { // Set the local ground elevation void fgFDMSetGroundElevation(int model, double ground_meters) { base_fdm_state.set_Runway_altitude( ground_meters * METER_TO_FEET ); - cur_fdm_state.set_Runway_altitude( ground_meters * METER_TO_FEET ); + cur_fdm_state->set_Runway_altitude( ground_meters * METER_TO_FEET ); } diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index 204f65799..5bc8f0f91 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -105,6 +105,10 @@ class FGInterface { public: + virtual int init( double dt ); + virtual int update( int multi_loop ); + virtual ~FGInterface(); + // Define the various supported flight models (many not yet implemented) enum { // Slew (in MS terminology) @@ -851,7 +855,7 @@ typedef fdm_state_list::iterator fdm_state_list_iterator; typedef fdm_state_list::const_iterator const_fdm_state_list_iterator; -extern FGInterface cur_fdm_state; +extern FGInterface * cur_fdm_state; // General interface to the flight model routines diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 1636fe21f..1a8ba5439 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -56,6 +56,8 @@ #include #include #include +#include +#include #include #include #include @@ -225,6 +227,16 @@ bool fgInitSubsystems( void ) { FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems"); FG_LOG( FG_GENERAL, FG_INFO, "========== =========="); + if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) { + cur_fdm_state = new FGLaRCsim; + } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) { + cur_fdm_state = new FGJSBsim; + } else { + FG_LOG( FG_GENERAL, FG_ALERT, + "No flight model, can't init aircraft" ); + exit(-1); + } + // allocates structures so must happen before any of the flight // model or control parameters are set fgAircraftInit(); // In the future this might not be the case. @@ -263,13 +275,13 @@ bool fgInitSubsystems( void ) { // now handled inside of the fgTileMgrUpdate() /* - geod_pos = Point3D( cur_fdm_state.get_Longitude(), cur_fdm_state.get_Latitude(), 0.0); + geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0); tmp_abs_view_pos = fgGeodToCart(geod_pos); FG_LOG( FG_GENERAL, FG_DEBUG, "Initial abs_view_pos = " << tmp_abs_view_pos ); scenery.cur_elev = - fgTileMgrCurElev( cur_fdm_state.get_Longitude(), cur_fdm_state.get_Latitude(), + fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), tmp_abs_view_pos ); FG_LOG( FG_GENERAL, FG_DEBUG, "Altitude after update " << scenery.cur_elev ); @@ -279,19 +291,19 @@ bool fgInitSubsystems( void ) { scenery.cur_elev ); // Reset our altitude if we are below ground - FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state.get_Altitude() ); + FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() ); FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " << - cur_fdm_state.get_Runway_altitude() ); + cur_fdm_state->get_Runway_altitude() ); - if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) { - cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 ); + if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) { + cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 ); } FG_LOG( FG_GENERAL, FG_INFO, "Updated position (after elevation adj): (" - << (cur_fdm_state.get_Latitude() * RAD_TO_DEG) << ", " - << (cur_fdm_state.get_Longitude() * RAD_TO_DEG) << ", " - << (cur_fdm_state.get_Altitude() * FEET_TO_METER) << ")" ); + << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", " + << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", " + << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" ); // We need to calculate a few more values here that would normally // be calculated by the FDM so that the v->UpdateViewMath() @@ -300,43 +312,43 @@ bool fgInitSubsystems( void ) { double sea_level_radius_meters; double lat_geoc; // Set the FG variables first - fgGeodToGeoc( cur_fdm_state.get_Latitude(), cur_fdm_state.get_Altitude(), + fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(), &sea_level_radius_meters, &lat_geoc); - cur_fdm_state.set_Geocentric_Position( lat_geoc, cur_fdm_state.get_Longitude(), - cur_fdm_state.get_Altitude() + + cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Altitude() + (sea_level_radius_meters * METER_TO_FEET) ); - cur_fdm_state.set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET ); + cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET ); - cur_fdm_state.set_sin_cos_longitude(cur_fdm_state.get_Longitude()); - cur_fdm_state.set_sin_cos_latitude(cur_fdm_state.get_Latitude()); + cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude()); + cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude()); - cur_fdm_state.set_sin_lat_geocentric(sin(lat_geoc)); - cur_fdm_state.set_cos_lat_geocentric(cos(lat_geoc)); + cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc)); + cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc)); // The following section sets up the flight model EOM parameters // and should really be read in from one or more files. // Initial Velocity - cur_fdm_state.set_Velocities_Local( current_options.get_uBody(), + cur_fdm_state->set_Velocities_Local( current_options.get_uBody(), current_options.get_vBody(), current_options.get_wBody()); // Initial Orientation - cur_fdm_state.set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD, + cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD, current_options.get_pitch() * DEG_TO_RAD, current_options.get_heading() * DEG_TO_RAD ); // Initial Angular Body rates - cur_fdm_state.set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 ); + cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 ); - cur_fdm_state.set_Earth_position_angle( 0.0 ); + cur_fdm_state->set_Earth_position_angle( 0.0 ); // Mass properties and geometry values - cur_fdm_state.set_Inertias( 8.547270E+01, + cur_fdm_state->set_Inertias( 8.547270E+01, 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 ); // CG position w.r.t. ref. point - cur_fdm_state.set_CG_Position( 0.0, 0.0, 0.0 ); + cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 ); // Initialize the event manager global_events.Init(); @@ -348,14 +360,14 @@ bool fgInitSubsystems( void ) { fgEVENT::FG_EVENT_READY, 60000 ); // Initialize the time dependent variables - t->init(cur_fdm_state); - t->update(cur_fdm_state); + t->init(*cur_fdm_state); + t->update(*cur_fdm_state); // Initialize view parameters FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()"); v->Init(); FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()"); - v->UpdateViewMath(cur_fdm_state); + v->UpdateViewMath(*cur_fdm_state); FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << v->get_abs_view_pos()); // v->UpdateWorldToEye(f); @@ -441,22 +453,23 @@ bool fgInitSubsystems( void ) { // Initialize the flight model subsystem data structures base on // above values - fgFDMInit( current_options.get_flight_model(), cur_fdm_state, - 1.0 / current_options.get_model_hz() ); + // fgFDMInit( current_options.get_flight_model(), cur_fdm_state, + // 1.0 / current_options.get_model_hz() ); + cur_fdm_state->init( 1.0 / current_options.get_model_hz() ); // I'm just sticking this here for now, it should probably move // eventually - scenery.cur_elev = cur_fdm_state.get_Runway_altitude() * FEET_TO_METER; + scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER; - if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) { - cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 ); + if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) { + cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 ); } FG_LOG( FG_GENERAL, FG_INFO, "Updated position (after elevation adj): (" - << (cur_fdm_state.get_Latitude() * RAD_TO_DEG) << ", " - << (cur_fdm_state.get_Longitude() * RAD_TO_DEG) << ", " - << (cur_fdm_state.get_Altitude() * FEET_TO_METER) << ")" ); + << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", " + << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", " + << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" ); // end of thing that I just stuck in that I should probably move // Joystick support @@ -502,53 +515,53 @@ void fgReInitSubsystems( void ) scenery.cur_elev ); // Reset our altitude if we are below ground - FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state.get_Altitude() ); + FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() ); FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " << - cur_fdm_state.get_Runway_altitude() ); + cur_fdm_state->get_Runway_altitude() ); - if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) { - cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 ); + if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) { + cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 ); } double sea_level_radius_meters; double lat_geoc; // Set the FG variables first - fgGeodToGeoc( cur_fdm_state.get_Latitude(), cur_fdm_state.get_Altitude(), + fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(), &sea_level_radius_meters, &lat_geoc); - cur_fdm_state.set_Geocentric_Position( lat_geoc, cur_fdm_state.get_Longitude(), - cur_fdm_state.get_Altitude() + + cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Altitude() + (sea_level_radius_meters * METER_TO_FEET) ); - cur_fdm_state.set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET ); + cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET ); - cur_fdm_state.set_sin_cos_longitude(cur_fdm_state.get_Longitude()); - cur_fdm_state.set_sin_cos_latitude(cur_fdm_state.get_Latitude()); + cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude()); + cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude()); - cur_fdm_state.set_sin_lat_geocentric(sin(lat_geoc)); - cur_fdm_state.set_cos_lat_geocentric(cos(lat_geoc)); + cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc)); + cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc)); // The following section sets up the flight model EOM parameters // and should really be read in from one or more files. // Initial Velocity - cur_fdm_state.set_Velocities_Local( current_options.get_uBody(), + cur_fdm_state->set_Velocities_Local( current_options.get_uBody(), current_options.get_vBody(), current_options.get_wBody()); // Initial Orientation - cur_fdm_state.set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD, + cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD, current_options.get_pitch() * DEG_TO_RAD, current_options.get_heading() * DEG_TO_RAD ); // Initial Angular Body rates - cur_fdm_state.set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 ); + cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 ); - cur_fdm_state.set_Earth_position_angle( 0.0 ); + cur_fdm_state->set_Earth_position_angle( 0.0 ); // Mass properties and geometry values - cur_fdm_state.set_Inertias( 8.547270E+01, + cur_fdm_state->set_Inertias( 8.547270E+01, 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 ); // CG position w.r.t. ref. point - cur_fdm_state.set_CG_Position( 0.0, 0.0, 0.0 ); + cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 ); // Initialize view parameters // FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()"); @@ -557,17 +570,18 @@ void fgReInitSubsystems( void ) v->set_goal_view_offset( 0.0 ); FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()"); - v->UpdateViewMath(cur_fdm_state); + v->UpdateViewMath(*cur_fdm_state); FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << v->get_abs_view_pos()); // v->UpdateWorldToEye(f); - fgFDMInit( current_options.get_flight_model(), cur_fdm_state, - 1.0 / current_options.get_model_hz() ); + // fgFDMInit( current_options.get_flight_model(), cur_fdm_state, + // 1.0 / current_options.get_model_hz() ); + cur_fdm_state->init( 1.0 / current_options.get_model_hz() ); - scenery.cur_elev = cur_fdm_state.get_Runway_altitude() * FEET_TO_METER; + scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER; - if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) { - cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 ); + if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) { + cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 ); } controls.reset_all(); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 00623bbf6..3705cb246 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -251,7 +251,7 @@ static void fgRenderFrame( void ) { // end of hack // update view volume parameters - current_view.UpdateViewParams(cur_fdm_state); + current_view.UpdateViewParams(*cur_fdm_state); // set the sun position xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); @@ -431,8 +431,9 @@ static void fgRenderFrame( void ) { // we've changed things elsewhere FGMaterialSlot m_slot; FGMaterialSlot *m_ptr = &m_slot; - if ( material_mgr.find( "Default", m_ptr ) ); - m_ptr->get_state()->force(); + if ( material_mgr.find( "Default", m_ptr ) ) { + m_ptr->get_state()->force(); + } // draw the ssg scene ssgCullAndDraw( scene ); @@ -460,7 +461,7 @@ static void fgRenderFrame( void ) { // Update internal time dependent calculations (i.e. flight model) void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { static fdm_state_list fdm_list; - FGInterface fdm_state; + // FGInterface fdm_state; fgLIGHT *l = &cur_light_params; FGTime *t = FGTime::cur_time_params; // FGView *v = ¤t_view; @@ -471,32 +472,36 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { multi_loop = 1; } - fdm_state = cur_fdm_state; + // fdm_state = *cur_fdm_state; if ( !t->getPause() ) { // run Autopilot system fgAPRun(); // printf("updating flight model x %d\n", multi_loop); - fgFDMUpdate( current_options.get_flight_model(), + /* fgFDMUpdate( current_options.get_flight_model(), fdm_state, multi_loop * current_options.get_speed_up(), - remainder ); + remainder ); */ + cur_fdm_state->update( multi_loop * current_options.get_speed_up() ); } else { - fgFDMUpdate( current_options.get_flight_model(), - fdm_state, 0, remainder ); + // fgFDMUpdate( current_options.get_flight_model(), + // fdm_state, 0, remainder ); + cur_fdm_state->update( 0 ); } + /* fdm_list.push_back( fdm_state ); while ( fdm_list.size() > 25 ) { fdm_list.pop_front(); } if ( current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FIRST_PERSON ) { - cur_fdm_state = fdm_state; + *cur_fdm_state = fdm_state; } else if ( current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW ) { - cur_fdm_state = fdm_list.front(); + *cur_fdm_state = fdm_list.front(); } + */ // update the view angle for ( i = 0; i < multi_loop; i++ ) { @@ -535,7 +540,7 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { } double tmp = -(l->sun_rotation + FG_PI) - - (cur_fdm_state.get_Psi() - current_view.get_view_offset() ); + - (cur_fdm_state->get_Psi() - current_view.get_view_offset() ); while ( tmp < 0.0 ) { tmp += FG_2PI; } @@ -602,15 +607,15 @@ static void fgMainLoop( void ) { /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n", scenery.cur_elev, - cur_fdm_state.get_Runway_altitude() * FEET_TO_METER, - cur_fdm_state.get_Altitude() * FEET_TO_METER); */ + cur_fdm_state->get_Runway_altitude() * FEET_TO_METER, + cur_fdm_state->get_Altitude() * FEET_TO_METER); */ if ( scenery.cur_elev > -9990 ) { - if ( cur_fdm_state.get_Altitude() * FEET_TO_METER < + if ( cur_fdm_state->get_Altitude() * FEET_TO_METER < (scenery.cur_elev + alt_adjust_m - 3.0) ) { // now set aircraft altitude above ground printf("Current Altitude = %.2f < %.2f forcing to %.2f\n", - cur_fdm_state.get_Altitude() * FEET_TO_METER, + cur_fdm_state->get_Altitude() * FEET_TO_METER, scenery.cur_elev + alt_adjust_m - 3.0, scenery.cur_elev + alt_adjust_m ); fgFDMForceAltitude( current_options.get_flight_model(), @@ -618,7 +623,7 @@ static void fgMainLoop( void ) { FG_LOG( FG_ALL, FG_DEBUG, "<*> resetting altitude to " - << cur_fdm_state.get_Altitude() * FEET_TO_METER << " meters" ); + << cur_fdm_state->get_Altitude() * FEET_TO_METER << " meters" ); } fgFDMSetGroundElevation( current_options.get_flight_model(), scenery.cur_elev ); // meters @@ -626,11 +631,11 @@ static void fgMainLoop( void ) { /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n", scenery.cur_elev, - cur_fdm_state.get_Runway_altitude() * FEET_TO_METER, - cur_fdm_state.get_Altitude() * FEET_TO_METER); */ + cur_fdm_state->get_Runway_altitude() * FEET_TO_METER, + cur_fdm_state->get_Altitude() * FEET_TO_METER); */ // update "time" - t->update(cur_fdm_state); + t->update(*cur_fdm_state); // Get elapsed time (in usec) for this past frame elapsed = fgGetTimeInterval(); @@ -719,16 +724,16 @@ static void fgMainLoop( void ) { double pitch = log((controls.get_throttle(0) * 14.0) + 1.0); //fprintf(stderr, "pitch1: %f ", pitch); - if (controls.get_throttle(0) > 0.0 || cur_fdm_state.v_rel_wind > 40.0) { - //fprintf(stderr, "rel_wind: %f ", cur_fdm_state.v_rel_wind); + if (controls.get_throttle(0) > 0.0 || cur_fdm_state->v_rel_wind > 40.0) { + //fprintf(stderr, "rel_wind: %f ", cur_fdm_state->v_rel_wind); // only add relative wind and AoA if prop is moving // or we're really flying at idle throttle if (pitch < 5.4) { // this needs tuning // prop tips not breaking sound barrier - pitch += log(cur_fdm_state.v_rel_wind + 0.8)/2; + pitch += log(cur_fdm_state->v_rel_wind + 0.8)/2; } else { // prop tips breaking sound barrier - pitch += log(cur_fdm_state.v_rel_wind + 0.8)/10; + pitch += log(cur_fdm_state->v_rel_wind + 0.8)/10; } //fprintf(stderr, "pitch2: %f ", pitch); //fprintf(stderr, "AoA: %f ", FG_Gamma_vert_rad); @@ -736,7 +741,7 @@ static void fgMainLoop( void ) { // Angle of Attack next... -x^3(e^x) is my best guess Just // need to calculate some reasonable scaling factor and // then clamp it on the positive aoa (neg adj) side - double aoa = cur_fdm_state.get_Gamma_vert_rad() * 2.2; + double aoa = cur_fdm_state->get_Gamma_vert_rad() * 2.2; double tmp = 3.0; double aoa_adj = pow(-aoa, tmp) * pow(M_E, aoa); if (aoa_adj < -0.8) aoa_adj = -0.8; @@ -750,7 +755,7 @@ static void fgMainLoop( void ) { //fprintf(stderr, "pitch4: %f\n", pitch); double volume = controls.get_throttle(0) * 1.15 + 0.3 + - log(cur_fdm_state.v_rel_wind + 1.0)/14.0; + log(cur_fdm_state->v_rel_wind + 1.0)/14.0; // fprintf(stderr, "volume: %f\n", volume); pitch_envelope.setStep ( 0, 0.01, pitch ); @@ -952,7 +957,7 @@ void fgReshape( int width, int height ) { // the main loop, so this will now work without seg faulting // the system. solarSystemRebuild(); - current_view.UpdateViewParams(cur_fdm_state); + current_view.UpdateViewParams(*cur_fdm_state); if ( current_options.get_panel_status() ) { FGPanel::OurPanel->ReInit(0, 0, 1024, 768); }