Skip to content
7 changes: 7 additions & 0 deletions source/Contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ We look forward to seeing your contributions and helping to improve **PhysioLab\
Run from source
*********************

.. raw :: html

<p align="center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/-r-ccR6MEIg?si=soU8sm7zDAn3j4ho" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</p>


To get started with PhysioLab\ :sup:`XR` development, you will want to run the app from source. The following section will
guide you through the process of running the app from source.

Expand Down
226 changes: 41 additions & 185 deletions source/WearableSensingDSI24.rst
Original file line number Diff line number Diff line change
@@ -1,228 +1,84 @@
.. _Wearable Sensing Stream:

##################################################
############################################
Stream data from Wearable Sensing's DSI-24
##################################################
############################################

This tutorial will demonstrate how to connect the DSI-24 to your computer and PhysioLab\ :sup:`XR`.
The `DSI-24 <https://wearablesensing.com/dsi-24/>`_ is `Wearable Sensing's <https://wearablesensing.com/>`_ dry electrode EEG system.
This tutorial will be primarily focused on the Windows platform
This tutorial will be primarily focused on the Windows platform.
This tutorial currently only works with the latest stable developmental version of PhysioLabXR. If you would like to know how to download the latest stable version of PhysioLabXR, you can check that out
`Here <https://physiolabxrdocs.readthedocs.io/en/latest/Contribute.html#run-from-source>`_.

1. Turn on the `DSI-24 <https://wearablesensing.com/dsi-24/>`_.

2. Go to Device Manager.
.. raw :: html

3. Expand the Bluetooth section.
<p align="center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/ExMdOJoQMc4?si=gM_J_3OZhBbGYdTI" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</p>

4. Disable Intel(R) Wireless Bluetooth(R) or whatever is your default Bluetooth driver.
If you would like to be more hands on and work with the data from DSI-24 as well as implement other functions from the DSI-24 you can check out `this <Wearable Sensing Stream Old>`_.

.. figure:: media/WearableSensing_BluetoothDisable.gif
:width: 800
:align: center
:alt: Turning off native Bluetooth
1. Ensure you have the batteries installed the DIS-24.

5. Plug in the Bluetooth adapter provided by `Wearable Sensing's <https://wearablesensing.com/>`_.
2. Turn on the `DSI-24 <https://wearablesensing.com/dsi-24/>`_ by double clicking on the power button.

6. Go to Bluetooth settings.
3. Go to Device Manager on your computer.

7. Scroll down to device settings.
4. Expand the Bluetooth section.

8. Turn the Bluetooth devices discovery setting from Default to Advanced. (If you are on Windows 10, this step can be ignored).
5. Disable Intel(R) Wireless Bluetooth(R) or your default Bluetooth driver (You can reenable at anytime, however if left enabled the DSI-24 will not work correctly).

5. Plug in the Bluetooth adapter provided by Wearable Sensing
6. Plug in the Bluetooth adapter provided by `Wearable Sensing's <https://wearablesensing.com/>`_ to any USB port.

6. Go to Bluetooth settings
7. Go to Bluetooth settings.

7. Scroll down to device settings
8. Scroll down to device settings.

8. Turn the Bluetooth devices discovery setting from Default to Advanced. (If you are on Windows 10, this step can be ignored)
9. Turn the Bluetooth devices discovery setting from Default to Advanced. (If you are on Windows 10, this step can be ignored).

.. figure:: media/WearableSensing_BluetoothDeviceDiscovery.gif
:width: 800
:align: center
:alt: Turning on Bluetooth Device Discovery
10. Plug in the Bluetooth adapter provided by Wearable Sensing.

11. Go to Bluetooth settings.

9. Connect the `DSI-24 <https://wearablesensing.com/dsi-24/>`_ to your device as if you would connect a mouse or headphones. (Should be named DSI24-{*serial number*}).
12. Scroll down to device settings.

10. Go back to Bluetooth Settings.
13. Turn the Bluetooth devices discovery setting from Default to Advanced. (If you are on Windows 10, this step can be ignored).z

11. Scroll down to more Related Settings.
14. Connect the `DSI-24 <https://wearablesensing.com/dsi-24/>`_ to your device as if you would connect a mouse or headphones. (Should be named DSI24-{*serial number*}).

12. Click on more Bluetooth Settings.
15. Go back to Bluetooth Settings.

13. Click on COM Ports and make note of the COM port number that has the name: DSI24-{*serial number*} "Bluetooth Serial Port".
16. Scroll down to more Related Settings.

14. Connect the DSI-24 to your device as if you would connect a mouse or headphones. (Should be named DSI24-{*serial number*})
17. Click on more Bluetooth Settings.

15. Go back to Bluetooth Settings
18. Click on COM Ports and make note of the COM port number that has the name: DSI24-{*serial number*} "Bluetooth Serial Port".

16. Scroll down to more Related Settings
19. Connect the DSI-24 to your device as if you would connect a mouse or headphones. (Should be named DSI24-{*serial number*}). It may state that the device isn't connected, this is *normal*.

17. Click on more Bluetooth Settings
20. Go back to Bluetooth Settings.

18. Click on COM Ports and make note of the COM port number that has the name: DSI24-{*serial number*} "Bluetooth Serial Port"
21. Scroll down to more Related Settings.

.. figure:: media/WearableSensing_BluetoothCOMPort.gif
:width: 800
:align: center
:alt: Finding the COM Port
22. Click on more Bluetooth Settings.

19. Open PhysioLab\ :sup:`XR`.
23. Click on COM Ports and make note of the COM port number that has the name: DSI24-{*serial number*} "Bluetooth Serial Port".

20. Go to `Script Tab <Scripting.html>`_.
24. Now we can open PhysioLabXR.

21. Click *Locate* and find the WearableSensingScript.py.

The script can be downloaded from `WearableSensingScript.py <https://github.com/LommyTea/WearableSensingXPhysioLabXR/blob/main/WearableSensingScript.py>`_.

.. code-block:: python

from pylsl import local_clock
from physiolabxr.scripting.RenaScript import RenaScript
from physiolabxr.thirdparty.WearableSensing.DSI_py3 import *
import numpy as np
import sys
from physiolabxr.utils.buffers import DataBuffer
25. In the Stream input line, you can type out "DSI24". This should open up the DSI-24 interface where the EEG data will be displayed as well an options window
where you can input the COM Port as well as whether or not you would like to test the impedance of the electrodes to make sure they are the correct fit. If the options window
does not show you can click on the far right button to open it.

#Creating a data buffer with the DataBuffer class
data_buffer = DataBuffer()
26. Once you have configured your options all you have to do is press the green play button on the bottom of the main window. By right clicking on the graph in the main window you can decide on how you want the data to be displayed.
There are also filters you can choose to add to the data by clicking on the blue button that is the second button from the bottom.

is_first_time = True
time_offset = 0 # time offset for the first packet to the local_clock()
@SampleCallback
def ExampleSampleCallback_Signals(headsetPtr, packetTime, userData):
#This is the function that will be called every time a new packet is received
global data_buffer
global is_first_time
global time_offset

#Grab the headset by using a pointer
h = Headset(headsetPtr)
#Get the signal from each channel and format it so that it can be created into an array
new_data = np.array(['%+08.2f' % (ch.GetSignal()) for ch in h.Channels()])
#Reshapes the array into a 24x1 array so that it can be inputted into the data_buffer
new_data = new_data.reshape(24,1)
#Rearrange new_data to fit with desired output format
new_data = new_data[[9, 10, 3, 2, 4, 17, 18, 7, 1, 5, 11, 22, 12, 21, 8, 0, 6, 13, 14, 20, 23, 19, 15, 16], :]
#Get the time of the packet as a temporary solution to timestamps
if is_first_time:
time_offset = local_clock() - float(packetTime)
is_first_time = False

t = [float(packetTime) + time_offset]
if new_data.shape[1] != len(t):
print('Data and timestamp mismatch')
print(new_data.shape)
print(len(t))

#Create a dictionary with the stream name, data, and timestamps
new_data_dict = {
'stream_name': 'DSI-24',
'frames': new_data,
'timestamps': t
}
#Update the data buffer with the new data
data_buffer.update_buffer(new_data_dict)
class DSI24(RenaScript):
def __init__(self, *args, **kwargs):
"""
Please do not edit this function
"""
super().__init__(*args, **kwargs)

def init(self, arg = ''):
#Create a headset object
self.headset = Headset()
#Set the message callback to ExampleMessageCallback
self.headset.SetMessageCallback(ExampleMessageCallback)
#Retrieves the command line arguments
args = getattr(sys, 'argv', [''])
#Set the default port to the first command line argument based on the parameter provided by user
default_port = self.params['COM Port']
#Connect the headset
self.headset.Connect(default_port)
#Start the data acquisition based on the parameter provided by user
if arg.lower().startswith('imp'):
#Currently not used
self.headset.SetSampleCallback(ExampleSampleCallback_Impedances, 0)
self.headset.StartImpedanceDriver()
else:
#Set the sample callback to ExampleSampleCallback_Signals
self.headset.SetSampleCallback(ExampleSampleCallback_Signals, 0)
if len(arg.strip()): self.headset.SetDefaultReference(arg, True)
#Start the data acquisition
self.headset.StartBackgroundAcquisition()


def loop(self):
#Called every loop based on the user's chosen frequency
global data_buffer
#If the data buffer has data, then set the output to the data buffer
if len(data_buffer.keys()) > 0:
self.set_output(stream_name = 'DSI-24', data = data_buffer.get_data('DSI-24'), timestamp = data_buffer.get_timestamps('DSI-24'))
#Clear the data buffer
data_buffer.clear_stream_buffer_data('DSI-24')

def cleanup(self):
#Called when the script is stopped
global data_buffer
global is_first_time
global time_offset
#Stop the data acquisition
self.headset.StopBackgroundAcquisition()
#Disconnect the headset
time_offset = 0
is_first_time = True
self.headset.Disconnect()
data_buffer.clear_buffer()

22. *Add* an output and name it "DSI-24".

23. Change the number of channels to 24.

24. *Add* a **Parameter Widget** to the script by clicking on the + sign.

25. Change the name of the parameter to *COM Port* and switch the type of input to "str" so that we can input the COM port.

26. Input the name of the COM port that you noted earlier. This will allow for PhysioLabXR to connect to the DSI-24.

27. Press *Run*.

.. figure:: media/WearableSensing_Scripting.gif
:width: 800
:align: center
:alt: Running in PhysioLabXR

Now the data stream is available as an LSL stream named DSI-24.

28. To view the data stream, go to the **Stream Tab**.

29. Input *DSI-24* in the Add Stream box and press the *Add Widget* button.

30. Click the *Start Button* to start data stream.

It is recommended that you change some of the settings for your stream. You can follow the steps `here <https://physiolabxrdocs.readthedocs.io/en/latest/Visualization.html#line-chart>`_ to change the settings.
For this tutorial, we added a Butterworth High Pass Filter with a cutoff frequency of 0.01 Hz, Nominal Sampling Rate of 250 and Group Channels Constant Offset to 50 by first pressing on the Gear icon and then on the top Default Group name.

.. figure:: media/WearableSensing_Stream.gif
:width: 800
:align: center
:alt: Viewing the stream on the Stream Tab

31. To see the FFT of the signals from the `DSI-24 <https://wearablesensing.com/dsi-24/>`_ right-click on the stream and select *FFT*.

.. figure:: media/WearableSensing_FFT.gif
:width: 800
:align: center
:alt: Showing FFT of data stream
**Note** Occasionally it may say that it cannot connect to the port, you should retry to connect by stopping the program with the red button on the bottom and rerunning it. If that does not work,
we recommend you reconnect the device by disconnecting it in the settings and reconnecting.

Now that you have the data streaming: check out these docs:

- :ref: `How to save the data <Recording>`_
- :ref: `How to run a classification model on the data <tutorials/BuildMultiModalERPClassifier>`_
- :ref: `Need help connecting the DSI-24 with Varjo's XR-3? <WearableSensingxVario>`_




Loading