How to run an independent callback function in parallel?

1 view (last 30 days)
Hi
rosinit
obj = StoredData;
image_sub = rossubscriber('/rgb/image_rect_color/compressed',{@callbackFn3a, obj}); % Independent, callback occurs on new image receive
depth_sub = rossubscriber('/depth/depth_registered/compressed',{@callbackFn3b, obj});% Dependent, callback occurs similarly on new depthmap receive
% Why dependent? Because inside callback3b after readImage(message)
% callback3b needs image recieved by image_sub.
% Additional info: image always arrives before depthmap arrives (~ 10ms before)
callback3a
function callbackFn3a(~, message, obj)
obj.im = [obj.im(2:end,:);... % deletes old 1st row; outputting in class object
{message.Header.Seq, readImage(message)}]; % adds new row in bottom {image_sequence, image}
% Additional info: readImage(message) takes ~25ms for rgb image
end
callback3b
function callbackFn3b(~, message, obj)
depthMap = readImage(message); % reads the depth map, ~10ms for grayscale image
[h, idx] = sort(depthMap(:), 'descend'); % an operation ~10ms, to utilize the timegap till the image in callbackFn3a is ready
while true
im_idx = [obj.im{:,1}] == message.Header.Seq; % matching image_sequence with depthmap_sequence
if sum(im_idx) == 1
break % break while loop when finds match
end
end % this while loop is only to wait if readImage in previous callback3a took more time
% if callback3a was not late then while loop survives for only 1 iteration
im = obj.im{im_idx,2}; % getting the matched image
...
%%%%%%% rest of code
...
end
By the way StoredData is nothing but a class object
classdef StoredData < handle
properties (SetAccess = public, GetAccess = public)
im = cell(10,2); % callbackFn3a feeds data, callbackFn3b uses data
end
end
I want to run callback3a in parallel !!!!
Problem I faced currently is due to simultaneous processing in callback3b some of the image sequence is skipped by callback3a.
Can a dedicated worker is assigned to image_sub??
Thanks for considerationCapture.JPG

Answers (0)

Categories

Find more on Read, Write, and Modify Image 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!