Skip to content

unicorn-bi/Unicorn-BCI-Core-Unity-Bandpower-Interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Unity Bandpower Interface

Unity Bandpower Interface is a seamless Unity plugin designed for developers working with Unicorn BCI Core devices. It enables real-time bandpower calculation, allowing effortless integration of bandpower-based BCI games and applications. With an intuitive setup and optimized performance, this interface empowers developers to create immersive, brain-driven experiences with ease.

Prerequisites
   Hardware Requirements
   Development
   Deployment
Prefabs
   Device
   Connection Dialog
   Logger
   SQ Bar
   Bandpower Bars
Quickstart Guide
Deploy to Windows
Deploy to macOS
Deploy to Android
Troubleshooting
   Android: No activity in the Android manifest
   macOs: libgtecble.dylib is blocked

Prerequisites

Hardware Requirements

  • Development: Windows or Mac computer
  • Deployment: Windows, Mac or Android device
  • Unicorn BCI Core
  • Bluetooth adapter supporting Bluetooth 5

Development

Windows

  • Windows 11
  • Unity
    2022.3.56f1
  • NET Framework
    .NET Framework 4.8
  • Visual Studio
    Microsoft Visual Studio 2022

Mac

  • macOS 14.5+
  • Unity
    2022.3.56f1
  • Xcode
    15.4
  • Command Line Tools for Xcode
    15.3
  • Visual Studio Code

Deployment

Windows

  • Windows 11
  • NET Framework
    .NET Framework 4.8

Mac

  • macOS 14.5+

Android

  • SDK Version 31+

Prefabs

Device

drawing

Settings

Type

  • Unicorn BCI Core - Adds Unicorn BCI Core devices to the available devices list
  • Simulator - Adds simulator devices to the available devices list
  • All Devices - Adds simulator and Unicorn BCI Core devices to the available devices list

It is possible to simulate good, floating or grounded EEG using the simulator devices. It is also possible to simulate alpha activity using the simulator devices.

Advanced Settings

drawing

Buffer Settings

It is possible to modify the buffersize and buffer overlap used for bandpower calculation. The output rate of calculated bandpower is affected by changing buffersize and buffer overlap.

$$ f_{bandpower} = {1 \over {(buffersize - bufferoverlap) \over samplingrate}} $$

Frequencyband Settings

The Unity Bandpower interface is estimating bandpower for various frequency bands. It is possible to modify the cutoff frequencies of each calculated frequency band in the advanced settings.

Bandpower Ratios

The Unity Bandpower interface calculates different bandpower ratios from the defined frequency bands. Available ratios are:

$$ PowerRatioIndex = {delta + theta \over alpha + beta} $$ $$ DeltaAlphaRatio = {delta \over alpha} $$ $$ ThetaAlphaRatio = {theta \over alpha} $$ $$ ThetaBetaRatio = {theta \over beta} $$ $$ ThetaBetaAlphaRatio = {theta \over alpha + beta} $$ $$ EngagementIndex = {beta \over theta + alpha} $$

EEG Data Settings

It is possible to set the output data rate of EEG in the EEG Data Settings. Data is buffered and output as [samples, channels] array to match the defined output data rate.

Events

The device prefab provides an event system as an interface to unity.

OnDevicesAvailable

The event called when devices are discovered. Available devices are provided as list of strings.
Event data: List<string>

OnDeviceStateChanged

The event called when device state changed. Th current device state is provided as 'State' enum.
Event data: List<State>

OnPipelineStateChanged

The event called when a signal rocessing pipeline state changed. The current state is provided as string.
Event data: string

OnRuntimeExceptionOccured

The event called when a runtime exception occured. The Exception is provided as 'Exception' object.
Event data: Exception

OnBandpowerAvailable

The event called when bandpower values for each channel individually are available. The frequency of the event is affected by the buffer settings and bandpower ranges set in the Advanced Settings. Data is provided as Dictionary with the frequency band name as Key (delta, theta, alpha, beta-low, beta-mid, beta-hig, gamma) and the bandpower values as double array as value.
Event data: Dictionary<string, double[]>

OnMeanBandpowerAvailable

The event called when averaged bandpower values over all channels are available. The frequency of the event is affected by the buffer settings and bandpower ranges set in the Advanced Settings. Data is provided as Dictionary with the frequency band name as Key (delta, theta, alpha, beta-low, beta-mid, beta-hig, gamma) and the bandpower value as double value.
Event data: Dictionary<string, double>

OnRatiosAvailable

The event called when bandpower ratios for each channel individually are available. The frequency of the event is affected by the buffer settings and bandpower ranges set in the Advanced Settings. Data is provided as Dictionary with the bandpower ratio name as Key (PowerRatioIndex, DeltaAlphaRatio, ThetaAlphaRatio, ThetaBetaRatio, ThetaBetaAlphaRatio, EngagementIndex) and the bandpower ratios as double array as value.
Event data: Dictionary<string, double[]>

OnMeanRatiosAvailable

The event called when averaged bandpower ratios over all channels are available. The frequency of the event is affected by the buffer settings and bandpower ranges set in the Advanced Settings. Data is provided as Dictionary with the bandpower ratio name as Key (PowerRatioIndex, DeltaAlphaRatio, ThetaAlphaRatio, ThetaBetaRatio, ThetaBetaAlphaRatio, EngagementIndex) and the bandpower ratio as double value.
Event data: Dictionary<string, double>

OnSignalQualityAvailable

The event called when new signal quality values are available.
Event data: List<ChannelStates>

OnBatteryLevelAvailable

The event called when battery level data is available.
Event data: float

OnDataLost

The event called when data is lost.
Event data: None

OnEEGDataAvailable

The event called when raw data is available
Event data: Dictionary<Rawdata>

Connection Dialog

The connection dialog prefab is a very simple pre defined connection dialog featuring a dropdown menu to select devices and a button to connect to a device or disconnect from a device. Drag this object into your scene ans a child object of the device object to automatically connect events or connect via the unity event system.

drawing

Logger

The logger prefab is a logging module writing messages provided by the device. Drag this object into your scene ans a child object of the device object to automatically connect events or connect via the unity event system.

drawing

SQ Bar

The sq bar prefab is a simple module visualizing the eeg signal quality. Drag this object into your scene ans a child object of the device object to automatically connect events or connect via the unity event system.

drawing

Bandpower Bars

The sq bar prefab is a simple module visualizing the averaged bandpower values. Drag this object into your scene ans a child object of the device object to automatically connect events or connect via the unity event system.

drawing

Quickstart Guide

  1. Open Unity Hub on your Windows or Mac

  2. Create a new Unity Project

drawing

  1. Import the Unity Bandpower Interface unity package.
    Click Assets -> Import Package -> Custom Package... -> load .unitypackage
    Ensure that all items are selected and click 'Import'.

drawing

  1. Open Assets -> Plugins -> gtec -> Bandpower -> Prefabs.

  2. Drag the device prefab into your scene.

  3. Drag the connection dialog prefab into your scene.

  4. Drag the logger prefab into your scene.

  5. Drag the sq bar prefab into your scene.

  6. Drag the bandpower bars prefab into your scene.

drawing

  1. Set the 'Type' setting is set to 'Unicorn BCI Core' or 'All Devices'

  2. Turn your Unicorn BCI Core device on

  3. Click the Play Button in the Unity Editor

drawing

  1. Wait until the device is discovered and click 'Connect'

  2. The bandpower bars should start moving and the signal quality bar should start changing colors

Deploy to Windows

  1. Select 'Windows' as Target Platform.
  2. Select target architecture
  3. Click 'Build'

drawing

Note:
An Windows device is required to build for Windows

Deploy to macOS

  1. Select 'macOS' as Target Platform.
  2. Select target architecture
  3. Click 'Build'

drawing

Note:
A mac device is required to build for macOS

Deploy to Android

  1. Select 'Android' as Target Platform.
  2. Select target architecture
  3. Click 'Build'

drawing

Note:
An Android device is required to build for Android

Troubleshooting

Android: No activity in the Android manifest

The Android manifest might look different for different Unity versions. It's recommended to use Unity 2022.3.56f1. If you want to go with your Unity version you can try to create a new Android manifest.

  1. Delete the installed Android manifest Assets/Plugins/Android/AndroidManifest.xml
  2. Create a new manifest by clicking Edit -> Project Settings -> Player -> Publishing Settings -> Custom Main Manifest
  3. A new Android manifest should have been created at Assets/Plugins/Android/AndroidManifest.xml.
<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application>
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:theme="@style/UnityThemeSelector"
				  android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application>
</manifest>
  1. Do not modify the <application> section. Add the required permissions to the Adnroid manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

	<uses-permission android:name="android.permission.BLUETOOTH" />
	<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
	<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
	<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />s

	<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>
	<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
	
    <application>
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:theme="@style/UnityThemeSelector"
				  android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application>
</manifest>

macOs: libgtecble.dylib is blocked

The library interacting with the device might be blocked on macOs, even if the library is signed.

drawing

To allow the library being used click Settings -> Privacy & Security -> Allow Anyway. It should be possible to load libgtecble.dylib in uUnity now.

drawing

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors