Conditional timer to increase or decrease value #2161
-
|
Hi, we have a task where visual stimuli are controlled by input from a rotary encoder or the mouse rotary via setting the value of the PublishSubject "RotaryPosition". We would like to create a passive version of the task where visual stimuli slowly move left or right or are stationary, depending on serial input sent to "BytesFromBpod". I've tried to implement that via a timer and I am able to increase "RotaryPosition" and thereby move the stimulus to the right. However, the issue is that the timer is directly controlling the RotaryPosition, which makes its value increase indefinitely. Instead, I would like to increase/decrease it only once a certain byte value is sent from BytesFromBpod, and then stop the increase/decrease once any other byt value is sent from BytesFromBpod. Any help or pointers would be greatly appreciated! Katharina |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
|
Do you want the increased value depending on the input byte value? I have a feeling that you need a Merge before the Multiply-Value. The Merge will receive input from the BytesFromBpod via a parallel path. On each of the path, there will be a Condition to check which one get passed. This is what I imaged the workflow is. |
Beta Was this translation helpful? Give feedback.
-
|
@KathaSchmack did the previous answer help? Do you still need help? |
Beta Was this translation helpful? Give feedback.
-
|
It only sends a byte for state change. I want it to start moving when it sends a certain byte and stop moving when it sends another byte. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @KathaSchmack not sure if this is the best way to do it but will this work for you? Basically, we use CreateObservable to generate three different observable streams depending on the Within the CreateObservable operator each observable stream is identical except for the equality check and the Int values (1 for I have attached a toy workflow, you can use keys A, B, C to control the |
Beta Was this translation helpful? Give feedback.
-
|
I may be missing something, but one easy way to achieve this behavior would be to simply toggle the gain: Workflow (Copy+Paste me)<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gl="clr-namespace:Bonsai.Shaders;assembly=Bonsai.Shaders"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="gl:CreateWindow">
<gl:Width>640</gl:Width>
<gl:Height>480</gl:Height>
<gl:VSync>On</gl:VSync>
<gl:SwapSync>false</gl:SwapSync>
<gl:ClearColor>Black</gl:ClearColor>
<gl:ClearMask>DepthBufferBit ColorBufferBit</gl:ClearMask>
<gl:CursorVisible>true</gl:CursorVisible>
<gl:Location xsi:nil="true" />
<gl:WindowBorder>Resizable</gl:WindowBorder>
<gl:WindowState>Normal</gl:WindowState>
<gl:DisplayDevice>Primary</gl:DisplayDevice>
<gl:TargetRenderFrequency>60</gl:TargetRenderFrequency>
<gl:TargetUpdateFrequency xsi:nil="true" />
<gl:RenderState />
<gl:GraphicsMode>
<gl:ColorFormat>
<gl:Red>8</gl:Red>
<gl:Green>8</gl:Green>
<gl:Blue>8</gl:Blue>
<gl:Alpha>8</gl:Alpha>
</gl:ColorFormat>
<gl:Depth>16</gl:Depth>
<gl:Stencil>0</gl:Stencil>
<gl:Samples>0</gl:Samples>
<gl:AccumulatorFormat>
<gl:Red>0</gl:Red>
<gl:Green>0</gl:Green>
<gl:Blue>0</gl:Blue>
<gl:Alpha>0</gl:Alpha>
</gl:AccumulatorFormat>
<gl:Buffers>2</gl:Buffers>
<gl:Stereo>false</gl:Stereo>
</gl:GraphicsMode>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Timer">
<rx:DueTime>PT0S</rx:DueTime>
<rx:Period>PT1S</rx:Period>
</Combinator>
</Expression>
<Expression xsi:type="Mod">
<Operand xsi:type="WorkflowProperty" TypeArguments="sys:Int64">
<Value>2</Value>
</Operand>
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>byte(it)</scr:Expression>
</Expression>
<Expression xsi:type="rx:PublishSubject">
<Name>BytesFromBpod</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="gl:Timer">
<gl:DueTime>PT0S</gl:DueTime>
<gl:Period>PT0.04S</gl:Period>
</Combinator>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>BytesFromBpod</Name>
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>it == 1 ? 1.0 : 0</scr:Expression>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Value" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="FloatProperty">
<Value>1</Value>
</Combinator>
</Expression>
<Expression xsi:type="rx:Accumulate" />
<Expression xsi:type="rx:PublishSubject">
<Name>RotaryPosition</Name>
</Expression>
</Nodes>
<Edges>
<Edge From="1" To="2" Label="Source1" />
<Edge From="2" To="3" Label="Source1" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="5" To="9" Label="Source1" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="7" To="8" Label="Source1" />
<Edge From="8" To="9" Label="Source2" />
<Edge From="9" To="10" Label="Source1" />
<Edge From="10" To="11" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
|
Beta Was this translation helpful? Give feedback.
-
|
Thank you so much, @bruno-f-cruz, @banchan86 and @chiyu1203! 'Accumulate' is what I needed, and implementing three different conditions similar to 'CreateObservable' with a 'merge' seems the way to go to implement three different behaviours. I can't fully test it right now but will close this thread because I am confident I will be able to solve it with all these great suggestions! Thanks again! |
Beta Was this translation helpful? Give feedback.





I may be missing something, but one easy way to achieve this behavior would be to simply toggle the gain:
Workflow (Copy+Paste me)