abax2000 Posted October 27, 2011 Report Posted October 27, 2011 (edited) At the bottom of this post there is a short Lua script that records some basic figures at landing (Vthreshold, VS and IAS at touchdown). Being not even remotely a programmer, the code is more of a patchwork out of the "example Lua pugins" doc. FSUIPC great documentation allows even to cavemen like me to enhance their FS experience. I would welcome some comments/tips on the two following points: There is a "while do" loop used to capture Vthreshold. Is there any other way that slips me to do so avoiding loops and the possible resource penalty? The flag event used [event.flag(0, "recordvref")], cannot be triggered via LuaSet or LuaToggle, as I would expect (Lua and LuaSet on the same keystroke is used to trigger the event). Wouldn't LuaSet or LuaToggle be enough on their one to trigger it? -- must assign "Lua Landing" and "LuaSet Landing" (with parameter 0) ipc.setflag(0) --if ipc.testflag(0) then -- ipc.log("FlagVref Set") --else -- ipc.log("FlagVref Not Set") --end function recordvref(n) while ipc.testflag(0) do --if ipc.testflag(0) then -- ipc.log("Flag2Set") --else -- ipc.log("Flag2NotSet") --end ralt = ipc.readUD(0x31E4)*3.28084/65536 if ralt<=52 then vrefias = ipc.readSD(0x02BC) / 128 ipc.log("Vref = " .. vrefias.." at thr "..ralt) ipc.lineDisplay("Vref = " .. vrefias.." at ft "..ralt, 1) ipc.setdisplay(100, 250, 220, 150) ipc.toggleflag(0) end ipc.sleep(50) end end function logvs(off, val) if val ~= 0 then -- if on ground flag just set, get VS, convert it and log it vs = ipc.readSD(0x030C) * 60 * 3.28084 / 256 ipc.log("Vertical speed at touchdown = " .. vs) tdias = ipc.readSD(0x02BC) / 128 ipc.log("IAS at touchdown = " .. tdias) ipc.lineDisplay("VS at td = "..vs.."\nIAS at td ="..tdias, 2) end end recordvref(0) event.flag(0, "recordvref") -- set to call above routine whenever "on ground" flag changes event.offset(0x0366, "UW", "logvs") Edited October 27, 2011 by abax2000
Pete Dowson Posted October 27, 2011 Report Posted October 27, 2011 There is a "while do" loop used to capture Vthreshold. Is there any other way that slips me to do so avoiding loops and the possible resource penalty? I'm not really sure exactly what you are doing (e.g. why you are using a Flag?), but it looks like you are simply monitoring the radio altitude and acting when it gets to 52 or less. You could of course monitor it by an event.offset on 31E4. However, I see you have a Sleep(50) in the loop, so it is not really a resource hog as it stands. The flag event used [event.flag(0, "recordvref")], cannot be triggered via LuaSet or LuaToggle, as I would expect (Lua and LuaSet on the same keystroke is used to trigger the event). Wouldn't LuaSet or LuaToggle be enough on their one to trigger it? Er, I'm not understanding what you are saying here, sorry. The flag event should certainly be triggered by a LuaSet, LuaClear or LuaToggle action, providing it changes the flag -- that is the main purpose of the event.flag facility, as documented. What exactly do you mean by "Lua and LuaSet on the same keystroke is used to trigger the event"? Are you re-loading and re-running your Lua plug-in each time? That rather spoils the point of using Events. I can help if you can explain a little more of what you are doing, please. Regards Pete
abax2000 Posted October 27, 2011 Author Report Posted October 27, 2011 Yes, just that. I monitor radio altitude to drop to 52 or less so I can record IAS. I used a flag just because it was the only thing I could think to trigger the code at a user-defined moment (e.g. at short final), and avoid having the loop going on for the whole flight. The sleep(50) is just there to "lighten up" things a bit, still giving an acceptable accuracy of appr 0.6ft. In fact, I do not know how a conditional event.offset can be used (e.g. in plain english "trigger the routine when radio alt drops below 52ft"). Certainly this would be a much more straightforward and simple solution. Could you pls give an example? As for the flag event: I tried to trigger the [event.flag(0,"recordvref")] via LuaSet (parameter 0) or LuaToggle (parameter 0). For some reason, both didn't work for me. It must be something I don't understand about flags and the syntax of the flag events in Lua code. Since I failed to use LuaSet or LuaToggle, I assigned to a key Lua (when pressed) and LuaSet-parameter0 (when released). Doing so I managed to get it going. To be more specific on what I am not sure of or do not understand clearly: I guess LuaSet sets the named flag to TRUE, LuaClear to FALSE and LuaToggle just toggles the two values. Available flags per .lua are 256 (0-255). Each flag can be either true or false (1 or 0). What is exactly the purpose and the result of the red line in .lua code (pls see edited initial post)? Why the syntax in the green line of the .lua code islike this and not {function recordvref(0)} (pls see edited initial post)? note: I used red and green lines following the example Baro in "Lua Plugins for VRInsight Devices". That does not mean that I fully understand their purpose. vbr
Pete Dowson Posted October 27, 2011 Report Posted October 27, 2011 I used a flag just because it was the only thing I could think to trigger the code at a user-defined moment (e.g. at short final), and avoid having the loop going on for the whole flight. Well it wouldn't have any noticeable impact really., and the loop wouldn't be needed if you merely monitored the altitude with an event.offset. In fact, I do not know how a conditional event.offset can be used (e.g. in plain english "trigger the routine when radio alt drops below 52ft"). Well, you are already monitoring the "on ground flag" with your event.offset(0x0366, "UW", "logvs") There's no difference monitoring the altitude. The "conditional" part is programmed, in whatever way you wish, in the called function. I tried to trigger the [event.flag(0,"recordvref")] via LuaSet (parameter 0) or LuaToggle (parameter 0). For some reason, both didn't work for me.It must be something I don't understand about flags and the syntax of the flag events in Lua code. Could you show me what you tried, please, as I don't understand. How was the Lua program being started -- maybe it simply wasn't running? Only the Lua and LuaDebug controls actually start a plug-in unless you have them automatically loaded via ipcReady.lua or some [Auto] section in the INI file. One of the latter methods is advisable for plug-ins you want running all the time monitoring events. Since I failed to use LuaSet or LuaToggle, I assigned to a key Lua (when pressed) and LuaSet-parameter0 (when released). Doing so I managed to get it going. Each time you loaded, compiled and ran the plug-in using the Lua command, you are killing the previous version that was running. so that makes a nonsense really of using events. Running Lua ptrograms on key or button-presses is used for one-off actions, not really something you want to keep running. I guess LuaSet sets the named flag to TRUE, LuaClear to FALSE and LuaToggle just toggles the two values. Yes, as documented. Available flags per .lua are 256 (0-255). Each flag can be either true or false (1 or 0). Yes. There used to be only 32 but this was extended recently. What is exactly the purpose and the result of the red line in .lua code (pls see edited initial post)? I don't know. you put it there I assume. It appears to be running executing the function, which wil be exected again when the next line executes in any case. Why did you put the red line in? Why the syntax in the green line of the .lua code islike this and not {function recordvref(0)} (pls see edited initial post)? The "function" line declares that the code from there until the complementing 'end' is a function (a sequence of code) which will be called by something else (like the event occurring). The parameters for the function must be given names if you want to use them in the function. You cannot declare a parameter as a number, like '0' because numbers cannot be given vslues -- they ARE values already! note: I used red and green lines following the example Baro in "Lua Plugins for VRInsight Devices". That does not mean that I fully understand their purpose. Probably best to visit the Lua website and browse some of the introductory texts they have there. I see now how you got the red line. That was needed to do the initial call to the function which, when that plug-in was written, was not carried out automatically when the related 'event' line is executed. FSUIPC was changed to do this automatically, so it is no longer necessary. Note that the Lua plug-ins supplied for VRI devices are intended to be run automatically by provisions made explicitly for VRI in the FSUIPC INI file. They were NOT designed to be run by keypress as you are doing. Regards Pete
abax2000 Posted October 28, 2011 Author Report Posted October 28, 2011 Your comments were a real eye opener for me and thank you for that. Most important: Could you show me what you tried, please, as I don't understand. How was the Lua program being started -- maybe it simply wasn't running? Only the Lua and LuaDebug controls actually start a plug-in unless you have them automatically loaded via ipcReady.lua or some [Auto] section in the INI file. One of the latter methods is advisable for plug-ins you want running all the time monitoring events. I was under the false impression that LuaSet, Clear and Toggle can also start a plugin. This misunderstanding was the cause of the whole frustration about starting the plugin. Just realised that starting a plugin is a different thing from triggering a function in it via events. Everything clear for me now on this front. Well, you are already monitoring the "on ground flag" with your event.offset(0x0366, "UW", "logvs") There's no difference monitoring the altitude. The "conditional" part is programmed, in whatever way you wish, in the called function. I was just thinking that monitoring a control that changes values continuously (and not just between two values like 0366 two times per flight) would keep calling the function continuously, and thus add an unwanted load to the system. I now understand from your input that this load is not noticeable, so we press on. Probably best to visit the Lua website and browse some of the introductory texts they have there. I did that but I was overwhelmed. I would need hard studying of a month to get me going, considering that my only hands on experience in programming was some 30 years ago in Fortran (no comments please) and a little of VisualBasic 20 years ago for office use. All other points taken and understood. Pls note that 'FSUIPC Lua Library' refers to 32 flags at ipc.testbuttonflag, ipc.testflag, and event.flag descriptions. All other flag references of the documentation correctly state 256 flags per plugin. Thank again for clarifying all for me. Hope you had a great weekend.
Pete Dowson Posted October 28, 2011 Report Posted October 28, 2011 Pls note that 'FSUIPC Lua Library' refers to 32 flags at ipc.testbuttonflag, ipc.testflag, and event.flag descriptions. All other flag references of the documentation correctly state 256 flags per plugin. Ah, thanks. Yes I'd missed those! Will fix on next update. Regards Pete
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now