Jump to content

Getting VerboseData at the fastest rate possible.


Recommended Posts

Is there a way to get VerboseData records faster than polling GetVerboseData in Update()? Internally it looks like it's using Time.frameCount to distinquish between new frames, but that implies that we're only getting 90 samples a second and not the 120 the website mentions. 

 

It'd be useful to have those extra frames!

 

Thanks!

Link to comment
Share on other sites

I wondered this too and that is useful to know that the data would be more recent if polled at the faster rate.

I've been using an eye tracking SDK in the past that allows you to register for the data refresh event in the SDK, which was a nice feature.

Link to comment
Share on other sites

I'll give it a try,  but internally it's using Time.frameCount to distinquish between frames. Given that I don't think any of the Time.xxxx calls are thread safe and Time.frameCount is updated per Update (and not 120hz) it seems like it wouldn't work. But I don't know what else to do!

Link to comment
Share on other sites

Having run some experiments, I don't think any of this can be called off the main thread.

If you start the system on the main thread, but ask for events off thread, you'll get them, but Unity will lock up if anything else tries to talk to the SRRuntime. For example, once you've called an SR call off thread, you can't hit Stop in the editor without restarting all of Unity via the Task Manager.

If you start the system on a dedicated thread, and try to isolate your calls to that thread, you'll quickly run into some part of SR calling into FindObjectOfType, which needs to be on the main thread.

It would be great if the Unity side of this was made thread safe so we could safely poll at 120hz.

(     - tag added by moderator) 

Link to comment
Share on other sites

 Hi kadakadakScott:

 

You can follow these step to get 120 frame data per second.

- Create an empty scene and add SRanipal_Framework into the scene. (The framework GameObject will be in Prefab folder)

- Create an empty GameObject and attach below two script on it.

- Start the scene preview then you can check the EyeData's frame sequence and timestamp in DataRecord.txt

 

Notice, If you use this method to get EyeData or VerboseData, you should not use other function in SRanipal_Eye simultaneously since the function in SRanipal_Eye are implement within Unity's main thread. 

 

Best Regards

Jason

 

 

// Sample_MainThread.csusing System.Collections;using System.Collections.Generic;using UnityEngine;using ViveSR.anipal.Eye;namespace Test120FPS{    public class Sample_MainThread : MonoBehaviour    {        private Sample_GetDataThread DataThread = null;        private EyeData data = new EyeData();        // Use this for initialization        void Start()        {            DataThread = FindObjectOfType<Sample_GetDataThread>();            if (DataThread == null) return;        }        // You can get data from another thread and use MonoBehaviour's method here.        // But in Unity's Update function, you can only have 90 FPS.        void Update()        {            data = DataThread.data;            Debug.Log("Left eye openness: " + data.verbose_data.left.eye_openness);            Debug.Log("Right eye openness: " + data.verbose_data.right.eye_openness);        }    }}
// Sample_GetDataThread.csusing 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 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();        }        private void OnApplicationQuit()        {            thread.Abort();        }        private void OnDisable()        {            thread.Abort();        }        // 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.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 % 120 == 0 && StartRecord)                {                    long ms = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;                    string text = "CurrentFrameSequence: " + CurrFrameSequence +                        " CurrentSystemTime(ms): " + ms.ToString() + Environment.NewLine;                    File.AppendAllText("DataRecord.txt", text);                    FrameCount = 0;                }                Thread.Sleep(FrequencyControl);            }        }    }}

 

 

  • Thanks 2
Link to comment
Share on other sites

  • 3 months later...

Dear @VIVE_Jason_Lu,

 

Thank you very much for sharing the helpful scripts!

They worked successfully after changing two minor things. The version of SDK is 1.1.0.1.

1. In sample_getdatathread.cs, SRanipal_Eye_API.GetEyeData needs to be used instead of SRanipal_Eye.GetEyeData.

2. In sample_getdatathread.cs, we may need to add another counter in while loop. Otherwise, we can't go out the loop, causing Unity to freeze.

 

Best regards,

imarin18

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...