How can I run two timer objects for infinite function callback in parallel in Matlab (R2012a)

2 views (last 30 days)
Since read up the answers from Answers:98217, which is very similar of what I am going to achieve. I am trying to compute two tasks continuously at same time in MATLAB, one is taking image frame from an IP cam, and do some object tracking to it, and another one is displaying various sensors data from other devices, I am able do these tasks individually in MATLAB, however not together. Currently, consulting the sample code offered in Answer 98217, as the code described, I am using two timer objects for each task: T_sen and T_cam, firing at different speed to callback the sensor display and camera functions in parallel computing, the timerFnc is called twice to assign to different tasks, and once the timer start, I expect it should callback the function continuously and in parallel, however the callback end up to only be executed once. May I have any suggestion on this? My timer function is written as below:
function timerFnc(period, ttype)
if ttype == 1
t=timer('ExecutionMode','fixedrate','Period',period,'TimerFcn',@sens_disp);
start(t);
else
t=timer('ExecutionMode','fixedrate','Period',period,'TimerFcn',@camera);
start(t);
end
end
  3 Comments
Neil Huang
Neil Huang on 4 Mar 2014
I am new to this Toolbox, I am fully understand that Matlab is single threaded, but just in the case of trying to find a chance to improve the processing speed. The following is the part of code that I think it is using the Parallel Toolbox, to start the timer callback, (as recommend changed the function name). As I am still evaluating this Toolbox, not pretty sure this toolbox is suitable for the tasks or not.
sched = findResource('scheduler','type','local');
j = createJob(sched);
% timer parameter
period1=1;
period2=0.5;
% create tasks
obj1 = createTask(j, @start_my_timers , 0, {period1,1});
obj2 = createTask(j, @start_my_timers , 0, {period2,2});
%set([obj1 obj2], 'CaptureCommandWindowOutput', true);
% submit
submit(j);
%[EOF]
After submit the job, I am not so clear what to do since I expect the timers will be fired over a certain period of time, and not affecting each other. If it is the case, where should I put out = timerfindall to check the running timer. It seems not able to find any timer, when I placed it after the job submit.
Many thanks
per isakson
per isakson on 4 Mar 2014
Edited: per isakson on 4 Mar 2014
  • Assuming that you didn't use the Parallel Toolbox, I meant that you should run out = timerfindall interactively (in the command window) to see what happened to the timers. If they encounters errors timers may stop automatically.
  • Maybe you want to make a few simpler experiments with one new feature at a time.

Sign in to comment.

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!