#Variable reset to 0/Save variable state

1 messages ยท Page 1 of 1 (latest)

eternal blade
#

I'm still messing with the PMGD B737 TOGA mode for a motorised throttle. Sadly there is no way to use the TOGA mode so I have to create one.
I found a variable which is for the TOGA button press. It is 0 at the start but after pressing it it changes to 1. If I press again, it becomes 2. To set it to 0, the session must be restarted.
Is there any way to "save" a variable until a certain operation happens?

In this case this variable must go to 0 and stay there if the AT switch is turned off (rejected take off for example), if the plane is airborne (so when pressing the button again, the go around will be initiated). So whenever the TOGA switch is changed from 1 to 2 or from 2 to 1, while the AT is on, the variable must go from 0 to one.

#

Variable reset to 0/Save variable state

rough forum
#

you can do this with a MobiFlight variable if there is not a suitable one in the simulated aircraft simvars. First create the logic with modifiers and config references so you can evaluate the other simvars that determine the state of your own MF variable.

Once you have that, you can set your Display for the variable to be of type Input Action, and this basically creates a virtual button input that triggers based on your own variable.

#

And since your constructed MF variable will be either 0 or 1, you can use the "OnPress / OnRelease" option and this gives you the same possibilities as if you had a regular button press.

eternal blade
#

So what I really want is to simulate the TOGA mode for the PMDG.
The TO part has 3 preconditions:

  1. A/T Armed
  2. Speed below 80kts
  3. TOGA button pressed.

The first 2 is easy to check. I have variables for them.
This decides when the steppers will be enabled.
If 1 or 2 is at 0, the stepper is not enabled.

The TOGA switch is what I struggle with. It has 3 states. 0 on start of the sim, and 1/2 after pressing it.

rough forum
#

so hmm

#

I guess it is a matter of laying out the different conditions and actions

#

so the first 2 you can likely check on the toga button press

#

bring in config references, set your own variable only if those are true

#

if true, set 1, else set it 0

eternal blade
#

But I need a variable which gets 0 after 1 or 2 is 0. And stays 0 until 3 changes its state form 1 to 2 or from 2 to 1.

rough forum
#

so you can set the input action for both 1 and 2

#

AT armed simvar then has two functions

#

TOGA button reads it to determine if the MF variable for TOGA MODE should be set to 1 when the toga button is pressed,

#

and if AT ARMED simvar changes to 0

#

then you set INPUT ACTION for the A/T Armed to set the TOGA MODE to 0

#

same for airspeed, if it goes above 80 kias, you set TOGA MODE to 0

#

I am thinking this as I write, so I guess it should work

#

this is pretty interesting example actually of more complex logic with MF variables and once this works, it would be nice as a wiki page

#

would this make sense or am I thinking it wrong?

eternal blade
#

I'm checking

#

Can you show me an example with the input actions? I try to understand them, but I miss something.

rough forum
#

actually if you show yours

#

maybe we can see

#

what the issue is

#

but I can too, let me think

#

but if you have "speed below 80kts" config

eternal blade
rough forum
#

you likely read simvar, then do compare modifier to make it 1 when it is <80 and else 0 ?

rough forum
#

yeah

#

so then your MODE is a separate MF variable

eternal blade
rough forum
#

yeah

#

now open Display tab

eternal blade
#

In airspeed there is nothing there

rough forum
#

so your airspeed shows 5, I guess current wind?

#

and it sets itself to 1 because it is below 80 kts I guess

#

with modifiers

eternal blade
rough forum
#

so set Device type to Input action

#

not Output device

eternal blade
#

I set it

rough forum
#

since it is 0 or 1, we use the "OnPress / OnRelease" option

#

and then it behaves like a button

#

when your airspeed after modifiers changes to 1, you get OnPress event here

#

and when it changes to 0, you get OnRelease

#

so set your MF variable -> Value -> 1

#

and then click "Copy" button on the right side

#

and paste that to OnRelease, and change value to 0

#

actually

eternal blade
#

done

rough forum
#

wait I am backwards again

#

lets think

#

it should only trip the mode OFF

#

and never on of course ๐Ÿ˜„

#

you dont want toga automatically activate, that happens with the button only

#

that would be a bad surprise

eternal blade
#

yes ๐Ÿ˜„

rough forum
#

so hold on, we leave OnPress empty

#

and we just set OnRelease to set the value to 0

#

I think then it should work

#

we basically create a robotic switch

#

that triggers when your Airspeed simvar changes to 0

eternal blade
#

ohh, I see

rough forum
#

it is just a bit weird brain bender to think of "Display -> input event" what the heck

#

but it is pretty useful to trigger stuff based on simvars

eternal blade
#

yeah, this is why it was not clear for me

rough forum
#

yeah I know

#

its a bit weird concept and maybe not the cleanest but that is how it fits the current idea of inputs and outputs

#

we basically loop the simvar value back into a virtual switch

eternal blade
#

I did the same with A/T

rough forum
#

yeah, so now you should have two "release triggers" for the mode

#

we could do it a bit smarter and make it trigger on 1

#

its now a bit weird that the action is on OnRelease actually now that I think of it

eternal blade
#

Yeah, my logic was when everything on 1 then starts the TOGA

rough forum
#

since its then always hidden and next week you think what the heck were we thinking ๐Ÿ˜„

#

but it works of course either way

#

change to 0 -> OnRelease action, or
change to 1 -> OnPress action

#

same thing, if you just flip the modifiers

#

but yeah

#

now your TOGA button

eternal blade
#

That is the fun part

rough forum
#

and this needs to match your toga button checks

#

so that the expectation is the same on both

#

so maybe a matter of how you do these. Naming it "airspeed below 80" and then set it to 1 when that is true, and then everything triggers OnPress and the config reference name also makes similarly sense

#

its good to name things like this so they make sense elsewhere

#

so its easier to read the config reference list etc

#

but if the button now triggers the mode to ON only when the two conditions are 1

#

it kinda should work?

#

then it stays on until either of those conditions become 0

#

actually in that sense they need to be onrelease

#

and it makes sense, duh

#

sorry, this is what happens when I think at the same time as I write ๐Ÿ˜„

#

we essentially split the logic into OnPress (the actual button press for either toga button) that turns the mode on

#

and then either of those conditions, when they change, and the check does not meet the criteria, the mode is turned off

#

the important thing is there needs to be a change in the MF var in order for the event to trigger

eternal blade
#

So I have the TOGA push event which has the state 1 and 2.
I have 2 other variables which changes:

TOGA push 1 = 1 if TOGA push =1 else 0
TOGA push 2 = 1 if TOGA push =2 else 0

rough forum
#

you mean the actual switches?

#

or do you read it from the sim so pressing it from the sim virtual cockpit also triggers the mode?

eternal blade
rough forum
#

or why are they variables?

eternal blade
#

I use the vitrtual cockpit now until make the whole TQ ready. But since it is a button, I can use it from another Arduino, but have to wire it up.

#

(L:TOGAPush)

rough forum
#

oh right true

#

so you could then do it the same way

#

on those variables

eternal blade
#

yeah

rough forum
#

set them to do the InputAction on Display so that they turn the Toga MODE mf variable off when triggered the correct way around

eternal blade
#

and for example I don't have the MCP at me, so I use the virtual A/T too currently.

rough forum
#

yeah

#

and that actually will work well because then your MF variable mode reacts to the simulator

#

even if you had the hardware

#

because the simulator could load a state where the AT switch was in different position for example

#

unless the mcp has a real magnetically held AT switch too

#

but even that wouldnt turn ON automatically

eternal blade
#

I will see. Currently have the TQ at me

rough forum
#

if you loaded a "ready for takeoff" state for the plane for example

eternal blade
#

yeah

#

Is it okey that I don't see anything in the Name seelction list on the Variable settings?

#

If I press this, it is empty

#

And now this happened. Can't hit RUN.

rough forum
#

hmm

#

yea the mv variable name is not listed here for some reason

#

copy and paste it and it will work though

#

I need to file a bug report about this, MF variable names get added to the dropdown on regular inputs and outputs but here they are not for some reason

#

the error might be because of that, there is no variable name defined if it is empty

#

so open the other config that sets the mode and copy from there unless you remember it offhand

eternal blade
rough forum
#

yea

#

just copy and paste that to the other field

#

it just needs to match the other places we use the same variable

eternal blade
#

All set.

rough forum
#

does it work?

#

๐Ÿ™‚

eternal blade
#

TO mode is 0. How can I set it to 1?

rough forum
#

press the toga button?

eternal blade
#

still 0

#

I miss something IMO

rough forum
#

so disable both of those triggers that set it to 0

#

with the checkbox

#

and press it again

#

its either one of those sets it wrongly to 0

#

or the enable trigger does not work

#

and lets split the problem in half by disabling temporarily half of the automation

#

but I assume the trigger to turn it on does not work

#

because the other simvars likely dont trigger if you are on ground

eternal blade
#

turned off the kias

rough forum
#

any change?

#

turn off also the A/T check

#

and see if your button events set the mode correctly

eternal blade
#

I turned off everything than the A/T and set a press event to 1 and now it works. Have to check all of these

rough forum
#

yeah I assume the logic might be backwards somewhere

#

its easy to do this kinda as you go and then get something backwards

eternal blade
#

Yeah. The Toga push 1/2 had to be on the press event, the other 2 is both on press and release

rough forum
#

ok cool

eternal blade
#

Thank you. Now I have to think about the Go around logic. ๐Ÿ˜„

rough forum
#

yeah its sometimes a bit hard to see everything at once - making a picture of how the flow should work might help

#

so you remember what values trigger what etc

#

you're welcome

eternal blade
#

Can I set multiple variables with 1 trigger?

rough forum
#

you can duplicate the config

eternal blade
#

Nice

rough forum
#

only one action is possible, I mean technically you can do it with RPN code but that mixes in a whole different concept

#

but then MF variables are not working

#

but you need to instead do custom L-vars

eternal blade
#

I will check it

rough forum
#

like if you instead of MF variable do MSFS 2020 / simconnect action and set custom code and do

1 (>L:MyOwnTogaMode)
1 (>L:MyAnotherMode)

in the custom code field it might work

#

but that is a different way of doing and works only with msfs2020 of course

#

this does not work with MF variables then, so then your mode var needs to be the L-var too of course, cannot mix those things