Git Product home page Git Product logo

brainframework's Introduction

BrainFramework

Unity Plugin for the Emotiv EPOC v2 API

Setup with Emotiv

  1. Create an App to get clientId and clientSecret: https://emotiv.gitbook.io/cortex-api/#create-a-cortex-app Create
  2. Login and connect your Headset with the EMOTIV App. Connect

Setup in Unity

  1. Install Package (export/BrainFramework.unitypackage) to your Unity Scene
  2. Add Prefab "BrainFramework" to your Scene or use Example Scene
  3. Fill in the settings in the BrainFramework Inspector
    Inspector
  4. On the first run you should get a notification inside the EMOTIV App.
    Approve your App and restart your Unity script.

Accept

A simple example to control a ball

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BallController : MonoBehaviour
{
    public GameObject BrainFramework;
    private BrainFramework EPOC;

    private Rigidbody Ball;

    void Start()
    {

        // ---------- BRAIN FRAMEWORK-----------
        // 1. Connect to EPOC Script
        EPOC = BrainFramework.GetComponent<BrainFramework>();

        // 2. Subscribe to Events
        EPOC.On("READY", Ready);
        EPOC.On("STREAM", Stream);
        // ------------------------------------

        // Prepare Ball
        Ball = GetComponent<Rigidbody>();
    }

    // EPOC IS READY
    void Ready()
    {
        Debug.Log("EPOC Ready!");


        // START STREAM
        EPOC.StartStream();


        // ------ TRAINING -------
        // It is best to place this command on a key, 
        // but make sure to call it after the "READY" event:

        // EPOC.StartTraining("neutral");

        // The next 8 seconds will then be recorded and saved into the profile

        // These are the parameters you could train:
        //"neutral"
        //"push"
        //"pull"
        //"lift"
        //"drop"
        //"left"
        //"right"
        //"rotateLeft"
        //"rotateRight"
        //"rotateClockwise"
        //"rotateCounterClockwise"
        //"rotateForwards"
        //"rotateReverse"
        //"disappear"

        // You could also listen to this events:
        // trainingStarted
        // trainingSucceeded
        // trainingCompleted

        // At the end of a training session you can save your progress to the profile
        // Call this after an "trainingCompleted" event or manually. 
        // EPOC.SaveProfile();

    }

    // DATA STREAM
    void Stream()
    {
        Debug.Log($"command: { EPOC.BRAIN.command } | eyeAction: { EPOC.BRAIN.eyeAction } | upperFaceAction: { EPOC.BRAIN.upperFaceAction } | lowerFaceAction: { EPOC.BRAIN.lowerFaceAction }");
    }


    // Update is called once per frame
    void FixedUpdate()
    {
        // BALL MOVEMENT EXAMPLE
        Vector3 movement = new Vector3(0.0f, 0.0f, 0.0f);

        if (EPOC.BRAIN.command == "push")
        {
            movement = new Vector3(0.0f, 0.0f, 1.0f);
        }
        if (EPOC.BRAIN.command == "pull")
        {
            movement = new Vector3(0.0f, 0.0f, -1.0f);
        }
        if (EPOC.BRAIN.command == "left")
        {
            movement = new Vector3(-1.0f, 0.0f, 0.0f);
        }
        if (EPOC.BRAIN.command == "right")
        {
            movement = new Vector3(1.0f, 0.0f, 0.0f);
        }


        Ball.AddForce(movement);
    }
}

brainframework's People

Contributors

brandlmax avatar

Stargazers

 avatar  avatar  avatar

Forkers

kennymarko

brainframework's Issues

Webserver Closed:An exception has occurred during an OnMessage event.

Hello,
I am trying to use your example to control the ball. After "EPOC Ready" and "stream ready", This error popped up.

Error log:
Webserver Closed: An exception has occurred during an OnMessage event.
BrainFramework:_close(Object, CloseEventArgs) (at Assets/BrainFramework/Framework/BrainFramework.cs:255)
WebSocketSharp.Ext:Emit(EventHandler1, Object, CloseEventArgs) (at Assets/BrainFramework/websocket-sharp/Ext.cs:1080) WebSocketSharp.WebSocket:close(CloseEventArgs, Boolean, Boolean) (at Assets/BrainFramework/websocket-sharp/WebSocket.cs:676) WebSocketSharp.WebSocket:processException(Exception, String) (at Assets/BrainFramework/websocket-sharp/WebSocket.cs:1000) WebSocketSharp.<>c__DisplayClass137_0:<startReceiving>b__1(WebSocketFrame) (at Assets/BrainFramework/websocket-sharp/WebSocket.cs:1444) WebSocketSharp.<>c__DisplayClass76_0:<ReadAsync>b__0(Byte[]) (at Assets/BrainFramework/websocket-sharp/WebSocketFrame.cs:570) WebSocketSharp.<>c__DisplayClass61_0:<ReadBytesAsync>b__0(IAsyncResult) (at Assets/BrainFramework/websocket-sharp/Ext.cs:730) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(Int32)
Mono.Net.Security.d__58:MoveNext()
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(AsyncProtocolResult) Mono.Net.Security.<StartOperation>d__23:MoveNext() System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult() Mono.Net.Security.<ProcessOperation>d__24:MoveNext() System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(Nullable1) Mono.Net.Security.<InnerRead>d__25:MoveNext() System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(Int32)
Mono.Net.Security.d__66:MoveNext()
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.