I am developing a VR experiment for my research on improving pedestrian safety at midblock crosswalks. The device I am using for the experiment is HTC Vive Pro Eye. I am very new to coding and Unity and I hope someone can help. So far, I built the environment for the experiment (i.e. crosswalk, road, buildings, vehicles), however, I am struggling on how I can collect data when after I run my experiment.
Can anyone please advise me on how I can export the headset position & rotation (with respect to time) to a csv or xml file format? Hope to hear from someone soon. Thank you.
Maybe you could run the app in debug mode and log the positions with Debug.Log lines. Just prefix them with something to make them easier to pull from the log.
Or setting up a server to send the data to, like this: (Haven’t tested it myself)
Thank you for your response. I tested your code and received a set of data in the form of a 4x4 matrix. One example with the frame index of 214 is shown below:
Thank you so much for your reply, you have really helped me a lot in my research and I highly appreciate it. The data looks great! I managed to code it to output CSV as well. But I would like to organize the data differently…
Right now, the data output looks like this on excel:
hi, Hope you are doing well.
I tried to use your code for access the gyro data of unity rift s, I’m completely new in programing.
I got two error in my unity console :
1)
DirectoryNotFoundException: Could not find a part of the path “C:\Users\mm2758\AppData\LocalLow\DefaultCompany\My project 1\motion_2022-10-19T11:23:37.json”.
System.IO.FileStream…ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at <9aad1b3a47484d63ba2b3985692d80e9>:0)
System.IO.FileStream…ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options) (at <9aad1b3a47484d63ba2b3985692d80e9>:0)
(wrapper remoting-invoke-with-check) System.IO.FileStream…ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions)
System.IO.StreamWriter…ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize) (at <9aad1b3a47484d63ba2b3985692d80e9>:0)
System.IO.StreamWriter…ctor (System.String path, System.Boolean append) (at <9aad1b3a47484d63ba2b3985692d80e9>:0)
(wrapper remoting-invoke-with-check) System.IO.StreamWriter…ctor(string,bool)
MotionRecorder.Start () (at Assets/Scripts/MotionRecorder.cs:27)
2)
NullReferenceException: Object reference not set to an instance of an object
MotionRecorder.LateUpdate () (at Assets/Scripts/MotionRecorder.cs:47)
and its the code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class MotionRecorder : MonoBehaviour
{
[System.Serializable]
private struct MotionFrame
{
public int frameIndex;
public float timeStamp;
public Vector3 position;
public Quaternion orientation;
}
void OnApplicationQuit()
{
writer.WriteLine(“]”);
writer.WriteLine(“}”);
writer.Close();
}
}
cloud you please help me. I really appreciate for any help.
Thanks
Hi, I’m trying to use your code to extract the gyro data of my oculus rift s through unity; I got these errors; I would appreciate it if anyone could help me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class MotionRecorder : MonoBehaviour
{
[System.Serializable]
private struct MotionFrame
{
public int frameIndex;
public float timeStamp;
public Vector3 position;
public Quaternion orientation;
}
Hi, Hope you are doing well.
I tried to use your code to access the gyro data of unity rift s, but I’m completely new to programming.
I got this error in my unity console :
1.
InvalidOperationException: The stream is currently in use by a previous operation on the stream.
System.IO.StreamWriter.ThrowAsyncIOInProgress () (at <9aad1b3a47484d63ba2b3985692d80e9>:0)
System.IO.StreamWriter.CheckAsyncTaskInProgress () (at <9aad1b3a47484d63ba2b3985692d80e9>:0)
System.IO.StreamWriter.WriteLine (System.String value) (at <9aad1b3a47484d63ba2b3985692d80e9>:0)
VRCamera.LateUpdate () (at Assets/Scripts/VRCamera.cs:46)
and its the code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class MotionRecorder : MonoBehaviour
{
[System.Serializable]
private struct MotionFrame
{
public int frameIndex;
public float timeStamp;
public Vector3 position;
public Quaternion orientation;
}
void OnApplicationQuit()
{
writer.WriteLine(“]”);
writer.WriteLine(“}”);
writer.Close();
}
}
cloud you please help me. I really appreciate for any help.
Thanks
void StartNewSession() {
string directoryPath = @“D:\Cathy\DataPLayer”; // Updated path of your folder to store the data
string fileName = “PlayerDataLog_” + DateTime.UtcNow.ToString(“yyyyMMdd_HHmmss”) + “.csv”;
if (!Directory.Exists(directoryPath)) {
Directory.CreateDirectory(directoryPath);
}
dataPath = Path.Combine(directoryPath, fileName);
File.WriteAllText(dataPath, “Timestamp,X,Y,Z,Speed\n”); // Include speed in header
}