Skip to content

Commit 3ce2594

Browse files
committed
Add 3rd exercise introduction to pulse trains
1 parent dad5f9c commit 3ce2594

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

tutorials/hobgoblin-closeloop.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Close-Loop Systems
22

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.
44

55
## Prerequisites
66

@@ -50,7 +50,7 @@ Lastly, we will use this sequence to toggle the digital output and initialize th
5050
### Exercise 2: Measuring video acquisition latency
5151

5252
![Hobgoblin LED](../images/hobgoblin-acquisition-led.svg){width=400px}
53-
- Connect a blue LED module to digital output channel `GP15` on the `Hobgoblin`.
53+
- Connect a red LED module to digital output channel `GP15` on the `Hobgoblin`.
5454

5555
:::workflow
5656
![Hobgoblin Closed-Loop Latency Video](../workflows/hobgoblin-closeloop-latency-video.bonsai)
@@ -63,10 +63,10 @@ Lastly, we will use this sequence to toggle the digital output and initialize th
6363
> [!Tip]
6464
> 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.
6565
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.
6767

6868
> [!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.
7070
7171
- Insert a [`GreaterThan`] transform.
7272
- Insert a [`BitwiseNot`] transform.
@@ -92,6 +92,34 @@ In order to measure the round-trip time between the LED toggle:
9292

9393
_Given the measurements obtained in Exercise 2, what would you estimate is the **input** latency for video acquisition?_
9494

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.
122+
95123
<!--Reference Style Links -->
96124
[`BitwiseNot`]: xref:Bonsai.Expressions.BitwiseNotBuilder
97125
[`CreateMessage`]: xref:Harp.Hobgoblin.CreateMessage
@@ -102,8 +130,8 @@ _Given the measurements obtained in Exercise 2, what would you estimate is the *
102130
[`DigitalOutputTogglePayload`]: xref:Harp.Hobgoblin.CreateDigitalOutputTogglePayload
103131
[`DistinctUntilChanged`]: xref:Bonsai.Reactive.DistinctUntilChanged
104132
<!-- [`DeviceDataWriter`]: xref:Harp.Hobgoblin.DeviceDataWriter -->
105-
<!-- [`DigitalOutputSet`]: xref:Harp.Hobgoblin.DigitalOutputSet -->
106-
<!-- [`DigitalOutputClear`]: xref:Harp.Hobgoblin.DigitalOutputClear -->
133+
[`DigitalOutputSet`]: xref:Harp.Hobgoblin.DigitalOutputSet
134+
[`DigitalOutputClear`]: xref:Harp.Hobgoblin.DigitalOutputClear
107135
<!-- [`DigitalOutputClearPayload`]: xref:Harp.Hobgoblin.CreateDigitalOutputSetPayload -->
108136
<!-- [`DigitalOutputSetPayload`]: xref:Harp.Hobgoblin.CreateDigitalOutputClearPayload -->
109137
[`GreaterThan`]: xref:Bonsai.Expressions.GreaterThanBuilder

0 commit comments

Comments
 (0)