# Customize Fixed-Wing Aircraft with the Object Interface

This example shows how to customize fixed-wing aircraft in MATLAB® using objects.

For an example of how to get started using fixed-wing aircraft in MATLAB, see “Get Started with Fixed-Wing Aircraft”.

For an example of setting realistic coefficients on an aircraft and calculating static stability, see “Determine Nonlinear Dynamics and Static Stability of Fixed-Wing Aircraft”.

For an example of importing coefficients from Digital DATCOM analysis and linearizing to a state-space model, see “Perform Controls and Static Stability Analysis with Linearized Fixed-Wing Aircraft”.

### Fixed-Wing Object Interface

Each fixed-wing aircraft function returns an object of its defining type.

Functions provide convenience to constructing each object. However, their predefined input structure might be inconvenient to some workflows. For example, consider using objects if you want more control over the specific inputs of each component, or if you want to avoid repmat calls to create arrays of each component. Objects let you directly construct each component.

The table mapping each function to object can be seen below.

Component = ["Properties"; "Environment"; "Aircraft"; "States"; "Coefficients"; "Surfaces"; "Thrust"]; Formal = ["Aero.Aircraft.Properties"; "Aero.Aircraft.Environment"; "Aero.FixedWing"; "Aero.FixedWing.State"; "Aero.FixedWing.Coefficient";"Aero.FixedWing.Surface"; "Aero.FixedWing.Thrust"]; Informal = ["aircraftProperties"; "aircraftEnvironment"; "fixedWingAircraft"; "fixedWingState"; "fixedWingCoefficient"; "fixedWingSurface"; "fixedWingThrust"]; objMap = table(Formal, Informal, 'RowNames', Component, 'VariableNames',["Formal Interface", "Informal Interface"])

`objMap=`*7×2 table*
Formal Interface Informal Interface
____________________________ ______________________
Properties "Aero.Aircraft.Properties" "aircraftProperties"
Environment "Aero.Aircraft.Environment" "aircraftEnvironment"
Aircraft "Aero.FixedWing" "fixedWingAircraft"
States "Aero.FixedWing.State" "fixedWingState"
Coefficients "Aero.FixedWing.Coefficient" "fixedWingCoefficient"
Surfaces "Aero.FixedWing.Surface" "fixedWingSurface"
Thrust "Aero.FixedWing.Thrust" "fixedWingThrust"

The constructor for each fixed-wing aircraft component is structured the same way:

The first argument is either a vector or repeating set of integers that specifies the size of the returned object array, like the "zeros" function, with the default being size 1.

Every argument after the first argument is a name-value pair specifying the object property and value for setting non-default values.

Each non-default value is set for every object in the returned object array.

For example, creating a 3-element fixed-wing state vector where each state has a mass of 50 kg would have the following syntax:

states = Aero.FixedWing.State(1,3, Mass=50)

`states=`*1×3 object*
1x3 State array with properties:
Alpha
Beta
AlphaDot
BetaDot
Mass
Inertia
CenterOfGravity
CenterOfPressure
AltitudeMSL
GroundHeight
XN
XE
XD
U
V
W
Phi
Theta
Psi
P
Q
R
Weight
AltitudeAGL
Airspeed
GroundSpeed
MachNumber
BodyVelocity
GroundVelocity
Ur
Vr
Wr
FlightPathAngle
CourseAngle
InertialToBodyMatrix
BodyToInertialMatrix
BodyToWindMatrix
WindToBodyMatrix
BodyToStabilityMatrix
StabilityToBodyMatrix
DynamicPressure
Environment
ControlStates
OutOfRangeAction
DiagnosticAction
Properties
UnitSystem
TemperatureSystem
AngleSystem

states.Mass

ans = 50

ans = 50

ans = 50

As can be seen from the returned Mass values, each state has a mass of 50 in the vector.

Following this format, this example constructs the same aircraft from the "Get Started with Fixed-Wing Aircraft" example, replacing the function interface with the associated object interface.

### Fixed-Wing Aircraft Configuration

Create the 3 control surfaces using Aero.FixedWing.Surface.

By default, the surface objects are defined to be symmetric and not controllable, so these two properties must be set for the aileron along with the maximum and minimum values.

aileron = Aero.FixedWing.Surface(... Controllable="on", ... Symmetry="Asymmetric", ... MinimumValue=-20, ... MaximumValue=20)

aileron = Surface with properties: Surfaces: [1x0 Aero.FixedWing.Surface] Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 20 MinimumValue: -20 Controllable: on Symmetry: "Asymmetric" ControlVariables: ["_1" "_2"] Properties: [1x1 Aero.Aircraft.Properties]

Additionally, the set the name on the properties of the aileron surface object. This is helpful for setting coefficients later.

`aileron.Properties.Name = "aileron"`

aileron = Surface with properties: Surfaces: [1x0 Aero.FixedWing.Surface] Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 20 MinimumValue: -20 Controllable: on Symmetry: "Asymmetric" ControlVariables: ["aileron_1" "aileron_2"] Properties: [1x1 Aero.Aircraft.Properties]

For the elevator and rudder, the symmetry is already the desired value, so the "Symmetry" name-value argument can be excluded.

elevator = Aero.FixedWing.Surface(... Controllable="on", ... MinimumValue=-20, ... MaximumValue=20)

elevator = Surface with properties: Surfaces: [1x0 Aero.FixedWing.Surface] Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 20 MinimumValue: -20 Controllable: on Symmetry: "Symmetric" ControlVariables: "" Properties: [1x1 Aero.Aircraft.Properties]

rudder = Aero.FixedWing.Surface(... Controllable="on", ... MinimumValue=-20, ... MaximumValue=20)

rudder = Surface with properties: Surfaces: [1x0 Aero.FixedWing.Surface] Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 20 MinimumValue: -20 Controllable: on Symmetry: "Symmetric" ControlVariables: "" Properties: [1x1 Aero.Aircraft.Properties]

`elevator.Properties.Name = "Elevator"`

elevator = Surface with properties: Surfaces: [1x0 Aero.FixedWing.Surface] Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 20 MinimumValue: -20 Controllable: on Symmetry: "Symmetric" ControlVariables: "Elevator" Properties: [1x1 Aero.Aircraft.Properties]

`rudder.Properties.Name = "Rudder"`

rudder = Surface with properties: Surfaces: [1x0 Aero.FixedWing.Surface] Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 20 MinimumValue: -20 Controllable: on Symmetry: "Symmetric" ControlVariables: "Rudder" Properties: [1x1 Aero.Aircraft.Properties]

With the control surfaces defined, define the thrust object using the Aero.FixedWing.Thrust object.

By default, the minimum and maximum values for the thrust object are 0 and 1, which represent the throttle lever position.

In this aircraft, they are limited to 0 and 0.75.

propeller = Aero.FixedWing.Thrust(MaximumValue=0.75)

propeller = Thrust with properties: Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 0.7500 MinimumValue: 0 Controllable: on Symmetry: "Symmetric" ControlVariables: "" Properties: [1x1 Aero.Aircraft.Properties]

The name of the thrust vector can also be set at this time.

`propeller.Properties.Name = "propeller"`

propeller = Thrust with properties: Coefficients: [1x1 Aero.FixedWing.Coefficient] MaximumValue: 0.7500 MinimumValue: 0 Controllable: on Symmetry: "Symmetric" ControlVariables: "propeller" Properties: [1x1 Aero.Aircraft.Properties]

With these control surfaces and thrust vectors defined, they can now be set on the body of the aircraft.

The aircraft body is defined through the Aero.FixedWing object.

For simplicity, this aircraft will have a reference area, span, and length of 3, 2, and 1, respectively.

aircraft = Aero.FixedWing(... ReferenceArea=3, ... ReferenceSpan=2, ... ReferenceLength=1)

aircraft = FixedWing with properties: ReferenceArea: 3 ReferenceSpan: 2 ReferenceLength: 1 Coefficients: [1x1 Aero.FixedWing.Coefficient] DegreesOfFreedom: "6DOF" Surfaces: [1x0 Aero.FixedWing.Surface] Thrusts: [1x0 Aero.FixedWing.Thrust] AspectRatio: 1.3333 Properties: [1x1 Aero.Aircraft.Properties] UnitSystem: "Metric" TemperatureSystem: "Kelvin" AngleSystem: "Radians"

aircraft.Surfaces = [aileron, elevator, rudder]

aircraft = FixedWing with properties: ReferenceArea: 3 ReferenceSpan: 2 ReferenceLength: 1 Coefficients: [1x1 Aero.FixedWing.Coefficient] DegreesOfFreedom: "6DOF" Surfaces: [1x3 Aero.FixedWing.Surface] Thrusts: [1x0 Aero.FixedWing.Thrust] AspectRatio: 1.3333 Properties: [1x1 Aero.Aircraft.Properties] UnitSystem: "Metric" TemperatureSystem: "Kelvin" AngleSystem: "Radians"

aircraft.Thrusts = propeller

aircraft = FixedWing with properties: ReferenceArea: 3 ReferenceSpan: 2 ReferenceLength: 1 Coefficients: [1x1 Aero.FixedWing.Coefficient] DegreesOfFreedom: "6DOF" Surfaces: [1x3 Aero.FixedWing.Surface] Thrusts: [1x1 Aero.FixedWing.Thrust] AspectRatio: 1.3333 Properties: [1x1 Aero.Aircraft.Properties] UnitSystem: "Metric" TemperatureSystem: "Kelvin" AngleSystem: "Radians"

Set the aircraft coefficients using the setCoefficient and getCoefficient methods, creating a coefficient using the Aero.FixedWing.Coefficient object, or indexing directly to the coefficient values.

coeff = Aero.FixedWing.Coefficient

coeff = Coefficient with properties: Table: [6x1 table] Values: {6x1 cell} StateVariables: "Zero" StateOutput: [6x1 string] ReferenceFrame: "Wind" MultiplyStateVariables: on NonDimensional: on Properties: [1x1 Aero.Aircraft.Properties]

aircraft.Coefficients.Values{3,3} = 0.2

aircraft = FixedWing with properties: ReferenceArea: 3 ReferenceSpan: 2 ReferenceLength: 1 Coefficients: [1x1 Aero.FixedWing.Coefficient] DegreesOfFreedom: "6DOF" Surfaces: [1x3 Aero.FixedWing.Surface] Thrusts: [1x1 Aero.FixedWing.Thrust] AspectRatio: 1.3333 Properties: [1x1 Aero.Aircraft.Properties] UnitSystem: "Metric" TemperatureSystem: "Kelvin" AngleSystem: "Radians"

aircraft.Coefficients.Table

`ans=`*6×9 table*
Zero U Alpha AlphaDot Q Beta BetaDot P R
____ _ _____ ________ _ ____ _______ _ _
CD 0 0 0 0 0 0 0 0 0
CY 0 0 0 0 0 0 0 0 0
CL 0 0 0.2 0 0 0 0 0 0
Cl 0 0 0 0 0 0 0 0 0
Cm 0 0 0 0 0 0 0 0 0
Cn 0 0 0 0 0 0 0 0 0

### Fixed-Wing Aircraft States

Define fixed-wing aircraft states using the Aero.FixedWing.State object.

To directly create an array of states that all have the same properties, use the state constructor instead of using the repmat function.

In this example, 11 states are created by varying mass, but with constant airspeed.

mass = num2cell(1000:50:1500)

`mass=`*1×11 cell array*
Columns 1 through 6
{[1000]} {[1050]} {[1100]} {[1150]} {[1200]} {[1250]}
Columns 7 through 11
{[1300]} {[1350]} {[1400]} {[1450]} {[1500]}

states = Aero.FixedWing.State(size(mass), U=100); [states.Mass] = mass{:}

`states=`*1×11 object*
1x11 State array with properties:
Alpha
Beta
AlphaDot
BetaDot
Mass
Inertia
CenterOfGravity
CenterOfPressure
AltitudeMSL
GroundHeight
XN
XE
XD
U
V
W
Phi
Theta
Psi
P
Q
R
Weight
AltitudeAGL
Airspeed
GroundSpeed
MachNumber
BodyVelocity
GroundVelocity
Ur
Vr
Wr
FlightPathAngle
CourseAngle
InertialToBodyMatrix
BodyToInertialMatrix
BodyToWindMatrix
WindToBodyMatrix
BodyToStabilityMatrix
StabilityToBodyMatrix
DynamicPressure
Environment
ControlStates
OutOfRangeAction
DiagnosticAction
Properties
UnitSystem
TemperatureSystem
AngleSystem

However, unlike the fixedWingState function, the control states are not automatically set up on the states from the aircraft.

To set up the control states, use the setupControlStates function.

states = setupControlStates(states, aircraft)

`states=`*1×11 object*
1x11 State array with properties:
Alpha
Beta
AlphaDot
BetaDot
Mass
Inertia
CenterOfGravity
CenterOfPressure
AltitudeMSL
GroundHeight
XN
XE
XD
U
V
W
Phi
Theta
Psi
P
Q
R
Weight
AltitudeAGL
Airspeed
GroundSpeed
MachNumber
BodyVelocity
GroundVelocity
Ur
Vr
Wr
FlightPathAngle
CourseAngle
InertialToBodyMatrix
BodyToInertialMatrix
BodyToWindMatrix
WindToBodyMatrix
BodyToStabilityMatrix
StabilityToBodyMatrix
DynamicPressure
Environment
ControlStates
OutOfRangeAction
DiagnosticAction
Properties
UnitSystem
TemperatureSystem
AngleSystem