1
0
Fork 0

Code optimization tweaks from Norman Vine.

This commit is contained in:
curt 1998-08-24 20:09:25 +00:00
parent f3d7ac2bd5
commit 8fbd4e41c7
4 changed files with 35 additions and 14 deletions

View file

@ -89,7 +89,7 @@ void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound,
int index; int index;
SCALAR daltp, daltn, daltp3, daltn3, density; SCALAR daltp, daltn, daltp3, daltn3, density;
SCALAR t_amb_r, p_amb_r; SCALAR t_amb_r, p_amb_r;
int nonconstant_const_param = 5.256; SCALAR tmp;
static SCALAR d_a_table[MAX_ALT_INDEX][5] = 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; t_amb_r = 1. - 6.875e-6*altitude;
// printf("index = %d t_amb_r = %.2f\n", index, t_amb_r); // 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, 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); // printf("p_amb_r = %.2f\n", p_amb_r);
} }
else else

View file

@ -38,6 +38,9 @@
$Header$ $Header$
$Log$ $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 Revision 1.3 1998/08/06 12:46:38 curt
Header change. Header change.
@ -102,6 +105,7 @@ void ls_accel( void ) {
SCALAR inv_Mass, inv_Radius; SCALAR inv_Mass, inv_Radius;
SCALAR ixz2, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10; 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 dx_pilot_from_cg, dy_pilot_from_cg, dz_pilot_from_cg;
SCALAR tan_Lat_geocentric;
/* Sum forces and moments at reference point */ /* Sum forces and moments at reference point */
@ -132,12 +136,13 @@ void ls_accel( void ) {
/* Calculate linear accelerations */ /* Calculate linear accelerations */
tan_Lat_geocentric = tan(Lat_geocentric);
inv_Mass = 1/Mass; inv_Mass = 1/Mass;
inv_Radius = 1/Radius_to_vehicle; inv_Radius = 1/Radius_to_vehicle;
V_dot_north = inv_Mass*F_north + 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 + 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 - V_dot_down = inv_Mass*(F_down) + Gravity -
inv_Radius*(V_north*V_north + V_east*V_east); inv_Radius*(V_north*V_north + V_east*V_east);
@ -146,14 +151,16 @@ void ls_accel( void ) {
ixz2 = I_xz*I_xz; ixz2 = I_xz*I_xz;
c0 = 1/(I_xx*I_zz - ixz2); c0 = 1/(I_xx*I_zz - ixz2);
c1 = c0*((I_yy-I_zz)*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; 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; c7 = 1/I_yy;
c5 = c7*(I_zz - I_xx); c5 = c7*(I_zz - I_xx);
c6 = c7*I_xz; c6 = c7*I_xz;
c8 = c0*((I_xx - I_yy)*I_xx + ixz2); 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; c10 = c0*I_xx;
/* Calculate the rotational body axis accelerations */ /* Calculate the rotational body axis accelerations */

View file

@ -47,6 +47,9 @@
$Header$ $Header$
$Log$ $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 Revision 1.3 1998/08/06 12:46:38 curt
Header change. Header change.
@ -140,6 +143,7 @@ void ls_aux( void ) {
/* SCALAR inv_radius_ratio; */ /* SCALAR inv_radius_ratio; */
SCALAR cos_rwy_hdg, sin_rwy_hdg; SCALAR cos_rwy_hdg, sin_rwy_hdg;
SCALAR mach2, temp_ratio, pres_ratio; SCALAR mach2, temp_ratio, pres_ratio;
SCALAR tmp;
/* update geodetic position */ /* update geodetic position */
@ -261,7 +265,8 @@ void ls_aux( void ) {
mach2 = Mach_number*Mach_number; mach2 = Mach_number*Mach_number;
temp_ratio = 1.0 + 0.2*mach2; 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_temperature = temp_ratio*Static_temperature;
Total_pressure = pres_ratio*Static_pressure; Total_pressure = pres_ratio*Static_pressure;

View file

@ -50,6 +50,9 @@
$Header$ $Header$
$Log$ $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 Revision 1.3 1998/07/12 03:11:04 curt
Removed some printf()'s. Removed some printf()'s.
Fixed the autopilot integration so it should be able to update it's control 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; 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_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; 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 */ /* 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) */ /* Calculate trajectory rate (geocentric coordinates) */
if (cos(Lat_geocentric) != 0) inv_Radius_to_vehicle = 1.0/Radius_to_vehicle;
Longitude_dot = V_east/(Radius_to_vehicle*cos(Lat_geocentric)); 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; 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 */ /* 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 */ /* Calculate local axis frame rates due to travel over curved earth */
P_local = V_east/Radius_to_vehicle; P_local = V_east*inv_Radius_to_vehicle;
Q_local = -V_north/Radius_to_vehicle; Q_local = -V_north*inv_Radius_to_vehicle;
R_local = -V_east*tan(Lat_geocentric)/Radius_to_vehicle; R_local = -V_east*tan(Lat_geocentric)*inv_Radius_to_vehicle;
/* Transform local axis frame rates to body axis rates */ /* Transform local axis frame rates to body axis rates */