Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi,

I'm working on a project that requires a flight data output to csv that will write one line of data (using several offsets) which will be over-written by the latest data at FSX/FSUIPC's native data output rate. Basically it's a real-time, one line, csv of current flight data.

I've gone through the SDK to see if i can work out how to do it but I'm not a programmer and I'm now completely stumped; can someone help with how this can be coded?

Posted

I'm working on a project that requires a flight data output to csv that will write one line of data (using several offsets) which will be over-written by the latest data at FSX/FSUIPC's native data output rate. Basically it's a real-time, one line, csv of current flight data. I've gone through the SDK to see if i can work out how to do it but I'm not a programmer and I'm now completely stumped; can someone help with how this can be coded?

Why not use a simple Lua plug-in? there's an example of something very like what you ask provided in the Lua plug-in examples. It's called "Record to csv.lua".

Pete

Posted

Many thanks Pete, I'll give it a go at work this week.

If I can't get it to work would you mind if I posted in here again asking for further assistance?

  • 2 weeks later...
Posted

Thanks for the help pete.

I think I've got my problem sorted but I can't really tell at the moment if it's working. Is there anyway I can monitor if data is updating in the csv while running fsx?


-- "Record to CSV example data logging LUA plug-in, by Pete Dowson, September 2008"
-- "Open an exisitng "FSrecord.csv" file to append to, or create it if it doesn't exist"
-- "It will go into the Modules folder because I've not included a full path (like "C:\....")"
-- "By using "assert" you get an error message if this fails"

f = assert(io.open("FSrecord.csv","w+"))

"-- write the CSV column headings

-- note the elapsed mSecs count now so can provide relative mSec timing column"
time0 = ipc.elapsedtime()
"-- Loop until our Flag 0 is set (by assigned FSUIPC control)"
while not ipc.testflag(0) do

f = assert(io.open("FSrecord.csv","w+"))

"-- Set the timestamp for this loop"
time = ipc.elapsedtime() - time0

"-- Read all the data we want from FSUIPC"
hour, min, sec, hourZ, minZ = ipc.readStruct(0x238, "5UB")
gs, tas, ias = ipc.readStruct(0x02B4, "3UD")
lat, lon, alt, pitch, bank, hdgT = ipc.readStruct(0x0560,"3DD", "2SD", "1UD")
mach = ipc.readUW(0x11C6)
vs = ipc.readSW(0x842)
"-- now convert them all from FS units into those we normally recognise"
gs = (gs * 3600) / (65536 * 1852)
tas = tas / 128
ias = ias / 128
mach = mach / 20480
vs = vs * -3.28084
lat = lat * 90 / (10001750 * 65536 * 65536)
lon = lon * 360 / (65536 * 65536 * 65536 * 65536)
alt = alt * 3.28084 / (65536 * 65536)
pitch = pitch * 360 / (65536 * 65536)
bank = bank * 360 / (65536 * 65536)
hdgM = hdgT - (ipc.readSW(0x02A0) * 65536)
hdgM = hdgM * 360 / (65536 * 65536)
hdgT = hdgT * 360 / (65536 * 65536)
"-- but only log this time IF we arent in an FS menu, or loading scenery
-- (check the "ready-to-fly" flag word at 3364)
-- and provided we are not paused (flagged at 0264)"

if (ipc.readUW(0x3364) == 0) and (ipc.readUW(0x0264) == 0) then
" -- write a CSV line to the open file"
f:write(string.format("%d,%02d:%02d:%02d,%02d%02dZ,%02.4f,%03.4f,%.1f,%.2f,%.2f,%03.1f,%93.1f,%d,%d,%d,%d,%.3f\n",
time,hour, min, sec, hourZ, minZ,lat,lon,alt,pitch,bank,hdgT,hdgM,vs,ias,tas,gs,mach))
end

"-- 40 times per second, roughly (allow 4 mSecs overhead)"
ipc.sleep(24)
end

"-- tidy up at end ..."
f:write("\n")
f:close()

"-- end of example program"
[/CODE]

Posted

I think I've got my problem sorted but I can't really tell at the moment if it's working. Is there anyway I can monitor if data is updating in the csv while running fsx?

Why not look at it?

Pete

  • 6 months later...
Posted

Hi all long time no speak,

I managed to get the above code working (mostly); this means I haven't touched LUA in months and have instead been getting to grips with MATLAB. Unfortunately I now have another requirement, I need to read in data from a continually updating external txt file with one line of data and six separated variables.

I've tried several different approaches but keep drawing a blank. I can obviously create the destination file but am getting stuck with importing the data as the file is left empty (and I can't see were the code is breaking as debugging won't seem to work); it's almost certain that I've got an error with the reading of the external file and the defining of it's variables but, as I'm still an absolute novice I can't see where, any thoughts?


' "Record to CSV" example data logging LUA plug-in, by Pete Dowson, September 2008'
' Open an exisitng "FSrecord.csv" file to append to, or create it if it doesnt exist'
' It will go into the Modules folder because Ive not included a full path (like "C:\....")'
' By using "assert" you get an error message if this fails'
' create the destination file'
f = assert(io.open("FSrecord.txt","a+"))
f:close()
' write the CSV column headings'
'f:write("\r\nmsecs,timeL,timeZ,lat,lon,alt(ft),pitch,bank,hdgT,hdgM,vs,ias,tas,gs,mach\n")'
' note the elapsed mSecs count now so can provide relative mSec timing column'
time0 = ipc.elapsedtime()
' Loop until our Flag 0 is set (by assigned FSUIPC control)'
while not ipc.testflag(0) do
' Set the timestamp for this loop'
time = ipc.elapsedtime() - time0
' Read all the data we want from FSUIPC'
hour, min, sec, hourZ, minZ = ipc.readStruct(0x238, "5UB")
gs, tas, ias = ipc.readStruct(0x02B4, "3UD")
lat, lon, alt, pitch, bank, hdgT = ipc.readStruct(0x0560,"3DD", "2SD", "1UD")
mach = ipc.readUW(0x11C6)
vs = ipc.readSW(0x842)
gr = ipc.readUB(0x0BE8) '--working - Gear position'
sw, os = ipc.readStruct(0x036C, "2UB") '--working - stall warning, overspeed'
apM, apwl, apnl, aphl, aphv, apal, apav = ipc.readStruct(0x7BC, "1UB", "3SW", "1UD", "1UB", "1DD") '--working - Autopilot data'
tp = ipc.readSW(0x088C)' --working - throttle position'
'-- now convert them all from FS units into those we normally recognise'
gs = (gs * 3600) / (65536 * 1852)
tas = tas / 128
ias = ias / 128
mach = mach / 20480
vs = vs * -3.28084
lat = lat * 90 / (10001750 * 65536 * 65536)
lon = lon * 360 / (65536 * 65536 * 65536 * 65536)
alt = alt * 3.28084 / (65536 * 65536)
pitch = pitch * 360 / (65536 * 65536)
bank = bank * 360 / (65536 * 65536)
hdgM = hdgT - (ipc.readSW(0x02A0) * 65536)
hdgM = hdgM * 360 / (65536 * 65536)
hdgT = hdgT * 360 / (65536 * 65536)
tp = (tp - 96) / 16192 * 100 '--working'
gr = gr / 255 '--working'
'-- but only log this time IF we arent in an FS menu, or loading scenery
-- (check the "ready-to-fly" flag word at 3364)
-- and provided we are not paused (flagged at 0264)
-- retrieve head postion data
-- open data source txt file'
f = assert(io.open("C:\Program Files (x86)\NaturalPoint\OptiTrack Camera SDK\samples\VectorTracking\headtrackstream.txt","r"))
'-- read data'
local x, y, z, yw, p, r = io.read("*number", "*number", "*number", "*number", "*number", "*number")
'-- close file'
f:close()



if (ipc.readUW(0x3364) == 0) and (ipc.readUW(0x0264) == 0) then
'-- write a CSV line to the open file'
'-- open destination file'
f = assert(io.open("FSrecord.txt","a+"))
f:write(string.format("%d,%02d:%02d:%02d,%02d%02dZ,%02.4f,%03.4f,%.1f,%.2f,%.2f,%03.1f,%93.1f,%d,%d,%d,%d,%.3f,%f,%f,%f,%s,%f,%f,%f,%93.1f,%s,%.1f,%f,%f,%f,%f,%f,%f,%f\n",
time,hour, min, sec, hourZ, minZ,lat,lon,alt,pitch,bank,hdgT,hdgM,vs,ias,tas,gs,mach,gr,sw,os,apM,apwl,apnl,aphl,aphv,apal,apav,tp,x,y,z,yw,p,r))
'-- close the destination file'
f:write("\n")
f:close()
end
'-- 20 times per second, roughly (allow 2 mSecs overhead)'
ipc.sleep(48)
end
'-- tidy up at end ...
--f:write("\n")
--f:close()
-- end of example program'
[/CODE]

Posted

it's almost certain that I've got an error with the reading of the external file

Isn't this getting an error? It should do. Did you check the Log, where Lua errors are posted?

f = assert(io.open("C:\Program Files (x86)\NaturalPoint\OptiTrack Camera SDK\samples\VectorTracking\headtrackstream.txt","r"))[/CODE]

As in C/C++. the "\" character is an escape character, used to inserts controls like line feeds. To get a real '\' in the string you have to use "\\".

Pete

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.