Jump to content

ABUSHATTAL

Verified Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by ABUSHATTAL

  1. Hi @Corvus
    I have tried the script and it return object name. but when I recall it in the update function to keep tracking where the player is looking it is freeze unity after hit play button. I also note when disable a script that recall the eye data from SRanipal it works fine. can you help me how to make it work to capture focus using update function?.  I have used the following script to get eye data using SRanipal eye frame and i want to incluse the detected object to the update section:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System;
    using System.Threading;
    using System.IO;
    using ViveSR.anipal.Eye;
    namespace Test120FPS
    {
        public class Sample_GetDataThread : MonoBehaviour
        {
            public GameObject Status;
            private string state;
            public GameObject Car;
            private string Carx;
            private string Cary;
            private string Bicyclex;
            private string Bicycley;
            private string distance;
            public GameObject Bicycle;
            public EyeData data = new EyeData();
            private Thread thread; private const int FrequencyControl = 1;
            private const int MaxFrameCount = 3600;
            void Start()
            {
                thread = new Thread(QueryEyeData);
                thread.Start();
                
                string text =  "distance"+ "?" + "Carx" + "?" + "Cary" + "?" +"Bicyclex" + "?" +"Bicycley"+"?"+"Left eye dia: "+"?" + "Right eye dia: " + "?" + "Left eye openess " + "?" + "Right eye openess " + "?" + "Left eye gaze " + "?" + "Right eye gaze " + "?" + "Status" + "?" + "CurrentFrameSequence" + "?" +  "CurrentSystemTime(ms)"  + Environment.NewLine;
                File.AppendAllText("DataRecord.txt", text);
            }
            private void OnApplicationQuit()
            {
                thread.Abort();                
            }
            private void OnDisable()
            {
                thread.Abort();
            }


          

            /// <summary>
            /// Checks name for current object in focus.
            /// </summary>
            

            void FixedUpdate()
            {
                Carx = Car.transform.position.x.ToString();
                Cary = Car.transform.position.z.ToString();
                Bicyclex = Bicycle.transform.position.x.ToString();
                Bicycley = Bicycle.transform.position.z.ToString();
                state = Status.name.ToString();
                float dist = Vector3.Distance(Car.transform.position, Bicycle.transform.position);
                float feet = dist * 3.28f;
                distance = ((int)dist*3.28f).ToString();
                
                

            }


            // You can only use C# native function in Unity's thread.
            // Use EyeData's frame_sequence to calculate frame numbers and record data in file.
            void QueryEyeData()
            {
                int FrameCount = 0;
                int PrevFrameSequence = 0, CurrFrameSequence = 0;
                bool StartRecord = false;
                while (FrameCount < MaxFrameCount)
                {
                    ViveSR.Error error = SRanipal_Eye_API.GetEyeData(ref data);
                    if (error == ViveSR.Error.WORK)
                    {
                        CurrFrameSequence = data.frame_sequence;
                        if (CurrFrameSequence != PrevFrameSequence)
                        { 
                            FrameCount ++;
                            PrevFrameSequence = CurrFrameSequence;
                            StartRecord = true;
                        } 
                    }
                    // Record time stamp every 120 frame.
                    if (FrameCount % 60 == 0 && StartRecord)
                    {

                        string text = distance + "?" + Carx+ "?"+ Cary+ "?" +Bicyclex + "?" + Bicycley +"?" + data.verbose_data.left.pupil_diameter_mm + "?" + data.verbose_data.right.pupil_diameter_mm + "?" + data.verbose_data.left.eye_openness + "?" + data.verbose_data.right.eye_openness + "?" + data.verbose_data.left.gaze_direction_normalized +"?"+ data.verbose_data.right.gaze_direction_normalized + "?" + state + "?" + CurrFrameSequence + "?" + DateTime.Now.ToString() + Environment.NewLine;
                        File.AppendAllText("DataRecord.txt", text);
                        FrameCount = 0;
                    } 
                    Thread.Sleep(FrequencyControl);
                }
            }
        }}


          

×
×
  • Create New...