脳波でテレビの電源を消す(NextMind)

NextMindのBMI機器を使って、LGのwebOS TVを操作する

前回は↓

filot-nextd2.hatenablog.com

 

環境

  • Unity(2020.2.1f1)
  • Node-Red(1.2.7)
  • Node.js(14.15.4)

Node-Redの環境を以前別のPC上に構築していたので、

今回はそちらからGETする。

 

BMI機器 -> Unity -> Node-Red -> TV

といった感じ。

 

 

※Unity、Node-redのインストール方法は割愛

 

Unity側

  1. Developers resources | NextMind Dev Kit からダウンロードできるNextMindSDK_Full.unitypackageをインポートする

  2. Hierarchy ウィンドウ上で右クリック->NextMind->NeuroManagerを選択
  3. NeuroManagerのInspectorウィンドウで、NeuroManager->Scene ConfigrationのSimulate device、Simulate focusのチェックを外す
  4. NextMindSDKフォルダ内の、ConnectedDeviceStatus PrefabをHierarchy ウィンドウ上にドラッグ
  5. Hierarchy ウィンドウ上で右クリック->3D Object->Sphereを選択
  6. SphereにNeuroTagコンポーネントを設定
  7. 以下のFixを選択すると、Materialに Neuro Tag Material_unlitが設定される

    f:id:filot_nextd2:20210115175126p:plain

  8. NextMindSDKフォルダ内の、TriangleFeedback PrefabをSphereの子階層にドラッグ
  9. http request用に、Hierarchy ウィンドウ上でGameObjectを作成(名前をHttpRequestとかにする)
  10. 作成したGameObjectに、HttpRequest用のscriptをアタッチする
    using System.Collections;
    using UnityEngine;
    using UnityEngine.Networking;
    
    public class HttpRequest : MonoBehaviour
    {
        private const string URL = "http://xxx.xxx.xxx.xxx:xxxx/turnoff";
    
        public void OnTriggerd()
        {
            StartCoroutine("OnSend", URL);
        }
    
        IEnumerator OnSend(string url)
        {
            UnityWebRequest webRequest = UnityWebRequest.Get(url);
            yield return webRequest.SendWebRequest();
    
            if (webRequest.isNetworkError)
            {
                Debug.Log(webRequest.error);
            }
            else
            {
                Debug.Log(webRequest.downloadHandler.text);
            }
        }
    } 
  11. SphereのNeuroタグコンポーネント->Tracking Events->Ontriggerd()に、HttpRequest.Ontriggerdを設定
  12. Hierarchy上の各オブジェクトのTransformを変更し、以下のように見えやすくする

    f:id:filot_nextd2:20210115182025p:plain

Node-Red側

  1.  node-red-contrib-lgtvパレットをインストール
  2. 追加されたlgtvパレットからcontrolノードを追加
  3. controlノードのプロパティ「Host」に、使用するTVのIPアドレスを入力

    f:id:filot_nextd2:20210115193321p:plain



  4. connectボタンをクリックすると、テレビに接続確認画面が表示されるので、はいを選択
  5. Node-redの画面で追加->完了ボタンをクリック
  6. templateノードを設定

    f:id:filot_nextd2:20210115192506p:plain
    今回はテレビの電源をOFFする

  7. http in ノードを追加する

    f:id:filot_nextd2:20210115193007p:plain

  8. あとはノードを並べて繋げてf:id:filot_nextd2:20210115193116p:plain
  9. できあがり

さて、さっそく試す

f:id:filot_nextd2:20210115200233p:plain

これが

f:id:filot_nextd2:20210115200316p:plain

こうなる。

テレビの電源消しただけだけど、脳で操る感覚、凄く楽しい。