You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/hobgoblin-reaction.md
+15-6Lines changed: 15 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ The task begins with an inter-trial interval (`ITI`), followed by stimulus prese
21
21
22
22
### Exercise 1: Generating a fixed-interval stimulus
23
23
24
-
In this first exercise, you will assemble the basic hardware and software components required to implement the reaction time task. Connect the LED to digital output channel `0` (`GP15`) on the `Hobgoblin`. Connect the push button to digital input channel `0` (`GP2`) on the `Hobgoblin`.
24
+
In this first exercise, you will assemble the basic hardware and software components required to implement the reaction time task. Connect the LED to digital output channel `GP15` on the `Hobgoblin`. Connect the push button to digital input channel `GP2` on the `Hobgoblin`.
25
25
26
26
>[!TIP]
27
27
> You can use other digital input or digital output channels, but make sure to change the appropriate properties.
@@ -39,7 +39,6 @@ Next, we will set up our `Hobgoblin`.
39
39
- During this tutorial we will need to have the ability to send/receive commands from distinct places in the workflow. To allow this kind of "many-to-one"/"one-to-many" communication, we will:
40
40
- Insert a [`PublishSubject`] operator and name it `Hobgoblin Events`.
41
41
42
-
43
42
- Right-click the [`Device`] operator, select `Create Source (Bonsai.Harp.HarpMessage)` > [`BehaviorSubject`]. Name the generated ``BehaviourSubject`1`` operator `Hobgoblin Commands`. Connect it as input to the [`Device`] operator.
44
43
45
44
>[!NOTE]
@@ -61,6 +60,7 @@ Lastly, we will set up a fixed-interval blinking LED as our stimulus.
61
60
- Insert a [`CreateMessage`] operator, configure the `Payload` property to [`DigitalOutputClearPayload`], and set the [`DigitalOutputClear`] property to the `GP15` pin.
62
61
- Insert a [`MulticastSubject`] operator and configure the `Name` property to `Hobgoblin Commands`.
63
62
- Insert a [`Repeat`] operator.
63
+
- Run the workflow, and verify that the LED is blinking.
64
64
65
65
### Exercise 2: Measuring reaction time
66
66
@@ -72,7 +72,7 @@ Lastly, we will set up a fixed-interval blinking LED as our stimulus.
72
72
- Insert a [`Parse`] operator after `Hobgoblin Events`. Configure the `Register` property to [`TimestampedDigitalOutputSet`].
73
73
- Insert a [`SubscribeSubject`] operator. Configure the `Name` property to `Hobgoblin Events`.
74
74
- Insert a [`Parse`] operator after `Hobgoblin Events`. Configure the `Register` property to [`TimestampedDigitalInputState`].
75
-
- Run the workflow, and verify that both the stimulus and the button are correctly recorded.
75
+
- Run the workflow, verify that both the stimulus and the button are correctly recorded.
76
76
77
77
>[!TIP]
78
78
> We use separate `Hobgoblin Events` operators to avoid issues with [branching](https://bonsai-rx.org/docs/articles/subjects.html#branching-subjects). See also [workflow guidelines](https://bonsai-rx.org/docs/articles/workflow-guidelines.html)
@@ -138,7 +138,7 @@ In order to translate our simple reaction time task in the previous exercises in
138
138
- Right-click, select `Group` > `Sink (Reactive)`. Set the `Name` property to `StimOff`.
139
139
140
140
> [!Note]
141
-
> The `Sink` operator allows you to specify arbitrary processing side-effects without affecting the original flow of events. It is often used to trigger and control stimulus presentation in response to events in the task. Inside the nested specification, `Source1` represents input events arriving at the sink. In the specific case of `Sink` operators, the `WorkflowOutput` node can be safely ignored.
141
+
> The [`Sink`] operator allows you to specify arbitrary processing side-effects without affecting the original flow of events. It is often used to trigger and control stimulus presentation in response to events in the task. Inside the nested specification, `Source1` represents input events arriving at the sink. In the specific case of `Sink` operators, the `WorkflowOutput` node can be safely ignored.
142
142
143
143
- Delete the [`Delay`] operator.
144
144
- Insert a [`SelectMany`] operator after `StimOn`, and set its `Name` property to `Response`.
@@ -148,25 +148,34 @@ In order to translate our simple reaction time task in the previous exercises in
- Insert a [`SubscribeSubject`] operator. Configure the `Name` property to `Hobgoblin Events`.
152
-
- Insert a [`Parse`] operator after `Hobgoblin Events`. Configure the `Register` property to [`TimestampedDigitalInputState`].
153
+
- Insert a [`Parse`] operator after `Hobgoblin Events`. Configure the `Register` property to [`DigitalInputState`].
154
+
- Insert a [`Condition`] operator after the [`Parse`] operator.
155
+
- Double-click on the [`Condition`] operator and add an [`Equal`] operator after the `Source1` operator. Set the `Value` property to `GP2`.
153
156
- Insert a [`Take`] operator and set its `Count` property to 1.
154
-
- Delete the `Source1` operator.
155
157
- Connect the [`Take`] operator to `WorkflowOutput`.
156
158
- Run the workflow a couple of times and validate the state machine is responding to the button press.
157
159
160
+
> [!Note]
161
+
> [`DigitalInputState`] sends a [`HarpMessage`] when it detects a change on any of the digital input pins on the `Hobgoblin`. Using a [`Condition`] with a nested [`Equal`] operator allows us to filter only messages from that pin. It also has the nice effect of only detecting a button press (when the value goes fron `None` > `GP2`) instead of a button release (`GP2`>`None`).
0 commit comments