void Update()
    {
        if (Input.GetKeyDown(KEY_STOP))
        {
            serialHandler.Write("0");
            Debug.Log("Stop!");
        }
        if (Input.GetKeyDown(KEY_DETACH))
        {
            serialHandler.Write("9");
            Debug.Log("Detach!");
        }

        if (Input.GetKeyDown(KEY_NORMAL))
        {
            serialHandler.Write("2");
            Debug.Log("Normal!");
        }
        if (Input.GetKeyUp(KEY_NORMAL))
        {
            serialHandler.Write("0");
            Debug.Log("Stop!");
        }
        if (Input.GetKeyDown(KEY_SHOT))
        {
            serialHandler.Write("3");
            Debug.Log("Shot!");
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime = 15;

        //TestID, TrialIDの更新
        ExperimentID.addNumberOfTestID();
        TestID = ExperimentID.getTestID();
        if (TestID > 2)
        {
            ExperimentID.addNumberOfTrialID();
        }

        //準備する香料の表示、鼻部皮膚温度制御の信号をArduinoへ送信
        string Condition = ExperimentID.getCondition();

        if (Condition == "A" || Condition == "B")
        {
            serialHandler.Write("r");
            Debug.Log("Room Temperature command!");  // ログを出力
        }
        else if (Condition == "C")
        {
            serialHandler.Write("h");
            Debug.Log("Hot command!");  // ログを出力
        }

        int AromaID = ExperimentID.getAromaID();

        Debug.Log("Aroma ID : " + AromaID.ToString());
    }
Example #3
0
    // Start is called before the first frame update
    void Start()
    {
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime = 15;

        TestID = ExperimentID.getTestID();

        //準備する香料の表示、鼻部皮膚温度制御の信号をArduinoへ送信
        string Condition = ExperimentID.getCondition();

        if (Condition == "A")
        {
            serialHandler.Write("h");
            Debug.Log("Hot command!");  // ログを出力
        }
        else if (Condition == "B" || Condition == "C")
        {
            serialHandler.Write("c");
            Debug.Log("Cool command!");  // ログを出力
        }

        int AromaID = ExperimentID.getAromaID();

        Debug.Log("Aroma ID : " + AromaID.ToString());
    }
    // Start is called before the first frame update
    void Start()
    {
        //serialHandler.GetComponent<SerialHandler>().enabled = true;
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime     = 15;
        GoFromArduino = false;

        //TestIDの更新
        ExperimentID.addNumberOfTestID();
        TestID  = ExperimentID.getTestID();
        TrialID = ExperimentID.getTrialID();

        //36試行まで終わったら、一度休憩
        if (TrialID == 36)
        {
            //ペルチェ素子にかかる電圧を0にする
            serialHandler.Write("o");
            Debug.Log("Off Command!");
            Debug.Log("Scene Change");
            //serialHandler.GetComponent<SerialHandler>().enabled = false;
            SceneManager.LoadScene("Intermission_Scene");
        }
        //72試行で実験終了
        else if (TrialID == 72)
        {
            //ペルチェ素子にかかる電圧を0にする
            serialHandler.Write("o");
            Debug.Log("Off Command!");
            Debug.Log("Scene Change");
            //serialHandler.GetComponent<SerialHandler>().enabled = false;
            SceneManager.LoadScene("End_Scene");
        }
        else
        {
            if (TestID > 2)
            {
                ExperimentID.addNumberOfTrialID();
            }
            TrialID = ExperimentID.getTrialID();
            //準備する香料の表示、鼻部皮膚温度制御の信号をArduinoへ送信
            string Condition = ExperimentID.getCondition();
            Debug.Log(Condition);
            if (Condition == "A" || Condition == "B")
            {
                serialHandler.Write("r");
                Debug.Log("Room Temperature command!");  // ログを出力
            }
            else if (Condition == "C")
            {
                serialHandler.Write("h");
                Debug.Log("Hot command!");  // ログを出力
            }

            int AromaID = ExperimentID.getAromaID();
            Debug.Log("Aroma ID : " + AromaID.ToString());
        }
    }
Example #5
0
    // Start is called before the first frame update
    void Start()
    {
        Transform myTransform = this.transform;

        nowpos = startpos;
        myTransform.LookAt(nowpos + dif);
        serialHandler.Write("1");
    }
Example #6
0
    // Update is called once per frame
    void Update()
    {
        if (mode == 0 && OVRInput.GetDown(OVRInput.RawButton.A))
        {
            // カウントのみを表示
            ExplainText.enabled = false;
            CountText.enabled   = true;
            EndText.enabled     = false;
            mode         = 1; //カウント表示モード
            mode_changed = true;
        }

        else if (mode == 1)
        {
            if (mode_changed == true)
            {
                // 匂い噴出を開始
                serialHandler.Write(PumpID.ToString());
                mode_changed = false;
            }

            // カウントダウンを表示
            totalTime     -= Time.deltaTime;
            sec            = (int)totalTime;
            CountText.text = sec.ToString();

            if (totalTime <= 0)
            {
                // 終わりのテキストのみを表示
                ExplainText.enabled = false;
                CountText.enabled   = false;
                EndText.enabled     = true;
                mode         = 2; //終わりのテキスト表示モード
                mode_changed = true;
                totalTime    = 5;
            }
        }

        else if (mode == 2)
        {
            if (mode_changed == true)
            {
                // 空気を噴出して、前の匂いを飛ばす  様子見
                //serialHandler.Write("4");
                serialHandler.Write("0"); // すべてのエアポンプをOFFにする
                serialHandler.Write("o"); // 鼻部皮膚温度制御を止める
                mode_changed = false;
            }

            totalTime -= Time.deltaTime;
            // 5秒経ったら、待機シーンに遷移
            if (totalTime <= 0)
            {
                //serialHandler.Write("0"); // すべてのエアポンプをOFFにする
                SceneManager.LoadScene("Rating_Scene");
            }
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        //serialHandler.GetComponent<SerialHandler>().enabled = true;

        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime     = 15;
        GoFromArduino = false;

        // 実験の順番、現在の試行番号・状態等を取得
        // 読み込みたいCSVファイルのパスを指定して開く
        StreamReader sr = new StreamReader(Application.dataPath + "/Data/" + "Experiment1_order.csv");
        // CSVファイルの一行を読み込む
        string orderLine = sr.ReadLine();

        // 読み込んだ一行をカンマ毎に分けて配列に格納する
        string[] orderString = orderLine.Split(',');
        // 各試行の香料のIDと条件(A, B, C)をリストに格納
        AromaCondition.AddRange(orderString);
        // 試行が練習なのか本番なのか、試行番号を読み込み
        string trialStateLine = sr.ReadLine();

        string[] trialState = trialStateLine.Split(',');
        Test_or_Trial = trialState[0];
        TrialID       = int.Parse(trialState[1]);

        //準備する香料の表示、鼻部皮膚温度制御の信号をArduinoへ送信
        if (Test_or_Trial == "Test")
        {
            Debug.Log(Test_or_Trial);
            int AromaID = TrialID;
            Debug.Log("Aroma ID : " + AromaID.ToString());
        }
        else
        {
            string line      = AromaCondition[TrialID - 1];
            int    AromaID   = int.Parse(line.Substring(0, line.Length - 1));
            string Condition = line.Substring(line.Length - 1);

            Debug.Log(Condition);
            if (Condition == "A")
            {
                serialHandler.Write("h");
                Debug.Log("Hot command!");  // ログを出力
            }
            else if (Condition == "B" || Condition == "C")
            {
                serialHandler.Write("c");
                Debug.Log("Cool command!");  // ログを出力
            }

            Debug.Log("Aroma ID : " + AromaID.ToString());
        }
    }
Example #8
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.A))
     {
         serialHandler.Write("0");
     }
     if (Input.GetKeyDown(KeyCode.S))
     {
         serialHandler.Write("1");
     }
 }
Example #9
0
    // Start is called before the first frame update
    void Start()
    {
        //serialHandler.GetComponent<SerialHandler>().enabled = true;
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime      = 15;
        totalTimeLimit = 30; //30秒後には必ず次のシーンに遷移する
        GoFromArduino  = false;

        // 実験の順番、現在の試行番号・状態等を取得
        // 読み込みたいCSVファイルのパスを指定して開く
        StreamReader sr = new StreamReader(Application.dataPath + "/Data/" + "Experiment3_order.csv");
        // CSVファイルの一行を読み込む
        string orderLine = sr.ReadLine();

        // 読み込んだ一行をカンマ毎に分けて配列に格納する
        string[] orderString = orderLine.Split(',');
        // 各試行の香料のIDと条件(R, H, C)をリストに格納
        AromaCondition.AddRange(orderString);
        // 試行が練習なのか本番なのか、試行番号を読み込み
        string trialStateLine = sr.ReadLine();

        string[] trialState = trialStateLine.Split(',');
        Test_or_Trial = trialState[0];
        TrialID       = int.Parse(trialState[1]);
        sr.Close();

        string line            = AromaCondition[TrialID - 1];
        int    AromaID         = int.Parse(line.Substring(0, line.Length - 1)) / 100;
        int    VisualStimuliID = int.Parse(line.Substring(0, line.Length - 1)) % 100;
        string Condition       = line.Substring(line.Length - 1);

        Debug.Log(Condition);
        if (Condition == "R")
        {
            serialHandler.Write("r");
            Debug.Log("Room Temperature command!");  // ログを出力
        }
        else if (Condition == "H")
        {
            serialHandler.Write("h");
            Debug.Log("Hot command!");  // ログを出力
        }
        else if (Condition == "C")
        {
            serialHandler.Write("c");
            Debug.Log("Cool command!");  // ログを出力
        }

        Debug.Log("Aroma ID : " + AromaID.ToString() + "  VisualID : " + VisualStimuliID.ToString());
    }
Example #10
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.A))
     {
         serialHandler.Write("0");
         Debug.Log("Light Off!");
     }
     if (Input.GetKeyDown(KeyCode.S))
     {
         serialHandler.Write("1");
         Debug.Log("Light On!");
     }
 }
    void Update()
    {
        if (targetScript.weekHit)
        {
            targetScript.weekHit = false;
            Debug.Log("week");
            serialHandler.Write("a");
        }
        if (targetScript.strongHit)
        {
            targetScript.strongHit = false;
            Debug.Log("strong");
            serialHandler.Write("b");
        }
        //文字列を送信するなら例えばココ
        if (targetScript.jklPress[0])
        {
            targetScript.jklPress[0] = false;
            if (targetScript.jklToggle[0])
            {
                //LED ON
                serialHandler.Write("a");
            }
            else
            {
                //LED OFF
                serialHandler.Write("b");
            }
        }
        if (targetScript.jklPress[1])
        {
            targetScript.jklPress[1] = false;
            if (targetScript.jklToggle[1])
            {
                //LED ON
                serialHandler.Write("c");
            }
            else
            {
                //LED OFF
                serialHandler.Write("d");
            }
        }
        if (targetScript.jklPress[2])
        {
            targetScript.jklPress[2] = false;
            if (targetScript.jklToggle[2])
            {
                //LED ON
                serialHandler.Write("e");
            }
            else
            {
                //LED OFF
                serialHandler.Write("f");
            }
        }

        //serialHandler.Write("hogehoge");
    }
Example #12
0
    void Update()
    {
        //姿勢初期化フラグ
        init = FaceController.GetComponent <FaceController_gyro_D_rotation>().init_flag;

        //Rキーで姿勢を初期化する
        if (Input.GetKey(KeyCode.R))
        {
            serialHandler.Write("0");   //文字列を送信
        }
        //Pキーでpitch姿勢のみ初期化する
        if (Input.GetKey(KeyCode.P) || init == true)
        {
            serialHandler.Write("1");   //文字列を送信
        }
    }
Example #13
0
    // PWMの値を送信(引数で値を受け取る) 
    public void SendPWMData(float pwm)
    {
        // PWMは0~255の間
        int sendPWM = (int)Mathf.Clamp(pwm, 0, 255);

        serial.Write("s" + sendPWM.ToString() + "e");
    }
Example #14
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log("test");
        //serialHandler.Write("hogehoge");
        //_rotation0 = _rigidbody.rotation.y;

        /*_rotation0 = transform.localEulerAngles.y;
         * vel = _rotation1 - _rotation0;
         * if (vel > 200 || vel < -200)
         * {
         *  vel = vel1;
         * }
         * //Debug.Log("回転y成分 速度" + _rotation0);
         * //Debug.Log("回転y成分 速度" + vel);
         * text = vel.ToString();
         * //Debug.Log("test表示" + text);
         * serialHandler.Write(text + ",");
         * _rotation1 = _rotation0;
         * vel1 = vel;*/

        _distance = (_indexFinger.transform.position - _unko.transform.position).magnitude;
        Debug.Log(_distance);
        serialHandler.Write(_distance.ToString() + ",");
        if (_distance < _threshold)
        {
            Debug.Log("@@@@@@@@@@@@@@@@@@@@@@@@");
            Purun(_distance);
        }
        else
        {
            Purun(_threshold);
        }
    }
Example #15
0
    void Update()
    {
        float SegwayX = Segway.transform.eulerAngles.x;

        Debug.Log(SegwayX);

        //Arduinoに文字を送る

        //セグウェイの傾きに応じて
        if (SegwayX >= 0 && SegwayX < 45)
        {
            serialHandler.Write("L");
        }
        else if(SegwayX >= 315 && SegwayX < 360)
        {
            serialHandler.Write("H");
        }
    void Update()
    {
        //フレーム書き換えごとに経過時間を累積
        duration += Time.deltaTime;

        //Arduinoに文字を送る
        serialHandler.Write("0");
    }
 // Start is called before the first frame update
 void Start()
 {
     // スライダーを取得する
     _slider = GameObject.Find("Slider").GetComponent <Slider>();
     //ペルチェ素子の電圧を0にする
     serialHandler.Write("o");
     Debug.Log("OFF command!");  // ログを出力
 }
 // Start is called before the first frame update
 void Start()
 {
     //信号を受信したときに、そのメッセージの処理を行う
     serialHandler.OnDataReceived += OnDataReceived;
     //テスト
     serialHandler.Write("c");
     Debug.Log("Cool command!");  // ログを出力
 }
Example #19
0
 public void SetCustomWave(SerialHandler serialHandler, System.Func <float, float> func)
 {
     byte[] dat = new byte[1000];
     byte[] h   = new byte[1] {
         1
     };
     serialHandler.Write(h);
     for (int i = 0; i < 1000; i++)
     {
         dat[i] = (byte)(func(0.001f * i) * 255);
     }
     for (int i = 0; i < 200; i++)
     {
         byte[] dat_div = new byte[5];
         System.Array.Copy(dat, 5 * i, dat_div, 0, 5);
         serialHandler.Write(dat_div);
     }
 }
Example #20
0
    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(10, 10, 100, 100));
        str = GUILayout.TextField(str);
        if (GUILayout.Button("SEND"))
        {
            serial.Write(str + "\r");
        }
        GUILayout.EndArea();

        // inputTest
        Event e = Event.current;

        if (Input.anyKeyDown && e.isKey && e.keyCode != KeyCode.None)
        {
            Debug.Log("Detected key code: " + e.keyCode);
            serial.Write(e.keyCode + "\n");
        }
    }
Example #21
0
 void Update()
 {
     //文字列を送信
     serialHandler.Write("Received!");
     // 位置を更新
     transform.localScale = m_pos;
     m_pos.x = signal / 1000 + 1;
     m_pos.y = signal / 1000 + 1;
     m_pos.z = signal / 1000 + 1;
 }
Example #22
0
    public void onClick()
    {
        Text text      = InputMessage.GetComponent <Text>();
        Text inputtext = input.GetComponent <Text>();

        text.text = inputtext.text;
        Debug.Log(text.text);
        SerialHandler sh = SerialHandler.GetComponent <SerialHandler>();

        sh.Write(text.text);
    }
Example #23
0
 void Start()
 {
     //信号を受信したときに、そのメッセージの処理を行う
     serialHandler.OnDataReceived += OnDataReceived;
     serialHandler.Write("0" + "\0");
     isMoving = false;
     angle    = 0;
 }
Example #24
0
    void FixedUpdate()
    {
        timeElapsed += Time.deltaTime;

        if (serial_sendable || timeElapsed > 0.5)
        {
            serial_sendable = false;
            timeElapsed     = 0;
            v0 = 0;
            v1 = 1;
            v2 = 2;
            serialHandler.Write("h" + v0.ToString() + "," + v1.ToString() + "," + v2.ToString() + "\0");
        }
    }
Example #25
0
    void Update()
    {
        //フレーム書き換えごとに経過時間を累積
        duration += Time.deltaTime;

        //Arduinoに文字を送る

        if (duration > 2.0f && start)
        {
            serialHandler.Write("0");
            start = false;
        }

        //キー入力
        if (Input.GetKeyDown(KeyCode.S))
        {
            serialHandler.Write("0");
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            serialHandler.Write("1");
        }
    }
Example #26
0
 private void ThreadMethod()
 {
     while (true)
     {
         var remoteEP = new IPEndPoint(IPAddress.Any, 8001);
         //IPEndPoint remoteEP = null;
         byte[] data = udp.Receive(ref remoteEP);
         //float recx = BitConverter.ToSingle(data, 0);
         string text = Encoding.ASCII.GetString(data);
         //text = "a";
         Debug.Log(text);
         //string s1 = recx.ToString("f1");
         //text = "a";
         serialHandler.Write(text);//受け取ったデータをシリアル通信でマイコンへ送信する部分をかく
         //Debug.Log("success");
     }
 }
Example #27
0
    void Update()
    {
        // put sensor data to global variable
        bendData   = serial.bend;
        isReleased = serial.release;
        //Debug.Log(bendData);

        // change force mode using keyboard for testing
        if (Input.GetKeyDown("space"))
        {
            serialHandler.Write("0");
            forceMode = 0;
            controllerMesh.material.color = new Vector4(0, 0, 0, 1);
        }

        // disable haptics for test mode
        if (Input.GetKeyDown("x"))
        {
            serialHandler.Write("9");
        }
    }
Example #28
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.A))
     {
         serialHandler.Write("11");
     }
     if (Input.GetKeyDown(KeyCode.S))
     {
         serialHandler.Write("21");
     }
     if (Input.GetKeyDown(KeyCode.D))
     {
         serialHandler.Write("31");
     }
     if (Input.GetKeyDown(KeyCode.F))
     {
         serialHandler.Write("2541");
     }
     if (Input.GetKeyDown(KeyCode.G))
     {
         serialHandler.Write("25541");
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime      = 15;
        totalTimeLimit = 30;  //30秒で必ず次のシーンに遷移する
        GoFromArduino  = false;
        recordTemp     = false;

        // 実験の順番、現在の試行番号・状態等を取得
        // 読み込みたいCSVファイルのパスを指定して開く
        StreamReader sr = new StreamReader(Application.dataPath + "/Data/" + "Experiment1_order.csv");
        // CSVファイルの一行を読み込む
        string orderLine = sr.ReadLine();

        // 読み込んだ一行をカンマ毎に分けて配列に格納する
        string[] orderString = orderLine.Split(',');
        // 各試行の香料のIDと条件(A, B, C)をリストに格納
        AromaCondition.AddRange(orderString);
        // 試行が練習なのか本番なのか、試行番号を読み込み
        string trialStateLine = sr.ReadLine();

        string[] trialState = trialStateLine.Split(',');
        Test_or_Trial = trialState[0];
        TrialID       = int.Parse(trialState[1]);
        sr.Close();

        //36試行まで終わったら、一度休憩
        if (TrialID == 36)
        {
            //ペルチェ素子にかかる電圧を0にする
            serialHandler.Write("o");
            Debug.Log("Off Command!");
            Debug.Log("Scene Change");
            // 新しい情報をcsvファイルに書き込み
            TrialID += 1;
            StreamWriter sw1;
            sw1 = new StreamWriter(Application.dataPath + "/Data/" + "Experiment1_order.csv", false);
            string orderLinesw = string.Join(",", AromaCondition);
            sw1.WriteLine(orderLinesw);
            string[] ids     = { Test_or_Trial, TrialID.ToString() };
            string   idsLine = string.Join(",", ids);
            sw1.WriteLine(idsLine);
            sw1.Flush();
            sw1.Close();
            SceneManager.LoadScene("Intermission_Scene");
        }
        //72試行で実験終了
        else if (TrialID == 72)
        {
            //ペルチェ素子にかかる電圧を0にする
            serialHandler.Write("o");
            Debug.Log("Off Command!");
            Debug.Log("Scene Change");
            SceneManager.LoadScene("End_Scene");
        }
        else
        {
            // 試行番号(TrialID)の更新
            if (Test_or_Trial == "Trial" || (Test_or_Trial == "Test" && TrialID < 2))
            {
                TrialID += 1;
            }
            else if (Test_or_Trial == "Test" && TrialID == 2)
            {
                Test_or_Trial = "Trial";
                TrialID       = 1;
                serialHandler.Write("s");
                Debug.Log("Sensor command!");  // ログを出力
            }

            if (Test_or_Trial == "Test")
            {
                Debug.Log(Test_or_Trial);
                int AromaID = TrialID;
                Debug.Log("Aroma ID : " + AromaID.ToString());
            }
            else
            {
                string line      = AromaCondition[TrialID - 1];
                int    AromaID   = int.Parse(line.Substring(0, line.Length - 1));
                string Condition = line.Substring(line.Length - 1);

                Debug.Log(Condition);
                if (Condition == "A" || Condition == "B")
                {
                    serialHandler.Write("r");
                    Debug.Log("Room Temperature command!");  // ログを出力
                }
                else if (Condition == "C")
                {
                    serialHandler.Write("h");
                    Debug.Log("Hot command!");  // ログを出力
                }

                Debug.Log("Aroma ID : " + AromaID.ToString());
            }

            // 新しい情報をcsvファイルに書き込み
            StreamWriter sw1;
            sw1 = new StreamWriter(Application.dataPath + "/Data/" + "Experiment1_order.csv", false);
            string orderLinesw = string.Join(",", AromaCondition);
            sw1.WriteLine(orderLinesw);
            string[] ids     = { Test_or_Trial, TrialID.ToString() };
            string   idsLine = string.Join(",", ids);
            sw1.WriteLine(idsLine);
            sw1.Flush();
            sw1.Close();
        }
    }
 // Update is called once per frame
 void Update()
 {
     serialHandler.Write(expression.isTouched.ToString());
 }