How do I check the state of ROS Master??
19 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
MathWorks Robotics and Autonomous Systems Team
on 6 Dec 2017
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
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!
See Also
Categories
Find more on Services and Actions 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!