Giter Club home page Giter Club logo

aircraft-physics's Introduction

Aircraft-Physics

Fixed wing aircraft physics for Unity. Based on paper by Khan and Nahon 2015.

W. Khan and M. Nahon, "Real-time modeling of agile fixed-wing UAV aerodynamics," 2015 International Conference on Unmanned Aircraft Systems (ICUAS), Denver, CO, 2015, pp. 1188-1195, doi: 10.1109/ICUAS.2015.7152411.

Video explaining the basics of how the system works.

Thumbnail

Getting started

To get started download the repo and open the project in Unity. Open the scene Cessna-172 in the folder Assets/Aircraft Physics/Example/Scenes. In this scene I set up a simple plane. You can try to fly it by hitting play and using instructions on the screen.

Note that this is not a fully realistic Cessna-172. The equations in Khan and Nahon 2015 result in about a 1.5 times more drag than measured for real Cessna. This is probably the result of me using the model outside of its range of applicability. Because of this reason I had to multiply the thrust of the real plane by 1.5. The other significant difference is in the position of the center of mass. Unity doesn't allow to set density to individual colliders, so the COM is way off.

Components

Let's see what components do we have on the Aircraft game object. First of all, there is a Rigidbody. Note that it has it's Drag and Angular Drag fields set to zero. Unity's built-in drag will mess up the physics of the plane. Though you can have a little bit of angular drag for extra stability, you don't need it.

The second component is AircraftPhysics. It applies aerodynamic forces and thrust to the Rigidbody. It exposes a field for the thrust force in newtons and a list of AeroSurfaces. This model computes the total force and torque acting on an airplane as a sum of impacts of separate parts, represented by the game objects with AeroSurface components. AeroSurface can be a wing, or a part of a wing, or a part of a tail etc. The rectangular gizmos represent all the AeroSurfaces that constitute this aircraft. The child object of Aircraft called Aerodynamics contains as its children a number of AeroSurfaces referenced in the list in AircraftPhysics.

Gizmos

The last component is AircraftController. It interacts with the AircraftPhysics and AeroSurfaces to apply control inputs to the plane. AircraftPhysics and AeroSurface are the core parts of the system and don't need to be changed most of the time. The AircraftController however is written as an example which you can expand upon.

The another important child of Aircraft called Collision has all the colliders which constitute the plane. For gears I use Unity's WheelCollider. It can be tricky to work with and quite unpredictable (though the same can probably be said about this system). You can change WheelCollider for something simpler and more robust.

AeroSurface

Let's take a look at the AeroSurface's inspector.

AeroSurface inspector

It has a reference to a AeroSurfaceConfig. It is a ScriptableObject that contains the aerodynamic parameters of the surface.

Parameter Description
Lift Slope Slope angle of the lift coefficient in low angle of attack mode
Skin Friction Determines how much drag the surface creates due to friction (note, that drag is also created due to lift)
Zero Lift AoA Angle of attack at which surface creates zero lift
Stall Angle High/Low Angles of attack at which stall starts
Chord Mean chord of the surface
Flap Fraction How much of the surface is movable as a control surface. Shown by the gizmo as an orange region
Span Length of the surface
Aspect Ratio Aspect Ratio. Can be calculated from the chord and span automatically or set manually for the surfaces which are a part of a longer one. For example the wings are made of two parts stacked next to each other, so the flaps and ailerons could be controlled separately. In this case the aspect ratio for the parts should be set manually as an aspect ratio of the whole wing.

Each AeroSurface with non zero Flap Fraction has a moving part, which deflection angle can be set by a SetFlapAngle method. Using them allows to implement control surfaces. AirplaneController has a list of AeroSurfaces marked as control surfaces. It sets their deflection angles according to their input type. As an example there are Pitch, Yaw, Roll and Flap types. Input multiplier is needed for the surfaces to react to the input in opposite directions (like ailerons).

Editor tools

The important part of constructing an aircraft is to understand the balance of it. This system has some rudimentary editor tools for that. First of all, it shows positions of the center of mass (COM, orange wire sphere) and the aerodynamic center (ADC, blue wire sphere). The latter is defined as a point of application of aerodynamic forces. Secondly, it shows force of gravity and combined aerodynamic forces (arrows pointing from the centers COM and ADC spheres). Lastly, it shows lift, drag and torque acting on each surface as blue, red and green arrows.

The scriptable object AircraftPhysicsDisplaySettings in the Core/Config folder allows to change the appearance of this gizmos. You can also choose angle of attack, airspeed and air density for which forces are calculated in Edit mode.

Display settings

aircraft-physics's People

Contributors

gasgiant 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aircraft-physics's Issues

Yaw fix?

Hi! This physics is quite good, however, I can't turn with the yaw at low speed, on the ground. I have to reach a certain amount of speed to turn on the ground. And this amount of speed is quite significant. So I tried to multiply the yaw sensitivity. But It didn't work. I'm not familiar with Unity's wheel colliders but maybe the issue come from here? Does the wheel collider rotate with the yaw movment?

Why are you using padded angles and how do you get the values?

Hi, I like your project and I was looking into your code. When you calculate your aerodynamic coefficients you add padding your your stall angles. Why? And you determine the padding by lerping between 8 and 14 degrees, why 8 and 14, or did you guess these values a bit?

image

Setup for jet aircraft

Hello
What adjustments do I need to make to the plane so that both the wings are positioned correctly and it moves correctly? When I adjust the location of the wings according to the shape of the fighter, it does not move correctly.
Thanks

simulate flat spin stall

Hi! I remember that you said : " When playing with this system I've even experieced unrecoverable spins. "
how did you done that ?
anyway to reproduce ?
I am interested in stalls and spins simuation.
thanks in advance

how to simlate stall ?

I wanted to simulate stall like DCS, or Lock on FC, in the F15 , Su 27 , there is always that pitch locked at high aoa(angle of attack), so how one can reproduce this https://imgur.com/a/BT6J9Yc the aoa remains high until the pilot do some manoeuver(moving the stick forward) to recover ? (because here it falls back to the velocity vector whatever I do). is there a trick that DCS or Lock on series does ?

Set Plane Position

Hi, I want to assign a starting point to the plane in the Start() function in the Airplanecontroller.cs file. Simply the plane must start from a specific x,y,z point when the game starts. What changes do I need to make in the Start() function for this?

Idea: 2D Aircraft Physics

Hey,

Wow! This is an absolutely stunning library, well detailed, well defined and I was exetremely impressed with the amount of information spilled into it.

I don't have an issue, but I do have an idea. (I don't know how create a discussion or anything so I went here to issues)
screenshots

I want to create a very simple aircraft physics, but in 2D, so I thought about connecting and using parts of the scripts for it.
However, I don't know how to perform a reduction on your library for it, I can try, but it will take me a lot of time.
I would like to know if you could minimize it for it? or at least guide me towards my vision?

I thought about only connecting the AeroSurface for the tail and ailerons, and removing yaw and roll (I could animate the roll easily I believe), so basically all I need is pitch movement. And I'm still clueless for the 2D aerodynamics for the plane.
What do I do with the scripts so I won't get any sudden movement on an axis that shouldn't move?
Of course, assuming the plane direction is Z and Y, The plane shouldn't change it position in X in 2D world.

Thanks,
Ori

How combined aspect ratio is calculated?

Hello!
So there are Wing_L_0 and Wing_L_1 stacked together, and the aspect ratio set to 7 for both. How this value is calculated, if I am doing something like this:

(span1 + span2) / ((chord1 + chord2) / 2)

I get something like 3.5. But I think I am doing this wrong.

yaw controls

Hi!

I tried flying your plane for a bit and I love this project. At the same time, some aspects of the aircraft's behavior are not very realistic.

The most noticeable sign of flight dynamics is the aircraft's response to pressing Q / E. It feels like the deflection of the rudder only creates a side-slip angle. At the same time, there is no noticeable curvature of the trajectory, as if the angle of the lateral slip does not affect the magnitude of the lateral force.

Of course, it would be more interesting to fly with different intermediate throttle values, between 0 and 100. It is also sad that the propeller is standing still.

I'm interested in such things, and I could try to make some improvements to your model. Unfortunately, I didn't find the open access article from the conference on aerodynamics to which you refer. And I haven't gotten to know the code in detail yet. Are you going to improve the flight dynamics model? Does it make sense for me to try to make changes to the model?

Idea: Set custom Center of Mass

First of all, I wanted to thank you for publishing your great work! Thanks for providing it here on github.

Now, I have a scene in which I would like simulate the flight of a glider (without thrust). However, a lot of gliders have longer fuselages than i.e. the cessna provided in the example. Now when adding colliders for the fuselage and the tail it distorts the real center of mass. In my situation, the center of mass is behind the wings, so the glider tilts backwards during stall, which is not realistic.

I had the idea that one could provide a custom (local) center of mass vector to override the calculated CoM world vector. So in my situation I did something like this in AirplanePhysics.cs:

public bool useCustomCoM;
public Vector3 customCoM;

...

Vector3 com;
if (useCustomCoM)
{
   com = rb.transform.TransformVector(customCoM);
}
else
{
   com = rb.worldCenterOfMass;
}

// use com instead of rb.worldCenterOfMass

(This is just an example of how I tried to do it. Implementation would need to be tailored to the specific use).

However, I failed to update the gizmo drawing, since the custom CoM would also be used in AircraftGizmos.cs. Maybe someone has an idea how to solve that?

In addition, the input variable customCoM would probably be only needed when useCustomCoM is true, so one would need to create a custom unity editor script. This, however, overwrites the other fields.

Off Topic: I also wanted to ask: Is a downward elevator / tail force supported? It seems like the cessna example uses a positive lift for the tail). However, I learned that stable aircrafts use a negative lift (in the opposite direction of the wing lift), so that in case of a stall the aircraft tilts forward.

Edit:
I forgot that one could simply set rb.centerOfMass, so in effect, something like this should do the trick:

public bool useCustomCoM;
public Vector3 customCoM;

...

private void Awake()
 {
     rb = GetComponent<Rigidbody>();
     if (useCustomCoM)
     {
         rb.centerOfMass = customCoM;
     }
 }

...

#if UNITY_EDITOR
    // For gizmos drawing.
    public void CalculateCenterOfLift(out Vector3 center, out Vector3 force, Vector3 displayAirVelocity, float displayAirDensity)
    {
        Vector3 com;
        BiVector3 forceAndTorque;
        if (aerodynamicSurfaces == null)
        {
            center = Vector3.zero;
            force = Vector3.zero;
            return;
        }

        if (rb == null)
        {
            rb = GetComponent<Rigidbody>();
            if (useCustomCoM)
            {
                rb.centerOfMass = customCoM;
            }
            com = rb.worldCenterOfMass;
            forceAndTorque = CalculateAerodynamicForces(-displayAirVelocity, Vector3.zero, Vector3.zero, displayAirDensity, com);
        }
        else
        {
            if (useCustomCoM)
            {
                rb.centerOfMass = customCoM;
            }
            com = rb.worldCenterOfMass;
            forceAndTorque = currentForceAndTorque;
        }

        force = forceAndTorque.p;
        center = com + Vector3.Cross(forceAndTorque.p, forceAndTorque.q) / forceAndTorque.p.sqrMagnitude;
    }
#endif

(Sorry, not really optimized).

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.