Giter Club home page Giter Club logo

flightmechanics.jl's Introduction

FlightMechanics

license docs

no_maint

⚠️ This package has been deprecated in favor of:

logo

Flight Mechanics utils ✈️

This package is intended to provide utils for Flight Mechanics computations. It runs on julia ≥ 1.0

  • International Standard Atmosphere: get pressure, temperature, density, sound velocity for a given altitude.
  • Conversion between different coordinate systems:
    • body
    • horizon
    • wind
    • ECEF
    • llh (latitude, longitude, height) over various ellipsoid models
  • Quaternion and euler angles conversions
  • Anemometry:
    • conversion between tas, cas, eas.
    • velocity calculation from airspeed indicator (ASI) pressure difference
    • dynamic pressure calculation (compressible and incompressible cases)
    • tas, alpha, beta from body velocity
  • 6 DOF Dynamic fixed mass models:
    • Flat Earth Euler angles
    • Flat Earth quaternions
    • Ellipsoidal Earth ECEF model quaternion
  • An experimental version of the simulator has been started. At the moment it comprises:
    • C310 aerodynamics model obtained from JSBSim with an oversimplified engine model.
    • F16 aerodynamics and engine (except for engine lag) model from ([1]).
    • A preliminary version of the trimmer able to trim both aircrafts and validated for F16 with text book examples.
    • Some base models serving as a for the development of the simulator: state, position, attitude, aerostate, mass, propulsion...
> [1] Stevens, B. L., Lewis, F. L., & Johnson, E. N. (2015). Aircraft control and simulation: dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 715)

Install 🚀

You can install this package cloning it:

Pkg> add [email protected]:AlexS12/FlightMechanics.jl.git

or if you want the dev version:

Pkg> dev [email protected]:AlexS12/FlightMechanics.jl.git

and run the tests:

Pkg> test FlightMechanics

If this package is useful for you and want to join efforts don't hesitate to let me know.

Ask Me Anything ! Open Source Love svg2

flightmechanics.jl's People

Contributors

alexs12 avatar fredrikekre avatar mortenpi avatar parthp08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flightmechanics.jl's Issues

DOC: markdown error

"""
quaternion2euler(q0, q1, q2, q3)
Transform quaternion orientation to Euler angles orientation.
#Arguments
`q0, q1, q2, q3`: quaternions.
Implementation from:
.. [1] Zipfel, P. H. (2007). Modeling and simulation of aerospace vehicle
dynamics. American Institute of Aeronautics and Astronautics.
(page 127, formula 4.82)
"""

https://alexs12.github.io/FlightMechanics.jl/latest/#FlightMechanics.quaternion2euler-NTuple{4,Any}

Use boundaries in optimization process for trimmer

Current situation
Right now the optimization process for trimming an aircraft does not use the control surfaces limits to constrain the results.

Objective

Tests for F16 trimming against Stevens passing without iterating out of controls surfaces ranges. Even if all the trimming validation done against Stevens for F16 converges to the same values. High Angle Of Attack (HAOA) cases require to iterate with out of range values to converge.

Avoid mutable struct for FCS As the FCS must be configured to allow out of range iteration and set back to the original values in the trimmer, it is now a mutating structure. Some other solutions to this situation may be proposed, but this would indirectly be solved if trimmer does not need out of range values.

Setup equations of motion with DifferentialEquations.jl?

Hey, found this repository from the discourse. Looks nice! It looks like a very small modification would need to be done for something like:

https://github.com/AlexS12/FlightMechanics.jl/blob/master/src/dynamics/sixdof_quaternion_fixed_mass.jl

to call the DifferentialEquations.jl ODE solvers. I think it would lead to some nice demos to have that setup. Note that in terms of the package, you can directly depend on the ODE solvers (OrdinaryDiffEq.jl) to reduce the dependency size.

Rethink dynamic system types

Some dynamic systems need more configurable attributes

# TODO: If ROT_VELOCITY in constants is set to zero this tests passes with atol=0.0
is an indication that it is necassary to:

  • configure Earth rotation speed as an optional argument with the current default value to SixDOFECEFQuaternionFixedMass at least for testing purposes
  • allow optional arguments to dynamic systems that are not currently considered, such as: lambda, Earth rotation speed or ellipsoid.

Are non-canonical convert methods acceptable?

Some convert methods in the project do not follow the "canonical" rule of receiving a type and an instance, but receive two instances. I think this can cause trouble at some point and maybe these methods shouldn't be called convert. Ie. conversion and promotion rules cannot be applied.

See #59 for examples of the problem

DOC: models/state.jl is mostly undocumented

Current situation
models/state.jl is mostly undocumented

Solution proposal
Generate docstring documentation for constructors (at least).
Is also desirable to include getters.
It would be convenient to have an entry in documentation describing the objective of the State struct (serving as an interface between different dynamic models and the simulator).

Implement some typical FCS inputs

Current situation
No generalized way in the package to generate typical inputs to controls.

Objective
Being able to generate typical inputs such as: step, doublet, ramp and harmonic. In a generalized way.

Solution proposal
Create a new file under Models module able to generate this inputs. Each input could be a struct storing its characteristic parameters (amplitude, duration...) then the input value could be calculated in a calculate_input(input, time) function.

Migration to julia 0.7

Julia 0.7 and Julia 1.0 have been launched. It is recommended to port firstly to 0.7 son incompatibility warnings will be raised and move to 1.0 afterwards.

Some tests are not passing in the nightly build because of this change, so this needs some attention.

AC AERO: F16 Aerodynamic models

Current situation
A set of differences that are enumerated in src/simulator/aircrafts/F16/aerodynamics.jl were found between Stevens and Morelli implementations. Currently, just Stevens implementation is in use and any check against Morelli is performed with wider tolerances.

Objective
Even if differences found are small having both implementation would be benefital for:

  • rigorous validation purposes
  • example of architecture of one aircraft whith several aerodynamic models associated

Solution proposal
Any solution should take place after #26 and #23

This is an easy task after issues above are solved

DOC: doc entry for environment

Current situation
Environment is an important piece for the simulator. however it does not have an entry where its roll and its entities (wind, gravity and atmos) are explained.

Solution proposal
Create an Environment entry in the documentation where it is described, as well as atmos, wind and gravity.

FCS: First order delays for inputs

Current situation
Inputs to FCS are applied immediately, however many real systems are simulated with a first order delay. A first example could be F16 Engine power demand with throttle.

Objective

  • To be able to apply inputs with first order delays.
  • Complete F16 model.

Solution proposal

  • Implement a new struct under controls.jl which acts like a Range control with a first order delay.
  • Look for existing Julia Packages that can be useful for this tasks.

Improve performance with mutating functions and Static arrays

Current situation
Most of the functions are non-mutating and use Base.Array

Objective
Although it performance is not a problem yet. Code would execute much faster using mutating functions to avoid reallocation and static arrays (https://juliaarrays.github.io/StaticArrays.jl/latest/pages/quickstart/)

Solution proposal

Trajectory visualization

From #65:

My idea was to implement some plotting, save, load... methods on that type. However, I think that could be accomplished on the Vector also...

It would be cool to pop up a plot of a trajectory whenever a ResultsStore is returned.

However, using ResultsStore as the primary mechanism for visualization has a few problems:

  1. If someone else wants to use your fancy plotting code, they have to understand and create everything in ResultsStore, like Aircraft, etc.
  2. Visualization typically involves many visualization-specific configuration options, for example velocity_vector_color="blue". It doesn't seem appropriate to store these options in ResultsStore.

In my opinion, a better pattern is to have a visualize_trajectory (or similar) function that takes in a trajectory along with visualization options and returns a displayable object. We can talk about more details if you decide to pursue this pattern.

Antipattern: Not implemented exceptions

Current situation
After reading https://white.ucc.asn.au/2020/04/19/Julia-Antipatterns.html, I realised that, currently, this situation occurs for some types in the code:
https://github.com/AlexS12/FlightMechanics.jl/blob/master/src/models/aerodynamics.jl#L24
https://github.com/AlexS12/FlightMechanics.jl/blob/master/src/models/dynamic_systems.jl#L10
https://github.com/AlexS12/FlightMechanics.jl/blob/master/src/models/propulsion.jl#L5

More may be found...

Objective
Adopt language paradigms and really obtain helpful error messages

Solution proposal
As suggested in: https://white.ucc.asn.au/2020/04/19/Julia-Antipatterns.html

MethodError indicates this quite well and as shown gives a more informative error message than you will write. An often overlooked feature is that you can declare a function without providing any methods.

When one is in this situation, defining a interface that another package would implement, one can provide a test-suite for testing it was implemented correctly. This is a function they can call in their tests to at least check they have the basics right. This can take the place of a formal interface (which Julia doesn’t have), in ensuring that a contract is being met.

Interaction between Control, Controls and FCS

Current situation
Right now the FCS is made up of Control elements which are responsible ie, for range check .

The FCSis Control elements are set with a set_controls(fcs, controls) method, where controls::Controls (notice final "s").

At least naming (Controls and Control) is confusing. This is an indication that something this types and their interaction might have duplicates in their function. In fact, and just as an example the values in Controls, are afterwards saved in FCS in different Control elements.

Objective

Develop a simple but functional FCS structure which can serve (at the present moment) to manage a Reversible control system. This will need to be refined to introduce a real FCS, AP, SAS...

Solution proposal
Some ideas to be explored are:

  • Use Control elements in Controls that could afterwards stored in FCS.
  • Store Controlsdirectly in FCS

DOC: documentation on position reference frames

Current situation
No documentation of reference frame description, axis direction and sign conventions

Solution proposal
Documentation of getter and constructo methods of position.jl.
Section on reference frames in project docs

atmosphere_f16 validation

Implementation of atmosphere_f16 produces results different from atmosphere_isa (see test\atmosphere.jl. Apparantly the model is the same and only units change. However, tests used for validation of F16 model relying on data from

Stevens, B. L., Lewis, F. L., & Johnson, E. N. (2015). Aircraft control
and simulation: dynamics, controls design, and autonomous systems. John Wiley
& Sons.

do not pass if ISA1978 is used.

Some investigations must be performed in order to determine the reason of the differences found.

Possible candidates:

  • Unit conversion factors
  • Model coefficients

DOC: navigation panel not showing as expected in documentation

According to Documenters.jl documentation, the following code shold create a navigation bar with the references 'Home', 'Api Reference' and 'Basics' :

makedocs(authors="Alejandro Saez Mollejo",
         pages = [
         "Home" => "index.md",
         "API Reference" => ["api-reference.md"],
         "Basics" => [
           "isa.md",
           "coordinate-systems.md",
           "dynamic_models.md",
           "anemometry.md",
           "kinematics.md"
         ],
         ])

However, the folliwng panel is obtained:

image

It seems to be working for other packages such as: https://github.com/juliohm/GeoStats.jl/blob/master/docs/make.jl and http://docs.juliadiffeq.org/latest/index.html#Supporting-and-Citing-1

GRAV: variable gravity models

Current situation
Currently only constant vertical gravity has been implemented.

Low priority

Objective

  • Provide a variable gravitation with height model
  • Provide a gravitation model taking J2 into account
  • Incorporate centrifugal effect in non-constant models

Solution proposal

  • Implementation of a gravity.jl file under flight mechanics with this functionality.
  • Make it available under models/gravity.jl

ENH: Reorganize modules

Current situation

Modules organization

  • FlightMechanics

    • Simulator
      • Aircrafts
      • Models
  • It is imposible to define the same variable or function for different aircrafts:

    • If DE_MAX or Sw is defined for one aircraft, it cannot be defined for another one, because every ac file is included in the same module.
    • funcitons like Cnda(aero::F16Aerodynamics, α, β, da) are redirected for each aircraft with the aero type. However, it could be easier to have Cnda(α, β, da) for each aircraft in a different module.
  • To access some variables like mac, Sw, the aircraft must be created first. This is sometimes a problem. For example, FCS might need to access surfaces limits before aircraft is created.

Objective

  • Being able to define variables and functions with the same name for different aircrafts without the need of using method dispatch based on a type that is not used inside.
  • Have a more modularized library: using Aircrafts.F16 is more clear than using.Simulator.Aircrafts

Solution proposal
Structure:

  • FlightMechanics
    • Models
    • Aircraft
      • F16
      • C310

Separation of static parameters and dynamic state

From #65:

Well, the aircraft type is still messy. It is used to dispatch on different methods depending on the aircraft type itself and also, it is composed of other types that store current value variables and are also used for dispatch in some cases:

  • total forces and moments
  • the flight control system: I would like to implement autopilots, stability augmentation systems... here in the future. It also stores control values and aerodynamic surfaces deflections.
  • Propulsion system
  • Aerodynamics

One important thing to think about is separation of static parameters and dynamic state. In my opinion, every dynamic state variable (e.g. actuator position for an actuator with lag, FCS memory, fuel, flow separation, dynamic stall) should be stored in a state that is separate from the static configuration parameters of the aircraft.

Some big advantages of this are:

  1. Everything can be immutable, resulting in more efficient, understandable, and differentiable code.
  2. There is less redundancy/confusion in storage - you only need to store the static parameters once and the state at every timestep.
  3. I think this will make solving the ODEs to propagate dynamics more natural.

Let me know what you think of this and we can discuss details about design patterns, modularity, and scaling from very simple aircraft to very complex ones.

[Question] Capabilities

Hi Alex

Thanks for your work. I am currently using JSBSim and its python interface to simulate the taxing of an aircraft. Would I be able to do the same with current master of FlightMechanics.jl

Thanks

TRIMMER: revision

Current situation
Current trimmer version has demonstrated to work and has been validated against Stevens examples. However, some improvements can be accomplished.

Objective

  • Introduce trimming variables (alpha, beta and controls) limits in optimization algorithm.
  • Improve integrity: re-initialization of non-converged cases with different initial conditions.
  • Capacity to interact with optimization method arguments.
  • Capacity to load predefined trimmed cases that can be used for initialization guess
  • Use tas, alpha, beta dynamic model instead of u, v, w
  • (optional) other trimming capabilities such as calculate tas given the alpha.

Solution proposal

None

FCS: relation of stick and pedals with deflection

Current situation
If maximum and minimum deflection limits are not symmetric, the stick position for zero deflection is not zero. This is related to the implementation of FCS: C310FCS and F16FCS.

Objective

  • Make the zero stick and pedals position produce zero deflection
  • Make deflection limits correspond to stick and pedals -1 and 1 positions

Solution proposal

Update state position completely for every dynamic system

Current situation

Currently in dynamic_systems.jl when dynamic system state (x) is transformed to a complete State the position attribute is not updated completely:

  • SixDOFEulerFixedMass and SixDOFQuaternionFixedMass only update PositionEarth

Objective
Have a full State in each integration step, particularly, a complete position.

Solution proposal

I can see three options:

  • Add a new argument to convert methods including State before the integration step, so the position could be updated with the difference.

    • 🟢 seems easy to implement
    • :red: convert would change it semantics. converting from two things into one iof one to one.
  • As PositionEarth is realtive compared to PositionLLH and PositionECEF another option would be to add an initial_position argument to PostitionEarth, which could be a PositionLLH or PositionECEF This would avoid passing steta before to convert.

    • 🟢 would make PositionEarth absolutely referenced (no difference with the others). Does not modify convert semantics.
    • 🔴 kind of more verbose perhaps.
  • Use dynamic system derivatives to calculate displacement instead of passing step before.

    • 🔴 needs time step information, probably accumulates error...

Possible colaboration

Hi, @parthp08. Let's open an issue here and talk about possible collaboration in the implementation of a Julia Flight Mechanics package.

My name is Alex and I am from Spain. I am an aerospace engineer, currently working at Airbus. I have always been passionate about scientific programming specially in Python, although lately I have become very interested in Julia. I can also do some Fortran and Matalb. For me this project is just a nice way to continue learning both programming and Flight Mechanincs. Being able to program and reproduce many of the methods described in Stevens is for me a very rewarding way of learning, but I don't always have all the time I would like to do it.

My main idea when I started this repo was to develop a flight simulator similar to what you already saw in PyFME (https://github.com/AeroPython/PyFME) while learning and practicing Julia. I performed a big sprint last Christmas (this is just a personal project for me) and implemented some of the basic reference frame conversions, the F16 Steven's model and the trimmer. I spent quite a big time on testing and I would say that's the most valuable part of the project until now. In fact, I checked that the error you found in PyFME is not present here 😅

The next step I had in mind was the implementation of the propagation, so "the aircraft could start flying" finally!

As this was my first "big project" in Julia, I feel less proud of the code structure:

  • I don't really see now if the models (src/models) I created are useful, make sense and generalize
  • I don't really trust the modules structure I implemented at first
  • Some methods are not exported where they should be and maybe some includes don'r really make sense.
    So I think there is still a lot of effort on making out of this repo a nice and useful package.

I will take some time to explore https://github.com/parthp08/Aircraft-Control-and-Simulation but I have seen you have progressed much more than me in the integration and control subjects. Is that the part you are more interested in? I have always wanted a control loop in the simulators I have implemented, but I have always got lost in the previous details.

I guess some collaboration would really lead to a more continuous, sustainable and promising development. 😃

Would you like to share some info about your background, objectives, roadmap for the project... or any other thing you consider important?

BUG: investigate optimizer convergence

To avoid obtaining different results on aircraft retrimming (cf1a110#diff-8e408ab9a35ce54481575395d19d78e3R73) a factor needed to be applied to the g_tol passed to the optimization method (cf1a110#diff-c1e986153ebd20572e1a0361e3ee60b2R123).

It seems that the optimization is sometimes finishing with a result.minimum greater than the demanded g_tol. When running trimmer.jl and setting show_trace = true in stready_state_trim, the following output is obatined:

Iter     Function value    √(Σ(yᵢ-ȳ)²)/n 
------   --------------    --------------
     0     1.970477e+02     1.936188e+02
 * time: 2.5987625122070312e-5
   100     2.927562e-01     3.709745e-03
 * time: 0.26558709144592285
   200     6.327670e-04     2.926142e-04
 * time: 0.27391600608825684
   300     1.285786e-08     5.180261e-09
 * time: 0.28388404846191406
   400     3.355999e-13     2.090312e-13
 * time: 0.2951359748840332
   500     1.262379e-17     2.479054e-18
 * time: 0.3080861568450928
   600     6.494414e-22     2.076720e-22
 * time: 0.3211390972137451
 * Status: success

 * Candidate solution
    Minimizer: [3.74e-02, 4.44e-15, 5.00e-01,  ...]
    Minimum:   1.681096e-25

 * Found with
    Algorithm:     Nelder-Mead
    Initial Point: [1.25e-01, 0.00e+00, 4.70e-01,  ...]

 * Convergence measures
    √(Σ(yᵢ-ȳ)²)/n ≤ 1.0e-25

 * Work counters
    Seconds run:   0  (vs limit Inf)
    Iterations:    675
    f(x) calls:    1201

Notice that Minimum: 1.681096e-25 while g_tol = 1e25

TEST: write some tests for dynamics

src/dynamics/*.jl contains the dynamic systems.

Some tests must be written for this part. However, it is difficult to find independent validation values.

Another way of writing some of these tests would be to test one model against some others in equivalent conditions. For examples, six_dof_euler_fixed_mass is supposed to provide similar results as six_dof_quaternion_fixed_mass if the attitude is not extreme (theta near 90º)

Some projects test the full simulator response: once an aircraft is implemented they integrate a solution for the aircraft response to a given input. Even if this this is not a unit test, this might be useful at some point.

AC: struct refactor

Current situation
Currently, each aircraft implements its own structure as it is a mean to dispatch the adequate method for functions like: get_arp, get_empty_cg, get_fuel_tanks... This is nonsense because:

  • some of this methods need to be called before or during the aircraft object construction (see ugly workarounds in: C310() and F16())
  • even there is a struct for each aircraft, they share the same attributes
  • some ac variables are stored in methods to benefit from constant propagation (http://www.stochasticlifestyle.com/type-dispatch-design-post-object-oriented-programming-julia/) but this prevents from making variations in these parameters (ie. empty cg position is changed in many F16 validation examples)

Objective

  • Create a unique struct to be shared by every aircraft
  • Separate aircraft parameters in a different struct that will be part of the aircraft object.
    • These parameters struct can be specific to each aircraft until a good generalization is found. However, a set of general methods to access common attributes must be provided.
    • For each aircraft a default configuration will be provided.

Solution proposal

abstract type Parameters end

get_name(p) = p.name
get_wing_area(p) = p.wing_area
get_wing_span(p) = p.b
get_chord(p) = p.mac
get_arp(p) = p.arp
struct Aircraft
    parameters::T where T<:Parameters
    mass_props::RigidSolid
    pfm::PointForcesMoments
    aerodynamics::T where T<:Aerodynamics
    propulsion::Propulsion
end
F16(params, mass_props, pfm, aero, prop) = Aircraft(params, mass_props, pfm, aero, prop)

function F16()
    # default initialization of params, mass_props, pfm, aero, prop
    # ...
    Aircraft(params, mass_props, pfm, aero, prop)
end

Concerns
This will not benefit from constant propagation anymore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.