WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   question regarding viz.getpostion written into text file (https://forum.worldviz.com/showthread.php?t=5798)

bbb 07-26-2016 07:03 AM

question regarding viz.getpostion written into text file
 
Hey all,
I'm using vizard 5.3 for navigation test using Oculus rift Dk2(runtime 0.8) and xbox one controller. In order to calculate some measurements from the experiment we write every 100ms:

# Get the tracking data.
def getData(tracking_data, startTime):
orientation = viz.MainView.getEuler()
position = viz.MainView.getPosition()
timeStamp = viz.tick()
# Make a string out of the data.
data = 'orientation: ' + str(orientation) + '\t' + 'position: ' + str(position) + '\t' 'time: ' + str(timeStamp - startTime) + '\n'
# Write it to the tracking file.
tracking_data.write(data)

The loop runs 3 times(3 tries per day for this test), each time is a different trial(try) and it uses the getData function to write to text file(different text file for each trial).

trials = range(1, 4)

for i in trials:
# enable movement
walking_transport.setEnabled(viz.ON)
# disable orientation
ori_transport.setEnabled(viz.OFF)

# store the time at which this trial started
startTime = viz.tick()
tracking_data = open(participant_code + '_hidden_12X12 trackingDataTrial' + str(i) + '.txt', 'a')
expTimer = vizact.ontimer(0.1, getData, tracking_data, startTime)

Sometimes it writes more data to text files than should be. It seems like the time start from the begining over and over and the last time it start, that is the correct data (i have another text file that the time of each trial is written in it, that is why i know the last data is the correct one). Does anyone can tell me way is it happening?

Thanks in advence.

Erikvdb 07-27-2016 03:32 AM

I'm not entirely sure what you mean, and it's hard to read the code without indentations (please use the CODE tags next time), but could it be that you are not stopping the timer and closing the datafile after each trial? If that's the case, the timer for the first trial just keeps on writing data during the second and third trial; the timer for the second trial will keep on writing during the third, and only the last one will write just the data of the last trial.

bbb 08-23-2016 11:54 PM

Hi Erik,
Sorry for the using indentation and thanks for your answer.
My problem apperent to be pretty simple:
I used 'a' for append instead of 'w' for writing so whenever the file name was existing my latest data was added to the same file creating long ones.


All times are GMT -7. The time now is 09:53 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC