coreDS™ fact – Lua Scripting Engine

coreDS™ fact – Lua Scripting Engine

Did you know you can use LUA to alter incoming or outgoing data? coreDS™ (and all related products) uses LUA as its main scripting engine. LUA is fast and powerful. All that information is available through two static variables that hold information on the current dataset to which the script is assigned and the global representation of the world.

LUA Scripts are loaded at runtime and can be live edited.

When using the LUA engine, two global variables are always defined:

DSimLocal

DSimLocal represents the local data to which the script was assigned. Let’s assume we are working with the Spatial attribute (from the beloved – or hated – RPR-FOM). DSimLocal will have the following structure:

DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.X
DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Y
DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Z
DSimLocal.DeadReckoningAlgorithm_A_Alternatives.isFrozen

Then you can convert from HLA (geocentric) to lat/long using the following code:

function func ()
angleConversions = require("angleConversions")
require("ecef2lla")

DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.X,DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Y,DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Z = ecef2lla(DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.X,DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Y,DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Z)

local lat = math.rad(DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.X) --converting to rad because function requires rad
local lon = math.rad(DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Y)

local psi = DSimLocal.DeadReckoningAlgorithm_A_Alternatives.Orientation.Psi-- heading
local theta = DSimLocal.DeadReckoningAlgorithm_A_Alternatives.Orientation.Theta--pitch
local phi = DSimLocal.DeadReckoningAlgorithm_A_Alternatives.Orientation.Phi --roll

DSimLocal.DeadReckoningAlgorithm_A_Alternatives.Orientation.Psi = angleConversions.getOrientationFromEuler(lat, lon, psi, theta)
DSimLocal.DeadReckoningAlgorithm_A_Alternatives.Orientation.Theta = angleConversions.getPitchFromEuler(lat, lon, psi, theta)
DSimLocal.DeadReckoningAlgorithm_A_Alternatives.Orientation.Phi = angleConversions.getRollFromEuler(lat, lon, psi, theta, phi)

end
DSimWorld

DSimWorld is the local representation of your simulator properties (as defined by the variables you choose to expose). For example, a flight simulator would have the following variable defined in DSimWorld

DSimWorld.Aircraft1.latitude

This allows you to access old values. The following example takes the last position of the Aircraft and assign it to the WeaponFire WorldLocation.

-- check the state of the weapon and allow to send interaction if any of the flags are set to one
   
angleConversions = require("angleConversions")
require("lla2ecef")
function func ()
  if (DSimWorld.Weapon == nil) then
    return;
  end

  if (lastState == nil) then
    lastState = DSimWorld.Weapon.action_mode
  end

  sendInter = 0;

  print(pairs(DSimWorld.Weapon.action_mode))
  
  for k,v in pairs(DSimWorld.Weapon.action_mode) do
    if (lastState[k] < v) then
      sendInter = 1;
    end
  end

  if (sendInter == 0) then
    DeleteValues = 1;
  else
    DSimLocal.X,DSimLocal.Y,DSimLocal.Z = lla2ecef(DSimWorld.Aircraft1.latitude,DSimWorld.Aircraft1.longitude,DSimWorld.Aircraft1.elevation)
  end

  lastState = DSimWorld.Weapon.action_mode
 end