An Open Source Flight Dynamics Model in C++
Total Page:16
File Type:pdf, Size:1020Kb
AIAA Modeling and Simulation Technologies Conference and Exhibit AIAA 2004-4923 16 - 19 August 2004, Providence, Rhode Island JSBSim: An Open Source Flight Dynamics Model in C++ Jon S. Berndt* JSBSim Project League City, TX Abstract: This paper gives an overview of JSBSim, an open source, multi-platform, flight dynamics model (FDM) framework written in the C++ programming language. JSBSim is designed to support simulation modeling of arbitrary aerospace craft without the need for specific compiled and linked program code. Instead, it relies on a relatively simple model specification written in an extensible markup language (XML) format. Also presented are some key (perhaps unique) features employed in the framework. Aspects of developing an open source project are identified. Notable uses of JSBSim are listed. I. Introduction SBSim1 was conceived in 1996 as a batch simulation application aimed at modeling flight dynamics and control J for aircraft.† It was accepted that such a tool could be useful in an academic setting as a freely available aid in aircraft design and controls courses. In 1998, the author began working with the FlightGear project.2 FlightGear is a sophisticated, full-featured, desktop flight simulator framework for use in research or academic environments, for the development and pursuit of interesting flight simulation ideas, and as an end-user application. At that time, FlightGear was using the LaRCsim3 flight dynamics model (FDM). LaRCsim requires new aircraft to be modeled in program code. Discussions with developers in the FlightGear community suggested that in order to make flight simulation more accessible, creating a generic, completely data-driven FDM framework would be helpful. That is, specific aircraft would be defined in data files, and no new program code would be required to model any arbitrary aircraft. Additional characteristics of such a framework include: • Employs object-oriented design principles • Compiles across common platforms and compilers • Readily available as an open source application • Is self-documenting JSBSim was integrated with FlightGear in 1999, and is today the default flight model. JSBSim retains the capability to run in a batch mode. The volunteer development team has grown over the years, and vigorous development continues. Since JSBSim is provided and developed under the GNU General Public License, it is available for use in other simulation projects with few restrictions. II. Architecture A. Benefits in the Use of C++ The C++ programming language is ideal for use in flight simulation software in part because of its support of the primary object-oriented concepts: polymorphism, inheritance, encapsulation, and abstraction. Polymorphism (i.e. “having many forms”) is a characteristic of objects that operate differently internally, but have the same interface. For example, the JSBSim implementation of a flight control system (FCS) consists of various classes of filters, switches, and gains that each have a unique internal implementation. The public interface to the components consists of the Run() and GetOutput() methods, which are both virtual member functions of the component base class. These two methods are overridden in derived classes that represent specific components with *JSBSim Project Architect and Development Coordinator, Senior Member AIAA. †Many types of “craft” can be modeled in JSBSim (e.g. a ball, aircraft, rocket, etc.) but within this paper the term “aircraft” will be used for all types. 1 American Institute of Aeronautics and Astronautics Copyright © 2004 by Jon S. Berndt. Published by the American Institute of Aeronautics and Astronautics, Inc., with permission. unique behavior. Each instance of a component is referred to by the base class pointer, but the behavior is determined by the logic defined within the Run() method of the specific derived component class. Inheritance is the derivation of a class from another in order to provide base class characteristics to the derived class. Using the example of the JSBSim FCS component classes again, each of the specific component classes (switch, summer, filter, etc.) is derived from a more generic component class that features characteristics that all components share. Inheritance is a common way to implement polymorphism. Encapsulation is the concept of hiding and protecting data in a class, preventing corruption by outside processes. For example, the output of the FCS components may only be retrieved, and not modified. In addition, some of the JSBSim FCS components store past values. These should never be accessible by any other part of the program. Abstraction is “the elimination of the irrelevant and the amplification of the essential”.4 The FCS component base class, for instance, provides the two simple functions Run() and GetOutput() that are used to operate a component. The details of how each specific component operates do not need to be exposed. The Standard Template Library (STL) is a library of containers and algorithms. The STL provides containers such as the vector class that operate like arrays that shrink or grow as needed. This capability is particularly useful in FGCoefficient → FGFactorGroup JSBSim, because the number of engines, coefficients, FCS FGColumnVector3 FGCondition components, etc. are unknown until the program is executed. FGConfigFile Other incidental advantages in the use of C++ include the FGElectric ready availability of engineers, mathematicians, etc. who are FGPiston FGEngine → also experienced C++ programmers, and the availability of FGRocket mature – and also free – C++ compilers, utilities, tools, and FGTurbine FGDeadBand integrated development environments (IDE) across the set of target platforms. FGFilter FGGain FGFCSComponent → FGGradient B. Class Hierarchy FGKinemat The collection of classes that make up the JSBSim FGSummer framework resembles a “family tree” with a common parent at FGSwitch the head of the hierarchy (see Fig. 1). This graphically FGFDMExec illustrates the concept of inheritance and – indirectly – code FGfdmSocket FGNozzle reuse. An entire class framework does not necessarily have to FGForce → FGThruster → FGPropeller conform to a completely hierarchical arrangement. In JSBSim, FGRotor several classes represent generic objects or concepts that are FGInitialCondition FGJSBBase → FGLGear each fully realized in derived classes. These base classes can be viewed as providing the abstract interface that is used to FGLocation FGMatrix33 access each of the derived objects. There are also operations FGAerodynamics and attributes (a fancy name for class member variables) that FGAircraft FGMars are common to almost all classes, so it makes sense to FGAtmosphere → FGMSIS implement those characteristics in a common base class. For FGAuxiliary instance, the framework base class (FGJSBBase*) implements FGFCS a messaging capability, providing message handling methods FGModel → FGGroundReactions and storage. Any descendant class can put a message on the FGInertial FGMassBalance queue to be retrieved and processed by the parent application, FGOutput or by any class instance that is also derived from the base FGPropagate class. Unit conversion routines and constants also reside in the FGPropulsion base class, available through inheritance to any of the many FGQuaternion descendant classes that need them. FGScript FGState One of the key challenges faced in creating a generic FDM FGTable is in designing it to permit the modeling of completely arbitrary vehicle configurations. The framework needs to be FGTank FGTrim able to transparently handle modeling craft ranging from a FGTrimAxis simple ball (useful for testing purposes, see Listing 1), to a missile, an aircraft, rocket, hybrid vehicle, a rotorcraft, and so Figure 1. JSBSim Class Hierarchy *The “FG” prefix refers to FlightGear. 2 American Institute of Aeronautics and Astronautics on. These craft could feature different propulsion systems, ground reaction mechanisms, aerodynamic characteristics, and control systems (if any). All four of the previously mentioned object oriented design characteristics played a part in addressing this challenge. For the propulsion system, an engine base class was created that provides a basic, common, engine interface. The class includes access methods for starter, throttle, and mixture settings, and methods for reading fuel flow rates, temperatures, etc. Specific engine types are derived from the engine base class, providing the actual implementations for turbine, rocket, piston, and electric engines. The derived classes each provide a Calculate() function (overriding the empty, virtual Calculate() function from the base class) that is called to run an iteration of the specific engine instance, determining the force and moment values that the particular engine transmits to the aircraft. In addition to the engine force and moment calculations performed inside the Calculate() function, other quantities are determined as well, including various temperatures, rotational rates, and pressures. A manager class handles all aspects of the propulsion system operation, including loading the definition of each engine, tank, and thruster (the device used to turn engine power into a force), initialization, cyclic execution while running, and destruction at completion. By providing an abstract interface to the engine object, each specific engine instance (no matter what derived type) can be executed the same way, from the point