Getting cursor position continuously during task

3 次查看(过去 30 天)
Hello, I’m designing a reaching task using Psychtoolbox, where a series of targets appear on screen in a certain sequence and the user has to reach them with the cursor. I need to get the position of the cursor with its relative timestamp continuously during the task, with a high frequency (at least 200Hz). In order to do so, I’m trying to use a timer to get the data. The problem is, the timer function isn’t being called with the frequency I’m setting it up with, but it has variable periods. When calling the timer inside the task function or any code using psychtoolbox logic the delays are even between 10-20ms, so the data isn’t being collected with the frequency I need.
Here’s how I’m setting up the timer:
function t = creaTimer()
t = timer;
t.TimerFcn = @basicData;
t.StartDelay = 0.003;
t.Period = 0.003;
t.ExecutionMode = 'fixedRate';
end
and the timer function:
function basicData(mTimer,~)
global dataMat;
global indexMat;
dataMat(indexMat)=GetSecs;
tmp=indexMat;
indexMat=tmp+1;
end
(In this code I’m only saving the timestamp and not the position of the cursor, but the logic would be the same. GetSecs is a psychtoolbox function).
And this is how I’m calling the timer from the task function:
global dataMat;
global indexMat;
indexMat=1;
dataMat = ones(20000,1);
t= creaTimer;
start(t)
% task code here
stop(t)
ind = (dataMat ~= 1);
data=dataMat(ind);
% here I look at the difference between subsequential timestamps, if
% everything works correctly this should be all 3(ms)
B=diff(data)*1000;
Any help or suggestions would be greatly appreciated. If you think of a better way to get the data continuously with high frequency I’d consider that too. Thank you in advance.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Installation and Operational Settings 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by