Difference between revisions of "DCS export"

From DCS World Wiki - Hoggitworld.com
m
Line 13: Line 13:
  
 
==Export.lua==
 
==Export.lua==
====Initialization====
+
===Initialization===
 
At the top of Export.lua, there's some comments about it's use
 
At the top of Export.lua, there's some comments about it's use
 
  -- Data export scripts  
 
  -- Data export scripts  
Line 47: Line 47:
 
DCS also prints to the Error.log file all other Lua error messages for the Export.lua script.
 
DCS also prints to the Error.log file all other Lua error messages for the Export.lua script.
  
====LuaExportStart and LuaExportStop====
+
===LuaExportStart and LuaExportStop===
 
DCS calls script functions for every mission simulation. It calls the LuaExportStart function just before mission start to make user script initializations. For example, to open a log file:
 
DCS calls script functions for every mission simulation. It calls the LuaExportStart function just before mission start to make user script initializations. For example, to open a log file:
  
Line 73: Line 73:
 
  c:close()
 
  c:close()
  
====LuaExportBeforeNextFrame====
+
===LuaExportBeforeNextFrame===
 
DCS calls the function LuaExportBeforeNextFrame just before every simulation frame. So if you want to set some input control commands then you can do it here. For example:
 
DCS calls the function LuaExportBeforeNextFrame just before every simulation frame. So if you want to set some input control commands then you can do it here. For example:
  
Line 88: Line 88:
  
  
====LuaExportAfterNextFrame====
+
===LuaExportAfterNextFrame===
 
DCS calls the function LuaExportAfterNextFrame every time the simulation frame finishes. So you need to code here your actions to get frame simulations results. For example:
 
DCS calls the function LuaExportAfterNextFrame every time the simulation frame finishes. So you need to code here your actions to get frame simulations results. For example:
  

Revision as of 18:24, 1 June 2018


DCS allows for the export of data within the game world to be used by a wide variety of applications. Example include tacview, simple radio, and physical cockpits.

Luasocket

DCS supplies LuaSocket 2.0 Beta files in the Scripts\LuaSocket folder and in the DCS installation folder. You can use LuaSocket to establish standard network connection between the Export.lua script and your local or remote program. Look into the Scripts\LuaSocket folder and find Listener.lua and Talker.lua files. You can use them as stand alone examples for Lua script networking.

Export.lua

Initialization

At the top of Export.lua, there's some comments about it's use

-- Data export scripts 
-- Copyright (C) 2004, Eagle Dynamics.
-- …
The Lua language use two sequential dashes "--" to start the single-line comment to the end of line. If you need to comment several lines then use "--" and "--" brackets:

-- Uncomment this function to enable data export!
--[[ 
function LuaExportStart()
-- Works once just before mission start.

-- Make initializations of your files or connections here.
-- For example:
-- 1) File
--	local file = io.open("./Temp/Export.log", "w")
--	if file then
--	io.output(file)
--	end
-- 2) Socket
-- dofile "lua.lua"
-- socket = require("socket")
-- host = host or "localhost"
-- port = port or 8080
-- c = socket.try(socket.connect(host, port)) -- connect to the listener socket
-- c:setoption("tcp-nodelay",true) -- set immediate transmission mode 

end
--]]

DCS activates the Config\Export\Export.lua script at every mission start. You need to uncomment the function LuaExportStart to activate it and to activate all other functions. For that add the single "-" just before "--[[" opening multi-line comment to convert it to the single-line comment "---[[". So the closing multi-line comment bracket without opening one becomes the single-line comment too. If you want to disable exporting features then remove additional third dash to make the comment multi-line again.

DCS also prints to the Error.log file all other Lua error messages for the Export.lua script.

LuaExportStart and LuaExportStop

DCS calls script functions for every mission simulation. It calls the LuaExportStart function just before mission start to make user script initializations. For example, to open a log file:

local file = io.open("./Temp/Export.log", "w")
if file then
io.output(file)
end

or to establish a network connection:

dofile "lua.lua"
socket = require("socket")
host = host or "localhost"
port = port or 8080
c = socket.try(socket.connect(host, port)) -- connect to the listener socket
c:setoption("tcp-nodelay",true) -- set immediate transmission mode

DCS calls the LuaExportStop function just after mission quit to make user finishing actions. For example, to close the log file:

io.close()
or to unlink the network connection:

socket.try(c:send("quit")) -- to close the listener socket
c:close()

LuaExportBeforeNextFrame

DCS calls the function LuaExportBeforeNextFrame just before every simulation frame. So if you want to set some input control commands then you can do it here. For example:

LoSetCommand(3, 0.25) -- rudder 0.25 right 
LoSetCommand(64) -- increase thrust

There are discrete and analogous input control commands. The discrete command has code only:

LoSetCommand(64) -- increase thrust

The analogous command has code and value:

LoSetCommand(3, 0.25) -- rudder 0.25 right


LuaExportAfterNextFrame

DCS calls the function LuaExportAfterNextFrame every time the simulation frame finishes. So you need to code here your actions to get frame simulations results. For example:

local t = LoGetModelTime()
local name = LoGetPilotName()
local altBar = LoGetAltitudeAboveSeaLevel()
local altRad = LoGetAltitudeAboveGroundLevel()
local pitch, bank, yaw = LoGetADIPitchBankYaw()

Then you can send data to your file:

io.write(string.format("t = %.2f, name = %s, altBar = %.2f, altRad = %.2f, pitch = %.2f, bank = %.2f, yaw = 
%.2f\n", t, name, altBar, altRad, pitch, bank, yaw))

or to your receiving network program:

socket.try(c:send(string.format("t = %.2f, name = %s, altBar = %.2f, alrRad = %.2f, pitch = %.2f, bank = %.2f, 
yaw = %.2f\n", t, name, altRad, altBar, pitch, bank, yaw)))

Multiplayer

When playing the game in single player every command is available, however in multiplayer there are options to disable specific settings as desired by the server creator. There are three options as defined by the following:

Object

Allows for all objects to be accessible. For example this is how tacview knows and returns where every single object in the game is at.

 LoGetObjectById
 LoGetWorldObjects

Sensor

Exports sensor data from your aircraft.

 LoGetTWSInfo
 LoGetTargetInformation
 LoGetLockedTargetInformation
 LoGetF15_TWS_Contacts
 LoGetSightingSystemInfo
 LoGetWingTargets

Ownship

Exports data about your own aircraft. For example simple radio uses one of these to get the players current location and radio information.

 LoGetPlayerPlaneId
 LoGetIndicatedAirSpeed
 LoGetAngleOfAttack
 LoGetAngleOfSideSlip
 LoGetAccelerationUnits
 LoGetVerticalVelocity
 LoGetADIPitchBankYaw
 LoGetTrueAirSpeed
 LoGetAltitudeAboveSeaLevel
 LoGetAltitudeAboveGroundLevel
 LoGetMachNumber
 LoGetRadarAltimeter
 LoGetMagneticYaw
 LoGetGlideDeviation
 LoGetSideDeviation
 LoGetSlipBallPosition
 LoGetBasicAtmospherePressure
 LoGetControlPanel_HSI
 LoGetEngineInfo
 LoGetSelfData
 LoGetCameraPosition
 LoSetCameraPosition
 LoSetCommand
 LoGetMCPState
 LoGetRoute
 LoGetNavigationInfo
 LoGetPayloadInfo
 LoGetWingInfo
 LoGetMechInfo
 LoGetRadioBeaconsStatus
 LoGetVectorVelocity
 LoGetVectorWindVelocity
 LoGetSnares
 LoGetAngularVelocity
 LoGetHeightWithObjects
 LoGetFMData

Always

 LoGetPilotName
 LoGetAltitude
 LoGetNameByType
 LoGeoCoordinatesToLoCoordinates
 LoCoordinatesToGeoCoordinates
 LoGetVersionInfo
 LoGetWindAtPoint
 LoGetModelTime
 LoGetMissionStartTime