Jump to content

Help needed with logic switch programming


Allan Bennett
 Share

Recommended Posts

I want to create a logic that will momentarily (say 0.5 seconds) switch SC down the first time SG is switched up (my throttle enable switch) and the throttle stick reaches or exceeds a certain threshhold.  I thought this needs two logic lines so that a flag can be set to prevent activation the second or subsequent time that condition is met, but in an OpenTX simulation with the logic  |a|>x  [I1]Thr  -50  SGv  0.5  I seem to get what I want (I've used SG down in the test because the simulator default position of the switch is up);  The logic switches on for 0.5 seconds whenever SG is switched to the down position and throttle is above -50, but it doesn't swich on again if SG remains down and the throttle goes below -50 and then back up above -50, so that seems to be what I want without the need for a second logic line.

 

BUT, it only works that way when I apply it to a channel that has no other line in its mix.  If I add it to my existing Ch6 mix in REPLACE mode it doesn't work, and to make matters work, Ch6 then no longer responds to the first line of its mix, which is SC Weight (+100%).

 

Any ideas please?

 

 

 

Link to comment
Share on other sites

Having come back to this problem this evening I've found that what I described in my original post no longer works in simulation the same way as it previously did.  The logic I've now got is:-

 

Clipboard01.thumb.jpg.f7a4c50a0b467b7c8386ba297066b1a5.jpg

 

The way it's mixed is:-

 

Clipboard02.thumb.jpg.945f7c0d7c8c46bda1968b939d8f6315.jpg

 

Now what happens when I move SG down and have the throttle greater than -50 is I get a half-second blip of CH06 to -100%, which is what I want.  If the throttle's at less than -50 when I move SG down, CH06 doesn't blip until the throttle is raised above -50, which is also what I want.

 

But if, having triggered the blip of CH06, I then reduce the throttle to less than -50, and then increase it again above -50, it triggers another blip of CH06, which is not what I want.  So it seems like I do need to set a 'flag' to prevent repeated blips of CH06 being triggered by throttle passing the -50 mark, but I can't figure how to do it.

Link to comment
Share on other sites

14 minutes ago, Graham Bowers said:

. . . 

Are you saying you want a logical switch to temporarily change the state of  physical switch C to down when physical switch G is commanded up?

 

Not quite:  I want to temporarily change the state of physical switch C to down when physical switch G is commanded up, but only if the throttle stick is also above a certain level (-50 in my test example).  BUT I only want it to happen once during a flight -- not to happen every time the throttle passes -50 while switch G is still up.

 

 

Link to comment
Share on other sites

Thanks for clarifying.

 

I don't know how to do what you want, or even if it's possible, however am interested enough to offer what limited help I can, and hope to learn something along the way.

 

This sort of discussion is hard by written word only, but that's no reason not to try. 

 

1) First off, as far as I know, logical switches just change their state in response to input conditions. Any action required is implemented by a Special Function, that takes the LS as an input. Edited to add. I see you're using the LS in a mix. My 3) still applies though.

 

2) Let's just assume the logic can be found and a special function can be implemented, for the sake of developing understanding. If I've kept up so far, that it seems the outcome would be such that the logic commanded output of the physical switch and it's physical commanded output (set by it's physical position) would be  in opposition. How could that work?

 

 

Edited by Graham Bowers
Link to comment
Share on other sites

I've spent a bit of time on this this morning and need to park it up for a bit. It's interesting though, as it's allowing me to learn some of the functionality of OTX I've not touched on yet - but wished to.

 

I have a suspicion the answer lies in some of the more esoteric logic functions. Edge, Sticky, that sort of thing. And one logical switch feeding another, to obtain a "latching" effect - that I think you described as a "flag".

 

 

Link to comment
Share on other sites

Thanks for looking Graham.  I've been reading up on Edge and Sticky, but I still can't understand how they work or if they're relevant to my quest.  I'm pretty sure I need a 'flag', but then the logic would need to be checking SG and throttle stick position as well as the flag, and I can't see how to use three conditions in a logic line.

 

I know there are some logic gurus out there, so I hope that one or more of them will chip in when they get the time 🙂

Link to comment
Share on other sites

The Sticky function is ideal for creating a throttle cut.  Essentially, the Sticky logic switch is "armed" (TRUE) when one set of conditions is met and remains armed until a completely different set of conditions is met.

For the throttle cut example, I set the arming conditions to be that the throttle channel is < 95 and a switch is in a particular position.  The disarm condition is that the switch is in any other position.  It means that the throttle is only enabled when the stick is down AND the arming switch is in position ensuring that you can't enable with the throttle suddenly bursting into life.

It needs a Special Function as well of course, to override the throttle channel with -100 when the Sticky logic switch is FALSE.

Link to comment
Share on other sites

Interesting.  I just add a MAX (-100%) Switch (!SG^) line to my throttle mix which ensures no throttle unless SG is up.  Admittedly that allows an instant startup if the throttle stick is anything other than fully down when SG is switched.

 

Nevertheless, I still can't figure how Sticky might help with what I'm trying to achieve.

Link to comment
Share on other sites

1 hour ago, Allan Bennett said:

Thanks for looking Graham.  I've been reading up on Edge and Sticky, but I still can't understand how they work or if they're relevant to my quest.  I'm pretty sure I need a 'flag', but then the logic would need to be checking SG and throttle stick position as well as the flag, and I can't see how to use three conditions in a logic line.

 

I know there are some logic gurus out there, so I hope that one or more of them will chip in when they get the time 🙂

I imagine it may be necessary to have several logic switches, each making pair wise comparisons. Then perhaps a one master logic switch to rule them all and bind them 😉

Link to comment
Share on other sites

41 minutes ago, Allan Bennett said:

Interesting.  I just add a MAX (-100%) Switch (!SG^) line to my throttle mix which ensures no throttle unless SG is up.  Admittedly that allows an instant startup if the throttle stick is anything other than fully down when SG is switched.

 

Nevertheless, I still can't figure how Sticky might help with what I'm trying to achieve.

I think with OpenTx there are always multiple ways to achieve a desired effect!

Link to comment
Share on other sites

Having given this problem some more thought I've realised that I can simplify it:  My throttle action is already inhibited by !SG^, so switch SG doesn't need to be included in my logic line.  That means I only need to create a logic that will blip on for 0.5 seconds when Thr value reaches a certain point.  This can be achieved with this simple logic line:-

 

Clipboard01.thumb.jpg.586bc30a4874f6deb83d239fb0031f5f.jpg

 

But I'm still stuck with the problem that I only want this to happen the first time the throttle is opened beyond the trigger point.  So I figure I need another logic line that will latch on when the Thr value exceeds the target, so that I can then include that in the AND Switch column, but I can't figure how to make a logic that latches on after the initial trigger.

Link to comment
Share on other sites

  • =IF(Something is True, then do something, otherwise do something else)

  • AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False)

  • OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False)

  • NOT – =IF(NOT(Something is True), Value if True, Value if False)

Microsoft's versions of Logic

Link to comment
Share on other sites

I haven't tested this Allan, so I might be talking rubbish!  If you set up a Special Function, triggered by your L3 in the example above, which sets a global variable, say GV1, to some arbitrary value, let's say 1, then add a new logical switch, say L4, which tests for GV1 having the value 1.  So this logical switch will only become TRUE after the first blip of the throttle above -50, but will then remain TRUE.  If you then add in your line above to test for L4 being FALSE, L3 will only be TRUE for the first occurrence.  Does that make sense?  As I say, it's untested but it seems to me that it should work.

Link to comment
Share on other sites

19 hours ago, Allan Bennett said:

Having given this problem some more thought I've realised that I can simplify it:  My throttle action is already inhibited by !SG^, so switch SG doesn't need to be included in my logic line.  That means I only need to create a logic that will blip on for 0.5 seconds when Thr value reaches a certain point.  This can be achieved with this simple logic line:-

 

Clipboard01.thumb.jpg.586bc30a4874f6deb83d239fb0031f5f.jpg

 

But I'm still stuck with the problem that I only want this to happen the first time the throttle is opened beyond the trigger point.  So I figure I need another logic line that will latch on when the Thr value exceeds the target, so that I can then include that in the AND Switch column, but I can't figure how to make a logic that latches on after the initial trigger.


Allan, this can absolutely be done using sticky switches, but trying to explain it her in words is tricky - I will try and create a demo in Companion tonight and upload it here for you to use.

Link to comment
Share on other sites

33 minutes ago, MattyB said:


Allan, this can absolutely be done using sticky switches, but trying to explain it her in words is tricky - I will try and create a demo in Companion tonight and upload it here for you to use.

I agree Matty and that was my other thought.  As I said earlier, there's usually more than one way to achieve the same outcome with OpenTx.

  • Like 1
Link to comment
Share on other sites

Allan, I think this should work for you:

 

image.thumb.png.cd528d572d80c035f1dcf2e40dfd9457.png

 

Your L3 switch will now only fire when L4 is FALSE, which it is initially.  When L3 triggers the first time it also triggers the sticky switch L4.  This will stay TRUE until Thr > 100, which it will never be.  So it will remain TRUE indefinitely and, because L3 will only trigger when L4 is FALSE your L3 switch will not trigger again.

Hopefully that's what you want!  I tried running iot on the simulator and iot seems to work.  I have no doubt that there are more elegant ways of doing it but at least it works!

Link to comment
Share on other sites

34 minutes ago, Tim Kearsley said:

Allan, I think this should work for you:

 

image.thumb.png.cd528d572d80c035f1dcf2e40dfd9457.png

 

Your L3 switch will now only fire when L4 is FALSE, which it is initially.  When L3 triggers the first time it also triggers the sticky switch L4.  This will stay TRUE until Thr > 100, which it will never be.  So it will remain TRUE indefinitely and, because L3 will only trigger when L4 is FALSE your L3 switch will not trigger again.

Hopefully that's what you want!  I tried running iot on the simulator and iot seems to work.  I have no doubt that there are more elegant ways of doing it but at least it works!


This looks like a good start and was similar to the approach I was thinking of, but how do you reset the switch at the end of the flight? 

Link to comment
Share on other sites

Thanks Tim Kearsley for taking the time, and for explaining the logic, and MattyB for looking into it too.  Use of the Sticky with a reference to L05 goes some way to explaining to me how Sticky works, which I couldn't figure out when I read the OTX manual.

 

I've just tried it on OTX Companion, and it does exactly what I wanted.  At the end of the flight switching off my Tx will reset the switch, won't it?

Link to comment
Share on other sites

40 minutes ago, Allan Bennett said:

Thanks Tim Kearsley for taking the time, and for explaining the logic, and MattyB for looking into it too.  Use of the Sticky with a reference to L05 goes some way to explaining to me how Sticky works, which I couldn't figure out when I read the OTX manual.

 

I've just tried it on OTX Companion, and it does exactly what I wanted.  At the end of the flight switching off my Tx will reset the switch, won't it?


It should, but that shouldn’t be required. I am still trying to bet small people to sleep at present(!) but once they are off I will look into adding the functionality needed to reset it off the throttle cut switch. 
 

Ps - whilst the OTX manual is much better these days, don’t forget OTX University, they normally have very good conceptual descriptions of key functionality…

 

https://open-txu.org/glossary/sticky/

 

Edited by MattyB
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...