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-closeloop.md
+34-6Lines changed: 34 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Close-Loop Systems
2
2
3
-
The exercises below will help you become familiar with using the [Harp Hobgoblin](https://github.com/harp-tech/device.hobgoblin) device for close-loop experiments. You will also learn how to use the `Hobgoblin` to interface with external cameras. Before you begin, it is recommended that you review the Bonsai [Acquisition and Tracking](https://bonsai-rx.org/docs/tutorials/acquisition.html) tutorial, which covers key video concepts.
3
+
The exercises below will help you become familiar with using the [Harp Hobgoblin](https://github.com/harp-tech/device.hobgoblin) device for close-loop experiments. You will also learn how to interface with external cameras. Before you begin, it is recommended that you review the Bonsai [Acquisition and Tracking](https://bonsai-rx.org/docs/tutorials/acquisition.html) tutorial, which covers key video concepts.
4
4
5
5
## Prerequisites
6
6
@@ -50,7 +50,7 @@ Lastly, we will use this sequence to toggle the digital output and initialize th
50
50
### Exercise 2: Measuring video acquisition latency
@@ -63,10 +63,10 @@ Lastly, we will use this sequence to toggle the digital output and initialize th
63
63
> [!Tip]
64
64
> You can use the visual editor for an easier calibration. While the workflow is running, right-click on the [`Crop`] transform and select `Show Default Editor` from the context menu or click in the small button with ellipsis that appears when you select the `RegionOfInterest` property.
65
65
66
-
- Insert a [`Sum`] transform and select the `Val0` field from the output.
66
+
- Insert a [`Sum`] transform and select the `Val2` field from the output.
67
67
68
68
> [!Note]
69
-
> The [`Sum`] operator adds the value of all the pixels in the image together, across all the color channels. Assuming the default BGR format, the result of summing all the pixels in the `Blue` channel of the image will be stored in `Val0`. `Val1` and `Val2` would store the `Green` and `Red` values, respectively. If you are using an LED with a color other than blue, please select the output field accordingly.
69
+
> The [`Sum`] operator adds the value of all the pixels in the image together, across all the color channels. Assuming the default BGR format, the result of summing all the pixels in the `Red` channel of the image will be stored in `Val2`. `Val0` and `Val1` would store the `Blue` and `Green` values, respectively. If you are using an LED with a color other than red, please select the output field accordingly.
70
70
71
71
- Insert a [`GreaterThan`] transform.
72
72
- Insert a [`BitwiseNot`] transform.
@@ -92,6 +92,34 @@ In order to measure the round-trip time between the LED toggle:
92
92
93
93
_Given the measurements obtained in Exercise 2, what would you estimate is the **input** latency for video acquisition?_
94
94
95
+
## Closed-Loop Control
96
+
97
+
### Exercise 3: Introduction to pulse trains
98
+
99
+
In neuroscience, pulse trains are commonly used to deliver precisely timed sequences of electrical states (`LOW` and `HIGH`) to control external devices, such as cameras for synchronization or lasers for optogenetic stimulation. However, due to operating system limitations, generating pulse trains by setting [`DigitalOutputSet`] and [`DigitalOutputClear`] in software like Bonsai can be prone to timing jitter (though this approach is sufficient for the stimuli we have been working with). Fortunately the `Hogoblin` provides dedicated `Registers` that can be used to start or stop hardware-programmed pulse trains. We will use such pulse trains as our close-loop stimuli for the next few exercises.
100
+
101
+
- Connect a red LED module to digital output channel `GP15` on the `Hobgoblin`.
102
+
- Insert a [`KeyDown`] operator and set the `Filter` property to the key `A`.
103
+
- Insert a [`Parse`] operator and select [`StartPulseTrainPayload`] from the `Register` property dropdown menu. Set the `DigitalOutput` property to `GP15`.
104
+
- Set the `PulseCount` property to `0`, `PulsePeriod` to `50000` and `PulseWidth` to `5000`. These parameters correspond to a continuous 20Hz pulse train with 5 ms pulses.
105
+
- Insert a [`MulticastSubject`] operator and configure the `Name` property to `Hobgoblin Commands`.
106
+
- Insert another [`KeyDown`] operator and set the `Filter` property to the key `S`.
107
+
- Insert a [`Parse`] operator and select [`StopPulseTrainPayload`] from the `Register` property dropdown menu. Set the `StopPulseTrain` property to `GP15`.
108
+
- Run the workflow, use the `A` and `S` keys to start and stop the pulse train.
109
+
**What do you observe?**
110
+
111
+
To better understand what each parameter controls, try the following modifications. Reset the values to the parameters above after each step.
112
+
113
+
- Increase the `PulsePeriod` to `200000`. What is the frequency of this stimulation? How would you increase the frequency of the pulses to 40Hz?
114
+
- Increase the `PulseWidth` to `40000`. What do you observe?
115
+
- How would you deliver a 2 second pulse train? (Hint: Use `PulseCount`)
116
+
117
+
>[!NOTE]
118
+
> **Optional** Verify the pulse train by connecting the output to a digital input pin. How would you visualize the results using what you've learned?
119
+
120
+
>[!NOTE]
121
+
> **Optional** If you have cameras that support external hardware triggering, use what you have learned in this exercise to trigger frame capture.
0 commit comments