Have Condition1 stays True until Condition2

127 views
Skip to first unread message

Vincent Prevosto

unread,
Dec 19, 2018, 12:34:18 AM12/19/18
to Bonsai Users
Hi all,
I'm building a workflow where there's a boolean (Threshold1 in excerpt below), that is quite noisy - it oscillates between True and False fairly rapidly, and I'd like it to stay True, until a second boolean value (Threshold2) becomes True (then become False until Threshold1's condition is met again). Basically, I'm trying to get clean ON / OFF cycles. I've tried a simple SkipUntil workflow, or adding DistinctUntilChanged conditions, or also use SkipWhile, but I can never actually get the desired outcome. I feel this has been solved many times previously, I just don't find the solution on the forum. Any tip on how to solve this?
Thanks


Vincent Prevosto

unread,
Dec 19, 2018, 3:12:08 PM12/19/18
to Bonsai Users
I just implemented a solution in a Python transform, but I'd be curious is someone has a more Bonsai-esque solution.

cycleOn = False

@returns(bool)
def process(value):
 
global cycleOn

 
if value.Item1>2 and value.Item2>2:
    onCycleTrig
= True
    offCycleTrig
= False
 
elif value.Item1<-2 and value.Item2>2:
    onCycleTrig
= False
    offCycleTrig
= True
 
else:
    onCycleTrig
= False
    offCycleTrig
= False

 
if cycleOn == True:
   
if offCycleTrig == False:
      cycleOn
= True
     
return False
   
else:
      cycleOn
= False
     
return False
   
 
if cycleOn == False:
   
if onCycleTrig == True:
      cycleOn
= True
     
return True
   
else:
      cycleOn
= False
     
return False


Gonçalo Lopes

unread,
Dec 19, 2018, 6:54:33 PM12/19/18
to Vincent Prevosto, Bonsai Users
Hi Vincent,

I think Chi-Yu posted a solution for this hysteresis double threshold very recently, using Scan:

Maybe we can move the discussion over there, if there is anything that is unclear?

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/44579451-f756-4e1c-92e6-c565853ed2e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vincent Prevosto

unread,
Dec 19, 2018, 6:56:10 PM12/19/18
to Bonsai Users
Sure
Reply all
Reply to author
Forward
0 new messages