This is the top-level namespace of the rocon_python_utils ROS package. This module provides a toolbox of general purpose python utilities.
This module is a library of general purpose exceptions that fill general needs not catered for by the python exception heirarchy. These exception names are all included in the main rocon_python_utils namespace. To catch one, import it this way:
from rocon_python_comms import TimeoutExpiredError
Bases: threading.Thread
The pinger class can run a threaded pinger at the desired frequency to check if a machine is available or not.
Usage:
from rocon_python_utils.network import Pinger
pinger = Pinger('192.168.1.3', 0.2)
pinger.start()
# after some time
print("Statistics: %s" % pinger.get_latency()) # [min,avg,max,mean deviation]
print("Time since last seen %s" % pinger.get_time_since_last_seen())
Initialises but doesn’t start the thread yet. Use run() to start pinging and collecting statistics.
Parameters: |
---|
Latency statistics generated from the internal window (buffer). This is a ring buffer, so it will only use the most recent ping data.
Returns: | latency statistics (min, avg, max, mean deviation) |
---|---|
Return type: | float[] |
This module makes use of the python-catkin-pkg module and adds a few extra functions for interacting with catkin packages.
Find all packages on the given list of paths
Iterates over the given list of paths in reverse order so that packages found in the paths at the beginning of the list get overlaid onto packages with the same name which were found in paths farther back in the list.
The resulting dictionary is keyed by the package name (so packages with duplicate names are overlaid) and the values are the catkin_pkg.package.Package class.
Parameters: | ros_package_path (str[]) – list of paths to search |
---|---|
Returns: | dictionary of package objects keyed by name of the package |
Return type: | dict |
Todo: | overlay duplicates only if the version is newer |
This module contains converters and ros resource finders for icons and icon messages.
Loads the icon resource and puts in rocon_std_msgs.Icon format
Parameters: | resource (str) – resource identifier (package/name) |
---|---|
Returns: | the icon in msg format |
Return type: | rocon_std_msgs.Icon |
Loads the specified filename and puts in rocon_std_msgs.Icon format
Parameters: | filename (str) – to the icon resource. |
---|---|
Returns: | the icon in msg format |
Return type: | rocon_std_msgs.Icon |
This module contains helpers that lookup or collect an index of ros resource names for various purposes.
Convenience wrapper around roslib to find a resource (file) inside a package. It checks the output, and provides the appropriate error if there is one.
Parameters: | |
---|---|
Returns: | absolute path to the file |
Return type: | str |
Raises: | rospkg.ResourceNotFound : raised if there is nothing found or multiple objects found. |
Convenience wrapper around roslib to find a resource (file) inside a package. This function passes off the work to find_resource once the input string is split.
Pass it a shared rospack (rospkg.RosPack) object to accelerate the crawling across the ROS_PACKAGE_PATH when you are calling this function for many resources consecutively.
rospack = rospkg.RosPack()
for ros_resource_name in ['rocon_interactions/pc.interactions', 'rocon_interactions/demo.interactions']
filename = find_resource_from_string(ros_resource_name, rospack)
# do something
Parameters: | |
---|---|
Returns: | full pathname to the resource |
Return type: | str |
Raises: | rospkg.ResourceNotFound raised if the resource is not found or has an inappropriate extension. |
Scans the package path looking for exports and grab the ones we are interested in.
Parameters: |
|
---|---|
Returns: | the dictionary of resource and its absolute path |
Return type: | dict { resource_name : os.path } |
Abstraction for pulling the rosdistro version (e.g. groovy/hydro). We are using the configured parameter here, but you could equally use one of the non-runtime techniques in rospkg elucidated on ros answers by Jack:
http://answers.ros.org/question/36485/how-do-i-test-the-ros-version-in-python-code/
Returns: | the human readable string version for the ros distro |
---|---|
Return type: | str |
This module wraps a few command line executables with a convenient python api.
This module includes a few helpers to enable working with system pids in python.
Check whether pid exists in the current process table.
Parameters: | pid (int) – |
---|---|
Returns: | true or false depending on its existence. |
Return type: | bool |
Wait for process with pid ‘pid’ to terminate and return its exit status code as an integer.
If pid is not a children of os.getpid() (current process) just waits until the process disappears and return None.
If pid does not exist at all return None immediately.
Parameters: | |
---|---|
Raises: | TimeoutExpiredError on timeout expired (if specified). |
This module helps workaround the official popen with another implementation that solves a few problems (post-exec callbacks, etc)
Bases: object
Use this if you want to attach a postexec function to popen (which is not supported by popen at all). It also defaults setting and terminating whole process groups (something we do quite often in ros).
Usage:
This is what you’d do starting a rosrunnable with a listener for termination.
def process_listener():
print("subprocess terminating")
command_args = ['rosrun', package_name, rosrunnable_filename, '__name:=my_node']
process = rocon_python_utils.system.Popen(command_args, postexec_fn=process_listener)
Parameters: |
|
---|