Jump to content
The simFlight Network Forums

Can I use lua to set a control based on the state of another control


Recommended Posts

What I want to do is this

(I haven't tried it yet beyond checking the log to make sure the controls can be recognised)

 

1. When the AP is switched on either by the "z" key or the button in the VC, switch the Yaw Damper On

2. When the AP is switched off either by the "z" key or the button in the VC, switch the Yaw Damper Off

 

I need to be able to differentiate between AP on and AP Off rather than just recognising the key press as depending on the initial condition of the AP I need to know whether to switch the YD on or Off

 

So something like

if AP_Master == On and YD == Off then
set YD on
elseif AP_Master == Off and YD == On then
set YD off
end

Is that doable, before I start trying

 

If you're interested Im trying to workaround an issue the Alabeo C400 has where Activating the AP turns on the YD but deactivating leaves it on.

 

Thanks in advance

 

Dave

Link to comment
Share on other sites

What I want to do is this

(I haven't tried it yet beyond checking the log to make sure the controls can be recognised)

 

1. When the AP is switched on either by the "z" key or the button in the VC, switch the Yaw Damper On

2. When the AP is switched off either by the "z" key or the button in the VC, switch the Yaw Damper Off

 

I need to be able to differentiate between AP on and AP Off rather than just recognising the key press as depending on the initial condition of the AP I need to know whether to switch the YD on or Off

 

States of things in FS are CHANGED by controls, but those are simply messages passed to FS to obey. They are just transient.

 

You need to check the current state, which is accomplished by reading the appropriate offset. All offsets for default aircraft (and used by many add-ons too) are listed and described in the List of Offsets document in your FSUIPC Documents folder. Note however that some add-ons (eg especially PMDG) implement their own methods with their own autopilot and you need to find the right way to get this information for your target aircraft.  I have mapped the PMDG 737NGX and 777X offsets into FSUIPC and these are also documented for you (you have to enable the service in the PMDG settings someplace first). But other aircraft may be more difficult, and may even require reading of LVars instead. Searching the User Contributions subforum might help.

 

The facilities to read (and write) both offsets and LVars are included in the ipc library for Lua plug-ins, so, yes what you want to do is clearly "doable". You'll want to use event.offset to call a function based on changes to the A/P status, and have the plug-in loaded automatically, perhaps via an [Auto] section in the INI file. You can have different ones for different aircraft loaded by Profile-specific [Auto...] sections.

 

Pete

Link to comment
Share on other sites

Got it, I think (well it seems to work) :razz:

--Lua file to automatically disable the Yaw Damper when the AP is disconnected
--and enable it (to mirror the VC button) when z is pressed
--Dave Dewhurst

function setyawdamper(offset, AP_Master)
    Yaw_Damper = ipc.readFLT(0x0808)
	if AP_Master > 0 and Yaw_Damper == 0 then
	ipc.writeFLT(0x0808, AP_Master)
    elseif AP_Master == 0 and Yaw_Damper > 0 then
	ipc.writeFLT(0x0808, 0)
    end
end

event.offset(0x07BC, "FLT", "setyawdamper")

Oddly, I was expecting ON == 1 and OFF = 0

but on seemed = 1.405......e-45

so I just set it equal to AP_MAster which was the same value when on

 

Thanks again, it took less time than I thought

 

Dave

Link to comment
Share on other sites

Got it, I think (well it seems to work) :razz:

--Lua file to automatically disable the Yaw Damper when the AP is disconnected
--and enable it (to mirror the VC button) when z is pressed
--Dave Dewhurst

function setyawdamper(offset, AP_Master)
    Yaw_Damper = ipc.readFLT(0x0808)
	if AP_Master > 0 and Yaw_Damper == 0 then
	ipc.writeFLT(0x0808, AP_Master)
    elseif AP_Master == 0 and Yaw_Damper > 0 then
	ipc.writeFLT(0x0808, 0)
    end
end

event.offset(0x07BC, "FLT", "setyawdamper")

Oddly, I was expecting ON == 1 and OFF = 0

but on seemed = 1.405......e-45

so I just set it equal to AP_MAster which was the same value when on

 

Oh dear.  Very few offsets are FLT (32-bit floating point). Where they are it says so. 07BC is just a UD (unsigned double word), i.e. a simple number, and is most certainly either 0 or 1.

 

Same for the yaw damper.

 

Pete

Link to comment
Share on other sites

Hmm,

Ill re read what I read that made me think it was a float and try again.

Thanks for the extra pointer

 

Dave

 

EDIT, yep it was me reading things wrong (nothing new)

changed them to UD and can now set the values as 0 & 1

 

Thanks

Edited by DaveDewhurst
Link to comment
Share on other sites

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.