How can I prevent or recover from a "joystick device error" during timer callback?
Show older comments
I have a script that repeatedly reads the position of a joystick initiated by vrjoystick() using read(). The repetition is currently handled by a timer() callback. This works quite well... most of the time. However, the timer will occasionally crash and return the following error:
"Joystick device error: Failed to read joystick status."
Below is a minimum working example. Unfortunately you will need a joystick to run it. It will often run successfully for a few minutes before crashing, so please wait a bit before responding that it works.
Thank you very much for any help you can provide, even just brainstorming.
function MWE
figure('CloseRequestFcn','delete(timerfind); delete(gcf);');
a = axes('XLim',[-1,1],'YLim',[-1,1],'NextPlot','replacechildren');
j = vrjoystick(1);
t = timer('ExecutionMode','fixedRate','Period',0.01,'TimerFcn',@t_Callback);
start(t);
function t_Callback(~,~)
[position,~,~] = read(j);
plot(a,position(1),position(2),'ko');
end
end
Answers (1)
Jeffrey Girard
on 1 Nov 2014
Categories
Find more on Robotics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!