diff --git a/src/prpy/base/barretthand.py b/src/prpy/base/barretthand.py index f8784eb..bdbf7c0 100644 --- a/src/prpy/base/barretthand.py +++ b/src/prpy/base/barretthand.py @@ -49,8 +49,11 @@ def __init__(self, sim, manipulator, owd_namespace, bhd_namespace, ft_sim=True): EndEffector.__init__(self, manipulator) self.simulated = sim - # Just in case the closing direction is missing. - manipulator.SetChuckingDirection([ 0., 1., 1., 1. ]) + import rospkg, distutils.version + ros_version = rospkg.RosStack().get_stack_version('ros') + if distutils.version.LooseVersion(ros_version) >= distutils.version.LooseVersion('1.9'): + # Just in case the closing direction is missing. + manipulator.SetChuckingDirection([ 0., 1., 1., 1. ]) # Hand controller robot = self.manipulator.GetRobot() diff --git a/src/prpy/dependency_manager.py b/src/prpy/dependency_manager.py index 2f36546..8030074 100644 --- a/src/prpy/dependency_manager.py +++ b/src/prpy/dependency_manager.py @@ -28,24 +28,117 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -import rospkg, os, sys - -def append_to_env(name, new_paths): - import os - paths = list(new_paths) - paths += os.environ.get(name, '').split(os.pathsep) - os.environ[name] = os.pathsep.join(paths) - -def export(): - import openravepy - from catkin.find_in_workspaces import find_in_workspaces - - # Compute the major-minor OpenRAVE version. - version, _, _ = openravepy.__version__.rpartition('.') - - # Append to OPENRAVE_PLUGINS. - plugins_dir = 'openrave-' + version - lib_directories = find_in_workspaces(search_dirs=[ 'lib' ]) - plugins_path = [ os.path.join(lib_dir, plugins_dir) \ - for lib_dir in lib_directories ] - append_to_env('OPENRAVE_PLUGINS', plugins_path) +import rospkg, os, sys, distutils.version + +def is_catkin(): + distro = os.environ.get('ROS_DISTRO', '') + if distro: + # Clever hack courtesy of Chris Dellin. + return ord(distro[0].lower()) >= ord('g') + else: + raise ValueError('Environment variable ROS_DISTRO is not set.') + +if is_catkin(): + def append_to_env(name, new_paths): + import os + paths = list(new_paths) + paths += os.environ.get(name, '').split(os.pathsep) + os.environ[name] = os.pathsep.join(paths) + + def export(): + import openravepy + from catkin.find_in_workspaces import find_in_workspaces + + # Compute the major-minor OpenRAVE version. + version, _, _ = openravepy.__version__.rpartition('.') + + # Append to OPENRAVE_PLUGINS. + plugins_dir = 'openrave-' + version + lib_directories = find_in_workspaces(search_dirs=[ 'lib' ]) + plugins_path = [ os.path.join(lib_dir, plugins_dir) \ + for lib_dir in lib_directories ] + append_to_env('OPENRAVE_PLUGINS', plugins_path) +else: + def append_to_env(variable, new_path, separator=':'): + paths = os.environ.get(variable, '') + if paths: + paths_list = paths.split(separator) + else: + paths_list = list() + + # Check if we're adding a duplicate entry. + duplicate = False + new_canonical_path = os.path.realpath(new_path) + for path in paths_list: + canonical_path = os.path.realpath(path) + if canonical_path == new_canonical_path: + duplicate = True + break + + # Add the new path to the environmental variable. + if not duplicate: + paths_list.insert(0, new_path) + paths = separator.join(paths_list) + os.environ[variable] = paths + + return paths + + def export_paths(pkg, package_name): + + packages = list() + + # first get all the required packages + try: + manifest = pkg.get_manifest(package_name) + required_packages = pkg.get_depends(package_name) + packages.extend(required_packages) + except rospkg.ResourceNotFound: + return False, [package_name] + + # next get all the optional packages + optional_packages = manifest.get_export('openrave', 'optional') + packages.extend(optional_packages) + + # Process the OpenRAVE export tags. + for plugin_path in manifest.get_export('openrave', 'plugins'): + plugin_paths = append_to_env('OPENRAVE_PLUGINS', plugin_path) + + for data_path in manifest.get_export('openrave', 'data'): + data_paths = append_to_env('OPENRAVE_DATA', data_path) + + for database_path in manifest.get_export('openrave', 'database'): + database_paths = append_to_env('OPENRAVE_DATABASE', database_path) + + for python_path in manifest.get_export('python', 'path'): + sys.path.append(python_path) + + # Add the appropriate directories to PYTHONPATH. + # TODO: This is a hack. Should I parsing a Python export instead? + sys.path.append(pkg.get_path(package_name) + '/src') + + # now dive into the subpackages + packages = set(packages) + missing_packages = list() + for package in packages: + success, missing = export_paths(pkg, package) + missing_packages.extend(missing) + if not success: + # check if this package is required + if package in required_packages: + return False, missing_packages + + return True, missing_packages + + def export(package_name): + pkg = rospkg.RosPack() + manifest = pkg.get_manifest(package_name) + + # Required dependencies. + success, missing_packages = export_paths(pkg, package_name) + if not success: + raise Exception('Unable to load required dependencies.') + + if missing_packages: + missing_packages.sort() + print 'Missing optional dependencies: %s' % ' '.join(missing_packages) + return missing_packages