Clear Filters
Clear Filters

How do I check the state of ROS Master??

19 views (last 30 days)
Gaston Castro
Gaston Castro on 1 Dec 2017
Commented: robotik bocholt on 13 May 2020
Hi, I'm a bit confuse with isCoreRunning and isNodeRunning functions.
I want to do a "while(ros::ok)" loop on matlab that checks if the global node is connected and master is reachable.
After using rosinit there is no output where it tells you which is the "ros device" so I don't get how I suppose to use isCoreRunning when it asks for a ros device.
I tried this: isCoreRunning(rosdevice('http://localhost','user','password')) but doesn't work.

Answers (1)

MathWorks Robotics and Autonomous Systems Team
Sorry for the late response. Note: In future please select the right product (as I added Robotics System Toolbox in the product list) to get a faster response.
Please note, "rosdevice" was introduced to be able to connect and start/stop Simulink generate ROS nodes only.
Also, note, "isCoreRunning" is a check for if the Master is up and running, whereas "isNodeRunning" takes an argument of "a node name" and checks if the specific "node" is running or not.
Regd, rosinit, "rosinit" will connect your MATLAB to an existing ROS network (if you use >> rosinit('ipadd') OR create a local MATLAB ROS master and connect to it (when you do >> rosinit).
Whereas, rosdevice is a function which should be called by: >> rosd = rosdevice(IPaddress, username, password)
it does not depend on "rosinit" being called or not.
If the intention is to just connect/bring up a ROS Master from MATLAB, then "rosinit" is the command you need. To check if the core is running or not, asking for ">> rosnode list" will not error if the ROS network is connected, else will error.
  2 Comments
Gaston Castro
Gaston Castro on 6 Dec 2017
So isCoreRunning should be only used when creating a core within Matlab?
Yes, I want to be able to check if the ROS Master is up and running inside a Matlab script. This would be the way to go?:
while true
try
rosnode list;
catch exp
break;
end
% everything ok, continue working..
end
Seems like an overkill to use 'rosnode list' for this. I understand that this is not the usual "callback-based" usage. But, I'm working with a simulated environment and I need to 'arbitrate' the rate of several concurrent events by stepping the /clock to simulate real time operation when is actually not performing in real time.
Thanks for your answer!
robotik bocholt
robotik bocholt on 13 May 2020
Finally this simple trick works for me:
% --- Start Matlab Global Node
try
rosnode list
catch exp % Error from rosnode list
rosinit % only if error: rosinit
end
% ....
Thank you very much!

Sign in to comment.

Categories

Find more on Services and Actions 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!