Search Unity

Question Exporting Log Data from Oculus Quest with CSV file format

Discussion in 'VR' started by thkimchi, Sep 23, 2022.

  1. thkimchi

    thkimchi

    Joined:
    Sep 23, 2022
    Posts:
    1
    Hi,

    When I tried to extract log data from desktop version, it worked well with this code:
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using UnityEngine;
    6.  
    7. public class PositionData : MonoBehaviour
    8. {
    9.     [Header("CSV File Name")]
    10.     [SerializeField] string csvName;
    11.  
    12.     [Header("OVRCameraRig")]
    13.     [SerializeField] GameObject player;
    14.  
    15.     private string participantID;
    16.     private string filePath;
    17.     private bool startWriting;
    18.     private bool canRecord;
    19.  
    20.     private void Start()
    21.     {
    22.         participantID = PlayerPrefs.GetString("ID", "INVALID");
    23.         startWriting = false;
    24.         canRecord = true;
    25.         filePath = GetFilePath();
    26.     }
    27.  
    28.     private void Update()
    29.     {
    30.         if (canRecord)
    31.         {
    32.             addRecord(participantID, Time.time, player.transform.position.x, player.transform.position.z, filePath);
    33.             StartCoroutine(delayRecord());
    34.         }
    35.     }
    36.  
    37.     private void addRecord(string ID, float time, float x, float z, string filePath)
    38.     {
    39.         print("Writing to file");
    40.         try
    41.         {
    42.             if (!startWriting)
    43.             {
    44.                 using (StreamWriter file = new StreamWriter(@filePath, false))
    45.                 {
    46.                     file.WriteLine("UserID" + "," + "Time" + "," + "XPos" + "," + "ZPos");
    47.                 }
    48.                 startWriting = true;
    49.             }
    50.             else
    51.             {
    52.                 using (StreamWriter file = new StreamWriter(@filePath, true))
    53.                 {
    54.                     file.WriteLine(ID + "," + time + "," + x + "," + z);
    55.                 }
    56.             }
    57.         }
    58.         catch (Exception ex)
    59.         {
    60.             Debug.Log("Something went wrong! Error: " + ex.Message);
    61.         }
    62.     }
    63.  
    64.     private IEnumerator delayRecord()
    65.     {
    66.         canRecord = false;
    67.         yield return new WaitForSeconds(0.2f);
    68.         canRecord = true;
    69.     }
    70.  
    71.     string GetFilePath()
    72.     {
    73.         return Application.dataPath + "/"  + "_" + csvName + ".csv";
    74.     }
    75. }
    However, if I build and launch this app with my Oculus Quest headset, then it does not generate csv file. I connected Quest to the desktop with a wire cable (and cable seems work well because I can build apps with this setting).

    Can anyone help me with this?
     
  2. ttempty

    ttempty

    Joined:
    Apr 19, 2019
    Posts:
    1
    Hey, thank you for sharing the code.

    For it to work on the Oculus Quest, you can change the "Application.dataPath" to "Application.persistentDataPath". The csv file is going to be saved in /sdcard/Android/data/com.oculus.XXX/files (with com.oculus.XXX is your Package Name).

    Another issue that might happen is that for the player GameObject, you need to reference a camera of the OVRCameraRig, e.g. CenterEyeAnchor for the position data to be recorded. At first, I referenced the OVRCameraRig and the position data remained the same.
     
    pir8-x likes this.