From 8fbd4e41c741e9b7be1d433a0cbe0b05b69b863a Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 24 Aug 1998 20:09:25 +0000 Subject: [PATCH] Code optimization tweaks from Norman Vine. --- LaRCsim/atmos_62.c | 5 +++-- LaRCsim/ls_accel.c | 17 ++++++++++++----- LaRCsim/ls_aux.c | 7 ++++++- LaRCsim/ls_step.c | 20 ++++++++++++++------ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/LaRCsim/atmos_62.c b/LaRCsim/atmos_62.c index 3415c529c..3c351882c 100644 --- a/LaRCsim/atmos_62.c +++ b/LaRCsim/atmos_62.c @@ -89,7 +89,7 @@ void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound, int index; SCALAR daltp, daltn, daltp3, daltn3, density; SCALAR t_amb_r, p_amb_r; - int nonconstant_const_param = 5.256; + SCALAR tmp; static SCALAR d_a_table[MAX_ALT_INDEX][5] = { @@ -254,7 +254,8 @@ void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound, t_amb_r = 1. - 6.875e-6*altitude; // printf("index = %d t_amb_r = %.2f\n", index, t_amb_r); // p_amb_r = pow( t_amb_r, 5.256 ); - p_amb_r = pow( t_amb_r, nonconstant_const_param ); + tmp = 5.256; // avoid a segfault (?) + p_amb_r = pow( t_amb_r, tmp ); // printf("p_amb_r = %.2f\n", p_amb_r); } else diff --git a/LaRCsim/ls_accel.c b/LaRCsim/ls_accel.c index fb091b0fe..7e419fdef 100644 --- a/LaRCsim/ls_accel.c +++ b/LaRCsim/ls_accel.c @@ -38,6 +38,9 @@ $Header$ $Log$ +Revision 1.4 1998/08/24 20:09:26 curt +Code optimization tweaks from Norman Vine. + Revision 1.3 1998/08/06 12:46:38 curt Header change. @@ -102,6 +105,7 @@ void ls_accel( void ) { SCALAR inv_Mass, inv_Radius; SCALAR ixz2, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10; SCALAR dx_pilot_from_cg, dy_pilot_from_cg, dz_pilot_from_cg; + SCALAR tan_Lat_geocentric; /* Sum forces and moments at reference point */ @@ -132,12 +136,13 @@ void ls_accel( void ) { /* Calculate linear accelerations */ + tan_Lat_geocentric = tan(Lat_geocentric); inv_Mass = 1/Mass; inv_Radius = 1/Radius_to_vehicle; V_dot_north = inv_Mass*F_north + - inv_Radius*(V_north*V_down - V_east*V_east*tan(Lat_geocentric)); + inv_Radius*(V_north*V_down - V_east*V_east*tan_Lat_geocentric); V_dot_east = inv_Mass*F_east + - inv_Radius*(V_east*V_down + V_north*V_east*tan(Lat_geocentric)); + inv_Radius*(V_east*V_down + V_north*V_east*tan_Lat_geocentric); V_dot_down = inv_Mass*(F_down) + Gravity - inv_Radius*(V_north*V_north + V_east*V_east); @@ -146,14 +151,16 @@ void ls_accel( void ) { ixz2 = I_xz*I_xz; c0 = 1/(I_xx*I_zz - ixz2); c1 = c0*((I_yy-I_zz)*I_zz - ixz2); - c2 = c0*I_xz*(I_xx - I_yy + I_zz); - c3 = c0*I_zz; c4 = c0*I_xz; + /* c2 = c0*I_xz*(I_xx - I_yy + I_zz); */ + c2 = c4*(I_xx - I_yy + I_zz); + c3 = c0*I_zz; c7 = 1/I_yy; c5 = c7*(I_zz - I_xx); c6 = c7*I_xz; c8 = c0*((I_xx - I_yy)*I_xx + ixz2); - c9 = c0*I_xz*(I_yy - I_zz - I_xx); + /* c9 = c0*I_xz*(I_yy - I_zz - I_xx); */ + c9 = c4*(I_yy - I_zz - I_xx); c10 = c0*I_xx; /* Calculate the rotational body axis accelerations */ diff --git a/LaRCsim/ls_aux.c b/LaRCsim/ls_aux.c index 58ddc7660..448448cf6 100644 --- a/LaRCsim/ls_aux.c +++ b/LaRCsim/ls_aux.c @@ -47,6 +47,9 @@ $Header$ $Log$ +Revision 1.4 1998/08/24 20:09:26 curt +Code optimization tweaks from Norman Vine. + Revision 1.3 1998/08/06 12:46:38 curt Header change. @@ -140,6 +143,7 @@ void ls_aux( void ) { /* SCALAR inv_radius_ratio; */ SCALAR cos_rwy_hdg, sin_rwy_hdg; SCALAR mach2, temp_ratio, pres_ratio; + SCALAR tmp; /* update geodetic position */ @@ -261,7 +265,8 @@ void ls_aux( void ) { mach2 = Mach_number*Mach_number; temp_ratio = 1.0 + 0.2*mach2; - pres_ratio = pow( temp_ratio, 3.5 ); + tmp = 3.5; + pres_ratio = pow( temp_ratio, tmp ); Total_temperature = temp_ratio*Static_temperature; Total_pressure = pres_ratio*Static_pressure; diff --git a/LaRCsim/ls_step.c b/LaRCsim/ls_step.c index 66f0ca230..58838e8d3 100644 --- a/LaRCsim/ls_step.c +++ b/LaRCsim/ls_step.c @@ -50,6 +50,9 @@ $Header$ $Log$ +Revision 1.4 1998/08/24 20:09:27 curt +Code optimization tweaks from Norman Vine. + Revision 1.3 1998/07/12 03:11:04 curt Removed some printf()'s. Fixed the autopilot integration so it should be able to update it's control @@ -140,6 +143,7 @@ void ls_step( SCALAR dt, int Initialize ) { SCALAR e_dot_0, e_dot_1, e_dot_2, e_dot_3; static SCALAR e_0, e_1, e_2, e_3; static SCALAR e_dot_0_past, e_dot_1_past, e_dot_2_past, e_dot_3_past; + SCALAR cos_Lat_geocentric, inv_Radius_to_vehicle; /* I N I T I A L I Z A T I O N */ @@ -233,10 +237,14 @@ void ls_step( SCALAR dt, int Initialize ) { /* Calculate trajectory rate (geocentric coordinates) */ - if (cos(Lat_geocentric) != 0) - Longitude_dot = V_east/(Radius_to_vehicle*cos(Lat_geocentric)); + inv_Radius_to_vehicle = 1.0/Radius_to_vehicle; + cos_Lat_geocentric = cos(Lat_geocentric); + + if ( cos_Lat_geocentric != 0) { + Longitude_dot = V_east/(Radius_to_vehicle*cos_Lat_geocentric); + } - Latitude_dot = V_north/Radius_to_vehicle; + Latitude_dot = V_north*inv_Radius_to_vehicle; Radius_dot = -V_down; /* A N G U L A R V E L O C I T I E S A N D P O S I T I O N S */ @@ -255,9 +263,9 @@ void ls_step( SCALAR dt, int Initialize ) { /* Calculate local axis frame rates due to travel over curved earth */ - P_local = V_east/Radius_to_vehicle; - Q_local = -V_north/Radius_to_vehicle; - R_local = -V_east*tan(Lat_geocentric)/Radius_to_vehicle; + P_local = V_east*inv_Radius_to_vehicle; + Q_local = -V_north*inv_Radius_to_vehicle; + R_local = -V_east*tan(Lat_geocentric)*inv_Radius_to_vehicle; /* Transform local axis frame rates to body axis rates */ -- 2.39.2