ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

How to find a node type during runtime

asked 2014-05-06 13:54:45 -0600

curranw gravatar image

I'd like to be able to find a node type (not user-defined name) of a currently running node. Basically, what file was actually being executed.

"Nodes also have a node type, that simplifies the process of referring to a node executable on the fileystem." -Wiki

This is relatively easy if the node is launched from a roslaunch command, I can simply look at the logging. From a rosrun command, I can't seem to find equivalent logging. Watching the loggers are a bit of a hack, and I'm sure there is a proper API to do this, but I can't seem to find it. Rosnode gets close.

The ideal solution is to use a getter to access elements of the Node class, a part of the roslaunch.core package. If this is not possible, is there a work-around?

edit retag flag offensive close merge delete

Comments

A bit of background: we're trying to automatically record which nodes are being run. We've instrumented roslaunch (minimally) to do this, but we're looking for a similarly minimal way to do this with rosrun.

Bill Smart gravatar image Bill Smart  ( 2014-05-08 13:12:08 -0600 )edit

A related thought: what are the ramifications of rewriting rosrun to use the roslaunch machinery, rather than just exec'ing the node (other then automatically starting up a core if one isn't already running)?

Bill Smart gravatar image Bill Smart  ( 2014-05-08 13:16:02 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2014-05-08 13:45:49 -0600

updated 2014-05-08 14:26:37 -0600

psutil can get you what you want in many instances.

import xmlrpclib, rosnode, rospy, psutil

def get_exe_path(node_name):
    ID = '/NODEINFO'
    node_api = rosnode.get_api_uri(rospy.get_master(), node_name)
    code, msg, pid = xmlrpclib.ServerProxy(node_api[2]).getPid(ID)
    p = psutil.Process(pid)
    return p.exe

As long as the node is running on the same machine, this will give you the path to the executable (this is how rqt_top gets info about running nodes).

edit flag offensive delete link more
0

answered 2014-05-08 13:20:49 -0600

Dirk Thomas gravatar image

updated 2014-05-08 16:30:38 -0600

A started node does not provide the name of the executable which was executed anywhere. Also rosrun has no equivalent logging which you could parse.

I don't see a way how you can currently retrieve that information via ROS.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2014-05-06 13:54:45 -0600

Seen: 1,400 times

Last updated: May 08 '14