• No results found

MATLAB Weapon Simulation Integration with X-Plane Plugins

3.3 Interactive Simulation

3.3.2 MATLAB Weapon Simulation Integration with X-Plane Plugins

X-Plane has a range of data which it can either send over a network via UDP packets or a larger set that can be accessed via DataRefs in plugin development [132]. A DataRef is an internal memory address within X-Plane that allows for reading and writing spe- cific properties used within the simulation. For example, setting the altitude property to 5000 (ft), would place the user aircraft at that altitude.

The complete DataRef list is expansive, with over 4800 items that can be interacted with through plugins developed using the SDK [133]. DataRefs are accessed with a string handle (a data type made up of characters) that navigates through the DataRefs structure. The specific set of DataRefs that are of significance to the integration of MATLAB weapon simulations are accessible through the ‘sim\weapons\...’ leader, followed by the string related to the specific data needed.

North

East

Down

Flat Earth

Origin at Reference Latitude and Longitude

X

OGL

Y

OGL

Z

OGL

Figure 3.32: Open GL Coordinate System and NED Flat Earth System

The main variables that need to be set to show weapons within the X-Plane environment with data generated from MATLAB are positional and attitude information. The X- Plane 3D environment uses the OpenGL coordinate system, and attitude is set using the quaternion rather than Euler angles. This data can be written to the simulation using the ‘x’, ‘y’, ‘z’, and ‘q1’, ‘q2’, ‘q3’, ‘q4’ handles. x, y, z in OpenGL relate to NED as shown in Figure 3.32. The quaternion is a form of representing rotational information in three axes with four unit quantities. The Euler Angle representation of orientation can be obtained by converting the quaternion as follows:

  ψ θ φ  =   arctan 2(2(q1q2+q3q4),1−2(q22+q23)) arcsin (2(q1q3−q4q2)) arctan 2(2(q1q4+q2q3),1−2(q23+q24))   (3.47)

Conversion from Euler to quaternion is achieved using the following:

q1= cos (φ/2) cos (θ/2) cos (ψ/2) + sin (φ/2) sin (θ/2) sin (ψ/2) (3.48)

q2= sin (φ/2) cos (θ/2) cos (ψ/2)−cos (φ/2) sin (θ/2) sin (ψ/2) (3.49)

q3= cos (φ/2) sin (θ/2) cos (ψ/2) + sin (φ/2) cos (θ/2) sin (ψ/2) (3.50)

q4= cos (φ/2) cos (θ/2) sin (ψ/2)−sin (φ/2) sin (θ/2) cos (ψ/2) (3.51)

where qn is the nth quaternion (total of 4)

In addition to the weapon DataRefs, the MATLAB simulation needs to know where to set the origin of its NED coordinate system so that the MATLAB simulation and the X-Plane environment share a common position. The LLA above sea level are used as a common geo-referencing system. The weapon simulation in MATLAB is initialised at point of release with the current LLA. This becomes a Reference LLA and is stored for the duration of the simulation of each weapon (GBU or LRAGM). This Reference LLA is set to zero altitude and is then used to position the NED coordinate system’s origin, placing the weapon at 0 metres North, 0 metres East and at the initial altitude in metres in the Down direction.

As the weapon simulation is running, position updates are sent to X-Plane for vi- sualisation. The positions of the weapon in MATLAB are first converted from NED to LLA to be sent to X-Plane. When X-Plane receives the position update in LLA, with attitude information in a Quaternion, X-Plane then converts the LLA into the OpenGL XYZ reference system and updates the DataRef that holds the weapon data, as well as the Quaternion. The graphical object in X-Plane then updates its position in the simulation environment.

Simulation Start

User Input

Set Constants

Weapon Type

Define Structures & Timing Constants

Initialise Senders, Receivers & Counters

Connect to X-Plane

Initialise Model Variables

Test Action Mode

If Action Mode = 0

Get X-Plane Data

Assign Delivery Parameters

Run Weapon Model Time Step (Release Flag = 0)

Output Time to Release

If Action Mode = 1

Start While Loop

Run Weapon Model Time Step (Release Flag = 1)

Send Data to X-Plane Test While Loop Condition (Impact)

If Action Mode = 2 or While Loop Break

End Simulation

Close X-Plane Connection End While Loop

Set Action Mode = 2

Figure 3.33: Flow Diagram of Weapon Simulation Including Networking Links With X-Plane

The MATLAB simulation of the weapon will only cease when an impact condition is met. This is defaulted to be when the weapon hits the ground. However, the MAT- LAB simulation is run in an idealised flat earth NED representation and cannot detect ground elevation information from within X-Plane. Instead, X-Plane must handle the condition of when a weapon hits the ground. A flag is then sent to the MATLAB simulation indicating that the weapon has hit the ground in X-Plane. X-Plane also has an SDK function that allows the ground elevation data to be read at a specific set of coordinates. When the impact flag is set, the SDK function ‘terrainYTest’ is run to obtain the ground elevation data at the position of weapon impact in the X, Z plane. The weapon is then set to this position in OpenGL coordinates and converted to LLA to be sent to MATLAB. Figure 3.33 shows a diagram of this process, from initialisation of the weapon to the handling of an impact condition. This process is common between the GBU and LRAGM weapon simulations.

The data structure used to transfer model information between X-Plane and the MAT- LAB simulation is shown in Figure 3.34. The structure includes several additional pieces of information that are required for initial targeting of the weapon, and to pro-

vide launch information to pilots in X-Plane. It is used to initialise the weapon with a target and update the physical location of the weapon in the X-Plane simulation environment, and differs from the VMF Re-tasking message structure in its message content and requirement for acknowledgement.

LAT Latitude of Weapon

LON Longitude of Weapon

ALT Altitude of Weapon

X OpenGL X Coordinate (metres)

Y OpenGL Y Coordinate (metres)

Z OpenGL Z Coordinate (metres)

VX OpenGL X Velocity (metres per second)

VY OpenGL Y Velocity (metres per second)

VZ OpenGL Z Velocity (metres per second)

P Roll Rate (radians per second)

Q Pitch Rate (radians per second)

R Yaw Rate (radians per second)

Q1 Quaternion Element

Q2 Quaternion Element

Q3 Quaternion Element

Q4 Quaternion Element

ACTION_MODE Weapon mode (caged, launched, hit)

TARGET_INDEX Index of X-Plane Target (if user object)

TTR_MIN Time To Release – Minimum (seconds)

TTR_MAX Time To Release – Maximum (seconds)

TTR_OPT Time To Release – Optimum (seconds)

TTG Time To Go (seconds)

CROSS_AXIS_LIMIT_L Max off-boresight Angle – Left (degrees)

CROSS_AXIS_LIMIT_R Max off-boresight Angle – Right (degrees)

TYPE X-Plane weapon type reference

LAT Latitude of Weapon

LON Longitude of Weapon

ALT Altitude of Weapon

X OpenGL X Coordinate (metres)

Y OpenGL Y Coordinate (metres)

Z OpenGL Z Coordinate (metres)

VX OpenGL X Velocity (metres per second)

VY OpenGL Y Velocity (metres per second)

VZ OpenGL Z Velocity (metres per second)

P Roll Rate (radians per second)

Q Pitch Rate (radians per second)

R Yaw Rate (radians per second)

Q1 Quaternion Element

Q2 Quaternion Element

Q3 Quaternion Element

Q4 Quaternion Element

ACTION_MODE Weapon mode (caged, launched, hit)

TARGET_INDEX Index of X-Plane Target (if user object)

TTR_MIN Time To Release – Minimum (seconds)

TTR_MAX Time To Release – Maximum (seconds)

TTR_OPT Time To Release – Optimum (seconds)

TTG Time To Go (seconds)

CROSS_AXIS_LIMIT_L Max off-boresight Angle – Left (degrees)

CROSS_AXIS_LIMIT_R Max off-boresight Angle – Right (degrees)

TYPE X-Plane weapon type reference

LAT_REF LON_REF WEAPON LASER

LAT Latitude of Weapon

LON Longitude of Weapon

ALT Altitude of Weapon

X OpenGL X Coordinate (metres)

Y OpenGL Y Coordinate (metres)

Z OpenGL Z Coordinate (metres)

VX OpenGL X Velocity (metres per second)

VY OpenGL Y Velocity (metres per second)

VZ OpenGL Z Velocity (metres per second)

P Roll Rate (radians per second)

Q Pitch Rate (radians per second)

R Yaw Rate (radians per second)

Q1 Quaternion Element

Q2 Quaternion Element

Q3 Quaternion Element

Q4 Quaternion Element

ACTION_MODE Weapon mode (caged, launched, hit)

TARGET_INDEX Index of X-Plane Target (if user object)

TTR_MIN Time To Release – Minimum (seconds)

TTR_MAX Time To Release – Maximum (seconds)

TTR_OPT Time To Release – Optimum (seconds)

TTG Time To Go (seconds)

CROSS_AXIS_LIMIT_L Max off-boresight Angle – Left (degrees)

CROSS_AXIS_LIMIT_R Max off-boresight Angle – Right (degrees)

TYPE X-Plane weapon type reference

ON Is Laser On

LOCKED Is Laser Locked

CODE Numerical ID Code

LAT Latitude of Laser Spot

LON Longitude of Laser Spot

ALT Altitude of Laser Spot

DATA STRUCTURE

Figure 3.34: Flow Diagram of Weapon Simulation Including Networking Links With X-Plane

3.3.3 MATLAB MEX Functions for UDP Messages

MATLAB MEX files allow for compiled C++ code to be included as functions within the MATLAB native environment. This additional functionality was used to generate a UDP message sending and receiving service between different instances of MATLAB (for the different simulations) and other programs such as X-Plane. The advantages of using compiled MEX code are that the execution speed is faster than using the MATLAB runtime environment and the structure of messages must be declared before compiling the MEX files.

Figure 3.35 shows a screen shot of two moving armoured targets simulated in MATLAB and visualised in X-Plane using graphical objects. MATLAB MEX files are used to send positioning information from MATLAB to X-Plane for real-time simulation.

Figure 3.36: Test GBU Launch Against a Mobile Armoured Target

Figure 3.36 shows a simulated test firing of a GBU against a mobile armoured target moments before impact. Debug graphics can be seen overlaid onto the screen including launch aircraft status, a radar and a high visibility cross to show weapon position.

Chapter 4

Real-Time Task Allocation for

Remote Weapon Operators