MATLAB Answers

custom ROS messages in parfeval function?

7 views (last 30 days)
Andreas Schwager
Andreas Schwager on 2 Jun 2021
Hi,
rosgenmsg allows Matlab reading from individually compiled ROS mesages (using ROS Toolbox).
This works fine in my environment.
Now, I like to read the ROS message inside a parfeval function.
There is the error message:
'Cannot determine the message type of the /myRosNode/myTopic topic. Either the topic is not registered with the ROS master, or the ROS master is not reachable.'
How to copy all environment settings to the parfeval function?
Is it possible to let the parfeval function heritage all settings from calling function or current workspace?
Thanks
  3 Comments
Jagadeesh Konakalla
Jagadeesh Konakalla on 8 Jun 2021
Hi Andreas,
Sorry for the late reply.
In ROS Toolbox, You have convenience functions like rossubscriber,rospublisher. Where all these functions uses one global node that is created at the time of rosinit. This looks like causing issues when you use functions provided by Parallel Computing Toolbox.
So, i recommend you to create and use objects of ros.Node, ros.Subscriber, ros.Publisher classes for creating a node, creating subscriber and publisher.
Please note that all the network intropsection API's (example : rostopic, rosnode) uses global node. So, i receommend you to avoid these functions in the code that is designed to run in other other workers. You can still use the introspection API's in the main MATLAB.
Below, i have provided some recommendations for you to make changes to your parFunction. Please note that i have provided a workaround (on cleanup,do rosshutdown) to work in rostopic list is in this function. This workaround should allow to use casual API's. I have not done much testing on my end.
But my recommendation is to aviod the casual API's and introspection API's in parFunction.
function rpOut = parFunction(q)
% I recommend you to avoid the rosinit and rostopic, rossubscriber in workers code.
% Use the following workaround if it works.
rosinit('192.168.213.1')
cleanVar = onCleanup(@rosshutdown);
send(q, sprintf('parFunction queue output'));
rtl = rostopic('list');
disp(rtl)
% I recommend you create a new node in worker code. In this case for subscriber create a new
% node and make sure to provide the MASTER_URI to which master uri that node to be connected.
sub_node = ros.Node('sub','http://192.168.213.1:11311');
rpOut = ros.Subscriber(sub_node,'/myDevice/myTopic_1',@PlotResultsCallback);
send(q, sprintf('PlotRadarCallback1 initiated'));
end
Please let me know if this works for you.
Thanks,
Jagadeesh K

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by