From: Tim Moore Date: Mon, 14 Sep 2009 11:38:55 +0000 (+0200) Subject: Merge FG_Simulator as subdirectory X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=66a0be21da96dc9f42a8516d72bfbb61174df3d6;p=flightgear.git Merge FG_Simulator as subdirectory --- 66a0be21da96dc9f42a8516d72bfbb61174df3d6 diff --cc Simulator/Aircraft/Makefile.am index 000000000,000000000..9620f85e1 new file mode 100644 --- /dev/null +++ b/Simulator/Aircraft/Makefile.am @@@ -1,0 -1,0 +1,5 @@@ ++noinst_LIBRARIES = libAircraft.a ++ ++libAircraft_a_SOURCES = aircraft.cxx aircraft.hxx ++ ++INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator diff --cc Simulator/Aircraft/aircraft.cxx index 000000000,000000000..ac4b067b0 new file mode 100644 --- /dev/null +++ b/Simulator/Aircraft/aircraft.cxx @@@ -1,0 -1,0 +1,158 @@@ ++// aircraft.cxx -- various aircraft routines ++// ++// Written by Curtis Olson, started May 1997. ++// ++// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#include ++ ++#include "aircraft.hxx" ++#include ++#include ++ ++// This is a record containing all the info for the aircraft currently ++// being operated ++fgAIRCRAFT current_aircraft; ++ ++ ++// Initialize an Aircraft structure ++void fgAircraftInit( void ) { ++ FG_LOG( FG_AIRCRAFT, FG_INFO, "Initializing Aircraft structure" ); ++ ++ current_aircraft.fdm_state = &cur_fdm_state; ++ current_aircraft.controls = &controls; ++} ++ ++ ++// Display various parameters to stdout ++void fgAircraftOutputCurrent(fgAIRCRAFT *a) { ++ FGInterface *f; ++ ++ f = a->fdm_state; ++ ++ FG_LOG( FG_FLIGHT, FG_DEBUG, ++ "Pos = (" ++ << (f->get_Longitude() * 3600.0 * RAD_TO_DEG) << "," ++ << (f->get_Latitude() * 3600.0 * RAD_TO_DEG) << "," ++ << f->get_Altitude() ++ << ") (Phi,Theta,Psi)=(" ++ << f->get_Phi() << "," ++ << f->get_Theta() << "," ++ << f->get_Psi() << ")" ); ++ ++ FG_LOG( FG_FLIGHT, FG_DEBUG, ++ "Kts = " << f->get_V_equiv_kts() ++ << " Elev = " << controls.get_elevator() ++ << " Aileron = " << controls.get_aileron() ++ << " Rudder = " << controls.get_rudder() ++ << " Power = " << controls.get_throttle( 0 ) ); ++} ++ ++ ++// $Log$ ++// Revision 1.7 1999/02/05 21:28:09 curt ++// Modifications to incorporate Jon S. Berndts flight model code. ++// ++// Revision 1.6 1998/12/05 15:53:59 curt ++// Renamed class fgFLIGHT to class FGState as per request by JSB. ++// ++// Revision 1.5 1998/12/03 01:14:58 curt ++// Converted fgFLIGHT to a class. ++// ++// Revision 1.4 1998/11/06 21:17:31 curt ++// Converted to new logstream debugging facility. This allows release ++// builds with no messages at all (and no performance impact) by using ++// the -DFG_NDEBUG flag. ++// ++// Revision 1.3 1998/10/25 14:08:37 curt ++// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. ++// ++// Revision 1.2 1998/10/17 01:33:52 curt ++// C++ ifying ... ++// ++// Revision 1.1 1998/10/16 23:26:47 curt ++// C++-ifying. ++// ++// Revision 1.19 1998/04/25 22:06:24 curt ++// Edited cvs log messages in source files ... bad bad bad! ++// ++// Revision 1.18 1998/04/18 04:13:56 curt ++// Moved fg_debug.c to it's own library. ++// ++// Revision 1.17 1998/02/12 21:59:31 curt ++// Incorporated code changes contributed by Charlie Hotchkiss ++// ++// ++// Revision 1.16 1998/02/07 15:29:31 curt ++// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss ++// ++// ++// Revision 1.15 1998/01/27 00:47:46 curt ++// Incorporated Paul Bleisch's new debug message ++// system and commandline/config file processing code. ++// ++// Revision 1.14 1998/01/19 19:26:56 curt ++// Merged in make system changes from Bob Kuehne ++// This should simplify things tremendously. ++// ++// Revision 1.13 1997/12/15 23:54:30 curt ++// Add xgl wrappers for debugging. ++// Generate terrain normals on the fly. ++// ++// Revision 1.12 1997/12/10 22:37:37 curt ++// Prepended "fg" on the name of all global structures that didn't have it yet. ++// i.e. "struct WEATHER {}" became "struct fgWEATHER {}" ++// ++// Revision 1.11 1997/09/13 02:00:05 curt ++// Mostly working on stars and generating sidereal time for accurate star ++// placement. ++// ++// Revision 1.10 1997/08/27 03:29:56 curt ++// Changed naming scheme of basic shared structures. ++// ++// Revision 1.9 1997/07/19 22:39:08 curt ++// Moved PI to ../constants.h ++// ++// Revision 1.8 1997/06/25 15:39:45 curt ++// Minor changes to compile with rsxnt/win32. ++// ++// Revision 1.7 1997/06/02 03:01:39 curt ++// Working on views (side, front, back, transitions, etc.) ++// ++// Revision 1.6 1997/05/31 19:16:26 curt ++// Elevator trim added. ++// ++// Revision 1.5 1997/05/30 19:30:14 curt ++// The LaRCsim flight model is starting to look like it is working. ++// ++// Revision 1.4 1997/05/30 03:54:11 curt ++// Made a bit more progress towards integrating the LaRCsim flight model. ++// ++// Revision 1.3 1997/05/29 22:39:56 curt ++// Working on incorporating the LaRCsim flight model. ++// ++// Revision 1.2 1997/05/23 15:40:29 curt ++// Added GNU copyright headers. ++// ++// Revision 1.1 1997/05/16 15:58:24 curt ++// Initial revision. ++// ++ diff --cc Simulator/Aircraft/aircraft.hxx index 000000000,000000000..02e7470ee new file mode 100644 --- /dev/null +++ b/Simulator/Aircraft/aircraft.hxx @@@ -1,0 -1,0 +1,122 @@@ ++//************************************************************************* ++// aircraft.hxx -- define shared aircraft parameters ++// ++// Written by Curtis Olson, started May 1997. ++// ++// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++//*************************************************************************/ ++ ++ ++#ifndef _AIRCRAFT_HXX ++#define _AIRCRAFT_HXX ++ ++ ++#ifndef __cplusplus ++# error This library requires C++ ++#endif ++ ++ ++#include ++#include ++ ++ ++// Define a structure containing all the parameters for an aircraft ++typedef struct{ ++ FGInterface *fdm_state; ++ FGControls *controls; ++} fgAIRCRAFT ; ++ ++ ++// current_aircraft contains all the parameters of the aircraft ++// currently being operated. ++extern fgAIRCRAFT current_aircraft; ++ ++ ++// Initialize an Aircraft structure ++void fgAircraftInit( void ); ++ ++ ++// Display various parameters to stdout ++void fgAircraftOutputCurrent(fgAIRCRAFT *a); ++ ++ ++#endif // _AIRCRAFT_HXX ++ ++ ++// $Log$ ++// Revision 1.6 1999/02/05 21:28:10 curt ++// Modifications to incorporate Jon S. Berndts flight model code. ++// ++// Revision 1.5 1999/02/01 21:33:24 curt ++// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since ++// Jon accepted my offer to do this and thought it was a good idea. ++// ++// Revision 1.4 1998/12/05 16:13:10 curt ++// Renamed class fgCONTROLS to class FGControls. ++// ++// Revision 1.3 1998/12/05 15:54:01 curt ++// Renamed class fgFLIGHT to class FGState as per request by JSB. ++// ++// Revision 1.2 1998/10/17 01:33:54 curt ++// C++ ifying ... ++// ++// Revision 1.1 1998/10/16 23:26:49 curt ++// C++-ifying. ++// ++// Revision 1.12 1998/04/22 13:26:15 curt ++// C++ - ifing the code a bit. ++// ++// Revision 1.11 1998/04/21 17:02:27 curt ++// Prepairing for C++ integration. ++// ++// Revision 1.10 1998/02/07 15:29:32 curt ++// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss ++// ++// ++// Revision 1.9 1998/01/22 02:59:23 curt ++// Changed #ifdef FILE_H to #ifdef _FILE_H ++// ++// Revision 1.8 1998/01/19 19:26:57 curt ++// Merged in make system changes from Bob Kuehne ++// This should simplify things tremendously. ++// ++// Revision 1.7 1997/12/10 22:37:38 curt ++// Prepended "fg" on the name of all global structures that didn't have it yet. ++// i.e. "struct WEATHER {}" became "struct fgWEATHER {}" ++// ++// Revision 1.6 1997/09/13 02:00:06 curt ++// Mostly working on stars and generating sidereal time for accurate star ++// placement. ++// ++// Revision 1.5 1997/08/27 03:29:58 curt ++// Changed naming scheme of basic shared structures. ++// ++// Revision 1.4 1997/07/23 21:52:17 curt ++// Put comments around the text after an #endif for increased portability. ++// ++// Revision 1.3 1997/06/21 17:12:42 curt ++// Capitalized subdirectory names. ++// ++// Revision 1.2 1997/05/23 15:40:30 curt ++// Added GNU copyright headers. ++// ++// Revision 1.1 1997/05/16 15:58:25 curt ++// Initial revision. ++// diff --cc Simulator/Airports/Makefile.am index 000000000,000000000..250420518 new file mode 100644 --- /dev/null +++ b/Simulator/Airports/Makefile.am @@@ -1,0 -1,0 +1,7 @@@ ++noinst_LIBRARIES = libAirports.a ++ ++libAirports_a_SOURCES = \ ++ genapt.cxx genapt.hxx \ ++ simple.cxx simple.hxx ++ ++INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator diff --cc Simulator/Airports/genapt.cxx index 000000000,000000000..b84009974 new file mode 100644 --- /dev/null +++ b/Simulator/Airports/genapt.cxx @@@ -1,0 -1,0 +1,345 @@@ ++// ++// genapt.cxx -- generate airport scenery from the given definition file ++// ++// Written by Curtis Olson, started September 1998. ++// ++// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#include ++ ++#include STL_STRING ++#include ++ ++#ifdef __BORLANDC__ ++# define exception c_exception ++#endif ++#include ++ ++#ifdef FG_HAVE_NATIVE_SGI_COMPILERS ++# include ++#endif ++ ++#include ++// #include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++// #include ++ ++#include "genapt.hxx" ++ ++FG_USING_STD(string); ++FG_USING_STD(vector); ++ ++ ++typedef vector < Point3D > container; ++typedef container::iterator iterator; ++typedef container::const_iterator const_iterator; ++ ++ ++#define FG_APT_BASE_TEX_CONSTANT 2000.0 ++ ++// Calculate texture coordinates for a given point. ++static Point3D calc_tex_coords(double *node, const Point3D& ref) { ++ Point3D cp; ++ Point3D pp; ++ ++ cp = Point3D( node[0] + ref.x(), node[1] + ref.y(), node[2] + ref.z() ); ++ ++ pp = fgCartToPolar3d(cp); ++ ++ pp.setx( fmod(FG_APT_BASE_TEX_CONSTANT * pp.x(), 10.0) ); ++ pp.sety( fmod(FG_APT_BASE_TEX_CONSTANT * pp.y(), 10.0) ); ++ ++ if ( pp.x() < 0.0 ) { ++ pp.setx( pp.x() + 10.0 ); ++ } ++ ++ if ( pp.y() < 0.0 ) { ++ pp.sety( pp.y() + 10.0 ); ++ } ++ ++ return(pp); ++} ++ ++ ++// generate the actual base area for the airport ++static void ++gen_base( const Point3D& average, const container& perimeter, fgTILE *t) ++{ ++ GLint display_list; ++ Point3D cart, cart_trans, tex; ++ MAT3vec normal; ++ double dist, max_dist, temp; ++ int center_num, i; ++ ++ fgFRAGMENT fragment; ++ ++ max_dist = 0.0; ++ ++ FG_LOG( FG_TERRAIN, FG_INFO, ++ "generating airport base for size = " << perimeter.size() ); ++ ++ fragment.init(); ++ fragment.tile_ptr = t; ++ ++ // find airport base material in the properties list ++ if ( ! material_mgr.find( APT_BASE_MATERIAL, fragment.material_ptr )) { ++ FG_LOG( FG_TERRAIN, FG_ALERT, ++ "Ack! unknown material name = " << APT_BASE_MATERIAL ++ << " in fgAptGenerat()" ); ++ } ++ ++ FG_LOG( FG_TERRAIN, FG_INFO, ++ " tile center = " ++ << t->center.x() << " " << t->center.y() << " " << t->center.z() ); ++ FG_LOG( FG_TERRAIN, FG_INFO, ++ " airport center = " ++ << average.x() << " " << average.y() << " " << average.z() ); ++ fragment.center = average; ++ ++ normal[0] = average.x(); ++ normal[1] = average.y(); ++ normal[2] = average.z(); ++ MAT3_NORMALIZE_VEC(normal, temp); ++ ++ display_list = xglGenLists(1); ++ xglNewList(display_list, GL_COMPILE); ++ xglBegin(GL_TRIANGLE_FAN); ++ ++ // first point center of fan ++ cart_trans = average - t->center; ++ t->nodes[t->ncount][0] = cart_trans.x(); ++ t->nodes[t->ncount][1] = cart_trans.y(); ++ t->nodes[t->ncount][2] = cart_trans.z(); ++ center_num = t->ncount; ++ t->ncount++; ++ ++ tex = calc_tex_coords( t->nodes[t->ncount-1], t->center ); ++ xglTexCoord2f(tex.x(), tex.y()); ++ xglNormal3dv(normal); ++ xglVertex3dv(t->nodes[t->ncount-1]); ++ ++ // first point on perimeter ++ const_iterator current = perimeter.begin(); ++ cart = fgGeodToCart( *current ); ++ cart_trans = cart - t->center; ++ t->nodes[t->ncount][0] = cart_trans.x(); ++ t->nodes[t->ncount][1] = cart_trans.y(); ++ t->nodes[t->ncount][2] = cart_trans.z(); ++ t->ncount++; ++ ++ i = 1; ++ tex = calc_tex_coords( t->nodes[i], t->center ); ++ dist = cart.distance3Dsquared(average); ++ if ( dist > max_dist ) { ++ max_dist = dist; ++ } ++ xglTexCoord2f(tex.x(), tex.y()); ++ xglVertex3dv(t->nodes[i]); ++ ++current; ++ ++i; ++ ++ const_iterator last = perimeter.end(); ++ for ( ; current != last; ++current ) { ++ cart = fgGeodToCart( *current ); ++ cart_trans = cart - t->center; ++ t->nodes[t->ncount][0] = cart_trans.x(); ++ t->nodes[t->ncount][1] = cart_trans.y(); ++ t->nodes[t->ncount][2] = cart_trans.z(); ++ t->ncount++; ++ fragment.add_face(center_num, i - 1, i); ++ ++ tex = calc_tex_coords( t->nodes[i], t->center ); ++ dist = cart.distance3Dsquared(average); ++ if ( dist > max_dist ) { ++ max_dist = dist; ++ } ++ xglTexCoord2f(tex.x(), tex.y()); ++ xglVertex3dv(t->nodes[i]); ++ i++; ++ } ++ ++ // last point (first point in perimeter list) ++ current = perimeter.begin(); ++ cart = fgGeodToCart( *current ); ++ cart_trans = cart - t->center; ++ fragment.add_face(center_num, i - 1, 1); ++ ++ tex = calc_tex_coords( t->nodes[1], t->center ); ++ xglTexCoord2f(tex.x(), tex.y()); ++ xglVertex3dv(t->nodes[1]); ++ ++ xglEnd(); ++ xglEndList(); ++ ++ fragment.bounding_radius = sqrt(max_dist); ++ fragment.display_list = display_list; ++ ++ t->fragment_list.push_back(fragment); ++} ++ ++ ++// Load a .apt file and register the GL fragments with the ++// corresponding tile ++int ++fgAptGenerate(const string& path, fgTILE *tile) ++{ ++ string token; ++ string apt_id, apt_name; ++ char c; ++ int i = 1; ++ ++ // face list (this indexes into the master tile vertex list) ++ container perimeter; ++ Point3D p, average; ++ double avex = 0.0, avey = 0.0, avez = 0.0; ++ int size; ++ ++ // gpc_vertex p_2d, list_2d[MAX_PERIMETER]; ++ // gpc_vertex_list perimeter_2d; ++ ++ fg_gzifstream in( path ); ++ if ( !in ) { ++ // exit immediately assuming an airport file for this tile ++ // doesn't exist. ++ return 0; ++ } ++ ++ apt_id = ""; ++ ++ // read in each line of the file ++ in >> skipcomment; ++ while ( ! in.eof() ) ++ { ++ in >> token; ++ ++ if ( token == "a" ) { ++ // airport info record (start of airport) ++ ++ if ( apt_id.length() > 0 ) { ++ // we have just finished reading and airport record. ++ // process the info ++ gen_base(average, perimeter, tile); ++ } ++ ++ FG_LOG( FG_TERRAIN, FG_INFO, "Reading airport record" ); ++ in >> apt_id; ++ apt_name = ""; ++ i = 1; ++ avex = avey = avez = 0.0; ++ perimeter.erase( perimeter.begin(), perimeter.end() ); ++ // skip to end of line. ++ while ( in.get(c) && c != '\n' ) { ++ apt_name += c; ++ } ++ FG_LOG( FG_TERRAIN, FG_INFO, ++ "\tID = " << apt_id << " Name = " << apt_name ); ++ } else if ( token == "p" ) { ++ // airport area bounding polygon coordinate. These ++ // specify a convex hull that should already have been cut ++ // out of the base terrain. The points are given in ++ // counter clockwise order and are specified in lon/lat ++ // degrees. ++ in >> p; ++ avex += tile->nodes[i][0]; ++ avey += tile->nodes[i][1]; ++ avez += tile->nodes[i][2]; ++ perimeter.push_back(p); ++ ++i; ++ } else if ( token == "r" ) { ++ // runway record ++ // skip for now ++ while ( in.get(c) && c != '\n' ); ++ } ++ ++ in >> skipcomment; ++ } ++ ++ if ( apt_id.length() > 0 ) { ++ // we have just finished reading and airport record. ++ // process the info ++ size = perimeter.size(); ++ average = Point3D( avex / (double)size + tile->center.x(), ++ avey / (double)size + tile->center.y(), ++ avez / (double)size + tile->center.z() ); ++ ++ gen_base(average, perimeter, tile); ++ } ++ ++ return 1; ++} ++ ++ ++// $Log$ ++// Revision 1.14 1999/03/02 01:02:31 curt ++// Tweaks for building with native SGI compilers. ++// ++// Revision 1.13 1999/02/26 22:08:34 curt ++// Added initial support for native SGI compilers. ++// ++// Revision 1.12 1999/02/01 21:08:33 curt ++// Optimizations from Norman Vine. ++// ++// Revision 1.11 1998/11/23 21:48:09 curt ++// Borland portability tweaks. ++// ++// Revision 1.10 1998/11/07 19:07:06 curt ++// Enable release builds using the --without-logging option to the configure ++// script. Also a couple log message cleanups, plus some C to C++ comment ++// conversion. ++// ++// Revision 1.9 1998/11/06 21:17:32 curt ++// Converted to new logstream debugging facility. This allows release ++// builds with no messages at all (and no performance impact) by using ++// the -DFG_NDEBUG flag. ++// ++// Revision 1.8 1998/11/06 14:46:59 curt ++// Changes to track Bernie's updates to fgstream. ++// ++// Revision 1.7 1998/10/20 18:26:06 curt ++// Updates to point3d.hxx ++// ++// Revision 1.6 1998/10/18 01:17:16 curt ++// Point3D tweaks. ++// ++// Revision 1.5 1998/10/16 23:27:14 curt ++// C++-ifying. ++// ++// Revision 1.4 1998/10/16 00:51:46 curt ++// Converted to Point3D class. ++// ++// Revision 1.3 1998/09/21 20:55:00 curt ++// Used the cartesian form of the airport area coordinates to determine the ++// center. ++// ++// Revision 1.2 1998/09/14 12:44:30 curt ++// Don't recalculate perimeter points since it is not likely that they will match ++// exactly with the previously calculated points, which will leave an ugly gap ++// around the airport area. ++// ++// Revision 1.1 1998/09/14 02:14:01 curt ++// Initial revision of genapt.[ch]xx for generating airport scenery. ++// diff --cc Simulator/Airports/genapt.hxx index 000000000,000000000..fa5c0dccf new file mode 100644 --- /dev/null +++ b/Simulator/Airports/genapt.hxx @@@ -1,0 -1,0 +1,77 @@@ ++// ++// getapt.hxx -- generate airport scenery from the given definition file ++// ++// Written by Curtis Olson, started September 1998. ++// ++// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#ifndef _GENAPT_HXX ++#define _GENAPT_HXX ++ ++ ++#ifndef __cplusplus ++# error This library requires C++ ++#endif ++ ++ ++#include ++ ++#include STL_STRING ++#include ++ ++#ifdef __BORLANDC__ ++# define exception c_exception ++#endif ++ ++#include ++ ++FG_USING_STD(string); ++FG_USING_STD(set); ++ ++ ++// maximum size of airport perimeter structure, even for complex ++// airports such as KORD this number is typically not very big. ++#define MAX_PERIMETER 20 ++ ++// name of the material to use for the airport base ++#define APT_BASE_MATERIAL "grass" ++ ++ ++// Load a .apt file and register the GL fragments with the ++// corresponding tile ++int ++fgAptGenerate(const string& path, fgTILE *tile); ++ ++ ++#endif /* _AIRPORTS_HXX */ ++ ++ ++// $Log$ ++// Revision 1.3 1999/03/02 01:02:32 curt ++// Tweaks for building with native SGI compilers. ++// ++// Revision 1.2 1998/11/23 21:48:10 curt ++// Borland portability tweaks. ++// ++// Revision 1.1 1998/09/14 02:14:01 curt ++// Initial revision of genapt.[ch]xx for generating airport scenery. ++// ++// diff --cc Simulator/Airports/simple.cxx index 000000000,000000000..eddc1c4ec new file mode 100644 --- /dev/null +++ b/Simulator/Airports/simple.cxx @@@ -1,0 -1,0 +1,236 @@@ ++// ++// simple.cxx -- a really simplistic class to manage airport ID, ++// lat, lon of the center of one of it's runways, and ++// elevation in feet. ++// ++// Written by Curtis Olson, started April 1998. ++// ++// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#include ++ ++#include ++#include ++#include
++ ++#include STL_STRING ++#include STL_FUNCTIONAL ++#include STL_ALGORITHM ++ ++#include "simple.hxx" ++ ++ ++fgAIRPORTS::fgAIRPORTS() { ++} ++ ++ ++// load the data ++int fgAIRPORTS::load( const string& file ) { ++ fgAIRPORT a; ++ ++ // build the path name to the airport file ++ string path = current_options.get_fg_root() + "/Airports/" + file; ++ ++ airports.erase( airports.begin(), airports.end() ); ++ ++ fg_gzifstream in( path ); ++ if ( !in ) { ++ FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path ); ++ exit(-1); ++ } ++ ++ /* ++ // We can use the STL copy algorithm because the input ++ // file doesn't contain and comments or blank lines. ++ copy( istream_iterator(in.stream()), ++ istream_iterator(), ++ inserter( airports, airports.begin() ) ); ++ */ ++ ++ // read in each line of the file ++ in >> skipcomment; ++ while ( ! in.eof() ) ++ { ++ in >> a; ++ airports.insert(a); ++ in >> skipcomment; ++ } ++ ++ return 1; ++} ++ ++ ++// search for the specified id ++bool ++fgAIRPORTS::search( const string& id, fgAIRPORT* a ) const ++{ ++ const_iterator it = airports.find( fgAIRPORT(id) ); ++ if ( it != airports.end() ) ++ { ++ *a = *it; ++ return true; ++ } ++ else ++ { ++ return false; ++ } ++} ++ ++ ++fgAIRPORT ++fgAIRPORTS::search( const string& id ) const ++{ ++ fgAIRPORT a; ++ this->search( id, &a ); ++ return a; ++} ++ ++ ++// Destructor ++fgAIRPORTS::~fgAIRPORTS( void ) { ++} ++ ++ ++// $Log$ ++// Revision 1.10 1999/02/26 22:08:35 curt ++// Added initial support for native SGI compilers. ++// ++// Revision 1.9 1998/11/06 21:17:34 curt ++// Converted to new logstream debugging facility. This allows release ++// builds with no messages at all (and no performance impact) by using ++// the -DFG_NDEBUG flag. ++// ++// Revision 1.8 1998/11/06 14:47:01 curt ++// Changes to track Bernie's updates to fgstream. ++// ++// Revision 1.7 1998/09/08 21:38:41 curt ++// Changes by Bernie Bright. ++// ++// Revision 1.6 1998/09/03 21:25:02 curt ++// tweaked in data file comment handling. ++// ++// Revision 1.5 1998/09/02 14:35:38 curt ++// Rewrote simple airport loader so it can deal with comments and blank lines. ++// ++// Revision 1.4 1998/09/01 19:02:53 curt ++// Changes contributed by Bernie Bright ++// - The new classes in libmisc.tgz define a stream interface into zlib. ++// I've put these in a new directory, Lib/Misc. Feel free to rename it ++// to something more appropriate. However you'll have to change the ++// include directives in all the other files. Additionally you'll have ++// add the library to Lib/Makefile.am and Simulator/Main/Makefile.am. ++// ++// The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf ++// test so I've included the required changes in config.tgz. ++// ++// There are a fair few changes to Simulator/Objects as I've moved ++// things around. Loading tiles is quicker but thats not where the delay ++// is. Tile loading takes a few tenths of a second per file on a P200 ++// but it seems to be the post-processing that leads to a noticeable ++// blip in framerate. I suppose its time to start profiling to see where ++// the delays are. ++// ++// I've included a brief description of each archives contents. ++// ++// Lib/Misc/ ++// zfstream.cxx ++// zfstream.hxx ++// C++ stream interface into zlib. ++// Taken from zlib-1.1.3/contrib/iostream/. ++// Minor mods for STL compatibility. ++// There's no copyright associated with these so I assume they're ++// covered by zlib's. ++// ++// fgstream.cxx ++// fgstream.hxx ++// FlightGear input stream using gz_ifstream. Tries to open the ++// given filename. If that fails then filename is examined and a ++// ".gz" suffix is removed or appended and that file is opened. ++// ++// stopwatch.hxx ++// A simple timer for benchmarking. Not used in production code. ++// Taken from the Blitz++ project. Covered by GPL. ++// ++// strutils.cxx ++// strutils.hxx ++// Some simple string manipulation routines. ++// ++// Simulator/Airports/ ++// Load airports database using fgstream. ++// Changed fgAIRPORTS to use set<> instead of map<>. ++// Added bool fgAIRPORTS::search() as a neater way doing the lookup. ++// Returns true if found. ++// ++// Simulator/Astro/ ++// Modified fgStarsInit() to load stars database using fgstream. ++// ++// Simulator/Objects/ ++// Modified fgObjLoad() to use fgstream. ++// Modified fgMATERIAL_MGR::load_lib() to use fgstream. ++// Many changes to fgMATERIAL. ++// Some changes to fgFRAGMENT but I forget what! ++// ++// Revision 1.3 1998/08/27 17:01:55 curt ++// Contributions from Bernie Bright ++// - use strings for fg_root and airport_id and added methods to return ++// them as strings, ++// - inlined all access methods, ++// - made the parsing functions private methods, ++// - deleted some unused functions. ++// - propogated some of these changes out a bit further. ++// ++// Revision 1.2 1998/08/25 20:53:24 curt ++// Shuffled $FG_ROOT file layout. ++// ++// Revision 1.1 1998/08/25 17:19:13 curt ++// Moved from ../Main/ ++// ++// Revision 1.8 1998/07/13 21:01:37 curt ++// Wrote access functions for current fgOPTIONS. ++// ++// Revision 1.7 1998/06/03 22:01:07 curt ++// Tweaking sound library usage. ++// ++// Revision 1.6 1998/06/03 00:47:13 curt ++// Updated to compile in audio support if OSS available. ++// Updated for new version of Steve's audio library. ++// STL includes don't use .h ++// Small view optimizations. ++// ++// Revision 1.5 1998/05/29 20:37:22 curt ++// Tweaked material properties & lighting a bit in GLUTmain.cxx. ++// Read airport list into a "map" STL for dynamic list sizing and fast tree ++// based lookups. ++// ++// Revision 1.4 1998/05/13 18:26:25 curt ++// Root path info moved to fgOPTIONS. ++// ++// Revision 1.3 1998/05/06 03:16:24 curt ++// Added an averaged global frame rate counter. ++// Added an option to control tile radius. ++// ++// Revision 1.2 1998/04/28 21:42:50 curt ++// Wrapped zlib calls up so we can conditionally comment out zlib support. ++// ++// Revision 1.1 1998/04/25 15:11:11 curt ++// Added an command line option to set starting position based on airport ID. ++// ++// diff --cc Simulator/Airports/simple.hxx index 000000000,000000000..38e4b8b65 new file mode 100644 --- /dev/null +++ b/Simulator/Airports/simple.hxx @@@ -1,0 -1,0 +1,238 @@@ ++// ++// simple.hxx -- a really simplistic class to manage airport ID, ++// lat, lon of the center of one of it's runways, and ++// elevation in feet. ++// ++// Written by Curtis Olson, started April 1998. ++// ++// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#ifndef _AIRPORTS_HXX ++#define _AIRPORTS_HXX ++ ++ ++#ifndef __cplusplus ++# error This library requires C++ ++#endif ++ ++ ++#include ++#ifdef FG_HAVE_STD_INCLUDES ++# include ++#else ++# include ++#endif ++ ++#include STL_STRING ++#include ++ ++FG_USING_STD(string); ++FG_USING_STD(set); ++FG_USING_STD(istream); ++ ++ ++class fgAIRPORT { ++public: ++ fgAIRPORT( const string& name = "", ++ double lon = 0.0, ++ double lat = 0.0, ++ double ele = 0.0 ) ++ : id(name), longitude(lon), latitude(lat), elevation(ele) {} ++ ++ bool operator < ( const fgAIRPORT& a ) const { ++ return id < a.id; ++ } ++ ++public: ++ string id; ++ double longitude; ++ double latitude; ++ double elevation; ++}; ++ ++inline istream& ++operator >> ( istream& in, fgAIRPORT& a ) ++{ ++ return in >> a.id >> a.longitude >> a.latitude >> a.elevation; ++} ++ ++class fgAIRPORTS { ++public: ++#ifdef FG_NO_DEFAULT_TEMPLATE_ARGS ++ typedef set< fgAIRPORT, less< fgAIRPORT > > container; ++#else ++ typedef set< fgAIRPORT > container; ++#endif ++ typedef container::iterator iterator; ++ typedef container::const_iterator const_iterator; ++ ++private: ++ container airports; ++ ++public: ++ ++ // Constructor ++ fgAIRPORTS(); ++ ++ // Destructor ++ ~fgAIRPORTS(); ++ ++ // load the data ++ int load( const string& file ); ++ ++ // search for the specified id. ++ // Returns true if successful, otherwise returns false. ++ // On success, airport data is returned thru "airport" pointer. ++ // "airport" is not changed if "id" is not found. ++ bool search( const string& id, fgAIRPORT* airport ) const; ++ fgAIRPORT search( const string& id ) const; ++}; ++ ++ ++#endif /* _AIRPORTS_HXX */ ++ ++ ++// $Log$ ++// Revision 1.8 1999/03/15 17:58:57 curt ++// MSVC++ portability tweaks contributed by Bernie Bright. ++// Added using std::istream declaration. ++// ++// Revision 1.7 1999/03/02 01:02:33 curt ++// Tweaks for building with native SGI compilers. ++// ++// Revision 1.6 1999/02/26 22:08:36 curt ++// Added initial support for native SGI compilers. ++// ++// Revision 1.5 1998/11/02 18:25:34 curt ++// Check for __CYGWIN__ (b20) as well as __CYGWIN32__ (pre b20 compilers) ++// Other misc. tweaks. ++// ++// Revision 1.4 1998/09/08 21:38:43 curt ++// Changes by Bernie Bright. ++// ++// Revision 1.3 1998/09/01 19:02:54 curt ++// Changes contributed by Bernie Bright ++// - The new classes in libmisc.tgz define a stream interface into zlib. ++// I've put these in a new directory, Lib/Misc. Feel free to rename it ++// to something more appropriate. However you'll have to change the ++// include directives in all the other files. Additionally you'll have ++// add the library to Lib/Makefile.am and Simulator/Main/Makefile.am. ++// ++// The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf ++// test so I've included the required changes in config.tgz. ++// ++// There are a fair few changes to Simulator/Objects as I've moved ++// things around. Loading tiles is quicker but thats not where the delay ++// is. Tile loading takes a few tenths of a second per file on a P200 ++// but it seems to be the post-processing that leads to a noticeable ++// blip in framerate. I suppose its time to start profiling to see where ++// the delays are. ++// ++// I've included a brief description of each archives contents. ++// ++// Lib/Misc/ ++// zfstream.cxx ++// zfstream.hxx ++// C++ stream interface into zlib. ++// Taken from zlib-1.1.3/contrib/iostream/. ++// Minor mods for STL compatibility. ++// There's no copyright associated with these so I assume they're ++// covered by zlib's. ++// ++// fgstream.cxx ++// fgstream.hxx ++// FlightGear input stream using gz_ifstream. Tries to open the ++// given filename. If that fails then filename is examined and a ++// ".gz" suffix is removed or appended and that file is opened. ++// ++// stopwatch.hxx ++// A simple timer for benchmarking. Not used in production code. ++// Taken from the Blitz++ project. Covered by GPL. ++// ++// strutils.cxx ++// strutils.hxx ++// Some simple string manipulation routines. ++// ++// Simulator/Airports/ ++// Load airports database using fgstream. ++// Changed fgAIRPORTS to use set<> instead of map<>. ++// Added bool fgAIRPORTS::search() as a neater way doing the lookup. ++// Returns true if found. ++// ++// Simulator/Astro/ ++// Modified fgStarsInit() to load stars database using fgstream. ++// ++// Simulator/Objects/ ++// Modified fgObjLoad() to use fgstream. ++// Modified fgMATERIAL_MGR::load_lib() to use fgstream. ++// Many changes to fgMATERIAL. ++// Some changes to fgFRAGMENT but I forget what! ++// ++// Revision 1.2 1998/08/27 17:01:56 curt ++// Contributions from Bernie Bright ++// - use strings for fg_root and airport_id and added methods to return ++// them as strings, ++// - inlined all access methods, ++// - made the parsing functions private methods, ++// - deleted some unused functions. ++// - propogated some of these changes out a bit further. ++// ++// Revision 1.1 1998/08/25 17:19:14 curt ++// Moved from ../Main/ ++// ++// Revision 1.7 1998/07/24 21:39:09 curt ++// Debugging output tweaks. ++// Cast glGetString to (char *) to avoid compiler errors. ++// Optimizations to fgGluLookAt() by Norman Vine. ++// ++// Revision 1.6 1998/07/06 21:34:19 curt ++// Added an enable/disable splash screen option. ++// Added an enable/disable intro music option. ++// Added an enable/disable instrument panel option. ++// Added an enable/disable mouse pointer option. ++// Added using namespace std for compilers that support this. ++// ++// Revision 1.5 1998/06/17 21:35:11 curt ++// Refined conditional audio support compilation. ++// Moved texture parameter setup calls to ../Scenery/materials.cxx ++// #include before various STL includes. ++// Make HUD default state be enabled. ++// ++// Revision 1.4 1998/06/03 00:47:14 curt ++// Updated to compile in audio support if OSS available. ++// Updated for new version of Steve's audio library. ++// STL includes don't use .h ++// Small view optimizations. ++// ++// Revision 1.3 1998/06/01 17:54:42 curt ++// Added Linux audio support. ++// avoid glClear( COLOR_BUFFER_BIT ) when not using it to set the sky color. ++// map stl tweaks. ++// ++// Revision 1.2 1998/05/29 20:37:22 curt ++// Tweaked material properties & lighting a bit in GLUTmain.cxx. ++// Read airport list into a "map" STL for dynamic list sizing and fast tree ++// based lookups. ++// ++// Revision 1.1 1998/04/25 15:11:11 curt ++// Added an command line option to set starting position based on airport ID. ++// ++// diff --cc Simulator/Astro/Makefile.am index 000000000,000000000..3d3af9f39 new file mode 100644 --- /dev/null +++ b/Simulator/Astro/Makefile.am @@@ -1,0 -1,0 +1,19 @@@ ++noinst_LIBRARIES = libAstro.a ++ ++libAstro_a_SOURCES = \ ++ celestialBody.cxx celestialBody.hxx \ ++ jupiter.cxx jupiter.hxx \ ++ mars.cxx mars.hxx \ ++ mercury.cxx mercury.hxx \ ++ moon.cxx moon.hxx \ ++ neptune.cxx neptune.hxx \ ++ pluto.hxx \ ++ saturn.cxx saturn.hxx \ ++ sky.cxx sky.hxx \ ++ solarsystem.cxx solarsystem.hxx \ ++ star.cxx star.hxx \ ++ stars.cxx stars.hxx \ ++ uranus.cxx uranus.hxx \ ++ venus.cxx venus.hxx ++ ++INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator diff --cc Simulator/Astro/celestialBody.cxx index 000000000,000000000..8af66d78b new file mode 100644 --- /dev/null +++ b/Simulator/Astro/celestialBody.cxx @@@ -1,0 -1,0 +1,177 @@@ ++/************************************************************************** ++ * celestialBody.cxx ++ * Written by Durk Talsma. Originally started October 1997, for distribution ++ * with the FlightGear project. Version 2 was written in August and ++ * September 1998. This code is based upon algorithms and data kindly ++ * provided by Mr. Paul Schlyter. (pausch@saaf.se). ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License as ++ * published by the Free Software Foundation; either version 2 of the ++ * License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ * $Id$ ++ * (Log is kept at end of this file) ++ **************************************************************************/ ++ ++#include "celestialBody.hxx" ++#include "star.hxx" ++#include ++ ++#ifdef FG_MATH_EXCEPTION_CLASH ++# define exception c_exception ++#endif ++#include ++ ++/************************************************************************** ++ * void CelestialBody::updatePosition(fgTIME *t, Star *ourSun) ++ * ++ * Basically, this member function provides a general interface for ++ * calculating the right ascension and declinaion. This function is ++ * used for calculating the planetary positions. For the planets, an ++ * overloaded member function is provided to additionally calculate the ++ * planet's magnitude. ++ * The sun and moon have their own overloaded updatePosition member, as their ++ * position is calculated an a slightly different manner. ++ * ++ * arguments: ++ * fgTIME t: provides the current time. ++ * Star *ourSun: the sun's position is needed to convert heliocentric ++ * coordinates into geocentric coordinates. ++ * ++ * return value: none ++ * ++ *************************************************************************/ ++void CelestialBody::updatePosition(fgTIME *t, Star *ourSun) ++{ ++ double eccAnom, v, ecl, actTime, ++ xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze; ++ ++ updateOrbElements(t); ++ actTime = fgCalcActTime(t); ++ ++ // calcualate the angle bewteen ecliptic and equatorial coordinate system ++ ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 *actTime); ++ ++ eccAnom = fgCalcEccAnom(M, e); //calculate the eccentric anomaly ++ xv = a * (cos(eccAnom) - e); ++ yv = a * (sqrt (1.0 - e*e) * sin(eccAnom)); ++ v = atan2(yv, xv); // the planet's true anomaly ++ r = sqrt (xv*xv + yv*yv); // the planet's distance ++ ++ // calculate the planet's position in 3D space ++ xh = r * (cos(N) * cos(v+w) - sin(N) * sin(v+w) * cos(i)); ++ yh = r * (sin(N) * cos(v+w) + cos(N) * sin(v+w) * cos(i)); ++ zh = r * (sin(v+w) * sin(i)); ++ ++ // calculate the ecliptic longitude and latitude ++ xg = xh + ourSun->getxs(); ++ yg = yh + ourSun->getys(); ++ zg = zh; ++ ++ lonEcl = atan2(yh, xh); ++ latEcl = atan2(zh, sqrt(xh*xh+yh*yh)); ++ ++ xe = xg; ++ ye = yg * cos(ecl) - zg * sin(ecl); ++ ze = yg * sin(ecl) + zg * cos(ecl); ++ rightAscension = atan2(ye, xe); ++ declination = atan2(ze, sqrt(xe*xe + ye*ye)); ++ FG_LOG(FG_GENERAL, FG_INFO, "Planet found at : " ++ << rightAscension << " (ra), " << declination << " (dec)" ); ++ ++ //calculate some variables specific to calculating the magnitude ++ //of the planet ++ R = sqrt (xg*xg + yg*yg + zg*zg); ++ s = ourSun->getDistance(); ++ ++ // It is possible from these calculations for the argument to acos ++ // to exceed the valid range for acos(). So we do a little extra ++ // checking. ++ ++ double tmp = (r*r + R*R - s*s) / (2*r*R); ++ if ( tmp > 1.0) { ++ tmp = 1.0; ++ } else if ( tmp < -1.0) { ++ tmp = -1.0; ++ } ++ ++ FV = RAD_TO_DEG * acos( tmp ); ++}; ++ ++/**************************************************************************** ++ * double CelestialBody::fgCalcEccAnom(double M, double e) ++ * this private member calculates the eccentric anomaly of a celestial body, ++ * given its mean anomaly and eccentricity. ++ * ++ * -Mean anomaly: the approximate angle between the perihelion and the current ++ * position. this angle increases uniformly with time. ++ * ++ * True anomaly: the actual angle between perihelion and current position. ++ * ++ * Eccentric anomaly: this is an auxilary angle, used in calculating the true ++ * anomaly from the mean anomaly. ++ * ++ * -eccentricity. Indicates the amount in which the orbit deviates from a ++ * circle (0 = circle, 0-1, is ellipse, 1 = parabola, > 1 = hyperbola). ++ * ++ * This function is also known as solveKeplersEquation() ++ * ++ * arguments: ++ * M: the mean anomaly ++ * e: the eccentricity ++ * ++ * return value: ++ * the eccentric anomaly ++ * ++ ****************************************************************************/ ++double CelestialBody::fgCalcEccAnom(double M, double e) ++{ ++ double ++ eccAnom, E0, E1, diff; ++ ++ eccAnom = M + e * sin(M) * (1.0 + e * cos (M)); ++ // iterate to achieve a greater precision for larger eccentricities ++ if (e > 0.05) ++ { ++ E0 = eccAnom; ++ do ++ { ++ E1 = E0 - (E0 - e * sin(E0) - M) / (1 - e *cos(E0)); ++ diff = fabs(E0 - E1); ++ E0 = E1; ++ } ++ while (diff > (DEG_TO_RAD * 0.001)); ++ return E0; ++ } ++ return eccAnom; ++} ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ diff --cc Simulator/Astro/celestialBody.hxx index 000000000,000000000..946226d2e new file mode 100644 --- /dev/null +++ b/Simulator/Astro/celestialBody.hxx @@@ -1,0 -1,0 +1,196 @@@ ++/************************************************************************** ++ * celestialBody.hxx ++ * Written by Durk Talsma. Originally started October 1997, for distribution ++ * with the FlightGear project. Version 2 was written in August and ++ * September 1998. This code is based upon algorithms and data kindly ++ * provided by Mr. Paul Schlyter. (pausch@saaf.se). ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License as ++ * published by the Free Software Foundation; either version 2 of the ++ * License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ * $Id$ ++ * (Log is kept at end of this file) ++ **************************************************************************/ ++ ++ ++#ifndef _CELESTIALBODY_H_ ++#define _CELESTIALBODY_H_ ++ ++#ifndef __cplusplus ++# error This library requires C++ ++#endif ++ ++ ++#include
++Longitudinal
++  CL0 - Reference lift at zero alpha
++  CD0 - Reference drag at zero alpha
++  CDM - Drag due to Mach
++  CLa - Lift curve slope (w.r.t. alpha)
++  CDa - Drag curve slope (w.r.t. alpha)
++  CLq - Lift due to pitch rate
++  CLM - Lift due to Mach
++  CLadt - Lift due to alpha rate
++
++  Cmadt - Pitching Moment due to alpha rate
++  Cm0 - Reference Pitching moment at zero alpha
++  Cma - Pitching moment slope (w.r.t. alpha)
++  Cmq - Pitch damping (pitch moment due to pitch rate)
++  CmM - Pitch Moment due to Mach
++
++Lateral
++  Cyb - Side force due to sideslip
++  Cyr - Side force due to yaw rate
++
++  Clb - Dihedral effect (roll moment due to sideslip)
++  Clp - Roll damping (roll moment due to roll rate)
++  Clr - Roll moment due to yaw rate
++  Cnb - Weathercocking stability (yaw moment due to sideslip)
++  Cnp - Rudder adverse yaw (yaw moment due to roll rate)
++  Cnr - Yaw damping (yaw moment due to yaw rate)
++
++Control
++  CLDe - Lift due to elevator
++  CDDe - Drag due to elevator
++  CyDr - Side force due to rudder
++  CyDa - Side force due to aileron
++
++  CmDe - Pitch moment due to elevator
++  ClDa - Roll moment due to aileron
++  ClDr - Roll moment due to rudder
++  CnDr - Yaw moment due to rudder
++  CnDa - Yaw moment due to aileron
++
++This class expects to be run in a directory which contains the subdirectory ++structure shown below (where example aircraft X-15 is shown): ++ ++
++aircraft/
++  X-15/
++    X-15.dat reset00 reset01 reset02 ...
++      CDRAG/
++        a0 a M De
++      CSIDE/
++        b r Dr Da
++      CLIFT/
++        a0 a M adt De
++      CROLL/
++        b p r Da Dr
++      CPITCH/
++        a0 a adt q M De
++      CYAW/
++        b p r Dr Da
++  F-16/
++    F-16.dat reset00 reset01 ...
++      CDRAG/
++        a0 a M De
++      ...
++
++ ++The General Idea ++ ++The file structure is arranged so that various modeled aircraft are stored in ++their own subdirectory. Each aircraft subdirectory is named after the aircraft. ++There should be a file present in the specific aircraft subdirectory (e.g. ++aircraft/X-15) with the same name as the directory with a .dat appended. This ++file contains mass properties information, name of aircraft, etc. for the ++aircraft. In that same directory are reset files numbered starting from 0 (two ++digit numbers), e.g. reset03. Within each reset file are values for important ++state variables for specific flight conditions (altitude, airspeed, etc.). Also ++within this directory are the directories containing lookup tables for the ++stability derivatives for the aircraft. ++@author Jon S. Berndt ++@memo Encompasses all aircraft functionality and objects ++@see ++
  • [1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling ++ Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate ++ School, January 1994
  • ++
  • [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices", ++ JSC 12960, July 1977
  • ++
  • [3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at ++ NASA-Ames", NASA CR-2497, January 1975
  • ++
  • [4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics", ++ Wiley & Sons, 1979 ISBN 0-471-03032-5
  • ++
  • [5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons, ++ 1982 ISBN 0-471-08936-2
  • ++
    ++*/ ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#include "FGModel.h" ++#include "FGCoefficient.h" ++#include "FGEngine.h" ++#include "FGTank.h" ++ ++/******************************************************************************* ++DEFINITIONS ++*******************************************************************************/ ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGAircraft : public FGModel ++{ ++public: ++ // *************************************************************************** ++ /** @memo Constructor ++ @param FGFDMExec* - a pointer to the "owning" FDM Executive ++ */ ++ FGAircraft(FGFDMExec*); ++ ++ // *************************************************************************** ++ /** Destructor */ ++ ~FGAircraft(void); ++ ++ // *************************************************************************** ++ /** This must be called for each dt to execute the model algorithm */ ++ bool Run(void); ++ ++ // *************************************************************************** ++ /** This function must be called with the name of an aircraft which ++ has an associated .dat file in the appropriate subdirectory. The paths ++ to the appropriate subdirectories are given as the first two parameters. ++ @memo Loads the given aircraft. ++ @param string Path to the aircraft files ++ @param string Path to the engine files ++ @param string The name of the aircraft to be loaded, e.g. "X15". ++ @return True - if successful ++ */ ++ bool LoadAircraft(string, string, string); ++ ++ // *************************************************************************** ++ /** @memo Gets the aircraft name as defined in the aircraft config file. ++ @param ++ @return string Aircraft name. ++ */ ++ inline string GetAircraftName(void) {return AircraftName;} ++ ++ // *************************************************************************** ++ /** @memo Sets the GearUp flag ++ @param boolean true or false ++ @return ++ */ ++ inline void SetGearUp(bool tt) {GearUp = tt;} ++ ++ // *************************************************************************** ++ /** @memo Returns the state of the GearUp flag ++ @param ++ @return boolean true or false ++ */ ++ inline bool GetGearUp(void) {return GearUp;} ++ ++ // *************************************************************************** ++ /** @memo Returns the area of the wing ++ @param ++ @return float wing area S, in square feet ++ */ ++ inline float GetWingArea(void) {return WingArea;} ++ ++ // *************************************************************************** ++ /** @memo Returns the wing span ++ @param ++ @return float wing span in feet ++ */ ++ inline float GetWingSpan(void) {return WingSpan;} ++ ++ // *************************************************************************** ++ /** @memo Returns the average wing chord ++ @param ++ @return float wing chord in feet ++ */ ++ inline float Getcbar(void) {return cbar;} ++ ++ // *************************************************************************** ++ /** @memo Returns an engine object ++ @param int The engine number ++ @return FGEengine* The pointer to the requested engine object. ++ */ ++ inline FGEngine* GetEngine(int tt) {return Engine[tt];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline FGTank* GetTank(int tt) {return Tank[tt];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetWeight(void) {return Weight;} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetMass(void) {return Mass;} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetL(void) {return Moments[0];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetM(void) {return Moments[1];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetN(void) {return Moments[2];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetFx(void) {return Forces[0];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetFy(void) {return Forces[1];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetFz(void) {return Forces[2];} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetIxx(void) {return Ixx;} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetIyy(void) {return Iyy;} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetIzz(void) {return Izz;} ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ inline float GetIxz(void) {return Ixz;} ++ ++private: ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void GetState(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void PutState(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void FAero(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void FGear(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void FMass(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void FProp(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void MAero(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void MGear(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void MMass(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void MProp(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ void MassChange(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ float Moments[3]; ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ float Forces[3]; ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ string AircraftName; ++ ++ // *************************************************************************** ++ /// ++ float Ixx, Iyy, Izz, Ixz, EmptyMass, Mass; ++ /// ++ float Xcg, Ycg, Zcg; ++ /// ++ float Xep, Yep, Zep; ++ /// ++ float rho, qbar, Vt; ++ /// ++ float alpha, beta; ++ /// ++ float WingArea, WingSpan, cbar; ++ /// ++ float phi, tht, psi; ++ /// ++ float Weight, EmptyWeight; ++ /// ++ float dt; ++ ++ /// ++ int numTanks; ++ /// ++ int numEngines; ++ /// ++ int numSelectedOxiTanks; ++ /// ++ int numSelectedFuelTanks; ++ /// ++ FGTank* Tank[MAX_TANKS]; ++ /// ++ FGEngine *Engine[MAX_ENGINES]; ++ ++ /// ++ FGCoefficient *Coeff[6][10]; ++ /// ++ int coeff_ctr[6]; ++ ++ /// ++ bool GearUp; ++ ++ /// ++ enum Param {LiftCoeff, ++ DragCoeff, ++ SideCoeff, ++ RollCoeff, ++ PitchCoeff, ++ YawCoeff, ++ numCoeffs}; ++ ++ /// ++ string Axis[6]; ++ ++protected: ++ ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGAtmosphere.cpp index 000000000,000000000..a066b3046 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGAtmosphere.cpp @@@ -1,0 -1,0 +1,78 @@@ ++/******************************************************************************* ++ ++ Module: FGAtmosphere.cpp ++ Author: Jon Berndt ++ Date started: 11/24/98 ++ Purpose: Models the atmosphere ++ Called by: FGSimExec ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++Models the atmosphere. The equation used below was determined by a third order ++curve fit using Excel. The data is from the ICAO atmosphere model. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/24/98 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGAtmosphere.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex) ++{ ++ Name = "FGAtmosphere"; ++} ++ ++ ++FGAtmosphere::~FGAtmosphere() ++{ ++} ++ ++ ++bool FGAtmosphere::Run(void) ++{ ++ if (!FGModel::Run()) { // if false then execute this Run() ++ rho = 0.002377 - 7.0E-08*State->Geth() ++ + 7.0E-13*State->Geth()*State->Geth() ++ - 2.0E-18*State->Geth()*State->Geth()*State->Geth(); ++ ++ State->SetMach(State->GetVt()/State->Geta()); ++ } else { // skip Run() execution this time ++ } ++ return false; ++} diff --cc Simulator/JSBsim/FGAtmosphere.h index 000000000,000000000..9993d2520 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGAtmosphere.h @@@ -1,0 -1,0 +1,87 @@@ ++/******************************************************************************* ++ ++ Header: FGAtmosphere.h ++ Author: Jon Berndt ++ Date started: 11/24/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/24/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGATMOSPHERE_H ++#define FGATMOSPHERE_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGModel.h" ++ ++/******************************************************************************* ++COMMENTS, REFERENCES, and NOTES ++*******************************************************************************/ ++/** ++The equation used in this model was determined by a third order curve fit using ++Excel. The data is from the ICAO atmosphere model. ++@memo Models the atmosphere. ++@author Jon S. Berndt ++*/ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGAtmosphere : public FGModel ++{ ++public: ++ // *************************************************************************** ++ /** @memo Constructor ++ @param FGFDMExec* - a pointer to the "owning" FDM Executive ++ */ ++ FGAtmosphere(FGFDMExec*); ++ ++ // *************************************************************************** ++ /** @memo Destructor ++ */ ++ ~FGAtmosphere(void); ++ ++ // *************************************************************************** ++ /** This must be called for each dt to execute the model algorithm */ ++ bool Run(void); ++ ++ // *************************************************************************** ++ /** @memo Returns the air density ++ @return float air density in slugs/cubic foot ++ */ ++ inline float Getrho(void) {return rho;} ++ ++protected: ++ ++private: ++ float rho; ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGAuxiliary.cpp index 000000000,000000000..232e05f09 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGAuxiliary.cpp @@@ -1,0 -1,0 +1,75 @@@ ++/******************************************************************************* ++ ++ Module: FGAuxiliary.cpp ++ Author: Jon Berndt ++ Date started: 01/26/99 ++ Purpose: Calculates additional parameters needed by the visual system, etc. ++ Called by: FGSimExec ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This class calculates various auxiliary parameters, mostly used by the visual ++system ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/26/99 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGAuxiliary.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGAtmosphere.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGPosition.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex) ++{ ++ Name = "FGAuxiliary"; ++} ++ ++ ++FGAuxiliary::~FGAuxiliary() ++{ ++} ++ ++ ++bool FGAuxiliary::Run() ++{ ++ if (!FGModel::Run()) { ++ } else { ++ } ++ return false; ++} ++ ++ diff --cc Simulator/JSBsim/FGAuxiliary.h index 000000000,000000000..9a369cb74 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGAuxiliary.h @@@ -1,0 -1,0 +1,65 @@@ ++/******************************************************************************* ++ ++ Header: FGAuxiliary.h ++ Author: Jon Berndt ++ Date started: 01/26/99 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/22/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGAUXILIARY_H ++#define FGAUXILIARY_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++#include "FGModel.h" ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGAuxiliary : public FGModel ++{ ++public: ++ FGAuxiliary(FGFDMExec*); ++ ~FGAuxiliary(void); ++ ++ bool Run(void); ++ ++protected: ++ ++private: ++ ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGCoefficient.cpp index 000000000,000000000..89c1ca1ef new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGCoefficient.cpp @@@ -1,0 -1,0 +1,457 @@@ ++/******************************************************************************* ++ ++ Module: FGCoefficient.cpp ++ Author: Jon S. Berndt ++ Date started: 12/28/98 ++ Purpose: Encapsulates the stability derivative class FGCoefficient; ++ Called by: FGAircraft ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This class models the stability derivative coefficient lookup tables or ++equations. Note that the coefficients need not be calculated each delta-t. ++ ++The coefficient files are located in the axis subdirectory for each aircraft. ++For instance, for the X-15, you would find subdirectories under the ++aircraft/X-15/ directory named CLIFT, CDRAG, CSIDE, CROLL, CPITCH, CYAW. Under ++each of these directories would be files named a, a0, q, and so on. The file ++named "a" under the CLIFT directory would contain data for the stability ++derivative modeling lift due to a change in alpha. See the FGAircraft.cpp file ++for additional information. The coefficient files have the following format: ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++<... repeat above for each column of data in table ...> ++ ++As an example for the X-15, for the lift due to mach: ++ ++CLa0 ++Lift_at_zero_alpha ++Table 8 3 ++16384 ++32768 ++16387 ++ ++0.00 ++0.0 0.0 ++0.5 0.4 ++0.9 0.9 ++1.0 1.6 ++1.1 1.3 ++1.4 1.0 ++2.0 0.5 ++3.0 0.5 ++ ++30000.00 ++0.0 0.0 ++0.5 0.5 ++0.9 1.0 ++1.0 1.7 ++1.1 1.4 ++1.4 1.1 ++2.0 0.6 ++3.0 0.6 ++ ++70000.00 ++0.0 0.0 ++0.5 0.6 ++0.9 1.1 ++1.0 1.7 ++1.1 1.5 ++1.4 1.2 ++2.0 0.7 ++3.0 0.7 ++ ++Note that the values in a row which index into the table must be the same value ++for each column of data, so the first column of numbers for each altitude are ++seen to be equal, and there are the same number of values for each altitude. ++ ++See the header file FGCoefficient.h for the values of the identifiers. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/28/98 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGCoefficient.h" ++#include "FGAtmosphere.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++FGCoefficient::FGCoefficient(FGFDMExec* fdex) ++{ ++ FDMExec = fdex; ++ State = FDMExec->GetState(); ++ Atmosphere = FDMExec->GetAtmosphere(); ++ FCS = FDMExec->GetFCS(); ++ Aircraft = FDMExec->GetAircraft(); ++ Translation = FDMExec->GetTranslation(); ++ Rotation = FDMExec->GetRotation(); ++ Position = FDMExec->GetPosition(); ++ Auxiliary = FDMExec->GetAuxiliary(); ++ Output = FDMExec->GetOutput(); ++ ++ rows = columns = 0; ++} ++ ++ ++FGCoefficient::FGCoefficient(FGFDMExec* fdex, string fname) ++{ ++ int r, c; ++ float ftrashcan; ++ ++ FDMExec = fdex; ++ State = FDMExec->GetState(); ++ Atmosphere = FDMExec->GetAtmosphere(); ++ FCS = FDMExec->GetFCS(); ++ Aircraft = FDMExec->GetAircraft(); ++ Translation = FDMExec->GetTranslation(); ++ Rotation = FDMExec->GetRotation(); ++ Position = FDMExec->GetPosition(); ++ Auxiliary = FDMExec->GetAuxiliary(); ++ Output = FDMExec->GetOutput(); ++ ++ ifstream coeffDefFile(fname.c_str()); ++ ++ if (coeffDefFile) { ++ if (!coeffDefFile.fail()) { ++ coeffDefFile >> name; ++ coeffDefFile >> description; ++ coeffDefFile >> method; ++ ++ if (method == "EQUATION") type = EQUATION; ++ else if (method == "TABLE") type = TABLE; ++ else if (method == "VECTOR") type = VECTOR; ++ else if (method == "VALUE") type = VALUE; ++ else type = UNKNOWN; ++ ++ if (type == VECTOR || type == TABLE) { ++ coeffDefFile >> rows; ++ if (type == TABLE) { ++ coeffDefFile >> columns; ++ } ++ coeffDefFile >> LookupR; ++ } ++ ++ if (type == TABLE) { ++ coeffDefFile >> LookupC; ++ } ++ ++ coeffDefFile >> multipliers; ++ ++ mult_count = 0; ++ if (multipliers & FG_QBAR) { ++ mult_idx[mult_count] = FG_QBAR; ++ mult_count++; ++ } ++ if (multipliers & FG_WINGAREA) { ++ mult_idx[mult_count] = FG_WINGAREA; ++ mult_count++; ++ } ++ if (multipliers & FG_WINGSPAN) { ++ mult_idx[mult_count] = FG_WINGSPAN; ++ mult_count++; ++ } ++ if (multipliers & FG_CBAR) { ++ mult_idx[mult_count] = FG_CBAR; ++ mult_count++; ++ } ++ if (multipliers & FG_ALPHA) { ++ mult_idx[mult_count] = FG_ALPHA; ++ mult_count++; ++ } ++ if (multipliers & FG_ALPHADOT) { ++ mult_idx[mult_count] = FG_ALPHADOT; ++ mult_count++; ++ } ++ if (multipliers & FG_BETA) { ++ mult_idx[mult_count] = FG_BETA; ++ mult_count++; ++ } ++ if (multipliers & FG_BETADOT) { ++ mult_idx[mult_count] = FG_BETADOT; ++ mult_count++; ++ } ++ if (multipliers & FG_PITCHRATE) { ++ mult_idx[mult_count] = FG_PITCHRATE; ++ mult_count++; ++ } ++ if (multipliers & FG_ROLLRATE) { ++ mult_idx[mult_count] = FG_ROLLRATE; ++ mult_count++; ++ } ++ if (multipliers & FG_YAWRATE) { ++ mult_idx[mult_count] = FG_YAWRATE; ++ mult_count++; ++ } ++ if (multipliers & FG_ELEVATOR) { ++ mult_idx[mult_count] = FG_ELEVATOR; ++ mult_count++; ++ } ++ if (multipliers & FG_AILERON) { ++ mult_idx[mult_count] = FG_AILERON; ++ mult_count++; ++ } ++ if (multipliers & FG_RUDDER) { ++ mult_idx[mult_count] = FG_RUDDER; ++ mult_count++; ++ } ++ if (multipliers & FG_MACH) { ++ mult_idx[mult_count] = FG_MACH; ++ mult_count++; ++ } ++ if (multipliers & FG_ALTITUDE) { ++ mult_idx[mult_count] = FG_ALTITUDE; ++ mult_count++; ++ } ++ ++ switch(type) { ++ case VALUE: ++ coeffDefFile >> StaticValue; ++ break; ++ case VECTOR: ++ Allocate(rows,2); ++ ++ for (r=1;r<=rows;r++) { ++ coeffDefFile >> Table3D[r][0]; ++ coeffDefFile >> Table3D[r][1]; ++ } ++ break; ++ case TABLE: ++ Allocate(rows, columns); ++ ++ for (c=1;c<=columns;c++) { ++ coeffDefFile >> Table3D[0][c]; ++ for (r=1;r<=rows;r++) { ++ if ( c==1 ) coeffDefFile >> Table3D[r][0]; ++ else coeffDefFile >> ftrashcan; ++ coeffDefFile >> Table3D[r][c]; ++ } ++ } ++ break; ++ } ++ } else { ++ cerr << "Empty file" << endl; ++ } ++ coeffDefFile.close(); ++ } ++} ++ ++ ++FGCoefficient::FGCoefficient(FGFDMExec* fdex, int r, int c) ++{ ++ FDMExec = fdex; ++ State = FDMExec->GetState(); ++ Atmosphere = FDMExec->GetAtmosphere(); ++ FCS = FDMExec->GetFCS(); ++ Aircraft = FDMExec->GetAircraft(); ++ Translation = FDMExec->GetTranslation(); ++ Rotation = FDMExec->GetRotation(); ++ Position = FDMExec->GetPosition(); ++ Auxiliary = FDMExec->GetAuxiliary(); ++ Output = FDMExec->GetOutput(); ++ ++ rows = r; ++ columns = c; ++ Allocate(r,c); ++} ++ ++ ++FGCoefficient::FGCoefficient(FGFDMExec* fdex, int n) ++{ ++ FDMExec = fdex; ++ State = FDMExec->GetState(); ++ Atmosphere = FDMExec->GetAtmosphere(); ++ FCS = FDMExec->GetFCS(); ++ Aircraft = FDMExec->GetAircraft(); ++ Translation = FDMExec->GetTranslation(); ++ Rotation = FDMExec->GetRotation(); ++ Position = FDMExec->GetPosition(); ++ Auxiliary = FDMExec->GetAuxiliary(); ++ Output = FDMExec->GetOutput(); ++ ++ rows = n; ++ columns = 0; ++ Allocate(n); ++} ++ ++ ++FGCoefficient::~FGCoefficient(void) ++{ ++} ++ ++ ++bool FGCoefficient::Allocate(int r, int c) ++{ ++ rows = r; ++ columns = c; ++ Table3D = new float*[r+1]; ++ for (int i=0;i<=r;i++) Table3D[i] = new float[c+1]; ++ return true; ++} ++ ++ ++bool FGCoefficient::Allocate(int n) ++{ ++ rows = n; ++ columns = 0; ++ Table2D = new float[n+1]; ++ return true; ++} ++ ++ ++float FGCoefficient::Value(float rVal, float cVal) ++{ ++ float rFactor, cFactor, col1temp, col2temp, Value; ++ int r, c, midx; ++ ++ if (rows < 2 || columns < 2) return 0.0; ++ ++ for (r=1;r<=rows;r++) if (Table3D[r][0] >= rVal) break; ++ for (c=1;c<=columns;c++) if (Table3D[0][c] >= cVal) break; ++ ++ c = c < 2 ? 2 : (c > columns ? columns : c); ++ r = r < 2 ? 2 : (r > rows ? rows : r); ++ ++ rFactor = (rVal - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]); ++ cFactor = (cVal - Table3D[0][c-1]) / (Table3D[0][c] - Table3D[0][c-1]); ++ ++ col1temp = rFactor*(Table3D[r][c-1] - Table3D[r-1][c-1]) + Table3D[r-1][c-1]; ++ col2temp = rFactor*(Table3D[r][c] - Table3D[r-1][c]) + Table3D[r-1][c]; ++ ++ Value = col1temp + cFactor*(col2temp - col1temp); ++ ++ for (midx=0;midx= Val) break; ++ r = r < 2 ? 2 : (r > rows ? rows : r); ++ ++ // make sure denominator below does not go to zero. ++ if (Table3D[r][0] != Table3D[r-1][0]) { ++ Factor = (Val - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]); ++ } else { ++ Factor = 1.0; ++ } ++ Value = Factor*(Table3D[r][1] - Table3D[r-1][1]) + Table3D[r-1][1]; ++ ++ for (midx=0;midxGetqbar(); ++ case FG_WINGAREA: ++ return Aircraft->GetWingArea(); ++ case FG_WINGSPAN: ++ return Aircraft->GetWingSpan(); ++ case FG_CBAR: ++ return Aircraft->Getcbar(); ++ case FG_ALPHA: ++ return Translation->Getalpha(); ++ case FG_ALPHADOT: ++ return State->Getadot(); ++ case FG_BETA: ++ return Translation->Getbeta(); ++ case FG_BETADOT: ++ return State->Getbdot(); ++ case FG_PITCHRATE: ++ return Rotation->GetQ(); ++ case FG_ROLLRATE: ++ return Rotation->GetP(); ++ case FG_YAWRATE: ++ return Rotation->GetR(); ++ case FG_ELEVATOR: ++ return FCS->GetDe(); ++ case FG_AILERON: ++ return FCS->GetDa(); ++ case FG_RUDDER: ++ return FCS->GetDr(); ++ case FG_MACH: ++ return State->GetMach(); ++ case FG_ALTITUDE: ++ return State->Geth(); ++ } ++ return 0; ++} diff --cc Simulator/JSBsim/FGCoefficient.h index 000000000,000000000..918e4c201 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGCoefficient.h @@@ -1,0 -1,0 +1,300 @@@ ++/******************************************************************************* ++ ++ Header: FGCoefficient.h ++ Author: Jon Berndt ++ Date started: 12/28/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/28/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGCOEFFICIENT_H ++#define FGCOEFFICIENT_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++#ifdef FGFS ++# include ++# include STL_STRING ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++ FG_USING_STD(string); ++#else ++# include ++# include ++#endif ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++#define FG_QBAR 1 ++#define FG_WINGAREA 2 ++#define FG_WINGSPAN 4 ++#define FG_CBAR 8 ++#define FG_ALPHA 16 ++#define FG_ALPHADOT 32 ++#define FG_BETA 64 ++#define FG_BETADOT 128 ++#define FG_PITCHRATE 256 ++#define FG_ROLLRATE 512 ++#define FG_YAWRATE 1024 ++#define FG_ELEVATOR 2048 ++#define FG_AILERON 4096 ++#define FG_RUDDER 8192 ++#define FG_MACH 16384 ++#define FG_ALTITUDE 32768L ++ ++/******************************************************************************* ++FORWARD DECLARATIONS ++*******************************************************************************/ ++class FGFDMExec; ++class FGState; ++class FGAtmosphere; ++class FGFCS; ++class FGAircraft; ++class FGTranslation; ++class FGRotation; ++class FGPosition; ++class FGAuxiliary; ++class FGOutput; ++ ++/******************************************************************************* ++COMMENTS, REFERENCES, and NOTES ++*******************************************************************************/ ++/** ++This class models the stability derivative coefficient lookup tables or ++equations. Note that the coefficients need not be calculated each delta-t. ++ ++The coefficient files are located in the axis subdirectory for each aircraft. ++For instance, for the X-15, you would find subdirectories under the ++aircraft/X-15/ directory named CLIFT, CDRAG, CSIDE, CROLL, CPITCH, CYAW. Under ++each of these directories would be files named a, a0, q, and so on. The file ++named "a" under the CLIFT directory would contain data for the stability ++derivative modeling lift due to a change in alpha. See the FGAircraft.cpp file ++for additional information. The coefficient files have the following format: ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++<... repeat above for each column of data in table ...> ++ ++As an example for the X-15, for the lift due to mach: ++
    ++
    ++CLa0
    ++Lift_at_zero_alpha
    ++Table 8 3
    ++16384
    ++32768
    ++16387
    ++
    ++0.00
    ++0.0 0.0
    ++0.5 0.4
    ++0.9 0.9
    ++1.0 1.6
    ++1.1 1.3
    ++1.4 1.0
    ++2.0 0.5
    ++3.0 0.5
    ++
    ++30000.00
    ++0.0 0.0
    ++0.5 0.5
    ++0.9 1.0
    ++1.0 1.7
    ++1.1 1.4
    ++1.4 1.1
    ++2.0 0.6
    ++3.0 0.6
    ++
    ++70000.00
    ++0.0 0.0
    ++0.5 0.6
    ++0.9 1.1
    ++1.0 1.7
    ++1.1 1.5
    ++1.4 1.2
    ++2.0 0.7
    ++3.0 0.7
    ++
    ++ ++Note that the values in a row which index into the table must be the same value ++for each column of data, so the first column of numbers for each altitude are ++seen to be equal, and there are the same number of values for each altitude. ++ ++
    ++FG_QBAR         1
    ++FG_WINGAREA     2
    ++FG_WINGSPAN     4
    ++FG_CBAR         8
    ++FG_ALPHA       16
    ++FG_ALPHADOT    32
    ++FG_BETA        64
    ++FG_BETADOT    128
    ++FG_PITCHRATE  256
    ++FG_ROLLRATE   512
    ++FG_YAWRATE   1024
    ++FG_ELEVATOR  2048
    ++FG_AILERON   4096
    ++FG_RUDDER    8192
    ++FG_MACH     16384
    ++FG_ALTITUDE 32768L
    ++
    ++@author Jon S. Berndt ++@memo This class models the stability derivative coefficient lookup tables or equations. ++*/ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGCoefficient ++{ ++public: ++ // *************************************************************************** ++ /** @memo Constructor ++ @param FGFDMExec* - pointer to owning simulation executive ++ */ ++ FGCoefficient(FGFDMExec*); ++ ++ // *************************************************************************** ++ /** @memo Constructor for two independent variable table ++ @param ++ @return ++ */ ++ FGCoefficient(FGFDMExec*, int, int); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ FGCoefficient(FGFDMExec*, int); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ FGCoefficient(FGFDMExec*, string); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ ~FGCoefficient(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ bool Allocate(int); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ bool Allocate(int, int); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ float Value(float, float); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ float Value(float); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ float Value(void); ++ ++ // *************************************************************************** ++ /** @memo ++ @param ++ @return ++ */ ++ enum Type {UNKNOWN, VALUE, VECTOR, TABLE, EQUATION}; ++ ++protected: ++ ++private: ++ string filename; ++ string description; ++ string name; ++ string method; ++ float StaticValue; ++ float *Table2D; ++ float **Table3D; ++ float LookupR, LookupC; ++ long int mult_idx[10]; ++ int rows, columns; ++ Type type; ++ int multipliers; ++ int mult_count; ++ ++ float GetCoeffVal(int); ++ ++ FGFDMExec* FDMExec; ++ FGState* State; ++ FGAtmosphere* Atmosphere; ++ FGFCS* FCS; ++ FGAircraft* Aircraft; ++ FGTranslation* Translation; ++ FGRotation* Rotation; ++ FGPosition* Position; ++ FGAuxiliary* Auxiliary; ++ FGOutput* Output; ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGControls.cpp index 000000000,000000000..e79535986 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGControls.cpp @@@ -1,0 -1,0 +1,97 @@@ ++// controls.cxx -- defines a standard interface to all flight sim controls ++// ++// Written by Curtis Olson, started May 1997. ++// ++// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#include "controls.hxx" ++ ++ ++FGControls controls; ++ ++ ++// Constructor ++FGControls::FGControls() : ++ aileron( 0.0 ), ++ elevator( 0.0 ), ++ elevator_trim( 1.969572E-03 ), ++ rudder( 0.0 ) ++{ ++ for ( int engine = 0; engine < MAX_ENGINES; engine++ ) { ++ throttle[engine] = 0.0; ++ } ++ ++ for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) { ++ brake[wheel] = 0.0; ++ } ++} ++ ++ ++// Destructor ++FGControls::~FGControls() { ++} ++ ++ ++// $Log$ ++// Revision 1.1 1999/02/13 01:12:03 curt ++// Initial Revision. ++// ++// Revision 1.1 1999/02/09 04:51:32 jon ++// Initial revision ++// ++// Revision 1.3 1998/12/05 16:13:12 curt ++// Renamed class fgCONTROLS to class FGControls. ++// ++// Revision 1.2 1998/10/25 14:08:41 curt ++// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. ++// ++// Revision 1.1 1998/10/18 01:51:05 curt ++// c++-ifying ... ++// ++// Revision 1.8 1998/09/29 02:01:31 curt ++// Added a brake. ++// ++// Revision 1.7 1998/02/07 15:29:36 curt ++// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss ++// ++// ++// Revision 1.6 1998/01/19 19:27:02 curt ++// Merged in make system changes from Bob Kuehne ++// This should simplify things tremendously. ++// ++// Revision 1.5 1998/01/19 18:40:22 curt ++// Tons of little changes to clean up the code and to remove fatal errors ++// when building with the c++ compiler. ++// ++// Revision 1.4 1997/12/10 22:37:41 curt ++// Prepended "fg" on the name of all global structures that didn't have it yet. ++// i.e. "struct WEATHER {}" became "struct fgWEATHER {}" ++// ++// Revision 1.3 1997/08/27 03:30:01 curt ++// Changed naming scheme of basic shared structures. ++// ++// Revision 1.2 1997/06/21 17:12:48 curt ++// Capitalized subdirectory names. ++// ++// Revision 1.1 1997/05/31 19:24:04 curt ++// Initial revision. ++// ++ diff --cc Simulator/JSBsim/FGControls.h index 000000000,000000000..e347b6b2b new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGControls.h @@@ -1,0 -1,0 +1,246 @@@ ++// controls.hxx -- defines a standard interface to all flight sim controls ++// ++// Written by Curtis Olson, started May 1997. ++// ++// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#ifndef _CONTROLS_HXX ++#define _CONTROLS_HXX ++ ++ ++#ifndef __cplusplus ++# error This library requires C++ ++#endif ++ ++ ++// Define a structure containing the control parameters ++ ++class FGControls { ++ ++public: ++ ++ static const int ALL_ENGINES = -1; ++ static const int MAX_ENGINES = 10; ++ ++ static const int ALL_WHEELS = -1; ++ static const int MAX_WHEELS = 3; ++ ++private: ++ ++ double aileron; ++ double elevator; ++ double elevator_trim; ++ double rudder; ++ double throttle[MAX_ENGINES]; ++ double brake[MAX_WHEELS]; ++ ++public: ++ ++ FGControls(); ++ ~FGControls(); ++ ++ // Query functions ++ inline double get_aileron() const { return aileron; } ++ inline double get_elevator() const { return elevator; } ++ inline double get_elevator_trim() const { return elevator_trim; } ++ inline double get_rudder() const { return rudder; } ++ inline double get_throttle(int engine) const { return throttle[engine]; } ++ inline double get_brake(int wheel) const { return brake[wheel]; } ++ ++ // Update functions ++ inline void set_aileron( double pos ) { ++ aileron = pos; ++ if ( aileron < -1.0 ) aileron = -1.0; ++ if ( aileron > 1.0 ) aileron = 1.0; ++ } ++ inline void move_aileron( double amt ) { ++ aileron += amt; ++ if ( aileron < -1.0 ) aileron = -1.0; ++ if ( aileron > 1.0 ) aileron = 1.0; ++ } ++ inline void set_elevator( double pos ) { ++ elevator = pos; ++ if ( elevator < -1.0 ) elevator = -1.0; ++ if ( elevator > 1.0 ) elevator = 1.0; ++ } ++ inline void move_elevator( double amt ) { ++ elevator += amt; ++ if ( elevator < -1.0 ) elevator = -1.0; ++ if ( elevator > 1.0 ) elevator = 1.0; ++ } ++ inline void set_elevator_trim( double pos ) { ++ elevator_trim = pos; ++ if ( elevator_trim < -1.0 ) elevator_trim = -1.0; ++ if ( elevator_trim > 1.0 ) elevator_trim = 1.0; ++ } ++ inline void move_elevator_trim( double amt ) { ++ elevator_trim += amt; ++ if ( elevator_trim < -1.0 ) elevator_trim = -1.0; ++ if ( elevator_trim > 1.0 ) elevator_trim = 1.0; ++ } ++ inline void set_rudder( double pos ) { ++ rudder = pos; ++ if ( rudder < -1.0 ) rudder = -1.0; ++ if ( rudder > 1.0 ) rudder = 1.0; ++ } ++ inline void move_rudder( double amt ) { ++ rudder += amt; ++ if ( rudder < -1.0 ) rudder = -1.0; ++ if ( rudder > 1.0 ) rudder = 1.0; ++ } ++ inline void set_throttle( int engine, double pos ) { ++ if ( engine == ALL_ENGINES ) { ++ for ( int i = 0; i < MAX_ENGINES; i++ ) { ++ throttle[i] = pos; ++ if ( throttle[i] < 0.0 ) throttle[i] = 0.0; ++ if ( throttle[i] > 1.0 ) throttle[i] = 1.0; ++ } ++ } else { ++ if ( (engine >= 0) && (engine < MAX_ENGINES) ) { ++ throttle[engine] = pos; ++ if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0; ++ if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0; ++ } ++ } ++ } ++ inline void move_throttle( int engine, double amt ) { ++ if ( engine == ALL_ENGINES ) { ++ for ( int i = 0; i < MAX_ENGINES; i++ ) { ++ throttle[i] += amt; ++ if ( throttle[i] < 0.0 ) throttle[i] = 0.0; ++ if ( throttle[i] > 1.0 ) throttle[i] = 1.0; ++ } ++ } else { ++ if ( (engine >= 0) && (engine < MAX_ENGINES) ) { ++ throttle[engine] += amt; ++ if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0; ++ if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0; ++ } ++ } ++ } ++ inline void set_brake( int wheel, double pos ) { ++ if ( wheel == ALL_WHEELS ) { ++ for ( int i = 0; i < MAX_WHEELS; i++ ) { ++ brake[i] = pos; ++ if ( brake[i] < 0.0 ) brake[i] = 0.0; ++ if ( brake[i] > 1.0 ) brake[i] = 1.0; ++ } ++ } else { ++ if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { ++ brake[wheel] = pos; ++ if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0; ++ if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0; ++ } ++ } ++ } ++ inline void move_brake( int wheel, double amt ) { ++ if ( wheel == ALL_WHEELS ) { ++ for ( int i = 0; i < MAX_WHEELS; i++ ) { ++ brake[i] += amt; ++ if ( brake[i] < 0.0 ) brake[i] = 0.0; ++ if ( brake[i] > 1.0 ) brake[i] = 1.0; ++ } ++ } else { ++ if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { ++ brake[wheel] += amt; ++ if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0; ++ if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0; ++ } ++ } ++ } ++}; ++ ++ ++extern FGControls controls; ++ ++ ++#endif // _CONTROLS_HXX ++ ++ ++// $Log$ ++// Revision 1.1 1999/02/13 01:12:03 curt ++// Initial Revision. ++// ++// Revision 1.3 1998/12/05 16:13:13 curt ++// Renamed class fgCONTROLS to class FGControls. ++// ++// Revision 1.2 1998/10/25 14:08:42 curt ++// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. ++// ++// Revision 1.1 1998/10/18 01:51:07 curt ++// c++-ifying ... ++// ++// Revision 1.17 1998/09/29 14:57:00 curt ++// c++-ified some comments. ++// ++// Revision 1.16 1998/09/29 02:01:32 curt ++// Added a brake. ++// ++// Revision 1.15 1998/04/25 22:06:27 curt ++// Edited cvs log messages in source files ... bad bad bad! ++// ++// Revision 1.14 1998/04/22 13:26:19 curt ++// C++ - ifing the code a bit. ++// ++// Revision 1.13 1998/04/21 17:02:35 curt ++// Prepairing for C++ integration. ++// ++// Revision 1.12 1998/02/09 22:56:48 curt ++// Removed "depend" files from cvs control. Other minor make tweaks. ++// ++// Revision 1.11 1998/02/07 15:29:36 curt ++// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss ++// ++// ++// Revision 1.10 1998/01/27 00:47:52 curt ++// Incorporated Paul Bleisch's new debug message ++// system and commandline/config file processing code. ++// ++// Revision 1.9 1998/01/22 02:59:31 curt ++// Changed #ifdef FILE_H to #ifdef _FILE_H ++// ++// Revision 1.8 1998/01/19 18:40:22 curt ++// Tons of little changes to clean up the code and to remove fatal errors ++// when building with the c++ compiler. ++// ++// Revision 1.7 1997/12/15 23:54:36 curt ++// Add xgl wrappers for debugging. ++// Generate terrain normals on the fly. ++// ++// Revision 1.6 1997/12/10 22:37:41 curt ++// Prepended "fg" on the name of all global structures that didn't have it yet. ++// i.e. "struct WEATHER {}" became "struct fgWEATHER {}" ++// ++// Revision 1.5 1997/08/27 03:30:02 curt ++// Changed naming scheme of basic shared structures. ++// ++// Revision 1.4 1997/07/23 21:52:18 curt ++// Put comments around the text after an #endif for increased portability. ++// ++// Revision 1.3 1997/05/31 19:16:27 curt ++// Elevator trim added. ++// ++// Revision 1.2 1997/05/23 15:40:33 curt ++// Added GNU copyright headers. ++// ++// Revision 1.1 1997/05/16 15:59:48 curt ++// Initial revision. ++// diff --cc Simulator/JSBsim/FGDefs.h index 000000000,000000000..92cae474b new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGDefs.h @@@ -1,0 -1,0 +1,52 @@@ ++/******************************************************************************* ++ ++ Header: FGDefs.h ++ Author: Jon S. Berndt ++ Date started: 02/01/99 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++02/01/99 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGDEFS_H ++#define FGDEFS_H ++ ++#define MAX_ENGINES 10 ++#define MAX_TANKS 30 ++#define GRAVITY 32.174 ++#define EARTHRAD 20898908.00 // feet ++#define OMEGAEARTH 7.2685E-3 // rad/sec ++#define EARTHRADSQRD 437882827922500.0 ++#define ONESECOND 4.848136811E-6 ++#define ECCENT 0.996647186 ++#define ECCENTSQRD 0.99330561 ++#define INVECCENTSQRD 1.0067395 ++#define INVECCENTSQRDM1 0.0067395 ++#define EPS 0.081819221 ++ ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGEngine.cpp index 000000000,000000000..275d793e5 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGEngine.cpp @@@ -1,0 -1,0 +1,177 @@@ ++/******************************************************************************* ++ ++ Module: FGEngine.cpp ++ Author: Jon Berndt ++ Date started: 01/21/99 ++ Called by: FGAircraft ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++See header file. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/21/99 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#include "FGEngine.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGAtmosphere.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName, int num) ++{ ++ string fullpath; ++ string tag; ++ ++ FDMExec = fdex; ++ ++ State = FDMExec->GetState(); ++ Atmosphere = FDMExec->GetAtmosphere(); ++ FCS = FDMExec->GetFCS(); ++ Aircraft = FDMExec->GetAircraft(); ++ Translation = FDMExec->GetTranslation(); ++ Rotation = FDMExec->GetRotation(); ++ Position = FDMExec->GetPosition(); ++ Auxiliary = FDMExec->GetAuxiliary(); ++ Output = FDMExec->GetOutput(); ++ ++ Name = engineName; ++ fullpath = enginePath + "/" + engineName + ".dat"; ++ ifstream enginefile(fullpath.c_str()); ++ ++ if (enginefile) { ++ enginefile >> tag; ++ ++ if (tag == "ROCKET") Type = etRocket; ++ else if (tag == "PISTON") Type = etPiston; ++ else if (tag == "TURBOPROP") Type = etTurboProp; ++ else if (tag == "TURBOJET") Type = etTurboJet; ++ else Type = etUnknown; ++ ++ enginefile >> X; ++ enginefile >> Y; ++ enginefile >> Z; ++ enginefile >> SLThrustMax; ++ enginefile >> VacThrustMax; ++ enginefile >> MaxThrottle; ++ enginefile >> MinThrottle; ++ enginefile >> SLFuelFlowMax; ++ if (Type == 1) ++ enginefile >> SLOxiFlowMax; ++ enginefile.close(); ++ } else { ++ cerr << "Unable to open engine definition file " << engineName << endl; ++ } ++ ++ EngineNumber = num; ++ Thrust = 0.0; ++ Starved = Flameout = false; ++} ++ ++ ++FGEngine::~FGEngine(void) ++{ ++} ++ ++ ++float FGEngine::CalcRocketThrust(void) ++{ ++ float lastThrust; ++ ++ Throttle = FCS->GetThrottle(EngineNumber); ++ lastThrust = Thrust; // last actual thrust ++ ++ if (Throttle < MinThrottle || Starved) { ++ PctPower = Thrust = 0.0; // desired thrust ++ Flameout = true; ++ } else { ++ PctPower = Throttle / MaxThrottle; ++ Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) + ++ SLThrustMax); // desired thrust ++ Flameout = false; ++ } ++ ++ Thrust += 0.8*(Thrust - lastThrust); // actual thrust ++ ++ return Thrust; ++} ++ ++ ++float FGEngine::CalcPistonThrust(void) ++{ ++ return Thrust; ++} ++ ++ ++float FGEngine::CalcThrust(void) ++{ ++ switch(Type) { ++ case etRocket: ++ return CalcRocketThrust(); ++ // break; ++ case etPiston: ++ return CalcPistonThrust(); ++ // break; ++ default: ++ return 9999.0; ++ // break; ++ } ++} ++ ++float FGEngine::CalcFuelNeed() { ++ FuelNeed = SLFuelFlowMax*PctPower; ++ return FuelNeed; ++} ++ ++ ++float FGEngine::CalcOxidizerNeed() { ++ OxidizerNeed = SLOxiFlowMax*PctPower; ++ return OxidizerNeed; ++} ++ diff --cc Simulator/JSBsim/FGEngine.h index 000000000,000000000..8ea2dada3 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGEngine.h @@@ -1,0 -1,0 +1,133 @@@ ++/******************************************************************************* ++ ++ Header: FGEngine.h ++ Author: Jon S. Berndt ++ Date started: 01/21/99 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++ ++Based on Flightgear code, which is based on LaRCSim. This class simulates ++a generic engine. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/21/99 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGEngine_H ++#define FGEngine_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# include STL_STRING ++ FG_USING_STD(string); ++#else ++# include ++#endif ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGFDMExec; ++class FGState; ++class FGAtmosphere; ++class FGFCS; ++class FGAircraft; ++class FGTranslation; ++class FGRotation; ++class FGPosition; ++class FGAuxiliary; ++class FGOutput; ++ ++class FGEngine ++{ ++public: ++ FGEngine(FGFDMExec*, string, string, int); ++ ~FGEngine(void); ++ ++ enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet}; ++ ++ float GetThrottle(void) {return Throttle;} ++ float GetThrust(void) {return Thrust;} ++ bool GetStarved(void) {return Starved;} ++ bool GetFlameout(void) {return Flameout;} ++ int GetType(void) {return Type;} ++ string GetName() {return Name;} ++ ++ void SetStarved(bool tt) {Starved = tt;} ++ void SetStarved(void) {Starved = true;} ++ ++ float CalcThrust(void); ++ float CalcFuelNeed(void); ++ float CalcOxidizerNeed(void); ++ ++private: ++ string Name; ++ EngineType Type; ++ float X, Y, Z; ++ float SLThrustMax; ++ float VacThrustMax; ++ float SLFuelFlowMax; ++ float SLOxiFlowMax; ++ float MaxThrottle; ++ float MinThrottle; ++ ++ float Thrust; ++ float Throttle; ++ float FuelNeed, OxidizerNeed; ++ bool Starved; ++ bool Flameout; ++ float PctPower; ++ int EngineNumber; ++ ++ FGFDMExec* FDMExec; ++ FGState* State; ++ FGAtmosphere* Atmosphere; ++ FGFCS* FCS; ++ FGAircraft* Aircraft; ++ FGTranslation* Translation; ++ FGRotation* Rotation; ++ FGPosition* Position; ++ FGAuxiliary* Auxiliary; ++ FGOutput* Output; ++ ++protected: ++ float CalcRocketThrust(void); ++ float CalcPistonThrust(void); ++ ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGFCS.cpp index 000000000,000000000..04bfb3880 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGFCS.cpp @@@ -1,0 -1,0 +1,74 @@@ ++/******************************************************************************* ++ ++ Module: FGFCS.cpp ++ Author: Jon Berndt ++ Date started: 12/12/98 ++ Purpose: Model the flight controls ++ Called by: FDMExec ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This class models the flight controls for a specific airplane ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/12/98 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGFCS.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGAtmosphere.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) ++{ ++ Name = "FGFCS"; ++} ++ ++ ++FGFCS::~FGFCS(void) ++{ ++} ++ ++ ++bool FGFCS::Run(void) ++{ ++ if (!FGModel::Run()) { ++ ++ } else { ++ } ++ return false; ++} diff --cc Simulator/JSBsim/FGFCS.h index 000000000,000000000..809980042 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGFCS.h @@@ -1,0 -1,0 +1,78 @@@ ++/******************************************************************************* ++ ++ Header: FGGFCS.h ++ Author: Jon S. Berndt ++ Date started: 12/12/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/12/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGFCS_H ++#define FGFCS_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGModel.h" ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++ ++class FGFCS : public FGModel ++{ ++public: ++ FGFCS(FGFDMExec*); ++ ~FGFCS(void); ++ ++ bool Run(void); ++ ++ inline float GetDa(void) {return Da;} ++ inline float GetDe(void) {return De;} ++ inline float GetDr(void) {return Dr;} ++ inline float GetDf(void) {return Df;} ++ inline float GetDs(void) {return Ds;} ++ inline float GetThrottle(int ii) {return Throttle[ii];} ++ ++ inline void SetDa(float tt) {Da = tt;} ++ inline void SetDe(float tt) {De = tt;} ++ inline void SetDr(float tt) {Dr = tt;} ++ inline void SetDf(float tt) {Df = tt;} ++ inline void SetDs(float tt) {Ds = tt;} ++ inline void SetThrottle(int ii, float tt) {Throttle[ii] = tt;} ++ ++protected: ++ ++private: ++ float Da, De, Dr, Df, Ds; ++ float Throttle[MAX_ENGINES]; ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGFDMExec.cpp index 000000000,000000000..9f4adfa80 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGFDMExec.cpp @@@ -1,0 -1,0 +1,174 @@@ ++/******************************************************************************* ++ ++ Module: FGFDMExec.cpp ++ Author: Jon S. Berndt ++ Date started: 11/17/98 ++ Purpose: Schedules and runs the model routines. ++ Called by: The GUI. ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++ ++This class wraps up the simulation scheduling routines. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/17/98 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# include ++# else ++# include ++# include ++# endif ++#else ++# include ++# include ++#endif ++ ++#include "FGFDMExec.h" ++#include "FGState.h" ++#include "FGAtmosphere.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++// Constructor ++ ++FGFDMExec::FGFDMExec(void) ++{ ++ FirstModel = 0; ++ Error = 0; ++ State = 0; ++ Atmosphere = 0; ++ FCS = 0; ++ Aircraft = 0; ++ Translation = 0; ++ Rotation = 0; ++ Position = 0; ++ Auxiliary = 0; ++ Output = 0; ++ ++ // Instantiate this FDM Executive's Models ++ ++ Atmosphere = new FGAtmosphere(this); ++ FCS = new FGFCS(this); ++ Aircraft = new FGAircraft(this); ++ Translation = new FGTranslation(this); ++ Rotation = new FGRotation(this); ++ Position = new FGPosition(this); ++ Auxiliary = new FGAuxiliary(this); ++ Output = new FGOutput(this); ++ ++ State = new FGState(this); ++ ++ // Initialize models so they can communicate with each other ++ ++ if (!Atmosphere->InitModel()) {cerr << "Atmosphere model init failed"; Error+=1;} ++ if (!FCS->InitModel()) {cerr << "FCS model init failed"; Error+=2;} ++ if (!Aircraft->InitModel()) {cerr << "Aircraft model init failed"; Error+=4;} ++ if (!Translation->InitModel()){cerr << "Translation model init failed"; Error+=8;} ++ if (!Rotation->InitModel()) {cerr << "Rotation model init failed"; Error+=16;} ++ if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;} ++ if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;} ++ if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;} ++ ++ Schedule(Atmosphere, 5); ++ Schedule(FCS, 1); ++ Schedule(Aircraft, 1); ++ Schedule(Rotation, 1); ++ Schedule(Translation, 1); ++ Schedule(Position, 1); ++ Schedule(Auxiliary, 1); ++ Schedule(Output, 5); ++ ++ terminate = false; ++ frozen = false; ++} ++ ++ ++FGFDMExec::~FGFDMExec(void) ++{ ++} ++ ++ ++int FGFDMExec::Schedule(FGModel* model, int rate) ++{ ++ FGModel* model_iterator; ++ ++ model_iterator = FirstModel; ++ ++ if (model_iterator == 0L) { // this is the first model ++ ++ FirstModel = model; ++ FirstModel->NextModel = 0L; ++ FirstModel->SetRate(rate); ++ ++ } else { // subsequent model ++ ++ while (model_iterator->NextModel != 0L) { ++ model_iterator = model_iterator->NextModel; ++ } ++ model_iterator->NextModel = model; ++ model_iterator->NextModel->SetRate(rate); ++ ++ } ++ return 0; ++} ++ ++ ++bool FGFDMExec::Run(void) ++{ ++ FGModel* model_iterator; ++ ++ if (frozen) return true; ++ ++ model_iterator = FirstModel; ++ if (model_iterator == 0L) return false; ++ ++ while (!model_iterator->Run()) ++ { ++ model_iterator = model_iterator->NextModel; ++ if (model_iterator == 0L) break; ++ } ++ ++ State->IncrTime(); ++ ++ return true; ++} ++ diff --cc Simulator/JSBsim/FGFDMExec.h index 000000000,000000000..7997a1cfe new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGFDMExec.h @@@ -1,0 -1,0 +1,100 @@@ ++/******************************************************************************* ++ ++ Header: FGFDMExec.h ++ Author: Jon Berndt ++ Date started: 11/17/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/17/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGFDMEXEC_HEADER_H ++#define FGFDMEXEC_HEADER_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGModel.h" ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGState; ++class FGAtmosphere; ++class FGFCS; ++class FGAircraft; ++class FGTranslation; ++class FGRotation; ++class FGPosition; ++class FGAuxiliary; ++class FGOutput; ++ ++class FGFDMExec ++{ ++public: ++ FGFDMExec::FGFDMExec(void); ++ FGFDMExec::~FGFDMExec(void); ++ ++ FGModel* FirstModel; ++ ++ bool Initialize(void); ++ int Schedule(FGModel* model, int rate); ++ bool Run(void); ++ void Freeze(void) {frozen = true;} ++ void Resume(void) {frozen = false;} ++ ++ inline FGState* GetState(void) {return State;} ++ inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;} ++ inline FGFCS* GetFCS(void) {return FCS;} ++ inline FGAircraft* GetAircraft(void) {return Aircraft;} ++ inline FGTranslation* GetTranslation(void) {return Translation;} ++ inline FGRotation* GetRotation(void) {return Rotation;} ++ inline FGPosition* GetPosition(void) {return Position;} ++ inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;} ++ inline FGOutput* GetOutput(void) {return Output;} ++ ++private: ++ bool frozen; ++ bool terminate; ++ int Error; ++ ++ FGState* State; ++ FGAtmosphere* Atmosphere; ++ FGFCS* FCS; ++ FGAircraft* Aircraft; ++ FGTranslation* Translation; ++ FGRotation* Rotation; ++ FGPosition* Position; ++ FGAuxiliary* Auxiliary; ++ FGOutput* Output; ++ ++protected: ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGMain.cpp index 000000000,000000000..93ac279ef new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGMain.cpp @@@ -1,0 -1,0 +1,41 @@@ ++#include "FGFDMExec.h" ++#include "FGRotation.h" ++#include "FGAtmosphere.h" ++#include "FGState.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++#include ++#include ++ ++void main(int argc, char** argv) ++{ ++ FGFDMExec* FDMExec; ++ ++ struct timespec short_wait = {0,100000000}; ++ struct timespec no_wait = {0,100000000}; ++ ++ if (argc != 3) { ++ cout << endl ++ << " You must enter the name of a registered aircraft and reset point:" ++ << endl << endl << " FDM " << endl; ++ exit(0); ++ } ++ ++ FDMExec = new FGFDMExec(); ++ ++ FDMExec->GetAircraft()->LoadAircraft("aircraft", "engine", string(argv[1])); ++ FDMExec->GetState()->Reset("aircraft", string(argv[2])); ++ ++ while (FDMExec->GetState()->Getsim_time() <= 25.0) ++ { ++ FDMExec->Run(); ++ nanosleep(&short_wait,&no_wait); ++ } ++ ++ delete FDMExec; ++} diff --cc Simulator/JSBsim/FGMatrix.cpp index 000000000,000000000..680ca1a20 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGMatrix.cpp @@@ -1,0 -1,0 +1,397 @@@ ++/******************************************************************************* ++ ++Module: FGMatrix.cpp ++Author: Tony Peden [formatted here by JSB] ++Date started: ?? ++Purpose: FGMatrix class ++Called by: Various ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++ ++ ++ARGUMENTS ++-------------------------------------------------------------------------------- ++ ++ ++HISTORY ++-------------------------------------------------------------------------------- ++??/??/?? TP Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include ++#include "FGMatrix.h" ++#include ++#include ++#include ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++#pragma warn -use ++ ++/******************************************************************************* ++CONSTANTS ++*******************************************************************************/ ++ ++ ++/******************************************************************************* ++TYPEDEFS ++*******************************************************************************/ ++ ++ ++/******************************************************************************* ++GLOBALS ++*******************************************************************************/ ++ ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++double** alloc(int rows,int cols) ++{ ++ double **A; ++ ++ A = new double *[rows+1]; ++ if (!A) return NULL; ++ ++ for (int i=0;i<=rows;i++){ ++ A[i]=new double[cols+1]; ++ if (!A[i]) return NULL; ++ } ++ return A; ++} ++ ++ ++void dealloc(double **A, int rows, int cols) ++{ ++ for(int i=0;i<=rows;i++){ ++ delete[] A[i]; ++ } ++ ++ delete[] A; ++} ++ ++ ++FGMatrix::FGMatrix(unsigned rows, unsigned cols) ++{ ++ this->rows=rows; ++ this->cols=cols; ++ keep=false; ++ data=alloc(rows,cols); ++} ++ ++ ++FGMatrix::FGMatrix(const FGMatrix& A) ++{ ++ data=NULL; ++ *this=A; ++} ++ ++ ++FGMatrix::~FGMatrix(void) ++{ ++ if (keep == false) { ++ dealloc(data,rows,cols); ++ rows=cols=0; ++ } ++} ++ ++ ++FGMatrix& FGMatrix::operator=(const FGMatrix& A) ++{ ++ if (&A != this) { ++ if (data != NULL) dealloc(data,rows,cols); ++ ++ width = A.width; ++ prec = A.prec; ++ delim = A.delim; ++ origin = A.origin; ++ rows = A.rows; ++ cols = A.cols; ++ keep = false; ++ ++ if (A.keep == true) { ++ data = A.data; ++ } else { ++ data = alloc(rows,cols); ++ for (int i=0; i<=rows; i++) { ++ for (int j=0; j<=cols; j++) { ++ data[i][j] = A.data[i][j]; ++ } ++ } ++ } ++ } ++ return *this; ++} ++ ++ ++double& FGMatrix::operator()(unsigned row, unsigned col) ++{ ++ return data[row][col]; ++} ++ ++ ++unsigned FGMatrix::Rows(void) const ++{ ++ return rows; ++} ++ ++ ++unsigned FGMatrix::Cols(void) const ++{ ++ return cols; ++} ++ ++ ++void FGMatrix::SetOParams(char delim,int width,int prec,int origin) ++{ ++ FGMatrix::delim=delim; ++ FGMatrix::width=width; ++ FGMatrix::prec=prec; ++ FGMatrix::origin=origin; ++} ++ ++ ++void FGMatrix::InitMatrix(double value) ++{ ++ if (data) { ++ for (int i=0;i<=rows;i++) { ++ for (int j=0;j<=cols;j++) { ++ operator()(i,j) = value; ++ } ++ } ++ } ++} ++ ++ ++void FGMatrix::InitMatrix(void) ++{ ++ this->InitMatrix(0); ++} ++ ++ ++FGMatrix operator-(FGMatrix& A, FGMatrix& B) ++{ ++ if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) { ++ cout << endl << "FGMatrix::operator-" << endl << '\t'; ++ cout << "Subtraction not defined for matrices of different sizes"; ++ cout << endl; ++ exit(1); ++ } ++ ++ FGMatrix Diff(A.Rows(),A.Cols()); ++ Diff.keep=true; ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ Diff(i,j)=A(i,j)-B(i,j); ++ } ++ } ++ return Diff; ++} ++ ++ ++void operator-=(FGMatrix &A,FGMatrix &B) ++{ ++ if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) { ++ cout << endl << "FGMatrix::operator-" << endl << '\t'; ++ cout << "Subtraction not defined for matrices of different sizes"; ++ cout << endl; ++ exit(1); ++ } ++ ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ A(i,j)-=B(i,j); ++ } ++ } ++} ++ ++ ++FGMatrix operator+(FGMatrix& A, FGMatrix& B) ++{ ++ if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) { ++ cout << endl << "FGMatrix::operator+" << endl << '\t'; ++ cout << "Addition not defined for matrices of different sizes"; ++ cout << endl; ++ exit(1); ++ } ++ ++ FGMatrix Sum(A.Rows(),A.Cols()); ++ Sum.keep = true; ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ Sum(i,j)=A(i,j)+B(i,j); ++ } ++ } ++ return Sum; ++} ++ ++ ++void operator+=(FGMatrix &A,FGMatrix &B) ++{ ++ if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) { ++ cout << endl << "FGMatrix::operator+" << endl << '\t'; ++ cout << "Addition not defined for matrices of different sizes"; ++ cout << endl; ++ exit(1); ++ } ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ A(i,j)+=B(i,j); ++ } ++ } ++} ++ ++ ++FGMatrix operator*(double scalar,FGMatrix &A) ++{ ++ FGMatrix Product(A.Rows(),A.Cols()); ++ Product.keep = true; ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ Product(i,j) = scalar*A(i,j); ++ } ++ } ++ return Product; ++} ++ ++ ++void operator*=(FGMatrix &A,double scalar) ++{ ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ A(i,j)*=scalar; ++ } ++ } ++} ++ ++ ++FGMatrix operator*(FGMatrix &Left, FGMatrix &Right) ++{ ++ if (Left.Cols() != Right.Rows()) { ++ cout << endl << "FGMatrix::operator*" << endl << '\t'; ++ cout << "The number of rows in the right matrix must match the number"; ++ cout << endl << '\t' << "of columns in the left." << endl; ++ cout << '\t' << "Multiplication not defined." << endl; ++ exit(1); ++ } ++ ++ FGMatrix Product(Left.Rows(),Right.Cols()); ++ Product.keep = true; ++ for (int i=1;i<=Left.Rows();i++) { ++ for (int j=1;j<=Right.Cols();j++) { ++ Product(i,j) = 0; ++ for (int k=1;k<=Left.Cols();k++) { ++ Product(i,j)+=Left(i,k)*Right(k,j); ++ } ++ } ++ } ++ return Product; ++} ++ ++ ++void operator*=(FGMatrix &Left,FGMatrix &Right) ++{ ++ if (Left.Cols() != Right.Rows()) { ++ cout << endl << "FGMatrix::operator*" << endl << '\t'; ++ cout << "The number of rows in the right matrix must match the number"; ++ cout << endl << '\t' << "of columns in the left." << endl; ++ cout << '\t' << "Multiplication not defined." << endl; ++ exit(1); ++ } ++ ++ double **prod; ++ ++ prod=alloc(Left.Rows(),Right.Cols()); ++ for (int i=1;i<=Left.Rows();i++) { ++ for (int j=1;j<=Right.Cols();j++) { ++ prod[i][j] = 0; ++ for (int k=1;k<=Left.Cols();k++) { ++ prod[i][j]+=Left(i,k)*Right(k,j); ++ } ++ } ++ } ++ dealloc(Left.data,Left.Rows(),Left.Cols()); ++ Left.data=prod; ++ Left.cols=Right.cols; ++} ++ ++ ++FGMatrix operator/(FGMatrix& A, double scalar) ++{ ++ FGMatrix Quot(A.Rows(),A.Cols()); ++ A.keep = true; ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ Quot(i,j)=A(i,j)/scalar; ++ } ++ } ++ return Quot; ++} ++ ++ ++void operator/=(FGMatrix &A,double scalar) ++{ ++ for (int i=1;i<=A.Rows();i++) { ++ for (int j=1;j<=A.Cols();j++) { ++ A(i,j)/=scalar; ++ } ++ } ++} ++ ++ ++void FGMatrix::T(void) ++{ ++ if (rows==cols) ++ TransposeSquare(); ++ else ++ TransposeNonSquare(); ++} ++ ++ ++void FGMatrix::TransposeSquare(void) ++{ ++ for (int i=1;i<=rows;i++) { ++ for (int j=i+1;j<=cols;j++) { ++ double tmp=data[i][j]; ++ data[i][j]=data[j][i]; ++ data[j][i]=tmp; ++ } ++ } ++} ++ ++ ++void FGMatrix::TransposeNonSquare(void) ++{ ++ double **tran; ++ ++ tran=alloc(rows,cols); ++ for (int i=1;i<=rows;i++) { ++ for (int j=1;j<=cols;j++) { ++ tran[j][i]=data[i][j]; ++ } ++ } ++ dealloc(data,rows,cols); ++ ++ data=tran; ++ unsigned m=rows; ++ rows=cols; ++ cols=m; ++} ++ ++ ++FGColumnVector::FGColumnVector(void):FGMatrix(3,1) { } ++FGColumnVector::FGColumnVector(int m):FGMatrix(m,1) { } ++FGColumnVector::FGColumnVector(FGColumnVector& b):FGMatrix(b) { } ++FGColumnVector::~FGColumnVector() { } ++double& FGColumnVector::operator()(int m) ++{ ++ return FGMatrix::operator()(m,1); ++} ++ diff --cc Simulator/JSBsim/FGMatrix.h index 000000000,000000000..b3591b946 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGMatrix.h @@@ -1,0 -1,0 +1,98 @@@ ++/******************************************************************************* ++ ++Header: FGMatrix.h ++Author: Tony Peden [formatted here by Jon Berndt] ++Date started: Unknown ++ ++HISTORY ++-------------------------------------------------------------------------------- ++??/??/?? TP Created ++ ++/******************************************************************************* ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGMATRIX_H ++#define FGMATRIX_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#include ++#include ++#include ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++ ++/******************************************************************************* ++CONSTANTS ++*******************************************************************************/ ++ ++ ++/******************************************************************************* ++TYPEDEFS ++*******************************************************************************/ ++ ++ ++/******************************************************************************* ++GLOBALS ++*******************************************************************************/ ++ ++class FGMatrix ++{ ++private: ++ double **data; ++ unsigned rows,cols; ++ bool keep; ++ char delim; ++ int width,prec,origin; ++ void TransposeSquare(void); ++ void TransposeNonSquare(void); ++ ++public: ++ FGMatrix(unsigned rows, unsigned cols); ++ FGMatrix(const FGMatrix& A); ++ ~FGMatrix(void); ++ ++ FGMatrix& FGMatrix::operator=(const FGMatrix& A); ++ double& FGMatrix::operator()(unsigned row, unsigned col); ++ ++ unsigned FGMatrix::Rows(void) const; ++ unsigned FGMatrix::Cols(void) const; ++ ++ void FGMatrix::T(void); ++ void InitMatrix(void); ++ void InitMatrix(double value); ++ ++ friend FGMatrix operator-(FGMatrix& A, FGMatrix& B); ++ friend FGMatrix operator+(FGMatrix& A, FGMatrix& B); ++ friend FGMatrix operator*(double scalar,FGMatrix& A); ++ friend FGMatrix operator*(FGMatrix& Left, FGMatrix& Right); ++ friend FGMatrix operator/(FGMatrix& A, double scalar); ++ ++ friend void operator-=(FGMatrix &A,FGMatrix &B); ++ friend void operator+=(FGMatrix &A,FGMatrix &B); ++ friend void operator*=(FGMatrix &A,FGMatrix &B); ++ friend void operator*=(FGMatrix &A,double scalar); ++ friend void operator/=(FGMatrix &A,double scalar); ++ ++ void SetOParams(char delim,int width,int prec, int origin=0); ++}; ++ ++class FGColumnVector : public FGMatrix ++{ ++public: ++ FGColumnVector(void); ++ FGColumnVector(int m); ++ FGColumnVector(FGColumnVector& b); ++ ~FGColumnVector(); ++ ++ double& operator()(int m); ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGModel.cpp index 000000000,000000000..95807830d new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGModel.cpp @@@ -1,0 -1,0 +1,117 @@@ ++/******************************************************************************* ++ ++ Module: FGModel.cpp ++ Author: Jon Berndt ++ Date started: 11/11/98 ++ Purpose: Base class for all models ++ Called by: FGSimExec, et. al. ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This base class for the FGAero, FGRotational, etc. classes defines methods ++common to all models. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/11/98 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGModel.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGAtmosphere.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++FGModel::FGModel(FGFDMExec* fdmex) ++{ ++ FDMExec = fdmex; ++ NextModel = 0L; ++ ++ State = 0; ++ Atmosphere = 0; ++ FCS = 0; ++ Aircraft = 0; ++ Translation = 0; ++ Rotation = 0; ++ Position = 0; ++ Auxiliary = 0; ++ Output = 0; ++ ++ exe_ctr = 1; ++} ++ ++ ++FGModel::~FGModel() ++{ ++} ++ ++ ++bool FGModel::InitModel(void) ++{ ++ State = FDMExec->GetState(); ++ Atmosphere = FDMExec->GetAtmosphere(); ++ FCS = FDMExec->GetFCS(); ++ Aircraft = FDMExec->GetAircraft(); ++ Translation = FDMExec->GetTranslation(); ++ Rotation = FDMExec->GetRotation(); ++ Position = FDMExec->GetPosition(); ++ Auxiliary = FDMExec->GetAuxiliary(); ++ Output = FDMExec->GetOutput(); ++ ++ if (!State || ++ !Atmosphere || ++ !FCS || ++ !Aircraft || ++ !Translation || ++ !Rotation || ++ !Position || ++ !Auxiliary || ++ !Output) return(false); ++ else return(true); ++} ++ ++ ++bool FGModel::Run() ++{ ++ if (exe_ctr == 1) { ++ if (exe_ctr++ >= rate) exe_ctr = 1; ++ return false; ++ } else { ++ if (exe_ctr++ >= rate) exe_ctr = 1; ++ return true; ++ } ++} ++ ++ diff --cc Simulator/JSBsim/FGModel.h index 000000000,000000000..c5cec51c5 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGModel.h @@@ -1,0 -1,0 +1,107 @@@ ++/******************************************************************************* ++ ++ Header: FGModel.h ++ Author: Jon Berndt ++ Date started: 11/21/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/22/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGMODEL_H ++#define FGMODEL_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGDefs.h" ++ ++#ifdef FGFS ++# include ++# include STL_STRING ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++ FG_USING_STD(string); ++#else ++# include ++# include ++#endif ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGFDMExec; ++class FGState; ++class FGAtmosphere; ++class FGFCS; ++class FGAircraft; ++class FGTranslation; ++class FGRotation; ++class FGPosition; ++class FGAuxiliary; ++class FGOutput; ++ ++class FGModel ++{ ++public: ++ FGModel(FGFDMExec*); ++ ~FGModel(void); ++ ++ FGModel* NextModel; ++ string Name; ++ virtual bool Run(void); ++ virtual bool InitModel(void); ++ void SetRate(int tt) {rate = tt;}; ++ ++protected: ++ int exe_ctr; ++ int rate; ++ ++ FGFDMExec* FDMExec; ++ FGState* State; ++ FGAtmosphere* Atmosphere; ++ FGFCS* FCS; ++ FGAircraft* Aircraft; ++ FGTranslation* Translation; ++ FGRotation* Rotation; ++ FGPosition* Position; ++ FGAuxiliary* Auxiliary; ++ FGOutput* Output; ++ ++private: ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGOutput.cpp index 000000000,000000000..f327e6b4f new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGOutput.cpp @@@ -1,0 -1,0 +1,222 @@@ ++/******************************************************************************* ++ ++ Module: FGOutput.cpp ++ Author: Jon Berndt ++ Date started: 12/02/98 ++ Purpose: Manage output of sim parameters to file or stdout ++ Called by: FGSimExec ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This is the place where you create output routines to dump data for perusal ++later. Some machines may not support the ncurses console output. Borland is one ++of those environments which does not, so the ncurses stuff is commented out. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/02/98 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#ifdef HAVE_CURSES ++ #include ++#endif ++ ++#include "FGOutput.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGAtmosphere.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex) ++{ ++ Name = "FGOutput"; ++ FirstPass = true; ++#ifdef HAVE_CURSES ++ initscr(); ++ cbreak(); ++ noecho(); ++#endif ++} ++ ++ ++FGOutput::~FGOutput(void) ++{ ++} ++ ++ ++bool FGOutput::Run(void) ++{ ++ if (!FGModel::Run()) { ++ DelimitedOutput(); ++// ConsoleOutput(); ++ } else { ++ } ++ return false; ++} ++ ++ ++void FGOutput::ConsoleOutput(void) ++{ ++#ifdef HAVE_CURSES ++ string buffer; ++ ++ clear(); ++ move(1,1); insstr("Quaternions"); ++ move(2,5); insstr("Q0"); ++ move(2,16); insstr("Q1"); ++ move(2,27); insstr("Q2"); ++ move(2,38); insstr("Q3"); ++ ++ move(3,1); buffer = Rotation->GetQ0(); insstr(buffer.c_str()); ++ move(3,12); buffer = Rotation->GetQ1(); insstr(buffer.c_str()); ++ move(3,23); buffer = Rotation->GetQ2(); insstr(buffer.c_str()); ++ move(3,34); buffer = Rotation->GetQ3(); insstr(buffer.c_str()); ++ ++ move(0,0); insstr("Time: "); ++ move(0,6); insstr(gcvt(State->Getsim_time(),6,buffer)); ++ ++ move(2,46); insstr("Phi"); ++ move(2,55); insstr("Tht"); ++ move(2,64); insstr("Psi"); ++ ++ move(3,45); buffer = Rotation->Getphi(); insstr(buffer.c_str()); ++ move(3,54); buffer = Rotation->Gettht(); insstr(buffer.c_str()); ++ move(3,63); buffer = Rotation->Getpsi(); insstr(buffer.c_str()); ++ ++ move(5,47); insstr("U"); ++ move(5,56); insstr("V"); ++ move(5,65); insstr("W"); ++ ++ move(6,45); buffer = Translation->GetU(); insstr(buffer.c_str()); ++ move(6,54); buffer = Translation->GetV(); insstr(buffer.c_str()); ++ move(6,63); buffer = Translation->GetW(); insstr(buffer.c_str()); ++ ++ move(8,47); insstr("Fx"); ++ move(8,56); insstr("Fy"); ++ move(8,65); insstr("Fz"); ++ ++ move(9,45); buffer = Aircraft->GetFx(); insstr(buffer.c_str()); ++ move(9,54); buffer = Aircraft->GetFy(); insstr(buffer.c_str()); ++ move(9,63); buffer = Aircraft->GetFz(); insstr(buffer.c_str()); ++ ++ move(11,47); insstr("Fn"); ++ move(11,56); insstr("Fe"); ++ move(11,65); insstr("Fd"); ++ ++ move(12,45); buffer = Position->GetFn(); insstr(buffer.c_str()); ++ move(12,54); buffer = Position->GetFe(); insstr(buffer.c_str()); ++ move(12,63); buffer = Position->GetFd(); insstr(buffer.c_str()); ++ ++ move(14,47); insstr("Latitude"); ++ move(14,57); insstr("Longitude"); ++ move(14,67); insstr("Altitude"); ++ ++ move(15,47); buffer = State->Getlatitude(); insstr(buffer.c_str()); ++ move(15,57); buffer = State->Getlongitude(); insstr(buffer.c_str()); ++ move(15,67); buffer = State->Geth(); insstr(buffer.c_str()); ++ ++ refresh(); ++ ++ move(LINES-1,1); ++ refresh(); ++#endif ++} ++ ++ ++void FGOutput::DelimitedOutput(void) ++{ ++ if (FirstPass) { ++ cout << "Time,"; ++ cout << "Altitude,"; ++ cout << "Phi,"; ++ cout << "Tht,"; ++ cout << "Psi,"; ++ cout << "Rho,"; ++ cout << "Vtotal,"; ++ cout << "U,"; ++ cout << "V,"; ++ cout << "W,"; ++ cout << "Vn,"; ++ cout << "Ve,"; ++ cout << "Vd,"; ++ cout << "Udot,"; ++ cout << "Vdot,"; ++ cout << "Wdot,"; ++ cout << "Fx,"; ++ cout << "Fy,"; ++ cout << "Fz,"; ++ cout << "Latitude,"; ++ cout << "Longitude,"; ++ cout << "QBar,"; ++ cout << "Alpha"; ++ cout << endl; ++ FirstPass = false; ++ } else { ++ cout << State->Getsim_time() << ","; ++ cout << State->Geth() << ","; ++ cout << Rotation->Getphi() << ","; ++ cout << Rotation->Gettht() << ","; ++ cout << Rotation->Getpsi() << ","; ++ cout << Atmosphere->Getrho() << ","; ++ cout << State->GetVt() << ","; ++ cout << Translation->GetU() << ","; ++ cout << Translation->GetV() << ","; ++ cout << Translation->GetW() << ","; ++ cout << Position->GetVn() << ","; ++ cout << Position->GetVe() << ","; ++ cout << Position->GetVd() << ","; ++ cout << Translation->GetUdot() << ","; ++ cout << Translation->GetVdot() << ","; ++ cout << Translation->GetWdot() << ","; ++ cout << Aircraft->GetFx() << ","; ++ cout << Aircraft->GetFy() << ","; ++ cout << Aircraft->GetFz() << ","; ++ cout << State->Getlatitude() << ","; ++ cout << State->Getlongitude() << ","; ++ cout << State->Getqbar() << ","; ++ cout << Translation->Getalpha() << ""; ++ cout << endl; ++ } ++} diff --cc Simulator/JSBsim/FGOutput.h index 000000000,000000000..2ec4e7a95 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGOutput.h @@@ -1,0 -1,0 +1,66 @@@ ++/******************************************************************************* ++ ++ Header: FGOutput.h ++ Author: Jon Berndt ++ Date started: 12/2/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/02/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGOUTPUT_H ++#define FGOUTPUT_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGModel.h" ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGOutput : public FGModel ++{ ++public: ++ FGOutput(FGFDMExec*); ++ ~FGOutput(void); ++ ++ bool Run(void); ++ ++ void ConsoleOutput(void); ++ void DelimitedOutput(void); ++ ++protected: ++ ++private: ++ bool FirstPass; ++}; ++ ++/******************************************************************************/ ++#endif ++ diff --cc Simulator/JSBsim/FGPosition.cpp index 000000000,000000000..2f7eb655c new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGPosition.cpp @@@ -1,0 -1,0 +1,189 @@@ ++/******************************************************************************* ++ ++ Module: FGPosition.cpp ++ Author: Jon S. Berndt ++ Date started: 01/05/99 ++ Purpose: Integrate the EOM to determine instantaneous position ++ Called by: FGFDMExec ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This class encapsulates the integration of rates and accelerations to get the ++current position of the aircraft. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/05/99 JSB Created ++ ++******************************************************************************** ++COMMENTS, REFERENCES, and NOTES ++******************************************************************************** ++[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling ++ Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate ++ School, January 1994 ++[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices", ++ JSC 12960, July 1977 ++[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at ++ NASA-Ames", NASA CR-2497, January 1975 ++[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics", ++ Wiley & Sons, 1979 ISBN 0-471-03032-5 ++[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons, ++ 1982 ISBN 0-471-08936-2 ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#include "FGPosition.h" ++#include "FGAtmosphere.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex) ++{ ++ Name = "FGPosition"; ++ AccelN = AccelE = AccelD = 0.0; ++ LongitudeDot = LatitudeDot = RadiusDot = 0.0; ++} ++ ++ ++FGPosition::~FGPosition(void) ++{ ++} ++ ++ ++bool FGPosition:: Run(void) ++{ ++ float tanLat, cosLat; ++ ++ if (!FGModel::Run()) { ++ GetState(); ++ T[1][1] = Q0*Q0 + Q1*Q1 - Q2*Q2 - Q3*Q3; // Page A-11 ++ T[1][2] = 2*(Q1*Q2 + Q0*Q3); // From ++ T[1][3] = 2*(Q1*Q3 - Q0*Q2); // Reference [2] ++ T[2][1] = 2*(Q1*Q2 - Q0*Q3); ++ T[2][2] = Q0*Q0 - Q1*Q1 + Q2*Q2 - Q3*Q3; ++ T[2][3] = 2*(Q2*Q3 + Q0*Q1); ++ T[3][1] = 2*(Q1*Q3 + Q0*Q2); ++ T[3][2] = 2*(Q2*Q3 - Q0*Q1); ++ T[3][3] = Q0*Q0 - Q1*Q1 - Q2*Q2 + Q3*Q3; ++ ++ Fn = T[1][1]*Fx + T[2][1]*Fy + T[3][1]*Fz; // Eqn. 3.5 ++ Fe = T[1][2]*Fx + T[2][2]*Fy + T[3][2]*Fz; // From ++ Fd = T[1][3]*Fx + T[2][3]*Fy + T[3][3]*Fz; // Reference [3] ++ ++ tanLat = tan(Latitude); // I made this up ++ cosLat = cos(Latitude); ++ ++ lastAccelN = AccelN; ++ lastAccelE = AccelE; ++ lastAccelD = AccelD; ++ ++ Vn = T[1][1]*U + T[2][1]*V + T[3][1]*W; ++ Ve = T[1][2]*U + T[2][2]*V + T[3][2]*W; ++ Vd = T[1][3]*U + T[2][3]*V + T[3][3]*W; ++ ++ AccelN = invMass * Fn + invRadius * (Vn*Vd - Ve*Ve*tanLat); // Eqn. 3.6 ++ AccelE = invMass * Fe + invRadius * (Ve*Vd + Vn*Ve*tanLat); // From ++ AccelD = invMass * Fd - invRadius * (Vn*Vn + Ve*Ve); // Reference [3] ++ ++ Vn += 0.5*dt*rate*(3.0*AccelN - lastAccelN); // Eqn. 3.7 ++ Ve += 0.5*dt*rate*(3.0*AccelE - lastAccelE); // From ++ Vd += 0.5*dt*rate*(3.0*AccelD - lastAccelD); // Reference [3] ++ ++ Vee = Ve - OMEGAEARTH * (Radius) * cosLat; // From Eq. 3.8 ++ // Reference [3] ++ lastLatitudeDot = LatitudeDot; ++ lastLongitudeDot = LongitudeDot; ++ lastRadiusDot = RadiusDot; ++ ++ if (cosLat != 0) LongitudeDot = Ve / (Radius * cosLat); ++ LatitudeDot = Vn * invRadius; ++ RadiusDot = -Vd; ++ ++ Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot); ++ Latitude += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot); ++ Radius += 0.5*dt*rate*(RadiusDot + lastRadiusDot); ++ ++ PutState(); ++ return false; ++ } else { ++ return true; ++ } ++} ++ ++ ++void FGPosition::GetState(void) ++{ ++ dt = State->Getdt(); ++ ++ Q0 = Rotation->GetQ0(); ++ Q1 = Rotation->GetQ1(); ++ Q2 = Rotation->GetQ2(); ++ Q3 = Rotation->GetQ3(); ++ ++ Fx = Aircraft->GetFx(); ++ Fy = Aircraft->GetFy(); ++ Fz = Aircraft->GetFz(); ++ ++ U = Translation->GetU(); ++ V = Translation->GetV(); ++ W = Translation->GetW(); ++ ++ Latitude = State->Getlatitude(); ++ Longitude = State->Getlongitude(); ++ ++ invMass = 1.0 / Aircraft->GetMass(); ++ invRadius = 1.0 / (State->Geth() + EARTHRAD); ++ Radius = State->Geth() + EARTHRAD; ++} ++ ++ ++void FGPosition::PutState(void) ++{ ++ State->Setlatitude(Latitude); ++ State->Setlongitude(Longitude); ++ State->Seth(Radius - EARTHRAD); ++} ++ diff --cc Simulator/JSBsim/FGPosition.h index 000000000,000000000..ab04df424 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGPosition.h @@@ -1,0 -1,0 +1,96 @@@ ++/******************************************************************************* ++ ++ Header: FGPosition.h ++ Author: Jon S. Berndt ++ Date started: 1/5/99 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/05/99 JSB Created ++ ++******************************************************************************** ++COMMENTS, REFERENCES, and NOTES ++******************************************************************************** ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGPOSITION_H ++#define FGPOSITION_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++#include "FGModel.h" ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGPosition : public FGModel ++{ ++public: ++ FGPosition(FGFDMExec*); ++ ~FGPosition(void); ++ ++ inline float GetFn(void) {return Fn;} ++ inline float GetFe(void) {return Fe;} ++ inline float GetFd(void) {return Fd;} ++ ++ inline float GetVn(void) {return Vn;} ++ inline float GetVe(void) {return Ve;} ++ inline float GetVd(void) {return Vd;} ++ ++ inline float GetT(int r, int c) {return T[r][c];} ++ inline void SetT(float t1, float t2, float t3, float t4, float t5, float t6, ++ float t7, float t8, float t9) ++ {T[1][1]=t1; T[1][2]=t2 ;T[1][3]=t3; ++ T[2][1]=t4; T[2][2]=t5 ;T[2][3]=t6; ++ T[3][1]=t7; T[3][2]=t8 ;T[3][3]=t9;} ++ ++ bool Run(void); ++ ++protected: ++ ++private: ++ float T[4][4]; ++ float Q0, Q1, Q2, Q3; ++ float Fn, Fe, Fd; ++ float Fx, Fy, Fz; ++ float U, V, W; ++ float Vn, Ve, Vd, Vee; ++ float invMass, invRadius; ++ float Radius; ++ float AccelN, AccelE, AccelD; ++ float lastAccelN, lastAccelE, lastAccelD; ++ float LatitudeDot, LongitudeDot, RadiusDot; ++ float lastLatitudeDot, lastLongitudeDot, lastRadiusDot; ++ float Longitude, Latitude; ++ float dt; ++ ++ void GetState(void); ++ void PutState(void); ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGRotation.cpp index 000000000,000000000..494d9da66 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGRotation.cpp @@@ -1,0 -1,0 +1,176 @@@ ++/******************************************************************************* ++ ++ Module: FGRotation.cpp ++ Author: Jon Berndt ++ Date started: 12/02/98 ++ Purpose: Integrates the rotational EOM ++ Called by: FGFDMExec ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This class integrates the rotational EOM. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/02/98 JSB Created ++ ++******************************************************************************** ++COMMENTS, REFERENCES, and NOTES ++******************************************************************************** ++[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling ++ Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate ++ School, January 1994 ++[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices", ++ JSC 12960, July 1977 ++[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at ++ NASA-Ames", NASA CR-2497, January 1975 ++[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics", ++ Wiley & Sons, 1979 ISBN 0-471-03032-5 ++[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons, ++ 1982 ISBN 0-471-08936-2 ++ ++ The order of rotations used in this class corresponds to a 3-2-1 sequence, ++ or Y-P-R, or Z-Y-X, if you prefer. ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGRotation.h" ++#include "FGAtmosphere.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++FGRotation::FGRotation(FGFDMExec* fdmex) : FGModel(fdmex) ++{ ++ Name = "FGRotation"; ++ Q0dot = Q1dot = Q2dot = Q3dot = 0.0; ++ Pdot = Qdot = Rdot = 0.0; ++} ++ ++ ++FGRotation::~FGRotation(void) ++{ ++} ++ ++ ++bool FGRotation::Run(void) ++{ ++ float L2, N1, iQtot, sum; ++ ++ if (!FGModel::Run()) { ++ GetState(); ++ ++ lastPdot = Pdot; ++ lastQdot = Qdot; ++ lastRdot = Rdot; ++ ++ L2 = L + Ixz*P*Q - (Izz-Iyy)*R*Q; ++ N1 = N - (Iyy-Ixx)*P*Q - Ixz*R*Q; ++ ++ Pdot = (L2*Izz - N1*Ixz) / (Ixx*Izz - Ixz*Ixz); ++ Qdot = (M - (Ixx-Izz)*P*R - Ixz*(P*P - R*R))/Iyy; ++ Rdot = (N1*Ixx + L2*Ixz) / (Ixx*Izz - Ixz*Ixz); ++ ++ P += dt*rate*(lastPdot + Pdot)/2.0; ++ Q += dt*rate*(lastQdot + Qdot)/2.0; ++ R += dt*rate*(lastRdot + Rdot)/2.0; ++ ++ lastQ0dot = Q0dot; ++ lastQ1dot = Q1dot; ++ lastQ2dot = Q2dot; ++ lastQ3dot = Q3dot; ++ ++ Q0dot = -0.5*(Q1*P + Q2*Q + Q3*R); ++ Q1dot = 0.5*(Q0*P + Q2*R - Q3*Q); ++ Q2dot = 0.5*(Q0*Q + Q3*P - Q1*R); ++ Q3dot = 0.5*(Q0*R + Q1*Q - Q2*P); ++ ++ Q0 += 0.5*dt*rate*(lastQ0dot + Q0dot); ++ Q1 += 0.5*dt*rate*(lastQ1dot + Q1dot); ++ Q2 += 0.5*dt*rate*(lastQ2dot + Q2dot); ++ Q3 += 0.5*dt*rate*(lastQ3dot + Q3dot); ++ ++ sum = Q0*Q0 + Q1*Q1 + Q2*Q2 + Q3*Q3; ++ ++ iQtot = 1.0 / sqrt(sum); ++ ++ Q0 *= iQtot; ++ Q1 *= iQtot; ++ Q2 *= iQtot; ++ Q3 *= iQtot; ++ ++ if (T[3][3] == 0) ++ phi = 0.0; ++ else ++ phi = atan2(T[2][3], T[3][3]); ++ ++ tht = asin(-T[1][3]); ++ ++ if (T[1][1] == 0.0) ++ psi = 0.0; ++ else ++ psi = atan2(T[1][2], T[1][1]); ++ ++ if (psi < 0.0) psi += 2*M_PI; ++ ++ PutState(); ++ } else { ++ } ++ return false; ++} ++ ++ ++void FGRotation::GetState(void) ++{ ++ dt = State->Getdt(); ++ ++ L = Aircraft->GetL(); ++ M = Aircraft->GetM(); ++ N = Aircraft->GetN(); ++ ++ Ixx = Aircraft->GetIxx(); ++ Iyy = Aircraft->GetIyy(); ++ Izz = Aircraft->GetIzz(); ++ Ixz = Aircraft->GetIxz(); ++ ++ for (int r=1;r<=3;r++) ++ for (int c=1;c<=3;c++) ++ T[r][c] = Position->GetT(r,c); ++} ++ ++ ++void FGRotation::PutState(void) ++{ ++} ++ diff --cc Simulator/JSBsim/FGRotation.h index 000000000,000000000..e0b40894b new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGRotation.h @@@ -1,0 -1,0 +1,142 @@@ ++/******************************************************************************* ++ ++ Header: FGRotation.h ++ Author: Jon Berndt ++ Date started: 12/02/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/02/98 JSB Created ++ ++******************************************************************************** ++COMMENTS, REFERENCES, and NOTES ++******************************************************************************** ++[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling ++ Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate ++ School, January 1994 ++[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices", ++ JSC 12960, July 1977 ++[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at ++ NASA-Ames", NASA CR-2497, January 1975 ++[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics", ++ Wiley & Sons, 1979 ISBN 0-471-03032-5 ++[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons, ++ 1982 ISBN 0-471-08936-2 ++ ++ The order of rotations used in this class corresponds to a 3-2-1 sequence, ++ or Y-P-R, or Z-Y-X, if you prefer. ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGROTATION_H ++#define FGROTATION_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#include "FGModel.h" ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGRotation : public FGModel ++{ ++public: ++ FGRotation(FGFDMExec*); ++ ~FGRotation(void); ++ ++ bool Run(void); ++ ++ inline float GetP(void) {return P;} ++ inline float GetQ(void) {return Q;} ++ inline float GetR(void) {return R;} ++ ++ inline float GetPdot(void) {return Pdot;} ++ inline float GetQdot(void) {return Qdot;} ++ inline float GetRdot(void) {return Rdot;} ++ ++ inline float Getphi(void) {return phi;} ++ inline float Gettht(void) {return tht;} ++ inline float Getpsi(void) {return psi;} ++ ++ inline float GetQ0(void) {return Q0;} ++ inline float GetQ1(void) {return Q1;} ++ inline float GetQ2(void) {return Q2;} ++ inline float GetQ3(void) {return Q3;} ++ ++ inline void SetP(float tt) {P = tt;} ++ inline void SetQ(float tt) {Q = tt;} ++ inline void SetR(float tt) {R = tt;} ++ ++ inline void SetPQR(float t1, float t2, float t3) {P=t1; ++ Q=t2; ++ R=t3;} ++ ++ inline void Setphi(float tt) {phi = tt;} ++ inline void Settht(float tt) {tht = tt;} ++ inline void Setpsi(float tt) {psi = tt;} ++ ++ inline void SetEuler(float t1, float t2, float t3) {phi=t1; ++ tht=t2; ++ psi=t3;} ++ ++ inline void SetQ0123(float t1, float t2, float t3, float t4) {Q0=t1; ++ Q1=t2; ++ Q2=t3; ++ Q3=t4;} ++ ++protected: ++ ++private: ++ float P, Q, R; ++ float L, M, N; ++ float Ixx, Iyy, Izz, Ixz; ++ float Q0, Q1, Q2, Q3; ++ float phi, tht, psi; ++ float Pdot, Qdot, Rdot; ++ float Q0dot, Q1dot, Q2dot, Q3dot; ++ float lastPdot, lastQdot, lastRdot; ++ float lastQ0dot, lastQ1dot, lastQ2dot, lastQ3dot; ++ float dt; ++ float T[4][4]; ++ ++ void GetState(void); ++ void PutState(void); ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGState.cpp index 000000000,000000000..92ffa9de4 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGState.cpp @@@ -1,0 -1,0 +1,259 @@@ ++/******************************************************************************* ++ ++ Module: FGState.cpp ++ Author: Jon Berndt ++ Date started: 11/17/98 ++ Called by: FGFDMExec and accessed by all models. ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++See header file. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/17/98 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGAtmosphere.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++FGState::FGState(FGFDMExec* fdex) ++{ ++ FDMExec = fdex; ++ ++ Vt = 0.0; ++ latitude = longitude = 0.0; ++ adot = bdot = 0.0; ++ h = 0.0; ++ a = 1000.0; ++ qbar = 0.0; ++ sim_time = dt = 0.1; ++} ++ ++ ++FGState::~FGState(void) ++{ ++} ++ ++ ++bool FGState::Reset(string path, string fname) ++{ ++ string resetDef; ++ float U, V, W; ++ float phi, tht, psi; ++ float alpha, beta, gamma; ++ float Q0, Q1, Q2, Q3; ++ float T[4][4]; ++ ++ resetDef = path + "/" + FDMExec->GetAircraft()->GetAircraftName() + "/" + fname; ++ ++ ifstream resetfile(resetDef.c_str()); ++ ++ if (resetfile) { ++ resetfile >> U; ++ resetfile >> V; ++ resetfile >> W; ++ resetfile >> latitude; ++ resetfile >> longitude; ++ resetfile >> phi; ++ resetfile >> tht; ++ resetfile >> psi; ++ resetfile >> h; ++ resetfile.close(); ++ ++// Change all angular measurements from degrees (as in config file) to radians ++ ++ gamma = 0.0; ++ if (W != 0.0) ++ alpha = U*U > 0.0 ? atan2(W, U) : 0.0; ++ else ++ alpha = 0.0; ++ if (V != 0.0) ++ beta = U*U+W*W > 0.0 ? atan2(V, (fabs(U)/U)*sqrt(U*U + W*W)) : 0.0; ++ else ++ beta = 0.0; ++ ++ latitude *= M_PI / 180.0; ++ longitude *= M_PI / 180.0; ++ phi *= M_PI / 180.0; ++ tht *= M_PI / 180.0; ++ psi *= M_PI / 180.0; ++ ++ FDMExec->GetTranslation()->SetUVW(U, V, W); ++ FDMExec->GetRotation()->SetEuler(phi, tht, psi); ++ FDMExec->GetTranslation()->SetABG(alpha, beta, gamma); ++ ++ Vt = sqrt(U*U + V*V + W*W); ++ qbar = sqrt(U*U + V*V + W*W); ++ ++ Q0 = sin(psi*0.5)*sin(tht*0.5)*sin(phi*0.5) + cos(psi*0.5)*cos(tht*0.5)*cos(phi*0.5); ++ Q1 = -sin(psi*0.5)*sin(tht*0.5)*cos(phi*0.5) + cos(psi*0.5)*cos(tht*0.5)*sin(phi*0.5); ++ Q2 = sin(psi*0.5)*cos(tht*0.5)*sin(phi*0.5) + cos(psi*0.5)*sin(tht*0.5)*cos(phi*0.5); ++ Q3 = sin(psi*0.5)*cos(tht*0.5)*cos(phi*0.5) - cos(psi*0.5)*sin(tht*0.5)*sin(phi*0.5); ++ ++ FDMExec->GetRotation()->SetQ0123(Q0, Q1, Q2, Q3); ++ ++ T[1][1] = Q0*Q0 + Q1*Q1 - Q2*Q2 - Q3*Q3; ++ T[1][2] = 2*(Q1*Q2 + Q0*Q3); ++ T[1][3] = 2*(Q1*Q3 - Q0*Q2); ++ T[2][1] = 2*(Q1*Q2 - Q0*Q3); ++ T[2][2] = Q0*Q0 - Q1*Q1 + Q2*Q2 - Q3*Q3; ++ T[2][3] = 2*(Q2*Q3 + Q0*Q1); ++ T[3][1] = 2*(Q1*Q3 + Q0*Q2); ++ T[3][2] = 2*(Q2*Q3 - Q0*Q1); ++ T[3][3] = Q0*Q0 - Q1*Q1 - Q2*Q2 + Q3*Q3; ++ ++ FDMExec->GetPosition()->SetT(T[1][1], T[1][2], T[1][3], ++ T[2][1], T[2][2], T[2][3], ++ T[3][1], T[3][2], T[3][3]); ++ ++ return true; ++ } else { ++ cerr << "Unable to load reset file " << fname << endl; ++ return false; ++ } ++} ++ ++ ++bool FGState::StoreData(string fname) ++{ ++ ofstream datafile(fname.c_str()); ++ ++ if (datafile) { ++ datafile << FDMExec->GetTranslation()->GetU(); ++ datafile << FDMExec->GetTranslation()->GetV(); ++ datafile << FDMExec->GetTranslation()->GetW(); ++ datafile << latitude; ++ datafile << longitude; ++ datafile << FDMExec->GetRotation()->Getphi(); ++ datafile << FDMExec->GetRotation()->Gettht(); ++ datafile << FDMExec->GetRotation()->Getpsi(); ++ datafile << h; ++ datafile.close(); ++ return true; ++ } else { ++ cerr << "Could not open dump file " << fname << endl; ++ return false; ++ } ++} ++ ++ ++bool FGState::DumpData(string fname) ++{ ++ ofstream datafile(fname.c_str()); ++ ++ if (datafile) { ++ datafile << "U: " << FDMExec->GetTranslation()->GetU() << endl; ++ datafile << "V: " << FDMExec->GetTranslation()->GetV() << endl; ++ datafile << "W: " << FDMExec->GetTranslation()->GetW() << endl; ++ datafile << "P: " << FDMExec->GetRotation()->GetP() << endl; ++ datafile << "Q: " << FDMExec->GetRotation()->GetQ() << endl; ++ datafile << "R: " << FDMExec->GetRotation()->GetR() << endl; ++ datafile << "L: " << FDMExec->GetAircraft()->GetL() << endl; ++ datafile << "M: " << FDMExec->GetAircraft()->GetM() << endl; ++ datafile << "N: " << FDMExec->GetAircraft()->GetN() << endl; ++ datafile << "latitude: " << latitude << endl; ++ datafile << "longitude: " << longitude << endl; ++ datafile << "alpha: " << FDMExec->GetTranslation()->Getalpha() << endl; ++ datafile << "beta: " << FDMExec->GetTranslation()->Getbeta() << endl; ++ datafile << "gamma: " << FDMExec->GetTranslation()->Getgamma() << endl; ++ datafile << "phi: " << FDMExec->GetRotation()->Getphi() << endl; ++ datafile << "tht: " << FDMExec->GetRotation()->Gettht() << endl; ++ datafile << "psi: " << FDMExec->GetRotation()->Getpsi() << endl; ++ datafile << "Pdot: " << FDMExec->GetRotation()->GetPdot() << endl; ++ datafile << "Qdot: " << FDMExec->GetRotation()->GetQdot() << endl; ++ datafile << "Rdot: " << FDMExec->GetRotation()->GetRdot() << endl; ++ datafile << "h: " << h << endl; ++ datafile << "a: " << a << endl; ++ datafile << "rho: " << FDMExec->GetAtmosphere()->Getrho() << endl; ++ datafile << "qbar: " << qbar << endl; ++ datafile << "sim_time: " << sim_time << endl; ++ datafile << "dt: " << dt << endl; ++ datafile << "m: " << FDMExec->GetAircraft()->GetMass() << endl; ++ datafile.close(); ++ return true; ++ } else { ++ return false; ++ } ++} ++ ++ ++bool FGState::DisplayData(void) ++{ ++ cout << "U: " << FDMExec->GetTranslation()->GetU() << endl; ++ cout << "V: " << FDMExec->GetTranslation()->GetV() << endl; ++ cout << "W: " << FDMExec->GetTranslation()->GetW() << endl; ++ cout << "P: " << FDMExec->GetRotation()->GetP() << endl; ++ cout << "Q: " << FDMExec->GetRotation()->GetQ() << endl; ++ cout << "R: " << FDMExec->GetRotation()->GetR() << endl; ++ cout << "L: " << FDMExec->GetAircraft()->GetL() << endl; ++ cout << "M: " << FDMExec->GetAircraft()->GetM() << endl; ++ cout << "N: " << FDMExec->GetAircraft()->GetN() << endl; ++ cout << "Vt: " << Vt << endl; ++ cout << "latitude: " << latitude << endl; ++ cout << "longitude: " << longitude << endl; ++ cout << "alpha: " << FDMExec->GetTranslation()->Getalpha() << endl; ++ cout << "beta: " << FDMExec->GetTranslation()->Getbeta() << endl; ++ cout << "gamma: " << FDMExec->GetTranslation()->Getgamma() << endl; ++ cout << "phi: " << FDMExec->GetRotation()->Getphi() << endl; ++ cout << "tht: " << FDMExec->GetRotation()->Gettht() << endl; ++ cout << "psi: " << FDMExec->GetRotation()->Getpsi() << endl; ++ cout << "Pdot: " << FDMExec->GetRotation()->GetPdot() << endl; ++ cout << "Qdot: " << FDMExec->GetRotation()->GetQdot() << endl; ++ cout << "Rdot: " << FDMExec->GetRotation()->GetRdot() << endl; ++ cout << "h: " << h << endl; ++ cout << "a: " << a << endl; ++ cout << "rho: " << FDMExec->GetAtmosphere()->Getrho() << endl; ++ cout << "qbar: " << qbar << endl; ++ cout << "sim_time: " << sim_time << endl; ++ cout << "dt: " << dt << endl; ++ cout << "m: " << FDMExec->GetAircraft()->GetMass() << endl; ++ ++ return true; ++} diff --cc Simulator/JSBsim/FGState.h index 000000000,000000000..a5cf6a8f4 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGState.h @@@ -1,0 -1,0 +1,139 @@@ ++/******************************************************************************* ++ ++ Header: FGState.h ++ Author: Jon S. Berndt ++ Date started: 11/17/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++ ++Based on Flightgear code, which is based on LaRCSim. This class wraps all ++global state variables (such as velocity, position, orientation, etc.). ++ ++HISTORY ++-------------------------------------------------------------------------------- ++11/17/98 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGSTATE_H ++#define FGSTATE_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# include STL_STRING ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++ FG_USING_STD(string); ++#else ++# include ++# include ++#endif ++ ++#include "FGDefs.h" ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGFDMExec; ++class FGState ++{ ++public: ++ FGState(FGFDMExec*); ++ ~FGState(void); ++ ++ bool Reset(string, string); ++ bool StoreData(string); ++ bool DumpData(string); ++ bool DisplayData(void); ++ ++ inline float GetVt(void) {return Vt;} ++ ++ inline float Getlatitude(void) {return latitude;} ++ inline float Getlongitude(void) {return longitude;} ++ inline float GetGeodeticLat(void) {return GeodeticLat;} ++ ++ inline float Getadot(void) {return adot;} ++ inline float Getbdot(void) {return bdot;} ++ ++ inline float Geth(void) {return h;} ++ inline float Geta(void) {return a;} ++ inline float GetMach(void) {return Mach;} ++ ++ inline float Getsim_time(void) {return sim_time;} ++ inline float Getdt(void) {return dt;} ++ ++ inline float Getqbar(void) {return qbar;} ++ ++ inline void SetVt(float tt) {Vt = tt;} ++ ++ inline void Setlatitude(float tt) {latitude = tt;} ++ inline void Setlongitude(float tt) {longitude = tt;} ++ inline void SetGeodeticLat(float tt) {GeodeticLat = tt;} ++ ++ inline void Setadot(float tt) {adot = tt;} ++ inline void Setbdot(float tt) {bdot = tt;} ++ ++ inline void Setqbar(float tt) {qbar = tt;} ++ ++ inline void Seth(float tt) {h = tt;} ++ inline void Seta(float tt) {a = tt;} ++ inline void SetMach(float tt) {Mach = tt;} ++ ++ inline float Setsim_time(float tt) {sim_time = tt; return sim_time;} ++ inline void Setdt(float tt) {dt = tt;} ++ ++ inline float IncrTime(void) {sim_time+=dt;return sim_time;} ++ ++private: ++ ++ float Vt; // Total velocity ++ float latitude, longitude; // position ++ float GeodeticLat; // Geodetic Latitude ++ float adot, bdot; // alpha dot and beta dot ++ float h, a; // altitude above sea level, speed of sound ++ float qbar; // dynamic pressure ++ float sim_time, dt; ++ float Mach; // Mach number ++ ++ FGFDMExec* FDMExec; ++ ++protected: ++ ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGTank.cpp index 000000000,000000000..ea1180695 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGTank.cpp @@@ -1,0 -1,0 +1,85 @@@ ++/******************************************************************************* ++ ++ Module: FGTank.cpp ++ Author: Jon Berndt ++ Date started: 01/21/99 ++ Called by: FGAircraft ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++See header file. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/21/99 JSB Created ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++#include "FGTank.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++FGTank::FGTank(ifstream& acfile) ++{ ++ string type; ++ ++ acfile >> type; // Type = 0: fuel, 1: oxidizer ++ if (type == "FUEL") Type = ttFUEL; ++ else if (type == "OXIDIZER") Type = ttOXIDIZER; ++ else Type = ttUNKNOWN; ++ acfile >> X; // inches ++ acfile >> Y; // " ++ acfile >> Z; // " ++ acfile >> Radius; // " ++ acfile >> Capacity; // pounds (amount it can hold) ++ acfile >> Contents; // pounds (amount it is holding) ++ Selected = true; ++ PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0 ++} ++ ++ ++FGTank::~FGTank(void) ++{ ++} ++ ++ ++float FGTank::Reduce(float used) ++{ ++ float shortage; ++ ++ if (used < Contents) { ++ Contents -= used; ++ PctFull = 100.0*Contents/Capacity; ++ return Contents; ++ } else { ++ shortage = Contents - used; ++ Contents = 0.0; ++ PctFull = 0.0; ++ Selected = false; ++ return shortage; ++ } ++} ++ diff --cc Simulator/JSBsim/FGTank.h index 000000000,000000000..a41841c85 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGTank.h @@@ -1,0 -1,0 +1,95 @@@ ++/******************************************************************************* ++ ++ Header: FGTank.h ++ Author: Jon S. Berndt ++ Date started: 01/21/99 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++ ++Based on Flightgear code, which is based on LaRCSim. This class simulates ++a generic Tank. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/21/99 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGTank_H ++#define FGTank_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++#ifdef FGFS ++# include ++# include STL_STRING ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++ FG_USING_STD(string); ++#else ++# include ++# include ++#endif ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGTank ++{ ++public: ++ FGTank(ifstream&); ++ ~FGTank(void); ++ ++ float Reduce(float); ++ int GetType(void) {return Type;} ++ bool GetSelected(void) {return Selected;} ++ float GetPctFull(void) {return PctFull;} ++ float GetContents(void) {return Contents;} ++ ++ enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER}; ++ ++private: ++ TankType Type; ++ float X, Y, Z; ++ float Capacity; ++ float Radius; ++ float PctFull; ++ float Contents; ++ bool Selected; ++ ++protected: ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGTranslation.cpp index 000000000,000000000..63db8801f new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGTranslation.cpp @@@ -1,0 -1,0 +1,146 @@@ ++/******************************************************************************* ++ ++ Module: FGTranslation.cpp ++ Author: Jon Berndt ++ Date started: 12/02/98 ++ Purpose: Integrates the translational EOM ++ Called by: FDMExec ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This class integrates the translational EOM. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/02/98 JSB Created ++ ++******************************************************************************** ++COMMENTS, REFERENCES, and NOTES ++******************************************************************************** ++[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling ++ Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate ++ School, January 1994 ++[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices", ++ JSC 12960, July 1977 ++[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at ++ NASA-Ames", NASA CR-2497, January 1975 ++[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics", ++ Wiley & Sons, 1979 ISBN 0-471-03032-5 ++[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons, ++ 1982 ISBN 0-471-08936-2 ++ ++ The order of rotations used in this class corresponds to a 3-2-1 sequence, ++ or Y-P-R, or Z-Y-X, if you prefer. ++ ++******************************************************************************** ++INCLUDES ++*******************************************************************************/ ++ ++#include "FGTranslation.h" ++#include "FGRotation.h" ++#include "FGAtmosphere.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++#include "FGFCS.h" ++#include "FGAircraft.h" ++#include "FGPosition.h" ++#include "FGAuxiliary.h" ++#include "FGOutput.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++ ++FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex) ++{ ++ Name = "FGTranslation"; ++ Udot = Vdot = Wdot = 0.0; ++} ++ ++ ++FGTranslation::~FGTranslation(void) ++{ ++} ++ ++ ++bool FGTranslation::Run(void) ++{ ++ if (!FGModel::Run()) { ++ ++ GetState(); ++ ++ lastUdot = Udot; ++ lastVdot = Vdot; ++ lastWdot = Wdot; ++ ++ Udot = V*R - W*Q + Fx/Mass; ++ Vdot = W*P - U*R + Fy/Mass; ++ Wdot = U*Q - V*P + Fz/Mass; ++ ++ U += 0.5*dt*rate*(lastUdot + Udot); ++ V += 0.5*dt*rate*(lastVdot + Vdot); ++ W += 0.5*dt*rate*(lastWdot + Wdot); ++ ++ Vt = U*U+V*V+W*W > 0.0 ? sqrt(U*U + V*V + W*W) : 0.0; ++ ++ if (W != 0.0) ++ alpha = U*U > 0.0 ? atan2(W, U) : 0.0; ++ if (V != 0.0) ++ beta = U*U+W*W > 0.0 ? atan2(V, (fabs(U)/U)*sqrt(U*U + W*W)) : 0.0; ++ ++ qbar = 0.5*rho*Vt*Vt; ++ ++ PutState(); ++ } else { ++ } ++ return false; ++} ++ ++ ++void FGTranslation::GetState(void) ++{ ++ dt = State->Getdt(); ++ ++ P = Rotation->GetP(); ++ Q = Rotation->GetQ(); ++ R = Rotation->GetR(); ++ ++ Fx = Aircraft->GetFx(); ++ Fy = Aircraft->GetFy(); ++ Fz = Aircraft->GetFz(); ++ ++ Mass = Aircraft->GetMass(); ++ rho = Atmosphere->Getrho(); ++ ++ phi = Rotation->Getphi(); ++ tht = Rotation->Gettht(); ++ psi = Rotation->Getpsi(); ++} ++ ++ ++void FGTranslation::PutState(void) ++{ ++ State->SetVt(Vt); ++ State->Setqbar(qbar); ++} ++ diff --cc Simulator/JSBsim/FGTranslation.h index 000000000,000000000..bbc3dc297 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGTranslation.h @@@ -1,0 -1,0 +1,127 @@@ ++/******************************************************************************* ++ ++ Header: FGTranslation.h ++ Author: Jon Berndt ++ Date started: 12/02/98 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++12/02/98 JSB Created ++ ++******************************************************************************** ++COMMENTS, REFERENCES, and NOTES ++******************************************************************************** ++[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling ++ Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate ++ School, January 1994 ++[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices", ++ JSC 12960, July 1977 ++[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at ++ NASA-Ames", NASA CR-2497, January 1975 ++[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics", ++ Wiley & Sons, 1979 ISBN 0-471-03032-5 ++[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons, ++ 1982 ISBN 0-471-08936-2 ++ ++ The order of rotations used in this class corresponds to a 3-2-1 sequence, ++ or Y-P-R, or Z-Y-X, if you prefer. ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGTRANSLATION_H ++#define FGTRANSLATION_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#include "FGModel.h" ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGTranslation : public FGModel ++{ ++public: ++ FGTranslation(FGFDMExec*); ++ ~FGTranslation(void); ++ ++ inline float GetU(void) {return U;} ++ inline float GetV(void) {return V;} ++ inline float GetW(void) {return W;} ++ ++ inline float GetUdot(void) {return Udot;} ++ inline float GetVdot(void) {return Vdot;} ++ inline float GetWdot(void) {return Wdot;} ++ ++ inline float Getalpha(void) {return alpha;} ++ inline float Getbeta (void) {return beta; } ++ inline float Getgamma(void) {return gamma;} ++ ++ inline void SetU(float tt) {U = tt;} ++ inline void SetV(float tt) {V = tt;} ++ inline void SetW(float tt) {W = tt;} ++ ++ inline void SetUVW(float t1, float t2, float t3) {U=t1; V=t2; W=t3;} ++ ++ inline void Setalpha(float tt) {alpha = tt;} ++ inline void Setbeta (float tt) {beta = tt;} ++ inline void Setgamma(float tt) {gamma = tt;} ++ ++ inline void SetABG(float t1, float t2, float t3) {alpha=t1; beta=t2; gamma=t3;} ++ ++ bool Run(void); ++ ++protected: ++ ++private: ++ float U, V, W; // Body frame velocities owned by FGTranslation ++ float P, Q, R; ++ float Vt, qbar; ++ float Udot, Vdot, Wdot; ++ float lastUdot, lastVdot, lastWdot; ++ float phi, tht, psi; ++ float Fx, Fy, Fz; ++ float Mass, dt; ++ float alpha, beta, gamma; ++ float rho; ++ ++ void GetState(void); ++ void PutState(void); ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/FGUtility.cpp index 000000000,000000000..f7e7d1de3 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGUtility.cpp @@@ -1,0 -1,0 +1,132 @@@ ++/******************************************************************************* ++ ++ Module: FGUtility.cpp ++ Author: Jon Berndt ++ Date started: 01/09/99 ++ Purpose: Contains utility classes for the FG FDM ++ Called by: FGPosition, et. al. ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++FUNCTIONAL DESCRIPTION ++-------------------------------------------------------------------------------- ++This class is a container for all utility classes used by the flight dynamics ++model. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/09/99 JSB Created ++ ++******************************************************************************** ++DEFINES ++*******************************************************************************/ ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++#ifdef FGFS ++# include ++# ifdef FG_HAVE_STD_INCLUDES ++# include ++# else ++# include ++# endif ++#else ++# include ++#endif ++ ++#include "FGUtility.h" ++#include "FGState.h" ++#include "FGFDMExec.h" ++ ++/******************************************************************************* ++************************************ CODE ************************************** ++*******************************************************************************/ ++ ++FGUtility::FGUtility() ++{ ++ // Move constant stuff to here (if any) so it won't take CPU time ++ // in the methods below. ++ SeaLevelR = EARTHRAD * ECCENT; ++} ++ ++ ++FGUtility::~FGUtility() ++{ ++} ++ ++ ++float FGUtility::ToGeodetic() ++{ ++ float GeodeticLat, Latitude, Radius, Altitude; ++ float tanLat, xAlpha, muAlpha, sinmuAlpha, denom, rhoAlpha, dMu; ++ float lPoint, lambdaSL, sinlambdaSL, dLambda, rAlpha; ++ ++ Latitude = State->Getlatitude(); ++ Radius = State->Geth() + EARTHRAD; ++ ++ if (( M_PI_2 - Latitude < ONESECOND) || ++ ( M_PI_2 + Latitude < ONESECOND)) { // Near a pole ++ GeodeticLat = Latitude; ++ Altitude = Radius - SeaLevelR; ++ } else { ++ tanLat = tan(Latitude); ++ xAlpha = ECCENT*EARTHRAD / ++ sqrt(tanLat*tanLat + ECCENTSQRD); ++ muAlpha = atan2(sqrt(EARTHRADSQRD - xAlpha*xAlpha), ECCENT*xAlpha); ++ ++ if (Latitude < 0.0) muAlpha = -muAlpha; ++ ++ sinmuAlpha = sin(muAlpha); ++ dLambda = muAlpha - Latitude; ++ rAlpha = xAlpha / cos(Latitude); ++ lPoint = Radius - rAlpha; ++ Altitude = lPoint*cos(dLambda); ++ denom = sqrt(1-EPS*EPS*sinmuAlpha*sinmuAlpha); ++ rhoAlpha = EARTHRAD*(1.0 - EPS) / (denom*denom*denom); ++ dMu = atan2(lPoint*sin(dLambda),rhoAlpha + Altitude); ++ State->SetGeodeticLat(muAlpha - dMu); ++ lambdaSL = atan(ECCENTSQRD*tan(GeodeticLat)); ++ sinlambdaSL = sin(lambdaSL); ++ SeaLevelR = sqrt(EARTHRADSQRD / (1 + INVECCENTSQRDM1* sinlambdaSL*sinlambdaSL)); ++ } ++ return 0.0; ++} ++ ++ ++float FGUtility:: FromGeodetic() ++{ ++ float lambdaSL, sinlambdaSL, coslambdaSL, sinMu, cosMu, py, px; ++ float Altitude, SeaLevelR; ++ ++ lambdaSL = atan(ECCENTSQRD*tan(State->GetGeodeticLat())); ++ sinlambdaSL = sin(lambdaSL); ++ coslambdaSL = cos(lambdaSL); ++ sinMu = sin(State->GetGeodeticLat()); ++ cosMu = cos(State->GetGeodeticLat()); ++ SeaLevelR = sqrt(EARTHRADSQRD / ++ (1 + INVECCENTSQRDM1*sinlambdaSL*sinlambdaSL)); ++ px = SeaLevelR*coslambdaSL + Altitude*cosMu; ++ py = SeaLevelR*sinlambdaSL + Altitude*sinMu; ++ State->Setlatitude(atan2(py,px)); ++ return 0.0; ++} ++ diff --cc Simulator/JSBsim/FGUtility.h index 000000000,000000000..d5dc6499a new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/FGUtility.h @@@ -1,0 -1,0 +1,70 @@@ ++/******************************************************************************* ++ ++ Header: FGUtility.h ++ Author: Jon Berndt ++ Date started: 01/09/99 ++ ++ ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- ++ ++ This program is free software; you can redistribute it and/or modify it under ++ the terms of the GNU General Public License as published by the Free Software ++ Foundation; either version 2 of the License, or (at your option) any later ++ version. ++ ++ This program is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ++ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ++ details. ++ ++ You should have received a copy of the GNU General Public License along with ++ this program; if not, write to the Free Software Foundation, Inc., 59 Temple ++ Place - Suite 330, Boston, MA 02111-1307, USA. ++ ++ Further information about the GNU General Public License can also be found on ++ the world wide web at http://www.gnu.org. ++ ++HISTORY ++-------------------------------------------------------------------------------- ++01/09/99 JSB Created ++ ++******************************************************************************** ++SENTRY ++*******************************************************************************/ ++ ++#ifndef FGUTILITY_H ++#define FGUTILITY_H ++ ++/******************************************************************************* ++INCLUDES ++*******************************************************************************/ ++ ++/******************************************************************************* ++DEFINES ++*******************************************************************************/ ++ ++/******************************************************************************* ++CLASS DECLARATION ++*******************************************************************************/ ++ ++class FGFDMExec; ++class FGState; ++ ++class FGUtility ++{ ++public: ++ FGUtility(void); ++ ~FGUtility(void); ++ ++ float ToGeodetic(void); ++ float FromGeodetic(void); ++ ++protected: ++ ++private: ++ float SeaLevelR; ++ FGState* State; ++ FGFDMExec* FDMExec; ++}; ++ ++/******************************************************************************/ ++#endif diff --cc Simulator/JSBsim/Makefile.am index 000000000,000000000..bc540a476 new file mode 100644 --- /dev/null +++ b/Simulator/JSBsim/Makefile.am @@@ -1,0 -1,0 +1,22 @@@ ++noinst_LIBRARIES = libJSBsim.a ++ ++libJSBsim_a_SOURCES = FGAircraft.cpp FGAircraft.h \ ++ FGAtmosphere.cpp FGAtmosphere.h \ ++ FGAuxiliary.cpp FGAuxiliary.h \ ++ FGCoefficient.cpp FGCoefficient.h \ ++ FGDefs.h \ ++ FGFCS.cpp FGFCS.h \ ++ FGFDMExec.cpp FGFDMExec.h \ ++ FGModel.cpp FGModel.h \ ++ FGOutput.cpp FGOutput.h \ ++ FGPosition.cpp FGPosition.h \ ++ FGRotation.cpp FGRotation.h \ ++ FGState.cpp FGState.h \ ++ FGTranslation.cpp FGTranslation.h \ ++ FGUtility.cpp FGUtility.h \ ++ FGEngine.cpp FGEngine.h \ ++ FGTank.cpp FGTank.h ++ ++INCLUDES += -I$(top_builddir) ++ ++DEFS += -DFGFS diff --cc Simulator/Joystick/Makefile.am index 000000000,000000000..416b40d67 new file mode 100644 --- /dev/null +++ b/Simulator/Joystick/Makefile.am @@@ -1,0 -1,0 +1,16 @@@ ++if ENABLE_LINUX_JOYSTICK ++DEFS += -DENABLE_LINUX_JOYSTICK ++else ++DEFS += -DENABLE_GLUT_JOYSTICK ++endif ++ ++EXTRA_DIST = js.cxx ++ ++noinst_LIBRARIES = libJoystick.a ++ ++libJoystick_a_SOURCES = joystick.cxx joystick.hxx js.hxx ++ ++INCLUDES += -I$(top_builddir) \ ++ -I$(top_builddir)/Lib \ ++ -I$(top_builddir)/Lib/plib/include \ ++ -I$(top_builddir)/Simulator diff --cc Simulator/Joystick/joystick.cxx index 000000000,000000000..b5bef5280 new file mode 100644 --- /dev/null +++ b/Simulator/Joystick/joystick.cxx @@@ -1,0 -1,0 +1,253 @@@ ++// joystick.cxx -- joystick support ++// ++// Written by Curtis Olson, started October 1998. ++// ++// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#ifdef HAVE_CONFIG_H ++# include ++#endif ++ ++#ifdef HAVE_WINDOWS_H ++# include ++#endif ++ ++#include ++#include ++ ++#if defined( ENABLE_LINUX_JOYSTICK ) ++# include ++#elif defined( ENABLE_GLUT_JOYSTICK ) ++# include ++# include ++#endif ++ ++ ++#include "joystick.hxx" ++ ++ ++#if defined( ENABLE_LINUX_JOYSTICK ) ++ ++// joystick classes ++static jsJoystick *js0; ++static jsJoystick *js1; ++ ++// these will hold the values of the axes ++static float *js_ax0, *js_ax1; ++ ++#elif defined( ENABLE_GLUT_JOYSTICK ) ++ ++// Do we want these user settable ?? ++static float joy_scale = 1./1000; ++ ++// play with following to get your desired sensitivity ++static int x_dead_zone = 50; ++static int y_dead_zone = 2*x_dead_zone; ++ ++// Joystick support using glut -- William Riley -- riley@technologist.com ++ ++// Joystick fixed values for calibration and scaling ++static float joy_x_max = joy_scale; ++static float joy_y_max = joy_scale; ++ ++static int joy_z_min = 1000, /* joy_z_ctr=0, */ joy_z_max = -1000; ++static int joy_z_dead_min = 100, joy_z_dead_max = -100; ++ ++#else ++# error port me: no joystick support ++#endif ++ ++ ++ ++#if defined( ENABLE_GLUT_JOYSTICK ) ++ ++// Function called by glutJoystickFunc(), adjusts read values and ++// passes them to the necessary aircraft control functions ++void joystick(unsigned int buttonMask, int js_x, int js_y, int js_z) ++{ ++ float joy_x, joy_y, joy_z; ++ // adjust the values to fgfs's scale and allow a 'dead zone' to ++ // reduce jitter code adapted from joystick.c by Michele ++ // F. America - nomimarketing@mail.telepac.pt ++ ++ if( js_x > -x_dead_zone && js_x < x_dead_zone) { ++ joy_x = 0.0; ++ } else { ++ joy_x = js_x * joy_scale; ++ } ++ ++ if( js_y > -y_dead_zone && js_y < y_dead_zone) { ++ joy_y = 0.0; ++ } else { ++ joy_y = js_y * joy_scale; ++ } ++ ++ if( js_z >= joy_z_dead_min && js_z <= joy_z_dead_max ) { ++ joy_z = 0.0; ++ } ++ joy_z = (float)js_z / (float)(joy_z_max - joy_z_min); ++ joy_z = (((joy_z*2.0)+1.0)/2); ++ ++ // Pass the values to the control routines ++ controls.set_elevator( -joy_y ); ++ controls.set_aileron( joy_x ); ++ controls.set_throttle( FGControls::ALL_ENGINES, joy_z ); ++} ++ ++#endif // ENABLE_GLUT_JOYSTICK ++ ++ ++// Initialize the joystick(s) ++int fgJoystickInit( void ) { ++ ++ FG_LOG( FG_INPUT, FG_INFO, "Initializing joystick" ); ++ ++#if defined( ENABLE_LINUX_JOYSTICK ) ++ ++ js0 = new jsJoystick ( 0 ); ++ js1 = new jsJoystick ( 1 ); ++ ++ if ( js0->notWorking () ) { ++ // not working ++ } else { ++ // allocate storage for axes values ++ js_ax0 = new float [ js0->getNumAxes() ]; ++ ++ // configure ++ js0->setDeadBand( 0, 0.1 ); ++ js0->setDeadBand( 1, 0.1 ); ++ ++ FG_LOG ( FG_INPUT, FG_INFO, ++ " Joystick 0 detected with " << js0->getNumAxes() ++ << " axes" ); ++ } ++ ++ if ( js1->notWorking () ) { ++ // not working ++ } else { ++ // allocate storage for axes values ++ js_ax1 = new float [ js1->getNumAxes() ]; ++ ++ // configure ++ js1->setDeadBand( 0, 0.1 ); ++ js1->setDeadBand( 1, 0.1 ); ++ ++ FG_LOG ( FG_INPUT, FG_INFO, ++ " Joystick 1 detected with " << js1->getNumAxes() ++ << " axes" ); ++ } ++ ++ if ( js0->notWorking() && js1->notWorking() ) { ++ FG_LOG ( FG_INPUT, FG_INFO, " No joysticks detected" ); ++ return 0; ++ } ++ ++#elif defined( ENABLE_GLUT_JOYSTICK ) ++ ++ glutJoystickFunc(joystick, 100); ++ ++#else ++# error port me: no joystick support ++#endif ++ ++ return 1; ++} ++ ++ ++#if defined( ENABLE_LINUX_JOYSTICK ) ++ ++// update the control parameters based on joystick intput ++int fgJoystickRead( void ) { ++ int b; ++ ++ if ( ! js0->notWorking() ) { ++ js0->read( &b, js_ax0 ) ; ++ controls.set_aileron( js_ax0[0] ); ++ controls.set_elevator( -js_ax0[1] ); ++ } ++ ++ if ( ! js1->notWorking() ) { ++ js1->read( &b, js_ax1 ) ; ++ controls.set_rudder( js_ax1[0] ); ++ controls.set_throttle( FGControls::ALL_ENGINES, -js_ax1[1] * 1.05 ); ++ } ++ ++ return 1; ++} ++ ++#endif // ENABLE_LINUX_JOYSTICK ++ ++ ++// $Log$ ++// Revision 1.8 1999/04/03 04:20:33 curt ++// Integration of Steve's plib conglomeration. ++// ++// Revision 1.7 1999/01/19 17:52:30 curt ++// Some joystick tweaks by Norman Vine. ++// ++// Revision 1.6 1998/12/05 16:13:16 curt ++// Renamed class fgCONTROLS to class FGControls. ++// ++// Revision 1.5 1998/11/06 21:18:04 curt ++// Converted to new logstream debugging facility. This allows release ++// builds with no messages at all (and no performance impact) by using ++// the -DFG_NDEBUG flag. ++// ++// Revision 1.4 1998/10/27 02:14:32 curt ++// Changes to support GLUT joystick routines as fall back. ++// ++// Revision 1.3 1998/10/25 14:08:44 curt ++// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. ++// ++// Revision 1.2 1998/10/25 10:56:25 curt ++// Completely rewritten to use Steve Baker's joystick interface class. ++// ++// Revision 1.1 1998/10/24 22:28:16 curt ++// Renamed joystick.[ch] to joystick.[ch]xx ++// Added js.hxx which is Steve's joystick interface class. ++// ++// Revision 1.7 1998/04/25 22:06:29 curt ++// Edited cvs log messages in source files ... bad bad bad! ++// ++// Revision 1.6 1998/04/18 04:14:05 curt ++// Moved fg_debug.c to it's own library. ++// ++// Revision 1.5 1998/02/12 21:59:44 curt ++// Incorporated code changes contributed by Charlie Hotchkiss ++// ++// ++// Revision 1.4 1998/02/03 23:20:20 curt ++// Lots of little tweaks to fix various consistency problems discovered by ++// Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper ++// passed arguments along to the real printf(). Also incorporated HUD changes ++// by Michele America. ++// ++// Revision 1.3 1998/01/27 00:47:54 curt ++// Incorporated Paul Bleisch's new debug message ++// system and commandline/config file processing code. ++// ++// Revision 1.2 1997/12/30 20:47:40 curt ++// Integrated new event manager with subsystem initializations. ++// ++// Revision 1.1 1997/08/29 18:06:54 curt ++// Initial revision. ++// ++ diff --cc Simulator/Joystick/joystick.hxx index 000000000,000000000..23bebedc6 new file mode 100644 --- /dev/null +++ b/Simulator/Joystick/joystick.hxx @@@ -1,0 -1,0 +1,66 @@@ ++// joystick.cxx -- joystick support ++// ++// Written by Curtis Olson, started October 1998. ++// ++// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#ifndef _JOYSTICK_HXX ++#define _JOYSTICK_HXX ++ ++ ++#ifndef __cplusplus ++# error This library requires C++ ++#endif ++ ++ ++// Initialize the joystick(s) ++int fgJoystickInit( void ); ++ ++#if defined( ENABLE_LINUX_JOYSTICK ) ++ // update the control parameters based on joystick intput ++ int fgJoystickRead( void ); ++#endif // ENABLE_LINUX_JOYSTICK ++ ++ ++#endif // _JOYSTICK_HXX ++ ++ ++// $Log$ ++// Revision 1.3 1998/10/27 02:14:33 curt ++// Changes to support GLUT joystick routines as fall back. ++// ++// Revision 1.2 1998/10/25 10:56:27 curt ++// Completely rewritten to use Steve Baker's joystick interface class. ++// ++// Revision 1.1 1998/10/24 22:28:18 curt ++// Renamed joystick.[ch] to joystick.[ch]xx ++// Added js.hxx which is Steve's joystick interface class. ++// ++// Revision 1.3 1998/04/22 13:26:21 curt ++// C++ - ifing the code a bit. ++// ++// Revision 1.2 1998/01/22 02:59:36 curt ++// Changed #ifdef FILE_H to #ifdef _FILE_H ++// ++// Revision 1.1 1997/08/29 18:06:55 curt ++// Initial revision. ++// ++ diff --cc Simulator/LaRCsim/Makefile.am index 000000000,000000000..318df20b0 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/Makefile.am @@@ -1,0 -1,0 +1,26 @@@ ++if ENABLE_CHEROKEE ++AIRCRAFT_MODEL = cherokee_aero.c cherokee_engine.c cherokee_gear.c cherokee_init.c navion_init.h ++else ++AIRCRAFT_MODEL = navion_aero.c navion_engine.c navion_gear.c navion_init.c navion_init.h ++endif ++ ++noinst_LIBRARIES = libLaRCsim.a ++ ++libLaRCsim_a_SOURCES = \ ++ atmos_62.c atmos_62.h \ ++ default_model_routines.c default_model_routines.h \ ++ ls_accel.c ls_accel.h \ ++ ls_aux.c ls_aux.h \ ++ ls_cockpit.h ls_constants.h ls_generic.h \ ++ ls_geodesy.c ls_geodesy.h \ ++ ls_gravity.c ls_gravity.h \ ++ ls_init.c ls_init.h \ ++ ls_matrix.c ls_matrix.h \ ++ ls_model.c ls_model.h \ ++ ls_sim_control.h \ ++ ls_step.c ls_step.h \ ++ ls_sym.h ls_types.h \ ++ $(AIRCRAFT_MODEL) \ ++ ls_interface.c ls_interface.h ++ ++INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator diff --cc Simulator/LaRCsim/atmos_62.c index 000000000,000000000..3c351882c new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/atmos_62.c @@@ -1,0 -1,0 +1,272 @@@ ++/*************************************************************************** ++ ++ TITLE: atmos_62 ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: 1962 atmosphere table interpolation routine ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 920827 by Bruce Jackson as part of the C-castle ++ development effort. ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: B. Jackson ++ ++ CODED BY: B. Jackson ++ ++ MAINTAINED BY: B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ 931220 Added ambient pressure and temperature as outputs. EBJ ++ 940111 Changed includes from "ls_eom.h" to "ls_types.h" and ++ "ls_constants.h"; changed DATA to SCALAR types. EBJ ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++ [ 1] Hornbeck, Robert W.: "Numerical Methods", Prentice-Hall, ++ 1975. ISBN 0-13-626614-2 ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++ ++#include "ls_types.h" ++#include "ls_constants.h" ++ ++#include "atmos_62.h" ++ ++#include ++ ++#define alt_0 d_a_table[index ][0] ++#define alt_1 d_a_table[index+1][0] ++#define den_0 d_a_table[index ][1] ++#define den_1 d_a_table[index+1][1] ++#define sps_0 d_a_table[index ][2] ++#define sps_1 d_a_table[index+1][2] ++#define gden_0 d_a_table[index ][3] ++#define gden_1 d_a_table[index+1][3] ++#define gsps_0 d_a_table[index ][4] ++#define gsps_1 d_a_table[index+1][4] ++ ++#define MAX_ALT_INDEX 121 ++#define DELT_ALT 2000. ++#define HLEV 36089. ++#define TAMB0 518.7 ++#define PAMB0 2113.8 ++#define MAX_ALTITUDE 240000. ++ ++void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound, ++ SCALAR * t_amb, SCALAR * p_amb ) ++{ ++ ++ int index; ++ SCALAR daltp, daltn, daltp3, daltn3, density; ++ SCALAR t_amb_r, p_amb_r; ++ SCALAR tmp; ++ ++ static SCALAR d_a_table[MAX_ALT_INDEX][5] = ++ { ++ { 0., 2.37701E-03, 1.11642E+03, 0.00000E+00, 0.00000E+00 }, ++ { 2000., 2.24098E-03, 1.10872E+03, 1.92857E-12, -1.75815E-08 }, ++ { 4000., 2.11099E-03, 1.10097E+03, 1.34570E-12, -1.21740E-08 }, ++ { 6000., 1.98684E-03, 1.09315E+03, 1.44862E-12, -1.47225E-08 }, ++ { 8000., 1.86836E-03, 1.08529E+03, 1.36481E-12, -1.44359E-08 }, ++ { 10000., 1.75537E-03, 1.07736E+03, 1.32716E-12, -1.45340E-08 }, ++ { 12000., 1.64768E-03, 1.06938E+03, 1.27657E-12, -1.44280E-08 }, ++ { 14000., 1.54511E-03, 1.06133E+03, 1.24656E-12, -1.62540E-08 }, ++ { 16000., 1.44751E-03, 1.05323E+03, 1.19220E-12, -1.50560E-08 }, ++ { 18000., 1.35469E-03, 1.04506E+03, 1.15463E-12, -1.65220E-08 }, ++ { 20000., 1.26649E-03, 1.03683E+03, 1.11926E-12, -1.63562E-08 }, ++ { 22000., 1.18276E-03, 1.02853E+03, 1.07333E-12, -1.70533E-08 }, ++ { 24000., 1.10333E-03, 1.02016E+03, 1.03743E-12, -1.59305E-08 }, ++ { 26000., 1.02805E-03, 1.01173E+03, 1.00195E-12, -2.27248E-08 }, ++ { 28000., 9.56760E-04, 1.00322E+03, 9.39764E-13, 3.29851E-10 }, ++ { 30000., 8.89320E-04, 9.94641E+02, 1.01399E-12, -8.80946E-08 }, ++ { 32000., 8.25570E-04, 9.85988E+02, 5.39268E-13, 2.41048E-07 }, ++ { 34000., 7.65380E-04, 9.77258E+02, 2.16894E-12, -9.91599E-07 }, ++ { 36000., 7.08600E-04, 9.68448E+02, -4.10001E-12, 3.60535E-06 }, ++ { 38000., 6.44190E-04, 9.68053E+02, 2.78612E-12, -8.07290E-07 }, ++ { 40000., 5.85146E-04, 9.68053E+02, 1.00455E-12, 2.16313E-07 }, ++ { 42000., 5.31517E-04, 9.68053E+02, 1.31819E-12, -5.79609E-08 }, ++ { 44000., 4.82801E-04, 9.68053E+02, 1.09217E-12, 1.55309E-08 }, ++ { 46000., 4.38554E-04, 9.68053E+02, 1.01661E-12, -4.16262E-09 }, ++ { 48000., 3.98359E-04, 9.68053E+02, 9.19375E-13, 1.11961E-09 }, ++ { 50000., 3.61850E-04, 9.68053E+02, 8.34886E-13, -3.15801E-10 }, ++ { 52000., 3.28686E-04, 9.68053E+02, 7.58579E-13, 1.43600E-10 }, ++ { 54000., 2.98561E-04, 9.68053E+02, 6.89297E-13, -2.58597E-10 }, ++ { 56000., 2.71197E-04, 9.68053E+02, 6.25735E-13, 8.90788E-10 }, ++ { 58000., 2.46341E-04, 9.68053E+02, 5.69765E-13, -3.30456E-09 }, ++ { 60000., 2.23765E-04, 9.68053E+02, 5.15206E-13, 1.23274E-08 }, ++ { 62000., 2.03256E-04, 9.68053E+02, 4.69912E-13, -4.60052E-08 }, ++ { 64000., 1.84627E-04, 9.68053E+02, 4.25146E-13, 1.71693E-07 }, ++ { 66000., 1.67616E-04, 9.68314E+02, 2.56502E-13, -2.49268E-07 }, ++ { 68000., 1.51855E-04, 9.68676E+02, 4.23844E-13, 9.76878E-07 }, ++ { 70000., 1.37615E-04, 9.71034E+02, 3.29621E-13, -6.64245E-07 }, ++ { 72000., 1.24744E-04, 9.72390E+02, 3.11170E-13, 1.77102E-07 }, ++ { 74000., 1.13107E-04, 9.73745E+02, 2.76697E-13, -4.56627E-08 }, ++ { 76000., 1.02584E-04, 9.75099E+02, 2.53043E-13, 4.04902E-09 }, ++ { 78000., 9.30660E-05, 9.76450E+02, 2.18633E-13, 2.49667E-08 }, ++ { 80000., 8.44530E-05, 9.77799E+02, 2.29927E-13, -1.06916E-07 }, ++ { 82000., 7.67140E-05, 9.78950E+02, 1.72660E-13, 1.05696E-07 }, ++ { 84000., 6.97010E-05, 9.80290E+02, 1.68432E-13, -3.23682E-08 }, ++ { 86000., 6.33490E-05, 9.81620E+02, 1.45113E-13, 8.77690E-09 }, ++ { 88000., 5.75880E-05, 9.82950E+02, 1.37617E-13, -2.73938E-09 }, ++ { 90000., 5.23700E-05, 9.84280E+02, 1.18918E-13, 2.18061E-09 }, ++ { 92000., 4.76350E-05, 9.85610E+02, 1.11210E-13, -5.98306E-09 }, ++ { 94000., 4.33410E-05, 9.86930E+02, 9.77408E-14, 6.75162E-09 }, ++ { 96000., 3.94430E-05, 9.88260E+02, 9.18264E-14, -6.02343E-09 }, ++ { 98000., 3.59080E-05, 9.89580E+02, 7.94534E-14, 2.34210E-09 }, ++ { 100000., 3.26960E-05, 9.90900E+02, 7.48600E-14, -3.34498E-09 }, ++ { 102000., 2.97810E-05, 9.92210E+02, 6.66067E-14, -3.96219E-09 }, ++ { 104000., 2.71320E-05, 9.93530E+02, 5.77131E-14, 3.41937E-08 }, ++ { 106000., 2.46980E-05, 9.95410E+02, 2.50410E-14, 7.07187E-07 }, ++ { 108000., 2.24140E-05, 9.99070E+02, 6.71229E-14, -1.92943E-07 }, ++ { 110000., 2.03570E-05, 1.00272E+03, 4.69675E-14, 4.95832E-08 }, ++ { 112000., 1.85010E-05, 1.00636E+03, 4.65069E-14, -2.03903E-08 }, ++ { 114000., 1.68270E-05, 1.00998E+03, 4.00047E-14, 1.97789E-09 }, ++ { 116000., 1.53150E-05, 1.01359E+03, 3.64744E-14, -2.52130E-09 }, ++ { 118000., 1.39480E-05, 1.01719E+03, 3.15976E-14, -6.89271E-09 }, ++ { 120000., 1.27100E-05, 1.02077E+03, 3.06351E-14, 9.21465E-11 }, ++ { 122000., 1.15920E-05, 1.02434E+03, 2.58618E-14, -8.47587E-09 }, ++ { 124000., 1.05790E-05, 1.02789E+03, 2.34176E-14, 3.81135E-09 }, ++ { 126000., 9.66010E-06, 1.03144E+03, 2.16178E-14, -6.76951E-09 }, ++ { 128000., 8.82710E-06, 1.03497E+03, 1.89611E-14, -6.73330E-09 }, ++ { 130000., 8.07070E-06, 1.03848E+03, 1.74377E-14, 3.70270E-09 }, ++ { 132000., 7.38380E-06, 1.04199E+03, 1.55382E-14, -8.07752E-09 }, ++ { 134000., 6.75940E-06, 1.04548E+03, 1.41595E-14, -1.39263E-09 }, ++ { 136000., 6.19160E-06, 1.04896E+03, 1.27239E-14, -1.35196E-09 }, ++ { 138000., 5.67490E-06, 1.05243E+03, 1.15951E-14, -8.19953E-09 }, ++ { 140000., 5.20450E-06, 1.05588E+03, 1.03459E-14, 4.15010E-09 }, ++ { 142000., 4.77570E-06, 1.05933E+03, 9.42149E-15, -8.40086E-09 }, ++ { 144000., 4.38470E-06, 1.06276E+03, 8.66820E-15, -5.46671E-10 }, ++ { 146000., 4.02820E-06, 1.06618E+03, 7.65573E-15, -4.41246E-09 }, ++ { 148000., 3.70260E-06, 1.06959E+03, 7.05890E-15, 3.19650E-09 }, ++ { 150000., 3.40520E-06, 1.07299E+03, 6.40867E-15, -2.33736E-08 }, ++ { 152000., 3.13330E-06, 1.07637E+03, 5.55641E-15, 6.02977E-08 }, ++ { 154000., 2.88480E-06, 1.07975E+03, 6.46568E-15, -2.17817E-07 }, ++ { 156000., 2.66270E-06, 1.08202E+03, 8.18087E-15, -8.54029E-07 }, ++ { 158000., 2.46830E-06, 1.08202E+03, 2.36086E-15, 2.28931E-07 }, ++ { 160000., 2.28810E-06, 1.08202E+03, 3.67571E-15, -6.16972E-08 }, ++ { 162000., 2.12120E-06, 1.08202E+03, 2.88632E-15, 1.78573E-08 }, ++ { 164000., 1.96640E-06, 1.08202E+03, 2.92903E-15, -9.73206E-09 }, ++ { 166000., 1.82300E-06, 1.08202E+03, 2.49757E-15, 2.10709E-08 }, ++ { 168000., 1.69000E-06, 1.08202E+03, 2.68069E-15, -7.45517E-08 }, ++ { 170000., 1.56680E-06, 1.08202E+03, 1.47966E-15, 2.77136E-07 }, ++ { 172000., 1.45250E-06, 1.08202E+03, 4.75068E-15, -1.03399E-06 }, ++ { 174000., 1.35240E-06, 1.07963E+03, 8.17622E-16, 2.73830E-07 }, ++ { 176000., 1.25880E-06, 1.07723E+03, 1.72883E-15, -7.63301E-08 }, ++ { 178000., 1.17130E-06, 1.07482E+03, 1.41704E-15, 1.64901E-08 }, ++ { 180000., 1.08960E-06, 1.07240E+03, 1.30299E-15, -4.63038E-09 }, ++ { 182000., 1.01320E-06, 1.06998E+03, 1.32100E-15, 2.03140E-09 }, ++ { 184000., 9.41950E-07, 1.06756E+03, 1.13799E-15, -3.49522E-09 }, ++ { 186000., 8.75370E-07, 1.06513E+03, 1.13202E-15, -3.05052E-09 }, ++ { 188000., 8.13260E-07, 1.06269E+03, 1.03892E-15, 6.97283E-10 }, ++ { 190000., 7.55320E-07, 1.06025E+03, 9.67290E-16, 2.61383E-10 }, ++ { 192000., 7.01260E-07, 1.05781E+03, 9.11920E-16, -1.74281E-09 }, ++ { 194000., 6.50850E-07, 1.05536E+03, 8.60032E-16, -8.29013E-09 }, ++ { 196000., 6.03870E-07, 1.05290E+03, 7.92951E-16, 1.99033E-08 }, ++ { 198000., 5.60110E-07, 1.05044E+03, 7.98164E-16, -7.13232E-08 }, ++ { 200000., 5.19320E-07, 1.04798E+03, 4.69394E-16, 2.65389E-07 }, ++ { 202000., 4.81340E-07, 1.04550E+03, 1.53926E-15, -1.02023E-06 }, ++ { 204000., 4.47960E-07, 1.04063E+03, 2.73571E-16, 2.30547E-07 }, ++ { 206000., 4.16690E-07, 1.03565E+03, 5.31456E-16, -6.69551E-08 }, ++ { 208000., 3.87320E-07, 1.03065E+03, 4.50605E-16, 7.27308E-09 }, ++ { 210000., 3.59790E-07, 1.02562E+03, 4.26126E-16, -7.13720E-09 }, ++ { 212000., 3.33970E-07, 1.02057E+03, 4.09893E-16, -8.72426E-09 }, ++ { 214000., 3.09780E-07, 1.01549E+03, 3.79301E-16, -2.96576E-09 }, ++ { 216000., 2.87120E-07, 1.01039E+03, 3.67902E-16, -9.41272E-09 }, ++ { 218000., 2.65920E-07, 1.00526E+03, 3.39092E-16, -4.38337E-09 }, ++ { 220000., 2.46090E-07, 1.00011E+03, 3.30732E-16, -3.05378E-09 }, ++ { 222000., 2.27570E-07, 9.94940E+02, 3.02981E-16, -1.34015E-08 }, ++ { 224000., 2.10270E-07, 9.89730E+02, 2.87343E-16, -3.34027E-09 }, ++ { 226000., 1.94120E-07, 9.84500E+02, 2.72646E-16, -3.23743E-09 }, ++ { 228000., 1.79060E-07, 9.79250E+02, 2.57074E-16, -1.37100E-08 }, ++ { 230000., 1.65030E-07, 9.73960E+02, 2.44060E-16, -1.92258E-09 }, ++ { 232000., 1.51970E-07, 9.68650E+02, 2.21687E-16, -8.59969E-09 }, ++ { 234000., 1.39810E-07, 9.63310E+02, 2.19191E-16, -8.67865E-09 }, ++ { 236000., 1.28510E-07, 9.57940E+02, 1.91549E-16, -1.68569E-09 }, ++ { 238000., 1.18020E-07, 9.52550E+02, 2.29613E-16, -1.45786E-08 }, ++ { 240000., 1.08270E-07, 9.47120E+02, 0.00000E+00, 0.00000E+00 } ++ }; ++ ++ /* for purposes of doing the table lookup, force the incoming ++ altitude to be >= 0 */ ++ ++ // printf("altitude = %.2f\n", altitude); ++ ++ if ( altitude < 0.0 ) { ++ altitude = 0.0; ++ } ++ ++ // printf("altitude = %.2f\n", altitude); ++ ++ index = (int)( altitude / 2000 ); ++ if (index > (MAX_ALT_INDEX-2)) ++ { ++ index = MAX_ALT_INDEX-2; /* limit maximum altitude */ ++ altitude = MAX_ALTITUDE; ++ } ++ if (index < 0) index = 0; ++ daltp = alt_1 - altitude; ++ daltp3 = daltp*daltp*daltp; ++ daltn = altitude - alt_0; ++ daltn3 = daltn*daltn*daltn; ++ ++ density = (gden_0/6)*((daltp3/2000) - 2000*daltp) ++ + (gden_1/6)*((daltn3/2000) - 2000*daltn) ++ + den_0*daltp/2000 + den_1*daltn/2000; ++ ++ *v_sound = (gsps_0/6)*((daltp3/2000) - 2000*daltp) ++ + (gsps_1/6)*((daltn3/2000) - 2000*daltn) ++ + sps_0*daltp/2000 + sps_1*daltn/2000; ++ ++ *sigma = density/SEA_LEVEL_DENSITY; ++ ++ if (altitude < HLEV) /* BUG - these curve fits are only good to about 75000 ft */ ++ { ++ 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 ); ++ tmp = 5.256; // avoid a segfault (?) ++ p_amb_r = pow( t_amb_r, tmp ); ++ // printf("p_amb_r = %.2f\n", p_amb_r); ++ } ++ else ++ { ++ t_amb_r = 0.751895; ++ p_amb_r = 0.2234*exp( -4.806e-5 * (altitude - HLEV)); ++ } ++ ++ *p_amb = p_amb_r * PAMB0; ++ *t_amb = t_amb_r * TAMB0; ++ ++/* end of atmos_62 */ ++} ++/**************************************************************************/ diff --cc Simulator/LaRCsim/atmos_62.h index 000000000,000000000..f192cac11 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/atmos_62.h @@@ -1,0 -1,0 +1,12 @@@ ++/* a quick atmos_62.h */ ++ ++ ++#ifndef _ATMOS_62_H ++#define _ATMOS_62_H ++ ++ ++void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound, ++ SCALAR * t_amb, SCALAR * p_amb ); ++ ++ ++#endif /* _ATMOS_62_H */ diff --cc Simulator/LaRCsim/default_model_routines.c index 000000000,000000000..4fb611c95 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/default_model_routines.c @@@ -1,0 -1,0 +1,92 @@@ ++/*************************************************************************** ++ ++ TITLE: engine.c ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: dummy engine routine ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: incomplete ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 15 OCT 92 as dummy routine for checkout. EBJ ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: designer ++ ++ CODED BY: programmer ++ ++ MAINTAINED BY: maintainer ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ CURRENT RCS HEADER INFO: ++ ++$Header$ ++ ++$Log$ ++Revision 1.3 1998/08/06 12:46:37 curt ++Header change. ++ ++Revision 1.2 1998/01/19 18:40:23 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:09:53 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.3 1994/01/11 19:10:45 bjax ++ * Removed include files. ++ * ++ * Revision 1.2 1993/03/14 12:16:10 bjax ++ * simple correction: added ';' to end of default routines. EBJ ++ * ++ * Revision 1.1 93/03/10 06:43:46 bjax ++ * Initial revision ++ * ++ * Revision 1.1 92/12/30 13:21:46 bjax ++ * Initial revision ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ls_model(); ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: none ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++ ++ ++#include "ls_types.h" ++#include "default_model_routines.h" ++ ++void inertias( SCALAR dt, int Initialize ) {} ++void subsystems( SCALAR dt, int Initialize ) {} ++/* void engine() {} */ ++/* void gear() {} */ ++ ++ ++ ++ diff --cc Simulator/LaRCsim/default_model_routines.h index 000000000,000000000..930441ae7 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/default_model_routines.h @@@ -1,0 -1,0 +1,18 @@@ ++/* a quick default_model_routines.h */ ++ ++ ++#ifndef _DEFAULT_MODEL_ROUTINES_H ++#define _DEFAULT_MODEL_ROUTINES_H ++ ++ ++#include "ls_types.h" ++ ++ ++void inertias( SCALAR dt, int Initialize ); ++void subsystems( SCALAR dt, int Initialize ); ++void aero( SCALAR dt, int Initialize ); ++void engine( SCALAR dt, int Initialize ); ++void gear( SCALAR dt, int Initialize ); ++ ++ ++#endif /* _DEFAULT_MODEL_ROUTINES_H */ diff --cc Simulator/LaRCsim/ls_accel.c index 000000000,000000000..7e419fdef new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_accel.c @@@ -1,0 -1,0 +1,216 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_Accel ++ ++ ---------------------------------------------------------------------------- ++ ++ FUNCTION: Sums forces and moments and calculates accelerations ++ ++ ---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++ ---------------------------------------------------------------------------- ++ ++ GENEALOGY: Written 920731 by Bruce Jackson. Based upon equations ++ given in reference [1] and a Matrix-X/System Build block ++ diagram model of equations of motion coded by David Raney ++ at NASA-Langley in June of 1992. ++ ++ ---------------------------------------------------------------------------- ++ ++ DESIGNED BY: Bruce Jackson ++ ++ CODED BY: Bruce Jackson ++ ++ MAINTAINED BY: ++ ++ ---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE ++ ++ 931007 Moved calculations of auxiliary accelerations here from ls_aux.c BY ++ and corrected minus sign in front of A_Y_Pilot ++ contribution from Q_body*P_body*D_X_pilot term. ++ 940111 Changed DATA to SCALAR; updated header files ++ ++$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. ++ ++Revision 1.2 1998/01/19 18:40:24 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:09:53 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.5 1994/01/11 18:42:16 bjax ++ * Oops! Changed data types from DATA to SCALAR for precision control. ++ * ++ * Revision 1.4 1994/01/11 18:36:58 bjax ++ * Removed ls_eom.h include directive; replaced with ls_types, ls_constants, ++ * and ls_generic.h includes. ++ * ++ * Revision 1.3 1993/10/07 18:45:24 bjax ++ * Added local defn of d[xyz]_pilot_from_cg to support previous mod. EBJ ++ * ++ * Revision 1.2 1993/10/07 18:41:31 bjax ++ * Moved calculations of auxiliary accelerations here from ls_aux, and ++ * corrected sign on Q_body*P_body*d_x_pilot term of A_Y_pilot calc. EBJ ++ * ++ * Revision 1.1 1992/12/30 13:17:02 bjax ++ * Initial revision ++ * ++ ++ ---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++ [ 1] McFarland, Richard E.: "A Standard Kinematic Model ++ for Flight Simulation at NASA-Ames", NASA CR-2497, ++ January 1975 ++ ++ ---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++ ---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++ ---------------------------------------------------------------------------- ++ ++ INPUTS: Aero, engine, gear forces & moments ++ ++ ---------------------------------------------------------------------------- ++ ++ OUTPUTS: State derivatives ++ ++ -------------------------------------------------------------------------*/ ++#include "ls_types.h" ++#include "ls_generic.h" ++#include "ls_constants.h" ++#include "ls_accel.h" ++#include ++ ++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 */ ++ ++ ++ F_X = F_X_aero + F_X_engine + F_X_gear; ++ F_Y = F_Y_aero + F_Y_engine + F_Y_gear; ++ F_Z = F_Z_aero + F_Z_engine + F_Z_gear; ++ ++ M_l_rp = M_l_aero + M_l_engine + M_l_gear; ++ M_m_rp = M_m_aero + M_m_engine + M_m_gear; ++ M_n_rp = M_n_aero + M_n_engine + M_n_gear; ++ ++ /* Transfer moments to center of gravity */ ++ ++ M_l_cg = M_l_rp + F_Y*Dz_cg - F_Z*Dy_cg; ++ M_m_cg = M_m_rp + F_Z*Dx_cg - F_X*Dz_cg; ++ M_n_cg = M_n_rp + F_X*Dy_cg - F_Y*Dx_cg; ++ ++ /* Transform from body to local frame */ ++ ++ F_north = T_local_to_body_11*F_X + T_local_to_body_21*F_Y ++ + T_local_to_body_31*F_Z; ++ F_east = T_local_to_body_12*F_X + T_local_to_body_22*F_Y ++ + T_local_to_body_32*F_Z; ++ F_down = T_local_to_body_13*F_X + T_local_to_body_23*F_Y ++ + T_local_to_body_33*F_Z; ++ ++ /* 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); ++ V_dot_east = inv_Mass*F_east + ++ 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); ++ ++ /* Invert the symmetric inertia matrix */ ++ ++ ixz2 = I_xz*I_xz; ++ c0 = 1/(I_xx*I_zz - ixz2); ++ c1 = c0*((I_yy-I_zz)*I_zz - ixz2); ++ 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 = c4*(I_yy - I_zz - I_xx); ++ c10 = c0*I_xx; ++ ++ /* Calculate the rotational body axis accelerations */ ++ ++ P_dot_body = (c1*R_body + c2*P_body)*Q_body + c3*M_l_cg + c4*M_n_cg; ++ Q_dot_body = c5*R_body*P_body + c6*(R_body*R_body - P_body*P_body) + c7*M_m_cg; ++ R_dot_body = (c8*P_body + c9*R_body)*Q_body + c4*M_l_cg + c10*M_n_cg; ++ ++ /* Calculate body axis accelerations (move to ls_accel?) */ ++ ++ inv_Mass = 1/Mass; ++ ++ A_X_cg = F_X * inv_Mass; ++ A_Y_cg = F_Y * inv_Mass; ++ A_Z_cg = F_Z * inv_Mass; ++ ++ dx_pilot_from_cg = Dx_pilot - Dx_cg; ++ dy_pilot_from_cg = Dy_pilot - Dy_cg; ++ dz_pilot_from_cg = Dz_pilot - Dz_cg; ++ ++ A_X_pilot = A_X_cg + (-R_body*R_body - Q_body*Q_body)*dx_pilot_from_cg ++ + ( P_body*Q_body - R_dot_body )*dy_pilot_from_cg ++ + ( P_body*R_body + Q_dot_body )*dz_pilot_from_cg; ++ A_Y_pilot = A_Y_cg + ( P_body*Q_body + R_dot_body )*dx_pilot_from_cg ++ + (-P_body*P_body - R_body*R_body)*dy_pilot_from_cg ++ + ( Q_body*R_body - P_dot_body )*dz_pilot_from_cg; ++ A_Z_pilot = A_Z_cg + ( P_body*R_body - Q_dot_body )*dx_pilot_from_cg ++ + ( Q_body*R_body + P_dot_body )*dy_pilot_from_cg ++ + (-Q_body*Q_body - P_body*P_body)*dz_pilot_from_cg; ++ ++ N_X_cg = INVG*A_X_cg; ++ N_Y_cg = INVG*A_Y_cg; ++ N_Z_cg = INVG*A_Z_cg; ++ ++ N_X_pilot = INVG*A_X_pilot; ++ N_Y_pilot = INVG*A_Y_pilot; ++ N_Z_pilot = INVG*A_Z_pilot; ++ ++ ++ U_dot_body = T_local_to_body_11*V_dot_north + T_local_to_body_12*V_dot_east ++ + T_local_to_body_13*V_dot_down - Q_total*W_body + R_total*V_body; ++ V_dot_body = T_local_to_body_21*V_dot_north + T_local_to_body_22*V_dot_east ++ + T_local_to_body_23*V_dot_down - R_total*U_body + P_total*W_body; ++ W_dot_body = T_local_to_body_31*V_dot_north + T_local_to_body_32*V_dot_east ++ + T_local_to_body_33*V_dot_down - P_total*V_body + Q_total*U_body; ++ /* End of ls_accel */ ++ ++} ++/**************************************************************************/ ++ ++ ++ ++ diff --cc Simulator/LaRCsim/ls_accel.h index 000000000,000000000..9bbcfeb7c new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_accel.h @@@ -1,0 -1,0 +1,11 @@@ ++/* a quick ls_accel.h */ ++ ++ ++#ifndef _LS_ACCEL_H ++#define _LS_ACCEL_H ++ ++ ++void ls_accel( void ); ++ ++ ++#endif /* _LS_ACCEL_H */ diff --cc Simulator/LaRCsim/ls_aux.c index 000000000,000000000..448448cf6 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_aux.c @@@ -1,0 -1,0 +1,347 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_aux ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Atmospheric and auxilary relationships for LaRCSim EOM ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 9208026 as part of C-castle simulation project. ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: B. Jackson ++ ++ CODED BY: B. Jackson ++ ++ MAINTAINED BY: B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE ++ ++ 931006 Moved calculations of auxiliary accelerations from here ++ to ls_accel.c and corrected minus sign in front of A_Y_Pilot ++ contribution from Q_body*P_body*D_X_pilot term. EBJ ++ 931014 Changed calculation of Alpha from atan to atan2 so sign is correct. ++ EBJ ++ 931220 Added calculations for static and total temperatures & pressures, ++ as well as dynamic and impact pressures and calibrated airspeed. ++ EBJ ++ 940111 Changed #included header files from old "ls_eom.h" to newer ++ "ls_types.h", "ls_constants.h" and "ls_generic.h". EBJ ++ ++ 950207 Changed use of "abs" to "fabs" in calculation of signU. EBJ ++ ++ 950228 Fixed bug in calculation of beta_dot. EBJ ++ ++ CURRENT RCS HEADER INFO: ++ ++$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. ++ ++Revision 1.2 1998/01/19 18:40:24 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:09:54 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.12 1995/02/28 17:57:16 bjax ++ * Corrected calculation of beta_dot. EBJ ++ * ++ * Revision 1.11 1995/02/07 21:09:47 bjax ++ * Corrected calculation of "signU"; was using divide by ++ * abs(), which returns an integer; now using fabs(), which ++ * returns a double. EBJ ++ * ++ * Revision 1.10 1994/05/10 20:09:42 bjax ++ * Fixed a major problem with dx_pilot_from_cg, etc. not being calculated locally. ++ * ++ * Revision 1.9 1994/01/11 18:44:33 bjax ++ * Changed header files to use ls_types, ls_constants, and ls_generic. ++ * ++ * Revision 1.8 1993/12/21 14:36:33 bjax ++ * Added calcs of pressures, temps and calibrated airspeeds. ++ * ++ * Revision 1.7 1993/10/14 11:25:38 bjax ++ * Changed calculation of Alpha to use 'atan2' instead of 'atan' so alphas ++ * larger than +/- 90 degrees are calculated correctly. EBJ ++ * ++ * Revision 1.6 1993/10/07 18:45:56 bjax ++ * A little cleanup; no significant changes. EBJ ++ * ++ * Revision 1.5 1993/10/07 18:42:22 bjax ++ * Moved calculations of auxiliary accelerations here from ls_aux, and ++ * corrected sign on Q_body*P_body*d_x_pilot term of A_Y_pilot calc. EBJ ++ * ++ * Revision 1.4 1993/07/16 18:28:58 bjax ++ * Changed call from atmos_62 to ls_atmos. EBJ ++ * ++ * Revision 1.3 1993/06/02 15:02:42 bjax ++ * Changed call to geodesy calcs from ls_geodesy to ls_geoc_to_geod. ++ * ++ * Revision 1.1 92/12/30 13:17:39 bjax ++ * Initial revision ++ * ++ ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: [ 1] Shapiro, Ascher H.: "The Dynamics and Thermodynamics ++ of Compressible Fluid Flow", Volume I, The Ronald ++ Press, 1953. ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++#include "ls_types.h" ++#include "ls_constants.h" ++#include "ls_generic.h" ++ ++#include "ls_aux.h" ++ ++#include "atmos_62.h" ++#include "ls_geodesy.h" ++#include "ls_gravity.h" ++ ++#include ++ ++ ++void ls_aux( void ) { ++ ++ SCALAR dx_pilot_from_cg, dy_pilot_from_cg, dz_pilot_from_cg; ++ /* SCALAR inv_Mass; */ ++ SCALAR v_XZ_plane_2, signU, v_tangential; ++ /* SCALAR inv_radius_ratio; */ ++ SCALAR cos_rwy_hdg, sin_rwy_hdg; ++ SCALAR mach2, temp_ratio, pres_ratio; ++ SCALAR tmp; ++ ++ /* update geodetic position */ ++ ++ ls_geoc_to_geod( Lat_geocentric, Radius_to_vehicle, ++ &Latitude, &Altitude, &Sea_level_radius ); ++ Longitude = Lon_geocentric - Earth_position_angle; ++ ++ /* Calculate body axis velocities */ ++ ++ /* Form relative velocity vector */ ++ ++ V_north_rel_ground = V_north; ++ V_east_rel_ground = V_east ++ - OMEGA_EARTH*Sea_level_radius*cos( Lat_geocentric ); ++ V_down_rel_ground = V_down; ++ ++ V_north_rel_airmass = V_north_rel_ground - V_north_airmass; ++ V_east_rel_airmass = V_east_rel_ground - V_east_airmass; ++ V_down_rel_airmass = V_down_rel_ground - V_down_airmass; ++ ++ U_body = T_local_to_body_11*V_north_rel_airmass ++ + T_local_to_body_12*V_east_rel_airmass ++ + T_local_to_body_13*V_down_rel_airmass + U_gust; ++ V_body = T_local_to_body_21*V_north_rel_airmass ++ + T_local_to_body_22*V_east_rel_airmass ++ + T_local_to_body_23*V_down_rel_airmass + V_gust; ++ W_body = T_local_to_body_31*V_north_rel_airmass ++ + T_local_to_body_32*V_east_rel_airmass ++ + T_local_to_body_33*V_down_rel_airmass + W_gust; ++ ++ V_rel_wind = sqrt(U_body*U_body + V_body*V_body + W_body*W_body); ++ ++ ++ /* Calculate alpha and beta rates */ ++ ++ v_XZ_plane_2 = (U_body*U_body + W_body*W_body); ++ ++ if (U_body == 0) ++ signU = 1; ++ else ++ signU = U_body/fabs(U_body); ++ ++ if( (v_XZ_plane_2 == 0) || (V_rel_wind == 0) ) ++ { ++ Alpha_dot = 0; ++ Beta_dot = 0; ++ } ++ else ++ { ++ Alpha_dot = (U_body*W_dot_body - W_body*U_dot_body)/ ++ v_XZ_plane_2; ++ Beta_dot = (signU*v_XZ_plane_2*V_dot_body ++ - V_body*(U_body*U_dot_body + W_body*W_dot_body)) ++ /(V_rel_wind*V_rel_wind*sqrt(v_XZ_plane_2)); ++ } ++ ++ /* Calculate flight path and other flight condition values */ ++ ++ if (U_body == 0) ++ Alpha = 0; ++ else ++ Alpha = atan2( W_body, U_body ); ++ ++ Cos_alpha = cos(Alpha); ++ Sin_alpha = sin(Alpha); ++ ++ if (V_rel_wind == 0) ++ Beta = 0; ++ else ++ Beta = asin( V_body/ V_rel_wind ); ++ ++ Cos_beta = cos(Beta); ++ Sin_beta = sin(Beta); ++ ++ V_true_kts = V_rel_wind * V_TO_KNOTS; ++ ++ V_ground_speed = sqrt(V_north_rel_ground*V_north_rel_ground ++ + V_east_rel_ground*V_east_rel_ground ); ++ ++ V_rel_ground = sqrt(V_ground_speed*V_ground_speed ++ + V_down_rel_ground*V_down_rel_ground ); ++ ++ v_tangential = sqrt(V_north*V_north + V_east*V_east); ++ ++ V_inertial = sqrt(v_tangential*v_tangential + V_down*V_down); ++ ++ if( (V_ground_speed == 0) && (V_down == 0) ) ++ Gamma_vert_rad = 0; ++ else ++ Gamma_vert_rad = atan2( -V_down, V_ground_speed ); ++ ++ if( (V_north_rel_ground == 0) && (V_east_rel_ground == 0) ) ++ Gamma_horiz_rad = 0; ++ else ++ Gamma_horiz_rad = atan2( V_east_rel_ground, V_north_rel_ground ); ++ ++ if (Gamma_horiz_rad < 0) ++ Gamma_horiz_rad = Gamma_horiz_rad + 2*PI; ++ ++ /* Calculate local gravity */ ++ ++ ls_gravity( Radius_to_vehicle, Lat_geocentric, &Gravity ); ++ ++ /* call function for (smoothed) density ratio, sonic velocity, and ++ ambient pressure */ ++ ++ ls_atmos(Altitude, &Sigma, &V_sound, ++ &Static_temperature, &Static_pressure); ++ ++ Density = Sigma*SEA_LEVEL_DENSITY; ++ ++ Mach_number = V_rel_wind / V_sound; ++ ++ V_equiv = V_rel_wind*sqrt(Sigma); ++ ++ V_equiv_kts = V_equiv*V_TO_KNOTS; ++ ++ /* calculate temperature and pressure ratios (from [1]) */ ++ ++ mach2 = Mach_number*Mach_number; ++ temp_ratio = 1.0 + 0.2*mach2; ++ tmp = 3.5; ++ pres_ratio = pow( temp_ratio, tmp ); ++ ++ Total_temperature = temp_ratio*Static_temperature; ++ Total_pressure = pres_ratio*Static_pressure; ++ ++ /* calculate impact and dynamic pressures */ ++ ++ Impact_pressure = Total_pressure - Static_pressure; ++ ++ Dynamic_pressure = 0.5*Density*V_rel_wind*V_rel_wind; ++ ++ /* calculate calibrated airspeed indication */ ++ ++ V_calibrated = sqrt( 2.0*Dynamic_pressure / SEA_LEVEL_DENSITY ); ++ V_calibrated_kts = V_calibrated*V_TO_KNOTS; ++ ++ Centrifugal_relief = 1 - v_tangential/(Radius_to_vehicle*Gravity); ++ ++/* Determine location in runway coordinates */ ++ ++ Radius_to_rwy = Sea_level_radius + Runway_altitude; ++ cos_rwy_hdg = cos(Runway_heading*DEG_TO_RAD); ++ sin_rwy_hdg = sin(Runway_heading*DEG_TO_RAD); ++ ++ D_cg_north_of_rwy = Radius_to_rwy*(Latitude - Runway_latitude); ++ D_cg_east_of_rwy = Radius_to_rwy*cos(Runway_latitude) ++ *(Longitude - Runway_longitude); ++ D_cg_above_rwy = Radius_to_vehicle - Radius_to_rwy; ++ ++ X_cg_rwy = D_cg_north_of_rwy*cos_rwy_hdg ++ + D_cg_east_of_rwy*sin_rwy_hdg; ++ Y_cg_rwy =-D_cg_north_of_rwy*sin_rwy_hdg ++ + D_cg_east_of_rwy*cos_rwy_hdg; ++ H_cg_rwy = D_cg_above_rwy; ++ ++ dx_pilot_from_cg = Dx_pilot - Dx_cg; ++ dy_pilot_from_cg = Dy_pilot - Dy_cg; ++ dz_pilot_from_cg = Dz_pilot - Dz_cg; ++ ++ D_pilot_north_of_rwy = D_cg_north_of_rwy ++ + T_local_to_body_11*dx_pilot_from_cg ++ + T_local_to_body_21*dy_pilot_from_cg ++ + T_local_to_body_31*dz_pilot_from_cg; ++ D_pilot_east_of_rwy = D_cg_east_of_rwy ++ + T_local_to_body_12*dx_pilot_from_cg ++ + T_local_to_body_22*dy_pilot_from_cg ++ + T_local_to_body_32*dz_pilot_from_cg; ++ D_pilot_above_rwy = D_cg_above_rwy ++ - T_local_to_body_13*dx_pilot_from_cg ++ - T_local_to_body_23*dy_pilot_from_cg ++ - T_local_to_body_33*dz_pilot_from_cg; ++ ++ X_pilot_rwy = D_pilot_north_of_rwy*cos_rwy_hdg ++ + D_pilot_east_of_rwy*sin_rwy_hdg; ++ Y_pilot_rwy = -D_pilot_north_of_rwy*sin_rwy_hdg ++ + D_pilot_east_of_rwy*cos_rwy_hdg; ++ H_pilot_rwy = D_pilot_above_rwy; ++ ++/* Calculate Euler rates */ ++ ++ Sin_phi = sin(Phi); ++ Cos_phi = cos(Phi); ++ Sin_theta = sin(Theta); ++ Cos_theta = cos(Theta); ++ Sin_psi = sin(Psi); ++ Cos_psi = cos(Psi); ++ ++ if( Cos_theta == 0 ) ++ Psi_dot = 0; ++ else ++ Psi_dot = (Q_total*Sin_phi + R_total*Cos_phi)/Cos_theta; ++ ++ Theta_dot = Q_total*Cos_phi - R_total*Sin_phi; ++ Phi_dot = P_total + Psi_dot*Sin_theta; ++ ++/* end of ls_aux */ ++ ++} ++/*************************************************************************/ diff --cc Simulator/LaRCsim/ls_aux.h index 000000000,000000000..c59180337 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_aux.h @@@ -1,0 -1,0 +1,11 @@@ ++/* a quick ls_aux.h */ ++ ++ ++#ifndef _LS_AUX_H ++#define _LS_AUX_H ++ ++ ++void ls_aux( void ); ++ ++ ++#endif /* _LS_AUX_H */ diff --cc Simulator/LaRCsim/ls_cockpit.h index 000000000,000000000..3dcddcdc9 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_cockpit.h @@@ -1,0 -1,0 +1,104 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_cockpit.h ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Header for cockpit IO ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: Developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 20 DEC 93 by E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: E. B. Jackson ++ ++ CODED BY: E. B. Jackson ++ ++ MAINTAINED BY: E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 950314 Added "throttle_pct" field to cockpit header for both ++ display and trim purposes. EBJ ++ ++ CURRENT RCS HEADER: ++ ++$Header$ ++$Log$ ++Revision 1.5 1998/10/17 01:34:14 curt ++C++ ifying ... ++ ++Revision 1.4 1998/08/06 12:46:39 curt ++Header change. ++ ++Revision 1.3 1998/01/22 02:59:32 curt ++Changed #ifdef FILE_H to #ifdef _FILE_H ++ ++Revision 1.2 1997/05/31 19:16:27 curt ++Elevator trim added. ++ ++Revision 1.1 1997/05/29 00:09:54 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.3 1995/03/15 12:32:10 bjax ++ * Added throttle_pct field. ++ * ++ * Revision 1.2 1995/02/28 20:37:02 bjax ++ * Changed name of gear_sel_down switch to gear_sel_up to reflect ++ * correct sense of switch. EBJ ++ * ++ * Revision 1.1 1993/12/21 14:39:04 bjax ++ * Initial revision ++ * ++ ++--------------------------------------------------------------------------*/ ++ ++ ++#ifndef _LS_COCKPIT_H ++#define _LS_COCKPIT_H ++ ++ ++typedef struct { ++ float long_stick, lat_stick, rudder_pedal; ++ float long_trim; ++ float throttle[4]; ++ short forward_trim, aft_trim, left_trim, right_trim; ++ short left_pb_on_stick, right_pb_on_stick, trig_pos_1, trig_pos_2; ++ short sb_extend, sb_retract, gear_sel_up; ++ float throttle_pct; ++ float brake_pct; ++} COCKPIT; ++ ++extern COCKPIT cockpit_; ++ ++#define Left_button cockpit_.left_pb_on_stick ++#define Right_button cockpit_.right_pb_on_stick ++#define Rudder_pedal cockpit_.rudder_pedal ++#define Throttle cockpit_.throttle ++#define Throttle_pct cockpit_.throttle_pct ++#define First_trigger cockpit_.trig_pos_1 ++#define Second_trigger cockpit_.trig_pos_2 ++#define Long_control cockpit_.long_stick ++#define Long_trim cockpit_.long_trim ++#define Lat_control cockpit_.lat_stick ++#define Fwd_trim cockpit_.forward_trim ++#define Aft_trim cockpit_.aft_trim ++#define Left_trim cockpit_.left_trim ++#define Right_trim cockpit_.right_trim ++#define SB_extend cockpit_.sb_extend ++#define SB_retract cockpit_.sb_retract ++#define Gear_sel_up cockpit_.gear_sel_up ++#define Brake_pct cockpit_.brake_pct ++ ++ ++#endif /* _LS_COCKPIT_H */ diff --cc Simulator/LaRCsim/ls_constants.h index 000000000,000000000..2393f4c5d new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_constants.h @@@ -1,0 -1,0 +1,133 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_constants.h ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: LaRCSim constants definition header file ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 15 DEC 1993 by Bruce Jackson; was part of ++ old ls_eom.h header file ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: B. Jackson ++ ++ CODED BY: B. Jackson ++ ++ MAINTAINED BY: guess who ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++ [ 1] McFarland, Richard E.: "A Standard Kinematic Model ++ for Flight Simulation at NASA-Ames", NASA CR-2497, ++ January 1975 ++ ++ [ 2] ANSI/AIAA R-004-1992 "Recommended Practice: Atmos- ++ pheric and Space Flight Vehicle Coordinate Systems", ++ February 1992 ++ ++ [ 3] Beyer, William H., editor: "CRC Standard Mathematical ++ Tables, 28th edition", CRC Press, Boca Raton, FL, 1987, ++ ISBN 0-8493-0628-0 ++ ++ [ 4] Dowdy, M. C.; Jackson, E. B.; and Nichols, J. H.: ++ "Controls Analysis and Simulation Test Loop Environ- ++ ment (CASTLE) Programmer's Guide, Version 1.3", ++ NATC TM 89-11, 30 March 1989. ++ ++ [ 5] Halliday, David; and Resnick, Robert: "Fundamentals ++ of Physics, Revised Printing", Wiley and Sons, 1974. ++ ISBN 0-471-34431-1 ++ ++ [ 6] Anon: "U. S. Standard Atmosphere, 1962" ++ ++ [ 7] Anon: "Aeronautical Vest Pocket Handbook, 17th edition", ++ Pratt & Whitney Aircraft Group, Dec. 1977 ++ ++ [ 8] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft ++ Control and Simulation", Wiley and Sons, 1992. ++ ISBN 0-471-61397-5 ++ ++--------------------------------------------------------------------------*/ ++ ++#ifndef _LS_CONSTANTS ++#define _LS_CONSTANTS ++ ++ ++#ifndef CONSTANTS ++ ++#define CONSTANTS -1 ++ ++/* Define application-wide macros */ ++ ++#define PATHNAME "LARCSIMPATH" ++#ifndef NIL_POINTER ++#define NIL_POINTER 0L ++#endif ++ ++/* Define constants (note: many factors will need to change for other ++ systems of measure) */ ++ ++/* Value of Pi from ref [3] */ ++#ifdef PI ++# undef PI /* avoid a harmless compiler warning */ ++#endif ++#define PI 3.14159265358979323846264338327950288419716939967511 ++ ++/* Value of earth radius from [8], ft */ ++#define EQUATORIAL_RADIUS 20925650. ++#define RESQ 437882827922500. ++ ++/* Value of earth flattening parameter from ref [8] ++ ++ Note: FP = f ++ E = 1-f ++ EPS = sqrt(1-(1-f)^2) */ ++ ++#define FP .003352813178 ++#define E .996647186 ++#define EPS .081819221 ++#define INVG .031080997 ++ ++/* linear velocity of earth at equator from w*R; w=2pi/24 hrs, in ft/sec */ ++#define OMEGA_EARTH .00007272205217 ++ ++/* miscellaneous units conversions (ref [7]) */ ++#define V_TO_KNOTS 0.5921 ++#define DEG_TO_RAD 0.017453292 ++#define RAD_TO_DEG 57.29577951 ++#define FT_TO_METERS 0.3048 ++#define METERS_TO_FT 3.2808 ++#define K_TO_R 1.8 ++#define R_TO_K 0.55555556 ++#define NSM_TO_PSF 0.02088547 ++#define PSF_TO_NSM 47.8801826 ++#define KCM_TO_SCF 0.00194106 ++#define SCF_TO_KCM 515.183616 ++ ++ ++/* ENGLISH Atmospheric reference properties [6] */ ++#define SEA_LEVEL_DENSITY 0.002376888 ++ ++#endif ++ ++ ++#endif /* _LS_CONSTANTS_H */ ++ ++ ++/*------------------------- end of ls_constants.h -------------------------*/ diff --cc Simulator/LaRCsim/ls_generic.h index 000000000,000000000..6059cce1e new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_generic.h @@@ -1,0 -1,0 +1,426 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_generic.h ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: LaRCSim generic parameters header file ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 15 DEC 1993 by Bruce Jackson; ++ was part of old ls_eom.h header ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: B. Jackson ++ ++ CODED BY: B. Jackson ++ ++ MAINTAINED BY: guess who ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++ [ 1] McFarland, Richard E.: "A Standard Kinematic Model ++ for Flight Simulation at NASA-Ames", NASA CR-2497, ++ January 1975 ++ ++ [ 2] ANSI/AIAA R-004-1992 "Recommended Practice: Atmos- ++ pheric and Space Flight Vehicle Coordinate Systems", ++ February 1992 ++ ++ [ 3] Beyer, William H., editor: "CRC Standard Mathematical ++ Tables, 28th edition", CRC Press, Boca Raton, FL, 1987, ++ ISBN 0-8493-0628-0 ++ ++ [ 4] Dowdy, M. C.; Jackson, E. B.; and Nichols, J. H.: ++ "Controls Analysis and Simulation Test Loop Environ- ++ ment (CASTLE) Programmer's Guide, Version 1.3", ++ NATC TM 89-11, 30 March 1989. ++ ++ [ 5] Halliday, David; and Resnick, Robert: "Fundamentals ++ of Physics, Revised Printing", Wiley and Sons, 1974. ++ ISBN 0-471-34431-1 ++ ++ [ 6] Anon: "U. S. Standard Atmosphere, 1962" ++ ++ [ 7] Anon: "Aeronautical Vest Pocket Handbook, 17th edition", ++ Pratt & Whitney Aircraft Group, Dec. 1977 ++ ++ [ 8] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft ++ Control and Simulation", Wiley and Sons, 1992. ++ ISBN 0-471-61397-5 ++ ++--------------------------------------------------------------------------*/ ++ ++ ++#ifndef _LS_GENERIC_H ++#define _LS_GENERIC_H ++ ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++ ++#include "ls_types.h" ++ ++ ++typedef struct { ++ ++/*================== Mass properties and geometry values ==================*/ ++ ++ DATA mass, i_xx, i_yy, i_zz, i_xz; /* Inertias */ ++#define Mass generic_.mass ++#define I_xx generic_.i_xx ++#define I_yy generic_.i_yy ++#define I_zz generic_.i_zz ++#define I_xz generic_.i_xz ++ ++ VECTOR_3 d_pilot_rp_body_v; /* Pilot location rel to ref pt */ ++#define D_pilot_rp_body_v generic_.d_pilot_rp_body_v ++#define Dx_pilot generic_.d_pilot_rp_body_v[0] ++#define Dy_pilot generic_.d_pilot_rp_body_v[1] ++#define Dz_pilot generic_.d_pilot_rp_body_v[2] ++ ++ VECTOR_3 d_cg_rp_body_v; /* CG position w.r.t. ref. point */ ++#define D_cg_rp_body_v generic_.d_cg_rp_body_v ++#define Dx_cg generic_.d_cg_rp_body_v[0] ++#define Dy_cg generic_.d_cg_rp_body_v[1] ++#define Dz_cg generic_.d_cg_rp_body_v[2] ++ ++/*================================ Forces =================================*/ ++ ++ VECTOR_3 f_body_total_v; ++#define F_body_total_v generic_.f_body_total_v ++#define F_X generic_.f_body_total_v[0] ++#define F_Y generic_.f_body_total_v[1] ++#define F_Z generic_.f_body_total_v[2] ++ ++ VECTOR_3 f_local_total_v; ++#define F_local_total_v generic_.f_local_total_v ++#define F_north generic_.f_local_total_v[0] ++#define F_east generic_.f_local_total_v[1] ++#define F_down generic_.f_local_total_v[2] ++ ++ VECTOR_3 f_aero_v; ++#define F_aero_v generic_.f_aero_v ++#define F_X_aero generic_.f_aero_v[0] ++#define F_Y_aero generic_.f_aero_v[1] ++#define F_Z_aero generic_.f_aero_v[2] ++ ++ VECTOR_3 f_engine_v; ++#define F_engine_v generic_.f_engine_v ++#define F_X_engine generic_.f_engine_v[0] ++#define F_Y_engine generic_.f_engine_v[1] ++#define F_Z_engine generic_.f_engine_v[2] ++ ++ VECTOR_3 f_gear_v; ++#define F_gear_v generic_.f_gear_v ++#define F_X_gear generic_.f_gear_v[0] ++#define F_Y_gear generic_.f_gear_v[1] ++#define F_Z_gear generic_.f_gear_v[2] ++ ++/*================================ Moments ================================*/ ++ ++ VECTOR_3 m_total_rp_v; ++#define M_total_rp_v generic_.m_total_rp_v ++#define M_l_rp generic_.m_total_rp_v[0] ++#define M_m_rp generic_.m_total_rp_v[1] ++#define M_n_rp generic_.m_total_rp_v[2] ++ ++ VECTOR_3 m_total_cg_v; ++#define M_total_cg_v generic_.m_total_cg_v ++#define M_l_cg generic_.m_total_cg_v[0] ++#define M_m_cg generic_.m_total_cg_v[1] ++#define M_n_cg generic_.m_total_cg_v[2] ++ ++ VECTOR_3 m_aero_v; ++#define M_aero_v generic_.m_aero_v ++#define M_l_aero generic_.m_aero_v[0] ++#define M_m_aero generic_.m_aero_v[1] ++#define M_n_aero generic_.m_aero_v[2] ++ ++ VECTOR_3 m_engine_v; ++#define M_engine_v generic_.m_engine_v ++#define M_l_engine generic_.m_engine_v[0] ++#define M_m_engine generic_.m_engine_v[1] ++#define M_n_engine generic_.m_engine_v[2] ++ ++ VECTOR_3 m_gear_v; ++#define M_gear_v generic_.m_gear_v ++#define M_l_gear generic_.m_gear_v[0] ++#define M_m_gear generic_.m_gear_v[1] ++#define M_n_gear generic_.m_gear_v[2] ++ ++/*============================== Accelerations ============================*/ ++ ++ VECTOR_3 v_dot_local_v; ++#define V_dot_local_v generic_.v_dot_local_v ++#define V_dot_north generic_.v_dot_local_v[0] ++#define V_dot_east generic_.v_dot_local_v[1] ++#define V_dot_down generic_.v_dot_local_v[2] ++ ++ VECTOR_3 v_dot_body_v; ++#define V_dot_body_v generic_.v_dot_body_v ++#define U_dot_body generic_.v_dot_body_v[0] ++#define V_dot_body generic_.v_dot_body_v[1] ++#define W_dot_body generic_.v_dot_body_v[2] ++ ++ VECTOR_3 a_cg_body_v; ++#define A_cg_body_v generic_.a_cg_body_v ++#define A_X_cg generic_.a_cg_body_v[0] ++#define A_Y_cg generic_.a_cg_body_v[1] ++#define A_Z_cg generic_.a_cg_body_v[2] ++ ++ VECTOR_3 a_pilot_body_v; ++#define A_pilot_body_v generic_.a_pilot_body_v ++#define A_X_pilot generic_.a_pilot_body_v[0] ++#define A_Y_pilot generic_.a_pilot_body_v[1] ++#define A_Z_pilot generic_.a_pilot_body_v[2] ++ ++ VECTOR_3 n_cg_body_v; ++#define N_cg_body_v generic_.n_cg_body_v ++#define N_X_cg generic_.n_cg_body_v[0] ++#define N_Y_cg generic_.n_cg_body_v[1] ++#define N_Z_cg generic_.n_cg_body_v[2] ++ ++ VECTOR_3 n_pilot_body_v; ++#define N_pilot_body_v generic_.n_pilot_body_v ++#define N_X_pilot generic_.n_pilot_body_v[0] ++#define N_Y_pilot generic_.n_pilot_body_v[1] ++#define N_Z_pilot generic_.n_pilot_body_v[2] ++ ++ VECTOR_3 omega_dot_body_v; ++#define Omega_dot_body_v generic_.omega_dot_body_v ++#define P_dot_body generic_.omega_dot_body_v[0] ++#define Q_dot_body generic_.omega_dot_body_v[1] ++#define R_dot_body generic_.omega_dot_body_v[2] ++ ++ ++/*============================== Velocities ===============================*/ ++ ++ VECTOR_3 v_local_v; ++#define V_local_v generic_.v_local_v ++#define V_north generic_.v_local_v[0] ++#define V_east generic_.v_local_v[1] ++#define V_down generic_.v_local_v[2] ++ ++ VECTOR_3 v_local_rel_ground_v; /* V rel w.r.t. earth surface */ ++#define V_local_rel_ground_v generic_.v_local_rel_ground_v ++#define V_north_rel_ground generic_.v_local_rel_ground_v[0] ++#define V_east_rel_ground generic_.v_local_rel_ground_v[1] ++#define V_down_rel_ground generic_.v_local_rel_ground_v[2] ++ ++ VECTOR_3 v_local_airmass_v; /* velocity of airmass (steady winds) */ ++#define V_local_airmass_v generic_.v_local_airmass_v ++#define V_north_airmass generic_.v_local_airmass_v[0] ++#define V_east_airmass generic_.v_local_airmass_v[1] ++#define V_down_airmass generic_.v_local_airmass_v[2] ++ ++ VECTOR_3 v_local_rel_airmass_v; /* velocity of veh. relative to airmass */ ++#define V_local_rel_airmass_v generic_.v_local_rel_airmass_v ++#define V_north_rel_airmass generic_.v_local_rel_airmass_v[0] ++#define V_east_rel_airmass generic_.v_local_rel_airmass_v[1] ++#define V_down_rel_airmass generic_.v_local_rel_airmass_v[2] ++ ++ VECTOR_3 v_local_gust_v; /* linear turbulence components, L frame */ ++#define V_local_gust_v generic_.v_local_gust_v ++#define U_gust generic_.v_local_gust_v[0] ++#define V_gust generic_.v_local_gust_v[1] ++#define W_gust generic_.v_local_gust_v[2] ++ ++ VECTOR_3 v_wind_body_v; /* Wind-relative velocities in body axis */ ++#define V_wind_body_v generic_.v_wind_body_v ++#define U_body generic_.v_wind_body_v[0] ++#define V_body generic_.v_wind_body_v[1] ++#define W_body generic_.v_wind_body_v[2] ++ ++ DATA v_rel_wind, v_true_kts, v_rel_ground, v_inertial; ++ DATA v_ground_speed, v_equiv, v_equiv_kts; ++ DATA v_calibrated, v_calibrated_kts; ++#define V_rel_wind generic_.v_rel_wind ++#define V_true_kts generic_.v_true_kts ++#define V_rel_ground generic_.v_rel_ground ++#define V_inertial generic_.v_inertial ++#define V_ground_speed generic_.v_ground_speed ++#define V_equiv generic_.v_equiv ++#define V_equiv_kts generic_.v_equiv_kts ++#define V_calibrated generic_.v_calibrated ++#define V_calibrated_kts generic_.v_calibrated_kts ++ ++ VECTOR_3 omega_body_v; /* Angular B rates */ ++#define Omega_body_v generic_.omega_body_v ++#define P_body generic_.omega_body_v[0] ++#define Q_body generic_.omega_body_v[1] ++#define R_body generic_.omega_body_v[2] ++ ++ VECTOR_3 omega_local_v; /* Angular L rates */ ++#define Omega_local_v generic_.omega_local_v ++#define P_local generic_.omega_local_v[0] ++#define Q_local generic_.omega_local_v[1] ++#define R_local generic_.omega_local_v[2] ++ ++ VECTOR_3 omega_total_v; /* Diff btw B & L */ ++#define Omega_total_v generic_.omega_total_v ++#define P_total generic_.omega_total_v[0] ++#define Q_total generic_.omega_total_v[1] ++#define R_total generic_.omega_total_v[2] ++ ++ VECTOR_3 euler_rates_v; ++#define Euler_rates_v generic_.euler_rates_v ++#define Phi_dot generic_.euler_rates_v[0] ++#define Theta_dot generic_.euler_rates_v[1] ++#define Psi_dot generic_.euler_rates_v[2] ++ ++ VECTOR_3 geocentric_rates_v; /* Geocentric linear velocities */ ++#define Geocentric_rates_v generic_.geocentric_rates_v ++#define Latitude_dot generic_.geocentric_rates_v[0] ++#define Longitude_dot generic_.geocentric_rates_v[1] ++#define Radius_dot generic_.geocentric_rates_v[2] ++ ++/*=============================== Positions ===============================*/ ++ ++ VECTOR_3 geocentric_position_v; ++#define Geocentric_position_v generic_.geocentric_position_v ++#define Lat_geocentric generic_.geocentric_position_v[0] ++#define Lon_geocentric generic_.geocentric_position_v[1] ++#define Radius_to_vehicle generic_.geocentric_position_v[2] ++ ++ VECTOR_3 geodetic_position_v; ++#define Geodetic_position_v generic_.geodetic_position_v ++#define Latitude generic_.geodetic_position_v[0] ++#define Longitude generic_.geodetic_position_v[1] ++#define Altitude generic_.geodetic_position_v[2] ++ ++ VECTOR_3 euler_angles_v; ++#define Euler_angles_v generic_.euler_angles_v ++#define Phi generic_.euler_angles_v[0] ++#define Theta generic_.euler_angles_v[1] ++#define Psi generic_.euler_angles_v[2] ++ ++/*======================= Miscellaneous quantities ========================*/ ++ ++ DATA t_local_to_body_m[3][3]; /* Transformation matrix L to B */ ++#define T_local_to_body_m generic_.t_local_to_body_m ++#define T_local_to_body_11 generic_.t_local_to_body_m[0][0] ++#define T_local_to_body_12 generic_.t_local_to_body_m[0][1] ++#define T_local_to_body_13 generic_.t_local_to_body_m[0][2] ++#define T_local_to_body_21 generic_.t_local_to_body_m[1][0] ++#define T_local_to_body_22 generic_.t_local_to_body_m[1][1] ++#define T_local_to_body_23 generic_.t_local_to_body_m[1][2] ++#define T_local_to_body_31 generic_.t_local_to_body_m[2][0] ++#define T_local_to_body_32 generic_.t_local_to_body_m[2][1] ++#define T_local_to_body_33 generic_.t_local_to_body_m[2][2] ++ ++ DATA gravity; /* Local acceleration due to G */ ++#define Gravity generic_.gravity ++ ++ DATA centrifugal_relief; /* load factor reduction due to speed */ ++#define Centrifugal_relief generic_.centrifugal_relief ++ ++ DATA alpha, beta, alpha_dot, beta_dot; /* in radians */ ++#define Alpha generic_.alpha ++#define Beta generic_.beta ++#define Alpha_dot generic_.alpha_dot ++#define Beta_dot generic_.beta_dot ++ ++ DATA cos_alpha, sin_alpha, cos_beta, sin_beta; ++#define Cos_alpha generic_.cos_alpha ++#define Sin_alpha generic_.sin_alpha ++#define Cos_beta generic_.cos_beta ++#define Sin_beta generic_.sin_beta ++ ++ DATA cos_phi, sin_phi, cos_theta, sin_theta, cos_psi, sin_psi; ++#define Cos_phi generic_.cos_phi ++#define Sin_phi generic_.sin_phi ++#define Cos_theta generic_.cos_theta ++#define Sin_theta generic_.sin_theta ++#define Cos_psi generic_.cos_psi ++#define Sin_psi generic_.sin_psi ++ ++ DATA gamma_vert_rad, gamma_horiz_rad; /* Flight path angles */ ++#define Gamma_vert_rad generic_.gamma_vert_rad ++#define Gamma_horiz_rad generic_.gamma_horiz_rad ++ ++ DATA sigma, density, v_sound, mach_number; ++#define Sigma generic_.sigma ++#define Density generic_.density ++#define V_sound generic_.v_sound ++#define Mach_number generic_.mach_number ++ ++ DATA static_pressure, total_pressure, impact_pressure, dynamic_pressure; ++#define Static_pressure generic_.static_pressure ++#define Total_pressure generic_.total_pressure ++#define Impact_pressure generic_.impact_pressure ++#define Dynamic_pressure generic_.dynamic_pressure ++ ++ DATA static_temperature, total_temperature; ++#define Static_temperature generic_.static_temperature ++#define Total_temperature generic_.total_temperature ++ ++ DATA sea_level_radius, earth_position_angle; ++#define Sea_level_radius generic_.sea_level_radius ++#define Earth_position_angle generic_.earth_position_angle ++ ++ DATA runway_altitude, runway_latitude, runway_longitude, runway_heading; ++#define Runway_altitude generic_.runway_altitude ++#define Runway_latitude generic_.runway_latitude ++#define Runway_longitude generic_.runway_longitude ++#define Runway_heading generic_.runway_heading ++ ++ DATA radius_to_rwy; ++#define Radius_to_rwy generic_.radius_to_rwy ++ ++ VECTOR_3 d_cg_rwy_local_v; /* CG rel. to rwy in local coords */ ++#define D_cg_rwy_local_v generic_.d_cg_rwy_local_v ++#define D_cg_north_of_rwy generic_.d_cg_rwy_local_v[0] ++#define D_cg_east_of_rwy generic_.d_cg_rwy_local_v[1] ++#define D_cg_above_rwy generic_.d_cg_rwy_local_v[2] ++ ++ VECTOR_3 d_cg_rwy_rwy_v; /* CG relative to runway, in rwy coordinates */ ++#define D_cg_rwy_rwy_v generic_.d_cg_rwy_rwy_v ++#define X_cg_rwy generic_.d_cg_rwy_rwy_v[0] ++#define Y_cg_rwy generic_.d_cg_rwy_rwy_v[1] ++#define H_cg_rwy generic_.d_cg_rwy_rwy_v[2] ++ ++ VECTOR_3 d_pilot_rwy_local_v; /* pilot rel. to rwy in local coords */ ++#define D_pilot_rwy_local_v generic_.d_pilot_rwy_local_v ++#define D_pilot_north_of_rwy generic_.d_pilot_rwy_local_v[0] ++#define D_pilot_east_of_rwy generic_.d_pilot_rwy_local_v[1] ++#define D_pilot_above_rwy generic_.d_pilot_rwy_local_v[2] ++ ++ VECTOR_3 d_pilot_rwy_rwy_v; /* pilot rel. to rwy, in rwy coords. */ ++#define D_pilot_rwy_rwy_v generic_.d_pilot_rwy_rwy_v ++#define X_pilot_rwy generic_.d_pilot_rwy_rwy_v[0] ++#define Y_pilot_rwy generic_.d_pilot_rwy_rwy_v[1] ++#define H_pilot_rwy generic_.d_pilot_rwy_rwy_v[2] ++ ++ ++} GENERIC; ++ ++extern GENERIC generic_; /* usually defined in ls_main.c */ ++ ++ ++#ifdef __cplusplus ++} ++#endif ++ ++ ++#endif /* _LS_GENERIC_H */ ++ ++ ++/*--------------------------- end of ls_generic.h ------------------------*/ diff --cc Simulator/LaRCsim/ls_geodesy.c index 000000000,000000000..ed808d135 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_geodesy.c @@@ -1,0 -1,0 +1,160 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_geodesy ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Converts geocentric coordinates to geodetic positions ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Written as part of LaRCSim project by E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: E. B. Jackson ++ ++ CODED BY: E. B. Jackson ++ ++ MAINTAINED BY: E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 930208 Modified to avoid singularity near polar region. EBJ ++ 930602 Moved backwards calcs here from ls_step. EBJ ++ 931214 Changed erroneous Latitude and Altitude variables to ++ *lat_geod and *alt in routine ls_geoc_to_geod. EBJ ++ 940111 Changed header files from old ls_eom.h style to ls_types, ++ and ls_constants. Also replaced old DATA type with new ++ SCALAR type. EBJ ++ ++ CURRENT RCS HEADER: ++ ++$Header$ ++$Log$ ++Revision 1.3 1998/07/08 14:41:37 curt ++. ++ ++Revision 1.2 1998/01/19 18:40:25 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:09:56 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.5 1994/01/11 18:47:05 bjax ++ * Changed include files to use types and constants, not ls_eom.h ++ * Also changed DATA type to SCALAR type. ++ * ++ * Revision 1.4 1993/12/14 21:06:47 bjax ++ * Removed global variable references Altitude and Latitude. EBJ ++ * ++ * Revision 1.3 1993/06/02 15:03:40 bjax ++ * Made new subroutine for calculating geodetic to geocentric; changed name ++ * of forward conversion routine from ls_geodesy to ls_geoc_to_geod. ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++ [ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft ++ Control and Simulation", Wiley and Sons, 1992. ++ ISBN 0-471-61397-5 ++ ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ls_aux ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ lat_geoc Geocentric latitude, radians, + = North ++ radius C.G. radius to earth center, ft ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ lat_geod Geodetic latitude, radians, + = North ++ alt C.G. altitude above mean sea level, ft ++ sea_level_r radius from earth center to sea level at ++ local vertical (surface normal) of C.G. ++ ++--------------------------------------------------------------------------*/ ++ ++#include "ls_types.h" ++#include "ls_constants.h" ++#include "ls_geodesy.h" ++#include ++ ++/* ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator */ ++#define ONE_SECOND 4.848136811E-6 ++#define HALF_PI 0.5*PI ++ ++ ++void ls_geoc_to_geod( SCALAR lat_geoc, SCALAR radius, SCALAR *lat_geod, ++ SCALAR *alt, SCALAR *sea_level_r ) ++{ ++ SCALAR t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha; ++ SCALAR sin_mu_a, denom,delt_lambda, lambda_sl, sin_lambda_sl; ++ ++ if( ( (HALF_PI - lat_geoc) < ONE_SECOND ) /* near North pole */ ++ || ( (HALF_PI + lat_geoc) < ONE_SECOND ) ) /* near South pole */ ++ { ++ *lat_geod = lat_geoc; ++ *sea_level_r = EQUATORIAL_RADIUS*E; ++ *alt = radius - *sea_level_r; ++ } ++ else ++ { ++ t_lat = tan(lat_geoc); ++ x_alpha = E*EQUATORIAL_RADIUS/sqrt(t_lat*t_lat + E*E); ++ mu_alpha = atan2(sqrt(RESQ - x_alpha*x_alpha),E*x_alpha); ++ if (lat_geoc < 0) mu_alpha = - mu_alpha; ++ sin_mu_a = sin(mu_alpha); ++ delt_lambda = mu_alpha - lat_geoc; ++ r_alpha = x_alpha/cos(lat_geoc); ++ l_point = radius - r_alpha; ++ *alt = l_point*cos(delt_lambda); ++ denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a); ++ rho_alpha = EQUATORIAL_RADIUS*(1-EPS)/ ++ (denom*denom*denom); ++ delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt); ++ *lat_geod = mu_alpha - delt_mu; ++ lambda_sl = atan( E*E * tan(*lat_geod) ); /* SL geoc. latitude */ ++ sin_lambda_sl = sin( lambda_sl ); ++ *sea_level_r = sqrt(RESQ ++ /(1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)); ++ } ++} ++ ++ ++void ls_geod_to_geoc( SCALAR lat_geod, SCALAR alt, ++ SCALAR *sl_radius, SCALAR *lat_geoc ) ++{ ++ SCALAR lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py; ++ ++ lambda_sl = atan( E*E * tan(lat_geod) ); /* sea level geocentric latitude */ ++ sin_lambda_sl = sin( lambda_sl ); ++ cos_lambda_sl = cos( lambda_sl ); ++ sin_mu = sin(lat_geod); /* Geodetic (map makers') latitude */ ++ cos_mu = cos(lat_geod); ++ *sl_radius = sqrt(RESQ ++ /(1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)); ++ py = *sl_radius*sin_lambda_sl + alt*sin_mu; ++ px = *sl_radius*cos_lambda_sl + alt*cos_mu; ++ *lat_geoc = atan2( py, px ); ++} diff --cc Simulator/LaRCsim/ls_geodesy.h index 000000000,000000000..5443c0484 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_geodesy.h @@@ -1,0 -1,0 +1,15 @@@ ++/* a quick ls_geodesy.h */ ++ ++ ++#ifndef _LS_GEODESY_H ++#define _LS_GEODESY_H ++ ++ ++void ls_geoc_to_geod( SCALAR lat_geoc, SCALAR radius, ++ SCALAR *lat_geod, SCALAR *alt, SCALAR *sea_level_r ); ++ ++void ls_geod_to_geoc( SCALAR lat_geod, SCALAR alt, SCALAR *sl_radius, ++ SCALAR *lat_geoc ); ++ ++ ++#endif /* _LS_GEODESY_H */ diff --cc Simulator/LaRCsim/ls_gravity.c index 000000000,000000000..44b56349f new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_gravity.c @@@ -1,0 -1,0 +1,99 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_gravity ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Gravity model for LaRCsim ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created by Bruce Jackson on September 25, 1992. ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: Bruce Jackson ++ ++ CODED BY: Bruce Jackson ++ ++ MAINTAINED BY: Bruce Jackson ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 940111 Changed include files to "ls_types.h" and ++ "ls_constants.h" from "ls_eom.h"; also changed DATA types ++ to SCALAR types. EBJ ++ ++ ++$Header$ ++$Log$ ++Revision 1.3 1998/08/06 12:46:39 curt ++Header change. ++ ++Revision 1.2 1998/01/19 18:40:26 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:09:56 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.2 1994/01/11 18:50:35 bjax ++ * Corrected include files (was ls_eom.h) and DATA types changed ++ * to SCALARs. EBJ ++ * ++ * Revision 1.1 1992/12/30 13:18:46 bjax ++ * Initial revision ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: Stevens, Brian L.; and Lewis, Frank L.: "Aircraft ++ Control and Simulation", Wiley and Sons, 1992. ++ ISBN 0-471- ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++#include "ls_types.h" ++#include "ls_constants.h" ++#include "ls_gravity.h" ++#include ++ ++#define GM 1.4076431E16 ++#define J2 1.08263E-3 ++ ++void ls_gravity( SCALAR radius, SCALAR lat, SCALAR *gravity ) ++{ ++ ++ SCALAR radius_ratio, rrsq, sinsqlat; ++ ++ radius_ratio = radius/EQUATORIAL_RADIUS; ++ rrsq = radius_ratio*radius_ratio; ++ sinsqlat = sin(lat)*sin(lat); ++ *gravity = (GM/(radius*radius)) ++ *sqrt(2.25*rrsq*rrsq*J2*J2*(5*sinsqlat*sinsqlat -2*sinsqlat + 1) ++ + 3*rrsq*J2*(1 - 3*sinsqlat) + 1); ++ ++} diff --cc Simulator/LaRCsim/ls_gravity.h index 000000000,000000000..dd118dcda new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_gravity.h @@@ -1,0 -1,0 +1,11 @@@ ++/* a quick ls_gravity.h */ ++ ++ ++#ifndef _LS_GRAVITY_H ++#define _LS_GRAVITY_H ++ ++ ++void ls_gravity( SCALAR radius, SCALAR lat, SCALAR *gravity ); ++ ++ ++#endif _LS_GRAVITY_H diff --cc Simulator/LaRCsim/ls_init.c index 000000000,000000000..755076446 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_init.c @@@ -1,0 -1,0 +1,381 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_init.c ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Initializes simulation ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: incomplete ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Written 921230 by Bruce Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: EBJ ++ ++ CODED BY: EBJ ++ ++ MAINTAINED BY: EBJ ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 950314 Added get_set, put_set, and init routines. EBJ ++ ++ CURRENT RCS HEADER: ++ ++$Header$ ++$Log$ ++Revision 1.5 1998/07/12 03:11:03 curt ++Removed some printf()'s. ++Fixed the autopilot integration so it should be able to update it's control ++ positions every time the internal flight model loop is run, and not just ++ once per rendered frame. ++Added a routine to do the necessary stuff to force an arbitrary altitude ++ change. ++Gave the Navion engine just a tad more power. ++ ++Revision 1.4 1998/01/19 18:40:26 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.3 1998/01/05 22:19:25 curt ++#ifdef'd out some unused code that was problematic for MSVC++ to compile. ++ ++Revision 1.2 1997/05/29 22:39:58 curt ++Working on incorporating the LaRCsim flight model. ++ ++Revision 1.1 1997/05/29 00:09:57 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.4 1995/03/15 12:15:23 bjax ++ * Added ls_init_get_set() and ls_init_put_set() and ls_init_init() ++ * routines. EBJ ++ * ++ * Revision 1.3 1994/01/11 19:09:44 bjax ++ * Fixed header includes. ++ * ++ * Revision 1.2 1992/12/30 14:04:53 bjax ++ * Added call to ls_step(0, 1). ++ * ++ * Revision 1.1 92/12/30 14:02:19 bjax ++ * Initial revision ++ * ++ * Revision 1.1 92/12/30 13:21:21 bjax ++ * Initial revision ++ * ++ * Revision 1.3 93/12/31 10:34:11 bjax ++ * Added $Log marker as well. ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++static char rcsid[] = "$Id$"; ++ ++#include ++#include ++#include "ls_types.h" ++#include "ls_sym.h" ++#include "ls_step.h" ++#include "ls_init.h" ++#include "navion_init.h" ++ ++/* temp */ ++#include "ls_generic.h" ++ ++#define MAX_NUMBER_OF_CONTINUOUS_STATES 100 ++#define MAX_NUMBER_OF_DISCRETE_STATES 20 ++#define HARDWIRED 13 ++#define NIL_POINTER 0L ++ ++#define FACILITY_NAME_STRING "init" ++#define CURRENT_VERSION 10 ++ ++typedef struct ++{ ++ symbol_rec Symbol; ++ double value; ++} cont_state_rec; ++ ++typedef struct ++{ ++ symbol_rec Symbol; ++ long value; ++} disc_state_rec; ++ ++ ++extern SCALAR Simtime; ++ ++/* static int Symbols_loaded = 0; */ ++static int Number_of_Continuous_States = 0; ++static int Number_of_Discrete_States = 0; ++static cont_state_rec Continuous_States[ MAX_NUMBER_OF_CONTINUOUS_STATES ]; ++static disc_state_rec Discrete_States[ MAX_NUMBER_OF_DISCRETE_STATES ]; ++ ++ ++void ls_init_init( void ) { ++ int i; ++ /* int error; */ ++ ++ if (Number_of_Continuous_States == 0) ++ { ++ Number_of_Continuous_States = HARDWIRED; ++ ++ for (i=0;i bufptr)) ++ { ++ bufptr = strtok( 0L, "\n"); ++ if (bufptr == 0) return 0L; ++ if (strncasecmp( bufptr, "end", 3) == 0) break; ++ ++ sscanf( bufptr, "%s", line ); ++ if (line[0] != '#') /* ignore comments */ ++ { ++ switch (looking_for) ++ { ++ case cont_states_header: ++ { ++ if (strncasecmp( line, "continuous_states", 17) == 0) ++ { ++ n = sscanf( bufptr, "%s%d", line, ++ &Number_of_Continuous_States ); ++ if (n != 2) abrt = 1; ++ looking_for = cont_states; ++ i = 0; ++ } ++ break; ++ } ++ case cont_states: ++ { ++ n = sscanf( bufptr, "%s%s%le", ++ Continuous_States[i].Symbol.Mod_Name, ++ Continuous_States[i].Symbol.Par_Name, ++ &Continuous_States[i].value ); ++ if (n != 3) abrt = 1; ++ Continuous_States[i].Symbol.Addr = NIL_POINTER; ++ i++; ++ if (i >= Number_of_Continuous_States) ++ looking_for = disc_states_header; ++ break; ++ } ++ case disc_states_header: ++ { ++ if (strncasecmp( line, "discrete_states", 15) == 0) ++ { ++ n = sscanf( bufptr, "%s%d", line, ++ &Number_of_Discrete_States ); ++ if (n != 2) abrt = 1; ++ looking_for = disc_states; ++ i = 0; ++ } ++ break; ++ } ++ case disc_states: ++ { ++ n = sscanf( bufptr, "%s%s%ld", ++ Discrete_States[i].Symbol.Mod_Name, ++ Discrete_States[i].Symbol.Par_Name, ++ &Discrete_States[i].value ); ++ if (n != 3) abrt = 1; ++ Discrete_States[i].Symbol.Addr = NIL_POINTER; ++ i++; ++ if (i >= Number_of_Discrete_States) looking_for = done; ++ } ++ case done: ++ { ++ break; ++ } ++ } ++ ++ } ++ } ++ ++ Symbols_loaded = !abrt; ++ ++ return bufptr; ++} ++#endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */ ++ ++ ++void ls_init_put_set( FILE *fp ) ++{ ++ int i; ++ ++ if (fp==0) return; ++ fprintf(fp, "\n"); ++ fprintf(fp, "#============================== %s\n", FACILITY_NAME_STRING); ++ fprintf(fp, "\n"); ++ fprintf(fp, FACILITY_NAME_STRING); ++ fprintf(fp, "\n"); ++ fprintf(fp, "%04d\n", CURRENT_VERSION); ++ fprintf(fp, " continuous_states: %d\n", Number_of_Continuous_States); ++ fprintf(fp, "# module parameter value\n"); ++ for (i=0; i abort works from initial pause ++ state; added call to ls_unsync() immediately following ++ first ls_sync() call, if paused (to avoid alarm clock ++ timeout); moved call to ls_record() into non-paused ++ multiloop path (was filling buffer with identical data ++ during pause); put check of paused flag before calling sync ++ routine ls_pause(); and added call to exit() on termination. ++ ++ ++$Header$ ++$Original log: LaRCsim.c,v $ ++ * Revision 1.4.1.7 1995/04/07 01:04:37 bjax ++ * Many changes made to support storage of sim options from run to run, ++ * as well as restructuring storage buffer sizing and some loop logic ++ * changes. See the modification log for details. ++ * ++ * Revision 1.4.1.6 1995/03/29 16:12:09 bjax ++ * Added argument to -o switch; changed run loop to pass dt=0 ++ * if in paused mode. EBj ++ * ++ * Revision 1.4.1.5 1995/03/15 12:30:20 bjax ++ * Set paused flag to non-zero by default; moved 'i' I/O rate flag ++ * switch to 'o'; made 'i' an initial conditions file switch; added ++ * null string to ls_get_settings() call so that default settings ++ * file will be read. EBJ ++ * ++ * Revision 1.4.1.4 1995/03/08 12:31:34 bjax ++ * Added userid retrieval and proper termination of time & date strings. ++ * ++ * Revision 1.4.1.3 1995/03/08 12:00:21 bjax ++ * Moved setting of default options to ls_setdefopts from ++ * ls_checkopts; rearranged order of ls_get_settings() call ++ * to between ls_setdefopts and ls_checkopts, so command ++ * line options will override settings file options. ++ * EBJ ++ * ++ * Revision 1.4.1.2 1995/03/06 18:48:49 bjax ++ * Added calles to ls_get_settings() and ls_put_settings(); added ++ * passing of dt and init flags in ls_model(). EBJ ++ * ++ * Revision 1.4.1.1 1995/03/03 02:23:08 bjax ++ * Beta version for LaRCsim, version 1.4 ++ * ++ * Revision 1.3.2.7 1995/02/27 20:00:21 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.2.6 1995/02/25 16:52:31 bjax ++ * Added 'i' option to set I/O iteration rate. EBJ ++ * ++ * Revision 1.3.2.5 1995/02/06 19:33:15 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.2.4 1995/02/06 19:30:30 bjax ++ * Oops, should really compile these before checking in. Fixed capitailzation of ++ * Initialize in ls_loop parameter. ++ * ++ * Revision 1.3.2.3 1995/02/06 19:25:44 bjax ++ * Moved main simulation loop into subroutine ls_loop. EBJ ++ * ++ * Revision 1.3.2.2 1994/05/20 21:46:45 bjax ++ * A little better logic on checking for option arguments. ++ * ++ * Revision 1.3.2.1 1994/05/20 19:29:51 bjax ++ * Added options arguments to command line. ++ * ++ * Revision 1.3.1.16 1994/05/17 15:08:45 bjax ++ * Corrected so that full name to directyr and file is saved ++ * in new global variable "fullname"; this allows symbol table ++ * to be extracted when in another default directory. ++ * ++ * Revision 1.3.1.15 1994/05/17 14:50:24 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.14 1994/05/17 14:50:23 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.13 1994/05/17 14:50:21 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.12 1994/05/17 14:50:20 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.11 1994/05/17 13:56:24 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.10 1994/05/17 13:23:03 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.9 1994/05/17 13:20:03 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.8 1994/05/17 13:19:23 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.7 1994/05/17 13:18:29 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.6 1994/05/17 13:16:30 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.5 1994/05/17 13:03:44 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.4 1994/05/17 13:03:38 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.3 1994/05/17 12:49:08 bjax ++ * Rebuilt LaRCsim ++ * ++ * Revision 1.3.1.2 1994/05/17 12:48:45 bjax ++ * *** empty log message *** ++ * ++ * Revision 1.3.1.1 1994/05/13 20:39:17 bjax ++ * Top of 1.3 branch. ++ * ++ * Revision 1.2 1994/05/13 19:51:50 bjax ++ * Skip rev ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++ ++/* #include */ ++/* #include */ ++#include ++#include ++#include ++#include ++ ++#include "ls_types.h" ++#include "ls_constants.h" ++#include "ls_generic.h" ++#include "ls_sim_control.h" ++#include "ls_cockpit.h" ++#include "ls_interface.h" ++#include "ls_step.h" ++#include "ls_accel.h" ++#include "ls_aux.h" ++#include "ls_model.h" ++#include "ls_init.h" ++ ++// #include ++// #include ++// #include ++ ++ ++/* global variable declarations */ ++ ++/* TAPE *Tape; */ ++GENERIC generic_; ++SIM_CONTROL sim_control_; ++COCKPIT cockpit_; ++ ++SCALAR Simtime; ++ ++#define DEFAULT_TERM_UPDATE_HZ 20 ++#define DEFAULT_MODEL_HZ 120 ++#define DEFAULT_END_TIME 3600. ++#define DEFAULT_SAVE_SPACING 8 ++#define DEFAULT_WRITE_SPACING 1 ++#define MAX_FILE_NAME_LENGTH 80 ++ ++/* global variables */ ++ ++char *progname; ++char *fullname; ++ ++/* file variables - default simulation settings */ ++ ++static double model_dt; ++static double speedup; ++static char asc1name[MAX_FILE_NAME_LENGTH] = "run.asc1"; ++static char tabname[MAX_FILE_NAME_LENGTH] = "run.dat"; ++static char fltname[MAX_FILE_NAME_LENGTH] = "run.flt"; ++static char matname[MAX_FILE_NAME_LENGTH] = "run.m"; ++ ++ ++ ++void ls_stamp( void ) { ++ char rcsid[] = "$Id$"; ++ char revid[] = "$Revision$"; ++ char dateid[] = "$Date$"; ++ struct tm *nowtime; ++ time_t nowtime_t; ++ long date; ++ ++ /* report version of LaRCsim*/ ++ printf("\nLaRCsim %s, %s\n\n", revid, dateid); ++ ++ nowtime_t = time( 0 ); ++ nowtime = localtime( &nowtime_t ); /* set fields to correct time values */ ++ date = (nowtime->tm_year)*10000 ++ + (nowtime->tm_mon + 1)*100 ++ + (nowtime->tm_mday); ++ sprintf(sim_control_.date_string, "%06d\0", date); ++ sprintf(sim_control_.time_stamp, "%02d:%02d:%02d\0", ++ nowtime->tm_hour, nowtime->tm_min, nowtime->tm_sec); ++#ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE ++ cuserid( sim_control_.userid ); /* set up user id */ ++#endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */ ++ return; ++} ++ ++void ls_setdefopts( void ) { ++ /* set default values for most options */ ++ ++ sim_control_.debug = 0; /* change to non-zero if in dbx! */ ++ sim_control_.vision = 0; ++ sim_control_.write_av = 0; /* write Agile-Vu '.flt' file */ ++ sim_control_.write_mat = 0; /* write matrix-x/matlab script */ ++ sim_control_.write_tab = 0; /* write tab delim. history file */ ++ sim_control_.write_asc1 = 0; /* write GetData file */ ++ sim_control_.save_spacing = DEFAULT_SAVE_SPACING; ++ /* interpolation on recording */ ++ sim_control_.write_spacing = DEFAULT_WRITE_SPACING; ++ /* interpolation on output */ ++ sim_control_.end_time = DEFAULT_END_TIME; ++ sim_control_.model_hz = DEFAULT_MODEL_HZ; ++ sim_control_.term_update_hz = DEFAULT_TERM_UPDATE_HZ; ++ sim_control_.time_slices = (long int)(DEFAULT_END_TIME * DEFAULT_MODEL_HZ / ++ DEFAULT_SAVE_SPACING); ++ sim_control_.paused = 0; ++ ++ speedup = 1.0; ++} ++ ++ ++/* return result codes from ls_checkopts */ ++ ++#define OPT_OK 0 ++#define OPT_ERR 1 ++ ++#ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE ++ ++extern char *optarg; ++extern int optind; ++ ++int ls_checkopts(argc, argv) /* check and set options flags */ ++ int argc; ++ char *argv[]; ++ { ++ int c; ++ int opt_err = 0; ++ int mod_end_time = 0; ++ int mod_buf_size = 0; ++ float buffer_time, data_rate; ++ ++ /* set default values */ ++ ++ buffer_time = sim_control_.time_slices * sim_control_.save_spacing / ++ sim_control_.model_hz; ++ data_rate = sim_control_.model_hz / sim_control_.save_spacing; ++ ++ while ((c = getopt(argc, argv, "Aa:b:de:f:hi:kmo:r:s:t:x:")) != EOF) ++ switch (c) { ++ case 'A': ++ if (sim_control_.sim_type == GLmouse) ++ { ++ fprintf(stderr, "Cannot specify both keyboard (k) and ACES (A) cockpits option\n"); ++ fprintf(stderr, "Keyboard operation assumed.\n"); ++ break; ++ } ++ sim_control_.sim_type = cockpit; ++ break; ++ case 'a': ++ sim_control_.write_av = 1; ++ if (optarg != NULL) ++ if (*optarg != '-') ++ strncpy(fltname, optarg, MAX_FILE_NAME_LENGTH); ++ else ++ optind--; ++ break; ++ case 'b': ++ buffer_time = atof(optarg); ++ if (buffer_time <= 0.) opt_err = -1; ++ mod_buf_size++; ++ break; ++ case 'd': ++ sim_control_.debug = 1; ++ break; ++ case 'e': ++ sim_control_.end_time = atof(optarg); ++ mod_end_time++; ++ break; ++ case 'f': ++ sim_control_.model_hz = atof(optarg); ++ break; ++ case 'h': ++ opt_err = 1; ++ break; ++ case 'i': ++ /* ls_get_settings( optarg ); */ ++ break; ++ case 'k': ++ sim_control_.sim_type = GLmouse; ++ break; ++ case 'm': ++ sim_control_.vision = 1; ++ break; ++ case 'o': ++ sim_control_.term_update_hz = atof(optarg); ++ if (sim_control_.term_update_hz <= 0.) opt_err = 1; ++ break; ++ case 'r': ++ sim_control_.write_mat = 1; ++ if (optarg != NULL) ++ if (*optarg != '-') ++ strncpy(matname, optarg, MAX_FILE_NAME_LENGTH); ++ else ++ optind--; ++ break; ++ case 's': ++ data_rate = atof(optarg); ++ if (data_rate <= 0.) opt_err = -1; ++ break; ++ case 't': ++ sim_control_.write_tab = 1; ++ if (optarg != NULL) ++ if (*optarg != '-') ++ strncpy(tabname, optarg, MAX_FILE_NAME_LENGTH); ++ else ++ optind--; ++ break; ++ case 'x': ++ sim_control_.write_asc1 = 1; ++ if (optarg != NULL) ++ if (*optarg != '-') ++ strncpy(asc1name, optarg, MAX_FILE_NAME_LENGTH); ++ else ++ optind--; ++ break; ++ default: ++ opt_err = 1; ++ ++ } ++ ++ if (opt_err) ++ { ++ fprintf(stderr, "Usage: %s [-options]\n", progname); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " where [-options] is zero or more of the following:\n"); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [A|k] Run mode: [A]CES cockpit [default]\n"); ++ fprintf(stderr, " or [k]eyboard\n"); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [i ] [i]nitial conditions filename\n"); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [f ] Iteration rate [f]requency, Hz (default is %5.2f Hz)\n", ++ sim_control_.model_hz); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [o ] Display [o]utput frequency, Hz (default is %5.2f Hz)\n", ++ sim_control_.term_update_hz); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [s ] Data storage frequency, Hz (default is %5.2f Hz)\n", ++ data_rate); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [e ] [e]nd time in seconds (default %5.1f seconds)\n", ++ sim_control_.end_time); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [b ] circular time history storage [b]uffer size, in seconds \n"); ++ fprintf(stderr, " (default %5.1f seconds) (normally same as end time)\n", ++ sim_control_.time_slices*sim_control_.save_spacing/ ++ sim_control_.model_hz); ++ fprintf(stderr, "\n"); ++ fprintf(stderr, " [atxr []] Output: [a]gile-vu (default name: %s )\n", fltname); ++ fprintf(stderr, " and/or [t]ab delimited ( '' name: %s )\n", tabname); ++ fprintf(stderr, " and/or [x]plot (default name: %s)\n", asc1name); ++ fprintf(stderr, " and/or mat[r]ix script ( '' name: %s )\n", matname); ++ fprintf(stderr, "\n"); ++ return OPT_ERR; ++ } ++ ++/* calculate additional controls */ ++ ++ sim_control_.save_spacing = (int) (0.5 + sim_control_.model_hz / data_rate); ++ if (sim_control_.save_spacing < 1) sim_control_.save_spacing = 1; ++ ++ sim_control_.time_slices = buffer_time * sim_control_.model_hz / ++ sim_control_.save_spacing; ++ if (sim_control_.time_slices < 2) sim_control_.time_slices = 2; ++ ++ return OPT_OK; ++ } ++#endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */ ++ ++ ++void ls_loop( SCALAR dt, int initialize ) { ++ /* printf (" In ls_loop()\n"); */ ++ ls_step( dt, initialize ); ++ /* if (sim_control_.sim_type == cockpit ) ls_ACES(); */ ++ ls_aux(); ++ ls_model( dt, initialize ); ++ ls_accel(); ++} ++ ++ ++ ++int ls_cockpit( void ) { ++ // fgCONTROLS *c; ++ ++ sim_control_.paused = 0; ++ ++ // c = current_aircraft.controls; ++ ++ // Lat_control = FG_Aileron; ++ // Long_control = FG_Elevator; ++ // Long_trim = FG_Elev_Trim; ++ // Rudder_pedal = FG_Rudder; ++ // Throttle_pct = FG_Throttle[0]; ++ ++ /* printf("Mach = %.2f ", Mach_number); ++ printf("%.4f,%.4f,%.2f ", Latitude, Longitude, Altitude); ++ printf("%.2f,%.2f,%.2f\n", Phi, Theta, Psi); */ ++ ++ return( 0 ); ++} ++ ++ ++/* Initialize the LaRCsim flight model, dt is the time increment for ++ each subsequent iteration through the EOM */ ++int ls_toplevel_init(double dt) { ++ model_dt = dt; ++ ++ ls_setdefopts(); /* set default options */ ++ ++ ls_stamp(); /* ID stamp; record time and date of run */ ++ ++ if (speedup == 0.0) { ++ fprintf(stderr, "%s: Cannot run with speedup of 0.\n", progname); ++ return 1; ++ } ++ ++ /* printf("LS pre Init pos = %.2f\n", Latitude); */ ++ ++ ls_init(); ++ ++ /* printf("LS post Init pos = %.2f\n", Latitude); */ ++ ++ if (speedup > 0) { ++ /* Initialize (get) cockpit (controls) settings */ ++ ls_cockpit(); ++ } ++ ++ return(1); ++} ++ ++ ++/* Run an iteration of the EOM (equations of motion) */ ++int ls_update(int multiloop) { ++ int i; ++ ++ if (speedup > 0) { ++ ls_cockpit(); ++ } ++ ++ for ( i = 0; i < multiloop; i++ ) { ++ ls_loop( model_dt, 0); ++ } ++ ++ return 1; ++} ++ ++ ++/* Set the altitude (force) */ ++int ls_ForceAltitude(double alt_feet) { ++ Altitude = alt_feet; ++ ls_geod_to_geoc( Latitude, Altitude, &Sea_level_radius, &Lat_geocentric); ++ Radius_to_vehicle = Altitude + Sea_level_radius; ++} ++ ++ ++/* Flight Gear Modification Log ++ * ++ * $Log$ ++ * Revision 1.25 1999/01/19 20:57:02 curt ++ * MacOS portability changes contributed by "Robert Puyol" ++ * ++ * Revision 1.24 1998/12/14 13:27:47 curt ++ * Removed some old, outdated, no longer needed code. ++ * ++ * Revision 1.23 1998/10/16 23:27:44 curt ++ * C++-ifying. ++ * ++ * Revision 1.22 1998/09/29 02:02:59 curt ++ * Added a brake + autopilot mods. ++ * ++ * Revision 1.21 1998/08/22 14:49:56 curt ++ * Attempting to iron out seg faults and crashes. ++ * Did some shuffling to fix a initialization order problem between view ++ * position, scenery elevation. ++ * ++ * Revision 1.20 1998/07/12 03:11:03 curt ++ * Removed some printf()'s. ++ * Fixed the autopilot integration so it should be able to update it's control ++ * positions every time the internal flight model loop is run, and not just ++ * once per rendered frame. ++ * Added a routine to do the necessary stuff to force an arbitrary altitude ++ * change. ++ * Gave the Navion engine just a tad more power. ++ * ++ * Revision 1.19 1998/05/11 18:17:28 curt ++ * Output message tweaking. ++ * ++ * Revision 1.18 1998/04/21 16:59:38 curt ++ * Integrated autopilot. ++ * Prepairing for C++ integration. ++ * ++ * Revision 1.17 1998/02/23 19:07:58 curt ++ * Incorporated Durk's Astro/ tweaks. Includes unifying the sun position ++ * calculation code between sun display, and other FG sections that use this ++ * for things like lighting. ++ * ++ * Revision 1.16 1998/02/07 15:29:38 curt ++ * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss ++ * ++ * ++ * Revision 1.15 1998/01/22 22:03:47 curt ++ * Removed #include ++ * ++ * Revision 1.14 1998/01/19 19:27:04 curt ++ * Merged in make system changes from Bob Kuehne ++ * This should simplify things tremendously. ++ * ++ * Revision 1.13 1998/01/19 18:40:26 curt ++ * Tons of little changes to clean up the code and to remove fatal errors ++ * when building with the c++ compiler. ++ * ++ * Revision 1.12 1998/01/06 01:20:16 curt ++ * Tweaks to help building with MSVC++ ++ * ++ * Revision 1.11 1998/01/05 22:19:26 curt ++ * #ifdef'd out some unused code that was problematic for MSVC++ to compile. ++ * ++ * Revision 1.10 1997/12/10 22:37:43 curt ++ * Prepended "fg" on the name of all global structures that didn't have it yet. ++ * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" ++ * ++ * Revision 1.9 1997/08/27 03:30:08 curt ++ * Changed naming scheme of basic shared structures. ++ * ++ * Revision 1.8 1997/06/21 17:12:50 curt ++ * Capitalized subdirectory names. ++ * ++ * Revision 1.7 1997/05/31 19:16:28 curt ++ * Elevator trim added. ++ * ++ * Revision 1.6 1997/05/31 04:13:53 curt ++ * WE CAN NOW FLY!!! ++ * ++ * Continuing work on the LaRCsim flight model integration. ++ * Added some MSFS-like keyboard input handling. ++ * ++ * Revision 1.5 1997/05/30 23:26:25 curt ++ * Added elevator/aileron controls. ++ * ++ * Revision 1.4 1997/05/30 19:30:15 curt ++ * The LaRCsim flight model is starting to look like it is working. ++ * ++ * Revision 1.3 1997/05/30 03:54:12 curt ++ * Made a bit more progress towards integrating the LaRCsim flight model. ++ * ++ * Revision 1.2 1997/05/29 22:39:59 curt ++ * Working on incorporating the LaRCsim flight model. ++ * ++ * Revision 1.1 1997/05/29 00:09:57 curt ++ * Initial Flight Gear revision. ++ * ++ */ diff --cc Simulator/LaRCsim/ls_interface.h index 000000000,000000000..67745dd28 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_interface.h @@@ -1,0 -1,0 +1,113 @@@ ++/************************************************************************** ++ * ls_interface.h -- interface to the "LaRCsim" flight model ++ * ++ * Written by Curtis Olson, started May 1997. ++ * ++ * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License as ++ * published by the Free Software Foundation; either version 2 of the ++ * License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ * $Id$ ++ * (Log is kept at end of this file) ++ **************************************************************************/ ++ ++ ++#ifndef _LS_INTERFACE_H ++#define _LS_INTERFACE_H ++ ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++ ++#include "ls_types.h" ++ ++ ++/* reset flight params to a specific position */ ++int ls_toplevel_init(double dt); ++ ++/* update position based on inputs, positions, velocities, etc. */ ++int ls_update(int multiloop); ++ ++#if 0 ++/* Convert from the fgFLIGHT struct to the LaRCsim generic_ struct */ ++int fgFlight_2_LaRCsim (fgFLIGHT *f); ++ ++/* Convert from the LaRCsim generic_ struct to the fgFLIGHT struct */ ++int fgLaRCsim_2_Flight (fgFLIGHT *f); ++ ++void ls_loop( SCALAR dt, int initialize ); ++#endif ++ ++/* Set the altitude (force) */ ++int ls_ForceAltitude(double alt_feet); ++ ++ ++#endif /* _LS_INTERFACE_H */ ++ ++ ++#ifdef __cplusplus ++} ++#endif ++ ++ ++// $Log$ ++// Revision 1.11 1998/10/17 01:34:15 curt ++// C++ ifying ... ++// ++// Revision 1.10 1998/10/16 23:27:45 curt ++// C++-ifying. ++// ++// Revision 1.9 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 ++// positions every time the internal flight model loop is run, and not just ++// once per rendered frame. ++// Added a routine to do the necessary stuff to force an arbitrary altitude ++// change. ++// Gave the Navion engine just a tad more power. ++// ++// Revision 1.8 1998/04/21 16:59:39 curt ++// Integrated autopilot. ++// Prepairing for C++ integration. ++// ++// Revision 1.7 1998/02/07 15:29:39 curt ++// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss ++// ++// ++// Revision 1.6 1998/02/03 23:20:17 curt ++// Lots of little tweaks to fix various consistency problems discovered by ++// Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper ++// passed arguments along to the real printf(). Also incorporated HUD changes ++// by Michele America. ++// ++// Revision 1.5 1998/01/19 19:27:05 curt ++// Merged in make system changes from Bob Kuehne ++// This should simplify things tremendously. ++// ++// Revision 1.4 1998/01/19 18:40:27 curt ++// Tons of little changes to clean up the code and to remove fatal errors ++// when building with the c++ compiler. ++// ++// Revision 1.3 1997/07/23 21:52:20 curt ++// Put comments around the text after an #endif for increased portability. ++// ++// Revision 1.2 1997/05/29 22:39:59 curt ++// Working on incorporating the LaRCsim flight model. ++// ++// Revision 1.1 1997/05/29 00:09:58 curt ++// Initial Flight Gear revision. ++// diff --cc Simulator/LaRCsim/ls_matrix.c index 000000000,000000000..808eade4b new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_matrix.c @@@ -1,0 -1,0 +1,349 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_matrix.c ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: general real matrix routines; includes ++ gaussj() for matrix inversion using ++ Gauss-Jordan method with full pivoting. ++ ++ The routines in this module have come more or less from ref [1]. ++ Note that, probably due to the heritage of ref [1] (which has a ++ FORTRAN version that was probably written first), the use of 1 as ++ the first element of an array (or vector) is used. This is accomplished ++ in memory by allocating, but not using, the 0 elements in each dimension. ++ While this wastes some memory, it allows the routines to be ported more ++ easily from FORTRAN (I suspect) as well as adhering to conventional ++ matrix notation. As a result, however, traditional ANSI C convention ++ (0-base indexing) is not followed; as the authors of ref [1] point out, ++ there is some question of the portability of the resulting routines ++ which sometimes access negative indexes. See ref [1] for more details. ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 950222 E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: from Numerical Recipes in C, by Press, et. al. ++ ++ CODED BY: Bruce Jackson ++ ++ MAINTAINED BY: ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ CURRENT RCS HEADER: ++ ++$Header$ ++$Log$ ++Revision 1.1 1998/06/27 22:34:57 curt ++Initial revision. ++ ++ * Revision 1.1 1995/02/27 19:55:44 bjax ++ * Initial revision ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: [1] Press, William H., et. al, Numerical Recipes in ++ C, 2nd edition, Cambridge University Press, 1992 ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++ ++#ifdef HAVE_CONFIG_H ++# include ++#endif ++ ++#include ++#include ++#include ++ ++#ifdef HAVE_UNISTD_H ++# include ++#endif ++ ++#include "ls_matrix.h" ++ ++ ++#define SWAP(a,b) {temp=(a);(a)=(b);(b)=temp;} ++ ++static char rcsid[] = "$Id$"; ++ ++ ++int *nr_ivector(long nl, long nh) ++{ ++ int *v; ++ ++ v=(int *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(int))); ++ return v-nl+NR_END; ++} ++ ++ ++ ++double **nr_matrix(long nrl, long nrh, long ncl, long nch) ++/* allocate a double matrix with subscript range m[nrl..nrh][ncl..nch] */ ++{ ++ long i, nrow=nrh-nrl+1, ncol=nch-ncl+1; ++ double **m; ++ ++ /* allocate pointers to rows */ ++ m=(double **) malloc((size_t)((nrow+NR_END)*sizeof(double*))); ++ ++ if (!m) ++ { ++ fprintf(stderr, "Memory failure in routine 'nr_matrix'.\n"); ++ exit(1); ++ } ++ ++ m += NR_END; ++ m -= nrl; ++ ++ /* allocate rows and set pointers to them */ ++ m[nrl] = (double *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double))); ++ if (!m[nrl]) ++ { ++ fprintf(stderr, "Memory failure in routine 'matrix'\n"); ++ exit(1); ++ } ++ ++ m[nrl] += NR_END; ++ m[nrl] -= ncl; ++ ++ for (i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; ++ ++ /* return pointer to array of pointers to rows */ ++ return m; ++} ++ ++ ++void nr_free_ivector(int *v, long nl /* , long nh */) ++{ ++ free( (char *) (v+nl-NR_END)); ++} ++ ++ ++void nr_free_matrix(double **m, long nrl, long nrh, long ncl, long nch) ++/* free a double matrix allocated by nr_matrix() */ ++{ ++ free((char *) (m[nrl]+ncl-NR_END)); ++ free((char *) (m+nrl-NR_END)); ++} ++ ++ ++int nr_gaussj(double **a, int n, double **b, int m) ++ ++/* Linear equation solution by Gauss-Jordan elimination. a[1..n][1..n] is */ ++/* the input matrix. b[1..n][1..m] is input containing the m right-hand */ ++/* side vectors. On output, a is replaced by its matrix invers, and b is */ ++/* replaced by the corresponding set of solution vectors. */ ++ ++/* Note: this routine modified by EBJ to make b optional, if m == 0 */ ++ ++{ ++ int *indxc, *indxr, *ipiv; ++ int i, icol, irow, j, k, l, ll; ++ double big, dum, pivinv, temp; ++ ++ int bexists = ((m != 0) || (b == 0)); ++ ++ indxc = nr_ivector(1,n); /* The integer arrays ipiv, indxr, and */ ++ indxr = nr_ivector(1,n); /* indxc are used for pivot bookkeeping */ ++ ipiv = nr_ivector(1,n); ++ ++ for (j=1;j<=n;j++) ipiv[j] = 0; ++ ++ for (i=1;i<=n;i++) /* This is the main loop over columns */ ++ { ++ big = 0.0; ++ for (j=1;j<=n;j++) /* This is outer loop of pivot search */ ++ if (ipiv[j] != 1) ++ for (k=1;k<=n;k++) ++ { ++ if (ipiv[k] == 0) ++ { ++ if (fabs(a[j][k]) >= big) ++ { ++ big = fabs(a[j][k]); ++ irow = j; ++ icol = k; ++ } ++ } ++ else ++ if (ipiv[k] > 1) return -1; ++ } ++ ++(ipiv[icol]); ++ ++/* We now have the pivot element, so we interchange rows, if needed, */ ++/* to put the pivot element on the diagonal. The columns are not */ ++/* physically interchanged, only relabeled: indxc[i], the column of the */ ++/* ith pivot element, is the ith column that is reduced, while indxr[i] */ ++/* is the row in which that pivot element was orignally located. If */ ++/* indxr[i] != indxc[i] there is an implied column interchange. With */ ++/* this form of bookkeeping, the solution b's will end up in the correct */ ++/* order, and the inverse matrix will be scrambed by columns. */ ++ ++ if (irow != icol) ++ { ++/* for (l=1;1<=n;l++) SWAP(a[irow][l],a[icol][l]) */ ++ for (l=1;l<=n;l++) ++ { ++ temp=a[irow][l]; ++ a[irow][l]=a[icol][l]; ++ a[icol][l]=temp; ++ } ++ if (bexists) for (l=1;l<=m;l++) SWAP(b[irow][l],b[icol][l]) ++ } ++ indxr[i] = irow; /* We are now ready to divide the pivot row */ ++ indxc[i] = icol; /* by the pivot element, a[irow][icol] */ ++ if (a[icol][icol] == 0.0) return -1; ++ pivinv = 1.0/a[icol][icol]; ++ a[icol][icol] = 1.0; ++ for (l=1;l<=n;l++) a[icol][l] *= pivinv; ++ if (bexists) for (l=1;l<=m;l++) b[icol][l] *= pivinv; ++ for (ll=1;ll<=n;ll++) /* Next, we reduce the rows... */ ++ if (ll != icol ) /* .. except for the pivot one */ ++ { ++ dum = a[ll][icol]; ++ a[ll][icol] = 0.0; ++ for (l=1;l<=n;l++) a[ll][l] -= a[icol][l]*dum; ++ if (bexists) for (l=1;l<=m;l++) b[ll][i] -= b[icol][l]*dum; ++ } ++ } ++ ++/* This is the end of the mail loop over columns of the reduction. It ++ only remains to unscrambled the solution in view of the column ++ interchanges. We do this by interchanging pairs of columns in ++ the reverse order that the permutation was built up. */ ++ ++ for (l=n;l>=1;l--) ++ { ++ if (indxr[l] != indxc[l]) ++ for (k=1;k<=n;k++) ++ SWAP(a[k][indxr[l]],a[k][indxc[l]]) ++ } ++ ++/* and we are done */ ++ ++ nr_free_ivector(ipiv,1 /*,n*/ ); ++ nr_free_ivector(indxr,1 /*,n*/ ); ++ nr_free_ivector(indxc,1 /*,n*/ ); ++ ++ return 0; /* indicate success */ ++} ++ ++void nr_copymat(double **orig, int n, double **copy) ++/* overwrites matrix 'copy' with copy of matrix 'orig' */ ++{ ++ long i, j; ++ ++ if ((orig==0)||(copy==0)||(n==0)) return; ++ ++ for (i=1;i<=n;i++) ++ for (j=1;j<=n;j++) ++ copy[i][j] = orig[i][j]; ++} ++ ++void nr_multmat(double **m1, int n, double **m2, double **prod) ++{ ++ long i, j, k; ++ ++ if ((m1==0)||(m2==0)||(prod==0)||(n==0)) return; ++ ++ for (i=1;i<=n;i++) ++ for (j=1;j<=n;j++) ++ { ++ prod[i][j] = 0.0; ++ for(k=1;k<=n;k++) prod[i][j] += m1[i][k]*m2[k][j]; ++ } ++} ++ ++ ++ ++void nr_printmat(double **a, int n) ++{ ++ int i,j; ++ ++ printf("\n"); ++ for(i=1;i<=n;i++) ++ { ++ for(j=1;j<=n;j++) ++ printf("% 9.4f ", a[i][j]); ++ printf("\n"); ++ } ++ printf("\n"); ++ ++} ++ ++ ++void testmat( void ) /* main() for test purposes */ ++{ ++ double **mat1, **mat2, **mat3; ++ double invmaxlong; ++ int loop, i, j, n = 20; ++ long maxlong = RAND_MAX; ++ int maxloop = 2; ++ ++ invmaxlong = 1.0/(double)maxlong; ++ mat1 = nr_matrix(1, n, 1, n ); ++ mat2 = nr_matrix(1, n, 1, n ); ++ mat3 = nr_matrix(1, n, 1, n ); ++ ++/* for(i=1;i<=n;i++) mat1[i][i]= 5.0; */ ++ ++ for(loop=0;loop ++#include ++#include ++ ++#define NR_END 1 ++ ++/* matrix creation & destruction routines */ ++ ++int *nr_ivector(long nl, long nh); ++double **nr_matrix(long nrl, long nrh, long ncl, long nch); ++ ++void nr_free_ivector(int *v, long nl /* , long nh */); ++void nr_free_matrix(double **m, long nrl, long nrh, long ncl, long nch); ++ ++ ++/* Gauss-Jordan inversion routine */ ++ ++int nr_gaussj(double **a, int n, double **b, int m); ++ ++/* Linear equation solution by Gauss-Jordan elimination. a[1..n][1..n] is */ ++/* the input matrix. b[1..n][1..m] is input containing the m right-hand */ ++/* side vectors. On output, a is replaced by its matrix invers, and b is */ ++/* replaced by the corresponding set of solution vectors. */ ++ ++/* Note: this routine modified by EBJ to make b optional, if m == 0 */ ++ ++/* Matrix copy, multiply, and printout routines (by EBJ) */ ++ ++void nr_copymat(double **orig, int n, double **copy); ++void nr_multmat(double **m1, int n, double **m2, double **prod); ++void nr_printmat(double **a, int n); ++ ++ diff --cc Simulator/LaRCsim/ls_model.c index 000000000,000000000..b9646a14f new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_model.c @@@ -1,0 -1,0 +1,94 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_model() ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Model loop executive ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 15 October 1992 as part of LaRCSIM project ++ by Bruce Jackson. ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: Bruce Jackson ++ ++ CODED BY: Bruce Jackson ++ ++ MAINTAINED BY: maintainer ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 950306 Added parameters to call: dt, which is the step size ++ to be taken this loop (caution: may vary from call to call) ++ and Initialize, which if non-zero, implies an initialization ++ is requested. EBJ ++ ++ CURRENT RCS HEADER INFO: ++$Header$ ++$Log$ ++Revision 1.3 1998/08/06 12:46:39 curt ++Header change. ++ ++Revision 1.2 1998/01/19 18:40:27 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:09:58 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.3 1995/03/06 18:49:46 bjax ++ * Added dt and initialize flag parameters to subroutine calls. This will ++ * support trim routine (to allow single throttle setting to drive ++ * all four throttle positions, for example, if initialize is TRUE). ++ * ++ * Revision 1.2 1993/03/10 06:38:09 bjax ++ * Added additional calls: inertias() and subsystems()... EBJ ++ * ++ * Revision 1.1 92/12/30 13:19:08 bjax ++ * Initial revision ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ls_step (in initialization), ls_loop (planned) ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: aero(), engine(), gear() ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++#include "ls_types.h" ++#include "ls_model.h" ++#include "default_model_routines.h" ++ ++ ++void ls_model( SCALAR dt, int Initialize ) { ++ inertias( dt, Initialize ); ++ subsystems( dt, Initialize ); ++ aero( dt, Initialize ); ++ engine( dt, Initialize ); ++ gear( dt, Initialize ); ++} diff --cc Simulator/LaRCsim/ls_model.h index 000000000,000000000..cb0d0321f new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_model.h @@@ -1,0 -1,0 +1,11 @@@ ++/* a quick ls_model.h */ ++ ++ ++#ifndef _LS_MODEL_H ++#define _LS_MODEL_H ++ ++ ++void ls_model( SCALAR dt, int Initialize ); ++ ++ ++#endif /* _LS_MODEL_H */ diff --cc Simulator/LaRCsim/ls_sim_control.h index 000000000,000000000..753c75be5 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_sim_control.h @@@ -1,0 -1,0 +1,132 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_sim_control.h ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: LaRCSim simulation control parameters header file ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 18 DEC 1993 by Bruce Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: B. Jackson ++ ++ CODED BY: B. Jackson ++ ++ MAINTAINED BY: guess who ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 940204 Added "overrun" flag to indicate non-real-time frame. ++ 940210 Added "vision" flag to indicate use of shared memory. ++ 940513 Added "max_tape_channels" and "max_time_slices" EBJ ++ 950308 Increased size of time_stamp and date_string to include ++ terminating null char. EBJ ++ 950314 Addedf "paused" flag to make this global (was local to ++ ls_cockpit routine). EBJ ++ 950406 Removed tape_channels parameter, and added end_time, model_hz, ++ and term_update_hz parameters. EBJ ++ ++$Header$ ++$Log$ ++Revision 1.4 1998/08/06 12:46:39 curt ++Header change. ++ ++Revision 1.3 1998/01/22 02:59:33 curt ++Changed #ifdef FILE_H to #ifdef _FILE_H ++ ++Revision 1.2 1998/01/06 01:20:17 curt ++Tweaks to help building with MSVC++ ++ ++Revision 1.1 1997/05/29 00:09:59 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.11 1995/04/07 01:39:09 bjax ++ * Removed tape_channels and added end_time, model_hz, and term_update_hz. ++ * ++ * Revision 1.10 1995/03/15 12:33:29 bjax ++ * Added 'paused' flag. ++ * ++ * Revision 1.9 1995/03/08 12:34:21 bjax ++ * Increased size of date_string and time_stamp by 1 to include terminating null; ++ * added userid field and include of stdio.h. EBJ ++ * ++ * Revision 1.8 1994/05/13 20:41:43 bjax ++ * Increased size of time_stamp to 8 chars to allow for colons. ++ * Added fields "tape_channels" and "time_slices" to allow user to change. ++ * ++ * Revision 1.7 1994/05/10 15:18:49 bjax ++ * Modified write_cmp2 flag to write_asc1 flag, since XPLOT 4.00 doesn't ++ * support cmp2. Also added RCS header and log entries in header. ++ * ++ ++ ++--------------------------------------------------------------------------*/ ++ ++ ++#ifndef _LS_SIM_CONTROL_H ++#define _LS_SIM_CONTROL_H ++ ++ ++#include ++ ++#ifndef SIM_CONTROL ++ ++typedef struct { ++ ++ enum { batch, terminal, GLmouse, cockpit } sim_type; ++ char simname[64]; /* name of simulation */ ++ int run_number; /* run number of this session */ ++ char date_string[7]; /* like "931220" */ ++ char time_stamp[9]; /* like "13:00:00" */ ++#ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE ++ char userid[L_cuserid]; /* who is running this sim */ ++#endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */ ++ long time_slices; /* number of points that can be recorded (circ buff) */ ++ int write_av; /* will be writing out an Agile_VU file after run */ ++ int write_mat; /* will be writing out a matrix script of session */ ++ int write_tab; /* will be writing out a tab-delimited time history */ ++ int write_asc1; /* will be writing out a GetData ASCII 1 file */ ++ int save_spacing; /* spacing between data points when recording ++ data to memory; 0 = every point, 1 = every ++ other point; 2 = every fourth point, etc. */ ++ int write_spacing; /* spacing between data points when writing ++ output files; 0 = every point, 1 = every ++ other point; 2 = every fourth point, etc. */ ++ int overrun; /* indicates, if non-zero, a frame overrun ++ occurred in the previous frame. Suitable for ++ setting a display flag or writing an error ++ message. */ ++ int vision; /* indicates, if non-zero, marriage to LaRC VISION ++ software (developed A. Dare and J. Burley of the ++ former Cockpit Technologies Branch) */ ++ int debug; /* indicates, if non-zero, to operate in debug mode ++ which implies disable double-buffering and synch. ++ attempts to avoid errors */ ++ int paused; /* indicates simulation is paused */ ++ float end_time; /* end of simulation run value */ ++ float model_hz; /* current inner loop frame rate */ ++ float term_update_hz; /* current terminal refresh frequency */ ++ ++} SIM_CONTROL; ++ ++extern SIM_CONTROL sim_control_; ++ ++#endif ++ ++ ++#endif /* _LS_SIM_CONTROL_H */ ++ ++ ++/*------------------------ end of ls_sim_control.h ----------------------*/ diff --cc Simulator/LaRCsim/ls_step.c index 000000000,000000000..58838e8d3 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_step.c @@@ -1,0 -1,0 +1,361 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_step ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Integration routine for equations of motion ++ (vehicle states) ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Written 920802 by Bruce Jackson. Based upon equations ++ given in reference [1] and a Matrix-X/System Build block ++ diagram model of equations of motion coded by David Raney ++ at NASA-Langley in June of 1992. ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: Bruce Jackson ++ ++ CODED BY: Bruce Jackson ++ ++ MAINTAINED BY: ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 921223 Modified calculation of Phi and Psi to use the "atan2" routine ++ rather than the "atan" to allow full circular angles. ++ "atan" limits to +/- pi/2. EBJ ++ ++ 940111 Changed from oldstyle include file ls_eom.h; also changed ++ from DATA to SCALAR type. EBJ ++ ++ 950207 Initialized Alpha_dot and Beta_dot to zero on first pass; calculated ++ thereafter. EBJ ++ ++ 950224 Added logic to avoid adding additional increment to V_east ++ in case V_east already accounts for rotating earth. ++ EBJ ++ ++ CURRENT RCS HEADER: ++ ++$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 ++ positions every time the internal flight model loop is run, and not just ++ once per rendered frame. ++Added a routine to do the necessary stuff to force an arbitrary altitude ++ change. ++Gave the Navion engine just a tad more power. ++ ++Revision 1.2 1998/01/19 18:40:28 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:09:59 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.5 1995/03/02 20:24:13 bjax ++ * Added logic to avoid adding additional increment to V_east ++ * in case V_east already accounts for rotating earth. EBJ ++ * ++ * Revision 1.4 1995/02/07 20:52:21 bjax ++ * Added initialization of Alpha_dot and Beta_dot to zero on first ++ * pass; they get calculated by ls_aux on next pass... EBJ ++ * ++ * Revision 1.3 1994/01/11 19:01:12 bjax ++ * Changed from DATA to SCALAR type; also fixed header files (was ls_eom.h) ++ * ++ * Revision 1.2 1993/06/02 15:03:09 bjax ++ * Moved initialization of geocentric position to subroutine ls_geod_to_geoc. ++ * ++ * Revision 1.1 92/12/30 13:16:11 bjax ++ * Initial revision ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++ [ 1] McFarland, Richard E.: "A Standard Kinematic Model ++ for Flight Simulation at NASA-Ames", NASA CR-2497, ++ January 1975 ++ ++ [ 2] ANSI/AIAA R-004-1992 "Recommended Practice: Atmos- ++ pheric and Space Flight Vehicle Coordinate Systems", ++ February 1992 ++ ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: None. ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: State derivatives ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: States ++ ++--------------------------------------------------------------------------*/ ++ ++#include "ls_types.h" ++#include "ls_constants.h" ++#include "ls_generic.h" ++#include "ls_accel.h" ++#include "ls_aux.h" ++#include "ls_model.h" ++#include "ls_step.h" ++#include "ls_geodesy.h" ++#include "ls_gravity.h" ++/* #include "ls_sim_control.h" */ ++#include ++ ++extern SCALAR Simtime; /* defined in ls_main.c */ ++ ++void ls_step( SCALAR dt, int Initialize ) { ++ static int inited = 0; ++ SCALAR dth; ++ static SCALAR v_dot_north_past, v_dot_east_past, v_dot_down_past; ++ static SCALAR latitude_dot_past, longitude_dot_past, radius_dot_past; ++ static SCALAR p_dot_body_past, q_dot_body_past, r_dot_body_past; ++ SCALAR p_local_in_body, q_local_in_body, r_local_in_body; ++ SCALAR epsilon, inv_eps, local_gnd_veast; ++ 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 */ ++ ++ ++ if ( (inited == 0) || (Initialize != 0) ) ++ { ++/* Set past values to zero */ ++ v_dot_north_past = v_dot_east_past = v_dot_down_past = 0; ++ latitude_dot_past = longitude_dot_past = radius_dot_past = 0; ++ p_dot_body_past = q_dot_body_past = r_dot_body_past = 0; ++ e_dot_0_past = e_dot_1_past = e_dot_2_past = e_dot_3_past = 0; ++ ++/* Initialize geocentric position from geodetic latitude and altitude */ ++ ++ ls_geod_to_geoc( Latitude, Altitude, &Sea_level_radius, &Lat_geocentric); ++ Earth_position_angle = 0; ++ Lon_geocentric = Longitude; ++ Radius_to_vehicle = Altitude + Sea_level_radius; ++ ++/* Correct eastward velocity to account for earths' rotation, if necessary */ ++ ++ local_gnd_veast = OMEGA_EARTH*Sea_level_radius*cos(Lat_geocentric); ++ if( fabs(V_east - V_east_rel_ground) < 0.8*local_gnd_veast ) ++ V_east = V_east + local_gnd_veast; ++ ++/* Initialize quaternions and transformation matrix from Euler angles */ ++ ++ e_0 = cos(Psi*0.5)*cos(Theta*0.5)*cos(Phi*0.5) ++ + sin(Psi*0.5)*sin(Theta*0.5)*sin(Phi*0.5); ++ e_1 = cos(Psi*0.5)*cos(Theta*0.5)*sin(Phi*0.5) ++ - sin(Psi*0.5)*sin(Theta*0.5)*cos(Phi*0.5); ++ e_2 = cos(Psi*0.5)*sin(Theta*0.5)*cos(Phi*0.5) ++ + sin(Psi*0.5)*cos(Theta*0.5)*sin(Phi*0.5); ++ e_3 =-cos(Psi*0.5)*sin(Theta*0.5)*sin(Phi*0.5) ++ + sin(Psi*0.5)*cos(Theta*0.5)*cos(Phi*0.5); ++ T_local_to_body_11 = e_0*e_0 + e_1*e_1 - e_2*e_2 - e_3*e_3; ++ T_local_to_body_12 = 2*(e_1*e_2 + e_0*e_3); ++ T_local_to_body_13 = 2*(e_1*e_3 - e_0*e_2); ++ T_local_to_body_21 = 2*(e_1*e_2 - e_0*e_3); ++ T_local_to_body_22 = e_0*e_0 - e_1*e_1 + e_2*e_2 - e_3*e_3; ++ T_local_to_body_23 = 2*(e_2*e_3 + e_0*e_1); ++ T_local_to_body_31 = 2*(e_1*e_3 + e_0*e_2); ++ T_local_to_body_32 = 2*(e_2*e_3 - e_0*e_1); ++ T_local_to_body_33 = e_0*e_0 - e_1*e_1 - e_2*e_2 + e_3*e_3; ++ ++/* Calculate local gravitation acceleration */ ++ ++ ls_gravity( Radius_to_vehicle, Lat_geocentric, &Gravity ); ++ ++/* Initialize vehicle model */ ++ ++ ls_aux(); ++ ls_model(0.0, 0); ++ ++/* Calculate initial accelerations */ ++ ++ ls_accel(); ++ ++/* Initialize auxiliary variables */ ++ ++ ls_aux(); ++ Alpha_dot = 0.; ++ Beta_dot = 0.; ++ ++/* set flag; disable integrators */ ++ ++ inited = -1; ++ dt = 0; ++ ++ } ++ ++/* Update time */ ++ ++ dth = 0.5*dt; ++ Simtime = Simtime + dt; ++ ++/* L I N E A R V E L O C I T I E S */ ++ ++/* Integrate linear accelerations to get velocities */ ++/* Using predictive Adams-Bashford algorithm */ ++ ++ V_north = V_north + dth*(3*V_dot_north - v_dot_north_past); ++ V_east = V_east + dth*(3*V_dot_east - v_dot_east_past ); ++ V_down = V_down + dth*(3*V_dot_down - v_dot_down_past ); ++ ++/* record past states */ ++ ++ v_dot_north_past = V_dot_north; ++ v_dot_east_past = V_dot_east; ++ v_dot_down_past = V_dot_down; ++ ++/* Calculate trajectory rate (geocentric coordinates) */ ++ ++ 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*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 */ ++ ++/* Integrate rotational accelerations to get velocities */ ++ ++ P_body = P_body + dth*(3*P_dot_body - p_dot_body_past); ++ Q_body = Q_body + dth*(3*Q_dot_body - q_dot_body_past); ++ R_body = R_body + dth*(3*R_dot_body - r_dot_body_past); ++ ++/* Save past states */ ++ ++ p_dot_body_past = P_dot_body; ++ q_dot_body_past = Q_dot_body; ++ r_dot_body_past = R_dot_body; ++ ++/* Calculate local axis frame rates due to travel over curved earth */ ++ ++ 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 */ ++ ++ p_local_in_body = T_local_to_body_11*P_local + T_local_to_body_12*Q_local + T_local_to_body_13*R_local; ++ q_local_in_body = T_local_to_body_21*P_local + T_local_to_body_22*Q_local + T_local_to_body_23*R_local; ++ r_local_in_body = T_local_to_body_31*P_local + T_local_to_body_32*Q_local + T_local_to_body_33*R_local; ++ ++/* Calculate total angular rates in body axis */ ++ ++ P_total = P_body - p_local_in_body; ++ Q_total = Q_body - q_local_in_body; ++ R_total = R_body - r_local_in_body; ++ ++/* Transform to quaternion rates (see Appendix E in [2]) */ ++ ++ e_dot_0 = 0.5*( -P_total*e_1 - Q_total*e_2 - R_total*e_3 ); ++ e_dot_1 = 0.5*( P_total*e_0 - Q_total*e_3 + R_total*e_2 ); ++ e_dot_2 = 0.5*( P_total*e_3 + Q_total*e_0 - R_total*e_1 ); ++ e_dot_3 = 0.5*( -P_total*e_2 + Q_total*e_1 + R_total*e_0 ); ++ ++/* Integrate using trapezoidal as before */ ++ ++ e_0 = e_0 + dth*(e_dot_0 + e_dot_0_past); ++ e_1 = e_1 + dth*(e_dot_1 + e_dot_1_past); ++ e_2 = e_2 + dth*(e_dot_2 + e_dot_2_past); ++ e_3 = e_3 + dth*(e_dot_3 + e_dot_3_past); ++ ++/* calculate orthagonality correction - scale quaternion to unity length */ ++ ++ epsilon = sqrt(e_0*e_0 + e_1*e_1 + e_2*e_2 + e_3*e_3); ++ inv_eps = 1/epsilon; ++ ++ e_0 = inv_eps*e_0; ++ e_1 = inv_eps*e_1; ++ e_2 = inv_eps*e_2; ++ e_3 = inv_eps*e_3; ++ ++/* Save past values */ ++ ++ e_dot_0_past = e_dot_0; ++ e_dot_1_past = e_dot_1; ++ e_dot_2_past = e_dot_2; ++ e_dot_3_past = e_dot_3; ++ ++/* Update local to body transformation matrix */ ++ ++ T_local_to_body_11 = e_0*e_0 + e_1*e_1 - e_2*e_2 - e_3*e_3; ++ T_local_to_body_12 = 2*(e_1*e_2 + e_0*e_3); ++ T_local_to_body_13 = 2*(e_1*e_3 - e_0*e_2); ++ T_local_to_body_21 = 2*(e_1*e_2 - e_0*e_3); ++ T_local_to_body_22 = e_0*e_0 - e_1*e_1 + e_2*e_2 - e_3*e_3; ++ T_local_to_body_23 = 2*(e_2*e_3 + e_0*e_1); ++ T_local_to_body_31 = 2*(e_1*e_3 + e_0*e_2); ++ T_local_to_body_32 = 2*(e_2*e_3 - e_0*e_1); ++ T_local_to_body_33 = e_0*e_0 - e_1*e_1 - e_2*e_2 + e_3*e_3; ++ ++/* Calculate Euler angles */ ++ ++ Theta = asin( -T_local_to_body_13 ); ++ ++ if( T_local_to_body_11 == 0 ) ++ Psi = 0; ++ else ++ Psi = atan2( T_local_to_body_12, T_local_to_body_11 ); ++ ++ if( T_local_to_body_33 == 0 ) ++ Phi = 0; ++ else ++ Phi = atan2( T_local_to_body_23, T_local_to_body_33 ); ++ ++/* Resolve Psi to 0 - 359.9999 */ ++ ++ if (Psi < 0 ) Psi = Psi + 2*PI; ++ ++/* L I N E A R P O S I T I O N S */ ++ ++/* Trapezoidal acceleration for position */ ++ ++ Lat_geocentric = Lat_geocentric + dth*(Latitude_dot + latitude_dot_past ); ++ Lon_geocentric = Lon_geocentric + dth*(Longitude_dot + longitude_dot_past); ++ Radius_to_vehicle = Radius_to_vehicle + dth*(Radius_dot + radius_dot_past ); ++ Earth_position_angle = Earth_position_angle + dt*OMEGA_EARTH; ++ ++/* Save past values */ ++ ++ latitude_dot_past = Latitude_dot; ++ longitude_dot_past = Longitude_dot; ++ radius_dot_past = Radius_dot; ++ ++/* end of ls_step */ ++} ++/*************************************************************************/ ++ diff --cc Simulator/LaRCsim/ls_step.h index 000000000,000000000..e18f93e30 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_step.h @@@ -1,0 -1,0 +1,11 @@@ ++/* a quick ls_step.h */ ++ ++ ++#ifndef _LS_STEP_H ++#define _LS_STEP_H ++ ++ ++void ls_step( SCALAR dt, int Initialize ); ++ ++ ++#endif /* _LS_STEP_H */ diff --cc Simulator/LaRCsim/ls_sym.h index 000000000,000000000..eca19894b new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_sym.h @@@ -1,0 -1,0 +1,166 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_sym.h ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Header file for symbol table routines ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: production ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 930629 by E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: Bruce Jackson ++ ++ CODED BY: same ++ ++ MAINTAINED BY: ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 950227 Added header and declarations for ls_print_findsym_error(), ++ ls_get_double(), and ls_get_double() routines. EBJ ++ ++ 950302 Added structure for symbol description. EBJ ++ ++ 950306 Added ls_get_sym_val() and ls_set_sym_val() routines. ++ This is now the production version. EBJ ++ ++ CURRENT RCS HEADER: ++ ++$Header$ ++$Log$ ++Revision 1.3 1998/08/06 12:46:40 curt ++Header change. ++ ++Revision 1.2 1998/01/22 02:59:34 curt ++Changed #ifdef FILE_H to #ifdef _FILE_H ++ ++Revision 1.1 1997/05/29 00:10:00 curt ++Initial Flight Gear revision. ++ ++ * Revision 1.9 1995/03/07 12:52:33 bjax ++ * This production version now specified ls_get_sym_val() and ls_put_sym_val(). ++ * ++ * Revision 1.6.1.2 1995/03/06 18:45:41 bjax ++ * Added def'n of ls_get_sym_val() and ls_set_sym_val(); changed symbol_rec ++ * Addr field from void * to char *. ++ * EBJ ++ * ++ * Revision 1.6.1.1 1995/03/03 01:17:44 bjax ++ * Experimental version with just ls_get_double and ls_set_double() routines. ++ * ++ * Revision 1.6 1995/02/27 19:50:49 bjax ++ * Added header and declarations for ls_print_findsym_error(), ++ * ls_get_double(), and ls_set_double(). EBJ ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++ ++#ifndef _LS_SYM_H ++#define _LS_SYM_H ++ ++ ++/* Return codes */ ++ ++#define SYM_NOT_LOADED -2 ++#define SYM_UNEXPECTED_ERR -1 ++#define SYM_OK 0 ++#define SYM_OPEN_ERR 1 ++#define SYM_NO_SYMS 2 ++#define SYM_MOD_NOT_FOUND 3 ++#define SYM_VAR_NOT_FOUND 4 ++#define SYM_NOT_SCALAR 5 ++#define SYM_NOT_STATIC 6 ++#define SYM_MEMORY_ERR 7 ++#define SYM_UNMATCHED_PAREN 8 ++#define SYM_BAD_SYNTAX 9 ++#define SYM_INDEX_BOUNDS_ERR 10 ++ ++typedef enum {Unknown, Char, UChar, SHint, USHint, Sint, Uint, Slng, Ulng, flt, dbl} vartype; ++ ++typedef char SYMBOL_NAME[64]; ++typedef vartype SYMBOL_TYPE; ++ ++ ++ ++typedef struct ++{ ++ SYMBOL_NAME Mod_Name; ++ SYMBOL_NAME Par_Name; ++ SYMBOL_TYPE Par_Type; ++ SYMBOL_NAME Alias; ++ char *Addr; ++} symbol_rec; ++ ++ ++extern int ls_findsym( const char *modname, const char *varname, ++ char **addr, vartype *vtype ); ++ ++extern void ls_print_findsym_error(int result, ++ char *mod_name, ++ char *var_name); ++ ++extern double ls_get_double(vartype sym_type, void *addr ); ++ ++extern void ls_set_double(vartype sym_type, void *addr, double value ); ++ ++extern double ls_get_sym_val( symbol_rec *symrec, int *error ); ++ ++ /* This routine attempts to return the present value of the symbol ++ described in symbol_rec. If Addr is non-zero, the value of that ++ location, interpreted as type double, will be returned. If Addr ++ is zero, and Mod_Name and Par_Name are both not null strings, ++ the ls_findsym() routine is used to try to obtain the address ++ by looking at debugger symbol tables in the executable image, and ++ the value of the double contained at that address is returned, ++ and the symbol record is updated to contain the address of that ++ symbol. If an error is discovered, 'error' will be non-zero and ++ and error message is printed on stderr. */ ++ ++extern void ls_set_sym_val( symbol_rec *symrec, double value ); ++ ++ /* This routine sets the value of a double at the location pointed ++ to by the symbol_rec's Addr field, if Addr is non-zero. If Addr ++ is zero, and Mod_Name and Par_Name are both not null strings, ++ the ls_findsym() routine is used to try to obtain the address ++ by looking at debugger symbol tables in the executable image, and ++ the value of the double contained at that address is returned, ++ and the symbol record is updated to contain the address of that ++ symbol. If an error is discovered, 'error' will be non-zero and ++ and error message is printed on stderr. */ ++ ++ ++#endif /* _LS_SYM_H */ ++ ++ diff --cc Simulator/LaRCsim/ls_types.h index 000000000,000000000..c778e1df7 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/ls_types.h @@@ -1,0 -1,0 +1,52 @@@ ++/*************************************************************************** ++ ++ TITLE: ls_types.h ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: LaRCSim type definitions header file ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 15 DEC 1993 by Bruce Jackson from old ++ ls_eom.h header ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: B. Jackson ++ ++ CODED BY: B. Jackson ++ ++ MAINTAINED BY: guess who ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++--------------------------------------------------------------------------*/ ++ ++#ifndef _LS_TYPES_H ++#define _LS_TYPES_H ++ ++ ++/* SCALAR type is used throughout equations of motion code - sets precision */ ++ ++typedef double SCALAR; ++ ++typedef SCALAR VECTOR_3[3]; ++ ++/* DATA type is old style; this statement for continuity */ ++ ++#define DATA SCALAR ++ ++ ++#endif /* _LS_TYPES_H */ ++ ++ ++/* --------------------------- end of ls_types.h -------------------------*/ diff --cc Simulator/LaRCsim/mymain.c index 000000000,000000000..b4ecbddeb new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/mymain.c @@@ -1,0 -1,0 +1,13 @@@ ++/* test main for playing with the LaRCsim code */ ++ ++#include "ls_types.h" ++#include "ls_cockpit.h" ++#include "ls_generic.h" ++ ++ ++COCKPIT cockpit_; ++GENERIC generic_; ++ ++int main(int argc, char **argv) { ++ model_init(); ++} diff --cc Simulator/LaRCsim/navion_aero.c index 000000000,000000000..6839e457c new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/navion_aero.c @@@ -1,0 -1,0 +1,213 @@@ ++/*************************************************************************** ++ ++ TITLE: Navion_aero ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Linear aerodynamics model ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Based upon class notes from AA271, Stanford University, ++ Spring 1988. Dr. Robert Cannon, instructor. ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: Bruce Jackson ++ ++ CODED BY: Bruce Jackson ++ ++ MAINTAINED BY: Bruce Jackson ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ 921229 Changed Alpha, Beta into radians; added Alpha bias. ++ EBJ ++ 930105 Modified to support linear airframe simulation by ++ adding shared memory initialization routine. EBJ ++ 931013 Added scaling by airspeed, to allow for low-airspeed ++ ground operations. EBJ ++ 940216 Scaled long, lat stick and rudder to more appropriate values ++ of elevator and aileron. EBJ ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++The Navion "aero" routine is a simple representation of the North ++American Navion airplane, a 1950-s vintage single-engine, low-wing ++mono-lane built by NAA (who built the famous P-51 Mustang) supposedly ++as a plane for returning WW-II fighter jocks to carry the family ++around the country in. Unfortunately underpowered, it can still be ++found in small airports across the United States. From behind, it sort ++of looks like a Volkswagen driving a Piper by virtue of its nicely ++rounded cabin roof and small rear window. ++ ++The aero routine is only valid around 100 knots; it is referred to as ++a "linear model" of the navion; the data having been extracted by ++someone unknown from a more complete model, or more likely, from ++in-flight measurements and manuever time histories. It probably came ++from someone at Princeton U; they owned a couple modified Navions that ++had a variable-stability system installed, and were highly ++instrumented (and well calibrated, I assume). ++ ++In any event, a linearized model, such as this one, contains various ++"stability derivatives", or estimates of how aerodynamic forces and ++moments vary with changes in angle of attack, angular body rates, and ++control surface deflections. For example, L_beta is an estimate of how ++much roll moment varies per degree of sideslip increase. A decoding ++ring is given below: ++ ++ X Aerodynamic force, lbs, in X-axis (+ forward) ++ Y Aerodynamic force, lbs, in Y-axis (+ right) ++ Z Aerodynamic force, lbs, in Z-axis (+ down) ++ L Aero. moment about X-axis (+ roll right), ft-lbs ++ M Aero. moment about Y-axis (+ pitch up), ft-lbs ++ N Aero. moment about Z-axis (+ nose right), ft-lbs ++ ++ 0 Subscript implying initial, or nominal, value ++ u X-axis component of airspeed (ft/sec) (+ forward) ++ v Y-axis component of airspeed (ft/sec) (+ right) ++ w Z-axis component of airspeed (ft/sec) (+ down) ++ p X-axis ang. rate (rad/sec) (+ roll right), rad/sec ++ q Y-axis ang. rate (rad/sec) (+ pitch up), rad/sec ++ r Z-axis ang. rate (rad/sec) (+ yaw right), rad/sec ++ beta Angle of sideslip, degrees (+ wind in RIGHT ear) ++ da Aileron deflection, degrees (+ left ail. TE down) ++ de Elevator deflection, degrees (+ trailing edge down) ++ dr Rudder deflection, degrees (+ trailing edge LEFT) ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++ ++#include "ls_types.h" ++#include "ls_generic.h" ++#include "ls_cockpit.h" ++ ++/* define trimmed w_body to correspond with alpha_trim = 5 */ ++#define TRIMMED_W 15.34 ++ ++extern COCKPIT cockpit_; ++ ++ ++void aero( SCALAR dt, int Initialize ) { ++ static int init = 0; ++ ++ SCALAR u, w; ++ static SCALAR elevator, aileron, rudder; ++ static SCALAR long_scale = 0.3; ++ static SCALAR lat_scale = 0.1; ++ static SCALAR yaw_scale = -0.1; ++ static SCALAR scale = 1.0; ++ ++ /* static SCALAR trim_inc = 0.0002; */ ++ /* static SCALAR long_trim; */ ++ ++ static DATA U_0; ++ static DATA X_0; ++ static DATA M_0; ++ static DATA Z_0; ++ static DATA X_u; ++ static DATA X_w; ++ static DATA X_de; ++ static DATA Y_v; ++ static DATA Z_u; ++ static DATA Z_w; ++ static DATA Z_de; ++ static DATA L_beta; ++ static DATA L_p; ++ static DATA L_r; ++ static DATA L_da; ++ static DATA L_dr; ++ static DATA M_w; ++ static DATA M_q; ++ static DATA M_de; ++ static DATA N_beta; ++ static DATA N_p; ++ static DATA N_r; ++ static DATA N_da; ++ static DATA N_dr; ++ ++ if (!init) ++ { ++ init = -1; ++ ++ /* Initialize aero coefficients */ ++ ++ U_0 = 176; ++ X_0 = -573.75; ++ M_0 = 0; ++ Z_0 = -2750; ++ X_u = -0.0451; /* original value */ ++ /* X_u = 0.0000; */ /* for MUCH better performance - EBJ */ ++ X_w = 0.03607; ++ X_de = 0; ++ Y_v = -0.2543; ++ Z_u = -0.3697; /* original value */ ++ /* Z_u = -0.03697; */ /* for better performance - EBJ */ ++ Z_w = -2.0244; ++ Z_de = -28.17; ++ L_beta = -15.982; ++ L_p = -8.402; ++ L_r = 2.193; ++ L_da = 28.984; ++ L_dr = 2.548; ++ M_w = -0.05; ++ M_q = -2.0767; ++ M_de = -11.1892; ++ N_beta = 4.495; ++ N_p = -0.3498; ++ N_r = -0.7605; ++ N_da = -0.2218; ++ N_dr = -4.597; ++ } ++ ++ u = V_rel_wind - U_0; ++ w = W_body - TRIMMED_W; ++ ++ elevator = long_scale * Long_control; ++ aileron = lat_scale * Lat_control; ++ rudder = yaw_scale * Rudder_pedal; ++ ++ /* if(Aft_trim) long_trim = long_trim - trim_inc; */ ++ /* if(Fwd_trim) long_trim = long_trim + trim_inc; */ ++ ++ scale = V_rel_wind*V_rel_wind/(U_0*U_0); ++ if (scale > 1.0) scale = 1.0; /* ebj */ ++ ++ ++ F_X_aero = scale*(X_0 + Mass*(X_u*u + X_w*w + X_de*elevator)); ++ F_Y_aero = scale*(Mass*Y_v*V_body); ++ F_Z_aero = scale*(Z_0 + Mass*(Z_u*u + Z_w*w + Z_de*elevator)); ++ ++ M_l_aero = scale*(I_xx*(L_beta*Beta + L_p*P_body + L_r*R_body ++ + L_da*aileron + L_dr*rudder)); ++ M_m_aero = scale*(M_0 + I_yy*(M_w*w + M_q*Q_body + M_de*(elevator + Long_trim))); ++ M_n_aero = scale*(I_zz*(N_beta*Beta + N_p*P_body + N_r*R_body ++ + N_da*aileron + N_dr*rudder)); ++ ++} ++ ++ diff --cc Simulator/LaRCsim/navion_engine.c index 000000000,000000000..d1ae9018e new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/navion_engine.c @@@ -1,0 -1,0 +1,82 @@@ ++/*************************************************************************** ++ ++ TITLE: engine.c ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: dummy engine routine ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: incomplete ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 15 OCT 92 as dummy routine for checkout. EBJ ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: designer ++ ++ CODED BY: programmer ++ ++ MAINTAINED BY: maintainer ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ CURRENT RCS HEADER INFO: ++ ++$Header$ ++ ++ * Revision 1.1 92/12/30 13:21:46 bjax ++ * Initial revision ++ * ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ls_model(); ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: none ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++#include ++#include "ls_types.h" ++#include "ls_constants.h" ++#include "ls_generic.h" ++#include "ls_sim_control.h" ++#include "ls_cockpit.h" ++ ++extern SIM_CONTROL sim_control_; ++ ++void engine( SCALAR dt, int init ) { ++ /* if (init) { */ ++ Throttle[3] = Throttle_pct; ++ /* } */ ++ ++ /* F_X_engine = Throttle[3]*813.4/0.2; */ /* original code */ ++ /* F_Z_engine = Throttle[3]*11.36/0.2; */ /* original code */ ++ F_X_engine = Throttle[3]*813.4/0.83; ++ F_Z_engine = Throttle[3]*11.36/0.83; ++ ++ Throttle_pct = Throttle[3]; ++} ++ ++ diff --cc Simulator/LaRCsim/navion_gear.c index 000000000,000000000..d64fdea1a new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/navion_gear.c @@@ -1,0 -1,0 +1,333 @@@ ++/*************************************************************************** ++ ++ TITLE: gear ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Landing gear model for example simulation ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Created 931012 by E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: E. B. Jackson ++ ++ CODED BY: E. B. Jackson ++ ++ MAINTAINED BY: E. B. Jackson ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 931218 Added navion.h header to allow connection with ++ aileron displacement for nosewheel steering. EBJ ++ 940511 Connected nosewheel to rudder pedal; adjusted gain. ++ ++ CURRENT RCS HEADER: ++ ++$Header$ ++$Log$ ++Revision 1.6 1998/10/17 01:34:16 curt ++C++ ifying ... ++ ++Revision 1.5 1998/09/29 02:03:00 curt ++Added a brake + autopilot mods. ++ ++Revision 1.4 1998/08/06 12:46:40 curt ++Header change. ++ ++Revision 1.3 1998/02/03 23:20:18 curt ++Lots of little tweaks to fix various consistency problems discovered by ++Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper ++passed arguments along to the real printf(). Also incorporated HUD changes ++by Michele America. ++ ++Revision 1.2 1998/01/19 18:40:29 curt ++Tons of little changes to clean up the code and to remove fatal errors ++when building with the c++ compiler. ++ ++Revision 1.1 1997/05/29 00:10:02 curt ++Initial Flight Gear revision. ++ ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++#include ++#include "ls_types.h" ++#include "ls_constants.h" ++#include "ls_generic.h" ++#include "ls_cockpit.h" ++ ++ ++void sub3( DATA v1[], DATA v2[], DATA result[] ) ++{ ++ result[0] = v1[0] - v2[0]; ++ result[1] = v1[1] - v2[1]; ++ result[2] = v1[2] - v2[2]; ++} ++ ++void add3( DATA v1[], DATA v2[], DATA result[] ) ++{ ++ result[0] = v1[0] + v2[0]; ++ result[1] = v1[1] + v2[1]; ++ result[2] = v1[2] + v2[2]; ++} ++ ++void cross3( DATA v1[], DATA v2[], DATA result[] ) ++{ ++ result[0] = v1[1]*v2[2] - v1[2]*v2[1]; ++ result[1] = v1[2]*v2[0] - v1[0]*v2[2]; ++ result[2] = v1[0]*v2[1] - v1[1]*v2[0]; ++} ++ ++void multtrans3x3by3( DATA m[][3], DATA v[], DATA result[] ) ++{ ++ result[0] = m[0][0]*v[0] + m[1][0]*v[1] + m[2][0]*v[2]; ++ result[1] = m[0][1]*v[0] + m[1][1]*v[1] + m[2][1]*v[2]; ++ result[2] = m[0][2]*v[0] + m[1][2]*v[1] + m[2][2]*v[2]; ++} ++ ++void mult3x3by3( DATA m[][3], DATA v[], DATA result[] ) ++{ ++ result[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2]; ++ result[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2]; ++ result[2] = m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2]; ++} ++ ++void clear3( DATA v[] ) ++{ ++ v[0] = 0.; v[1] = 0.; v[2] = 0.; ++} ++ ++void gear( SCALAR dt, int Initialize ) { ++char rcsid[] = "$Id$"; ++ ++ /* ++ * Aircraft specific initializations and data goes here ++ */ ++ ++#define NUM_WHEELS 3 ++ ++ static int num_wheels = NUM_WHEELS; /* number of wheels */ ++ static DATA d_wheel_rp_body_v[NUM_WHEELS][3] = /* X, Y, Z locations */ ++ { ++ { 10., 0., 4. }, /* in feet */ ++ { -1., 3., 4. }, ++ { -1., -3., 4. } ++ }; ++ static DATA spring_constant[NUM_WHEELS] = /* springiness, lbs/ft */ ++ { 1500., 5000., 5000. }; ++ static DATA spring_damping[NUM_WHEELS] = /* damping, lbs/ft/sec */ ++ { 100., 150., 150. }; ++ static DATA percent_brake[NUM_WHEELS] = /* percent applied braking */ ++ { 0., 0., 0. }; /* 0 = none, 1 = full */ ++ static DATA caster_angle_rad[NUM_WHEELS] = /* steerable tires - in */ ++ { 0., 0., 0.}; /* radians, +CW */ ++ /* ++ * End of aircraft specific code ++ */ ++ ++ /* ++ * Constants & coefficients for tyres on tarmac - ref [1] ++ */ ++ ++ /* skid function looks like: ++ * ++ * mu ^ ++ * | ++ * max_mu | + ++ * | /| ++ * sliding_mu | / +------ ++ * | / ++ * | / ++ * +--+------------------------> ++ * | | | sideward V ++ * 0 bkout skid ++ * V V ++ */ ++ ++ ++ static DATA sliding_mu = 0.5; ++ static DATA rolling_mu = 0.01; ++ static DATA max_brake_mu = 0.6; ++ static DATA max_mu = 0.8; ++ static DATA bkout_v = 0.1; ++ static DATA skid_v = 1.0; ++ /* ++ * Local data variables ++ */ ++ ++ DATA d_wheel_cg_body_v[3]; /* wheel offset from cg, X-Y-Z */ ++ DATA d_wheel_cg_local_v[3]; /* wheel offset from cg, N-E-D */ ++ DATA d_wheel_rwy_local_v[3]; /* wheel offset from rwy, N-E-U */ ++ DATA v_wheel_body_v[3]; /* wheel velocity, X-Y-Z */ ++ DATA v_wheel_local_v[3]; /* wheel velocity, N-E-D */ ++ DATA f_wheel_local_v[3]; /* wheel reaction force, N-E-D */ ++ DATA temp3a[3], temp3b[3], tempF[3], tempM[3]; ++ DATA reaction_normal_force; /* wheel normal (to rwy) force */ ++ DATA cos_wheel_hdg_angle, sin_wheel_hdg_angle; /* temp storage */ ++ DATA v_wheel_forward, v_wheel_sideward, abs_v_wheel_sideward; ++ DATA forward_mu, sideward_mu; /* friction coefficients */ ++ DATA beta_mu; /* breakout friction slope */ ++ DATA forward_wheel_force, sideward_wheel_force; ++ ++ int i; /* per wheel loop counter */ ++ ++ /* ++ * Execution starts here ++ */ ++ ++ beta_mu = max_mu/(skid_v-bkout_v); ++ clear3( F_gear_v ); /* Initialize sum of forces... */ ++ clear3( M_gear_v ); /* ...and moments */ ++ ++ /* ++ * Put aircraft specific executable code here ++ */ ++ ++ /* replace with cockpit brake handle connection code */ ++ percent_brake[1] = Brake_pct; ++ percent_brake[2] = percent_brake[1]; ++ ++ caster_angle_rad[0] = 0.03*Rudder_pedal; ++ ++ for (i=0;i 0.) reaction_normal_force = 0.; ++ /* to prevent damping component from swamping spring component */ ++ } ++ ++ /* Calculate friction coefficients */ ++ ++ forward_mu = (max_brake_mu - rolling_mu)*percent_brake[i] + rolling_mu; ++ abs_v_wheel_sideward = sqrt(v_wheel_sideward*v_wheel_sideward); ++ sideward_mu = sliding_mu; ++ if (abs_v_wheel_sideward < skid_v) ++ sideward_mu = (abs_v_wheel_sideward - bkout_v)*beta_mu; ++ if (abs_v_wheel_sideward < bkout_v) sideward_mu = 0.; ++ ++ /* Calculate foreward and sideward reaction forces */ ++ ++ forward_wheel_force = forward_mu*reaction_normal_force; ++ sideward_wheel_force = sideward_mu*reaction_normal_force; ++ if(v_wheel_forward < 0.) forward_wheel_force = -forward_wheel_force; ++ if(v_wheel_sideward < 0.) sideward_wheel_force = -sideward_wheel_force; ++ ++ /* Rotate into local (N-E-D) axes */ ++ ++ f_wheel_local_v[0] = forward_wheel_force*cos_wheel_hdg_angle ++ - sideward_wheel_force*sin_wheel_hdg_angle; ++ f_wheel_local_v[1] = forward_wheel_force*sin_wheel_hdg_angle ++ + sideward_wheel_force*cos_wheel_hdg_angle; ++ f_wheel_local_v[2] = reaction_normal_force; ++ ++ /* Convert reaction force from local (N-E-D) axes to body (X-Y-Z) */ ++ ++ mult3x3by3( T_local_to_body_m, f_wheel_local_v, tempF ); ++ ++ /* Calculate moments from force and offsets in body axes */ ++ ++ cross3( d_wheel_cg_body_v, tempF, tempM ); ++ ++ /* Sum forces and moments across all wheels */ ++ ++ add3( tempF, F_gear_v, F_gear_v ); ++ add3( tempM, M_gear_v, M_gear_v ); ++ ++ } ++} diff --cc Simulator/LaRCsim/navion_init.c index 000000000,000000000..286c11d1a new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/navion_init.c @@@ -1,0 -1,0 +1,69 @@@ ++/*************************************************************************** ++ ++ TITLE: navion_init.c ++ ++---------------------------------------------------------------------------- ++ ++ FUNCTION: Initializes navion math model ++ ++---------------------------------------------------------------------------- ++ ++ MODULE STATUS: developmental ++ ++---------------------------------------------------------------------------- ++ ++ GENEALOGY: Added to navion package 930111 by Bruce Jackson ++ ++---------------------------------------------------------------------------- ++ ++ DESIGNED BY: EBJ ++ ++ CODED BY: EBJ ++ ++ MAINTAINED BY: EBJ ++ ++---------------------------------------------------------------------------- ++ ++ MODIFICATION HISTORY: ++ ++ DATE PURPOSE BY ++ ++ 950314 Removed initialization of state variables, since this is ++ now done (version 1.4b1) in ls_init. EBJ ++ 950406 Removed #include of "shmdefs.h"; shmdefs.h is a duplicate ++ of "navion.h". EBJ ++ ++ CURRENT RCS HEADER: ++ ++---------------------------------------------------------------------------- ++ ++ REFERENCES: ++ ++---------------------------------------------------------------------------- ++ ++ CALLED BY: ++ ++---------------------------------------------------------------------------- ++ ++ CALLS TO: ++ ++---------------------------------------------------------------------------- ++ ++ INPUTS: ++ ++---------------------------------------------------------------------------- ++ ++ OUTPUTS: ++ ++--------------------------------------------------------------------------*/ ++#include "ls_types.h" ++#include "ls_generic.h" ++#include "ls_cockpit.h" ++ ++void model_init( void ) { ++ ++ Throttle[3] = 0.2; Rudder_pedal = 0; Lat_control = 0; Long_control = 0; ++ ++ Dx_pilot = 0; Dy_pilot = 0; Dz_pilot = 0; ++ ++} diff --cc Simulator/LaRCsim/navion_init.h index 000000000,000000000..f7d097e14 new file mode 100644 --- /dev/null +++ b/Simulator/LaRCsim/navion_init.h @@@ -1,0 -1,0 +1,11 @@@ ++/* a quick navion_init.h */ ++ ++ ++#ifndef _NAVION_INIT_H ++#define _NAVION_INIT_H ++ ++ ++void model_init( void ); ++ ++ ++#endif _NAVION_INIT_H diff --cc Simulator/Main/GLUTkey.cxx index 000000000,000000000..4382653b8 new file mode 100644 --- /dev/null +++ b/Simulator/Main/GLUTkey.cxx @@@ -1,0 -1,0 +1,741 @@@ ++// GLUTkey.cxx -- handle GLUT keyboard events ++// ++// Written by Curtis Olson, started May 1997. ++// ++// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu ++// ++// This program is free software; you can redistribute it and/or ++// modify it under the terms of the GNU General Public License as ++// published by the Free Software Foundation; either version 2 of the ++// License, or (at your option) any later version. ++// ++// This program is distributed in the hope that it will be useful, but ++// WITHOUT ANY WARRANTY; without even the implied warranty of ++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++// General Public License for more details. ++// ++// You should have received a copy of the GNU General Public License ++// along with this program; if not, write to the Free Software ++// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++// ++// $Id$ ++// (Log is kept at end of this file) ++ ++ ++#ifdef HAVE_CONFIG_H ++# include ++#endif ++ ++#ifdef HAVE_WINDOWS_H ++# include ++#endif ++ ++#include ++#include ++ ++#if defined(FX) && defined(XMESA) ++#include ++#endif ++ ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include