get all the active namespaces rospy | roscpp
In my project, multiple robots may be spawned both at launch and at runtime, each under a certain namespace. Generally, that is 'robot_ID'
where ID == a robot-unique integer, but nothing stops the user from selecting its own namespace.
I need to programmaticaly retrieve a list of namespaces currently active from a node that is in the global namespace. That must be like that.
When I launch my project, on std rosout this gets printed:
NODES
/robot_2/ # <- NAMESPACE
amcl (amcl/amcl)
move_base (move_base/move_base)
robot_state_publisher (robot_state_publisher/robot_state_publisher)
spawn_urdf (gazebo_ros/spawn_model)
/robot_1/ # <- NAMESPACE
amcl (amcl/amcl)
move_base (move_base/move_base)
robot_state_publisher (robot_state_publisher/robot_state_publisher)
spawn_urdf (gazebo_ros/spawn_model)
/ # <- STANDARD NAMESPACE
gazebo (gazebo_ros/gzserver)
map_loader (map_server/map_server)
rviz (rviz/rviz)
So this leads me into thinking that there is a way to do so. I'm mostly using Python, but for this purpose only I would also be willing to use a C++ node.
EDIT: I've marked what I would like to retrieve from the above piece of output.
Can you provide more details about what you want to achieve please ? If you just want to list the namespaces without processing the list then a simple bash/python script parsing the ouput of
rosnode list
would work.I thought it was clear, I'm sorry. I would like to retrieve a "list" of all the namespaces, being all the "prefixes" being currently applied to nodes. In the rosout, at launch, that "resume" gets printed: I want to know if there is a direct/indirect way to get all the shown namespaces. Parsing the output of
rosnode list
is an option, but that requires some work, meaning that you have to do string comparison to find recurring pieces of string in all the nodes. Not much of a deal, but I was asking if there was a better way