Exemple #1
0
def get_ignore_data_helper(basename):
    fn = 'package://roscompile/data/' + basename + '.ignore'
    lines = []
    for s in get(fn).split('\n'):
        if len(s) > 0:
            lines.append(s + '\n')
    return lines
Exemple #2
0
def test_get_large_file():
    res_path = os.path.join(rospack.get_path("resource_retriever"),
                            "test/large_filepy.dat")
    with open(res_path, 'w') as f:
        for _ in range(1024 * 1024 * 50):
            f.write('A')
    res = r.get("package://resource_retriever/test/large_filepy.dat")
    assert len(res) == 1024 * 1024 * 50
Exemple #3
0
def maybe_download_python_deps():
    global PYTHON_DEPS
    if os.path.exists(PY_DEP_FILENAME):
        PYTHON_DEPS = yaml.load(open(PY_DEP_FILENAME))
        if 'last_download' in PYTHON_DEPS:
            now = datetime.datetime.now()
            if now - PYTHON_DEPS['last_download'] < datetime.timedelta(days=3):
                return

    ff = resource_retriever.get('https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml')
    PYTHON_DEPS = yaml.load(ff)
    PYTHON_DEPS['last_download'] = datetime.datetime.now()
    yaml.dump(PYTHON_DEPS, open(PY_DEP_FILENAME, 'w'))
Exemple #4
0
    def getMeshPath(self, input_urdf, link_name):
        # type: (AnyStr, AnyStr) -> AnyStr

        tree = self.parseURDF(input_urdf)
        link_found = False
        filepath = None  # type: AnyStr
        for l in tree.findall('link'):
            if l.attrib['name'] == link_name:
                link_found = True
                m = l.find('visual/geometry/mesh')
                if m is not None:
                    filepath = m.attrib['filename']
                    try:
                        self.mesh_scaling = m.attrib['scale']
                    except KeyError:
                        self.mesh_scaling = '1 1 1'

        if not link_found or m is None:
            #print(Fore.RED + "No mesh information specified for link '{}' in URDF! Using a very large box.".format(link_name) + Fore.RESET)
            filepath = None

        #if path is ros package path, get absolute system path
        if filepath and (filepath.startswith('package')
                         or filepath.startswith('model')):
            try:
                import resource_retriever  #ros package
                r = resource_retriever.get(filepath)
                filepath = r.url.replace('file://', '')
                #r.read() #get file into memory
            except ImportError:
                #if no ros installed, try to get stl files from 'meshes' dir relative to urdf files
                filename = filepath.split('/')
                try:
                    filename = filename[filename.index(self.opt['meshBaseDir']
                                                       ):]
                    filepath = '/'.join(input_urdf.split('/')[:-1] + filename)
                except ValueError:
                    filepath = None

        return filepath
    def getMeshPath(self, input_urdf, link_name):
        import xml.etree.ElementTree as ET
        tree = ET.parse(input_urdf)

        link_found = False
        filepath = None
        for l in tree.findall('link'):
            if l.attrib['name'] == link_name:
                link_found = True
                m = l.find('visual/geometry/mesh')
                if m != None:
                    filepath = m.attrib['filename']
                    try:
                        self.mesh_scaling = m.attrib['scale']
                    except KeyError:
                        self.mesh_scaling = '1 1 1'

        if not link_found or m is None:
            print(Fore.LIGHTRED_EX + "No mesh information specified for {} in URDF! Using approximation.".format(link_name) + Fore.RESET)
            filepath = None
        else:
            if not filepath.lower().endswith('stl'):
                raise ValueError("Can't open other than STL files.")
                # TODO: could use pycollada for *.dae

        #if path is ros package path, get absolute system path
        if filepath and (filepath.startswith('package') or filepath.startswith('model')):
            try:
                import resource_retriever    #ros package
                r = resource_retriever.get(filepath)
                filepath = r.url.replace('file://', '')
                #r.read() #get file into memory
            except ImportError:
                #if no ros installed, try to get stl files from 'meshes' dir relative to urdf files
                filename = filepath.split('/')[-1]
                filepath = '/'.join(input_urdf.split('/')[:-1] + ['meshes'] + [filename])

        return filepath
Exemple #6
0
from collections import defaultdict, OrderedDict
import re
import os.path
from resource_retriever import get
from roscompile.config import CFG

BREAKERS = ['catkin_package']
ALL_CAPS = re.compile('^[A-Z_]+$')
IGNORE_LINES = [s + '\n' for s in get('package://roscompile/data/cmake.ignore').read().split('\n') if len(s)>0]
IGNORE_PATTERNS = [s + '\n' for s in get('package://roscompile/data/cmake_patterns.ignore').read().split('\n') if len(s)>0]

ORDERING = ['cmake_minimum_required', 'project', 'find_package', 'catkin_python_setup', 'add_definitions',
            'add_message_files', 'add_service_files', 'add_action_files', 'generate_dynamic_reconfigure_options',
            'generate_messages', 'catkin_package', 
            ['add_library', 'add_executable', 'target_link_libraries', 'add_dependencies', 'include_directories'],
            'catkin_add_gtest', 'group', 'install']

SHOULD_ALPHABETIZE = ['COMPONENTS', 'DEPENDENCIES', 'FILES', 'CATKIN_DEPENDS']

INSTALL_CONFIGS = {
    'exec':    ('TARGETS', {'${CATKIN_PACKAGE_BIN_DESTINATION}': 'RUNTIME DESTINATION'}),
    'library': ('TARGETS', {'${CATKIN_PACKAGE_LIB_DESTINATION}': ('ARCHIVE DESTINATION', 'LIBRARY DESTINATION'),
                            '${CATKIN_GLOBAL_BIN_DESTINATION}':  'RUNTIME DESTINATION'}),
    'headers': ('FILES',   {'${CATKIN_PACKAGE_INCLUDE_DESTINATION}': 'DESTINATION'}),
    'misc':    ('FILES',   {'${CATKIN_PACKAGE_SHARE_DESTINATION}':   'DESTINATION'})
    }

def get_ordering_index(cmd):
    for i, o in enumerate(ORDERING):
        if type(o)==list:
            if cmd in o:
Exemple #7
0
    def add_footprint(self, topic, color=(0,170,255)):
        self.add_display('Robot Footprint', 'rviz/Polygon', topic, color)
        
    def add_path(self, topic, name, color=None):
        self.add_display(name, 'rviz/Path', topic, color)

    def add_pose(self, topic):
        self.add_display('Current Goal', 'rviz/Pose', topic)
        
    def set_goal(self, topic):
        self.set_tool_topic('rviz/SetGoal', topic)
        
    def write(self, f):
        f.write(yaml.dump( self.data, default_flow_style=False))

r = RVizConfig(get('package://navigation_config/config/base.rviz'))
if rospy.has_param('/robot_description'):
    r.add_model()
    
c = Configuration()    
for topic, name in c.maps.iteritems():
    r.add_map(topic, name)

for l in c.laser_scans():
    r.add_laserscan(l)

for topic, name in c.paths.items():
    r.add_path(topic, name)
    
if c.goal:
    r.add_pose(c.goal)
def process_vehicles(vehicles, datapath):
    '''
    Looks for the vehicle file in datapath
    Resolves corresponding urdf or xacro 
        - convention: uwsim urdf files come from Gazebo urdf files
        - XXX.urdf or XXX.xacro -> XXX_uwsim.urdf
    Creates Gazebo spawner with namespace
    '''
    vehicle_nodes = []
    for vehicle in vehicles:
        name = vehicle.findtext('name')
        uwsim_urdf_file = vehicle.findtext('file')
        # get to Gazebo xacro/urdf file
        gazebo_model_file, datadir = uwsim_to_abspath(uwsim_urdf_file.replace('_uwsim.urdf','.xacro'), datapath)
        if datadir == '':
            gazebo_model_file, datadir = uwsim_to_abspath(uwsim_urdf_file.replace('_uwsim',''), datapath)            
        if datadir == '':
            rospy.loginfo('Could not find original file for ' + uwsim_urdf_file + ' in ' + scene_file)
            sys.exit(1)
        uwsim_urdf_file = gazebo_model_file.replace('.urdf', '_uwsim.urdf').replace('.xacro', '_uwsim.urdf')
            
        # parse Gazebo file (urdf or xacro)
        if 'xacro' in gazebo_model_file:
            uwsim_urdf_xml = subprocess.Popen(['rosrun', 'xacro', 'xacro', gazebo_model_file], stdout=subprocess.PIPE)
            uwsim_urdf_xml = etree.fromstring(uwsim_urdf_xml.stdout.read())
         #   uwsim_urdf_xml = xacro.parse(gazebo_model_file)
         #   xacro.eval_self_contained(uwsim_urdf_xml)
         #   uwsim_urdf_xml = etree.fromstring(uwsim_urdf_xml.toxml())
        else:
            uwsim_urdf_xml = etree.parse(gazebo_model_file).getroot()

        # clean up URDF: keep only joints and links
        for child in uwsim_urdf_xml.getchildren():
            if child.tag not in ('joint', 'link'):
                uwsim_urdf_xml.remove(child)
        # and remove collision / inertial / buoyancy from links
        to_be_removed = ('collision', 'inertial', 'buoyancy')
        for link in uwsim_urdf_xml.findall('link'):
            for tag in to_be_removed:
                for node in link.findall(tag):
                    link.remove(node)
        # change mesh url-filenames to uwsim relative filenames
        meshes = uwsim_urdf_xml.findall('link/visual/geometry/mesh')
        if len(meshes) != 0:
            # create uwsim urdf only if mesh in gazebo urdf, otherwise trust the user 
            for mesh in meshes:
                mesh_file = resource_retriever.get(substitution_args.resolve_args(mesh.get('filename'))).url[7:]
                # get uwsim relative path for mesh
                mesh_file, datadir = abspath_to_uwsim(mesh_file, datapath)
                # if mesh in dae, try to find corresponding osg
                if '.dae' in mesh_file:
                    mesh_osg, datadir_osg = uwsim_to_abspath(mesh_file.replace('.dae','.osg'), datapath)
                    if datadir_osg != '':
                        mesh_file, datadir = abspath_to_uwsim(mesh_osg, datapath)
                if datadir == '':
                    rospy.loginfo('Could not find relative path for ' + mesh_file + ' in ' + gazebo_model_file)
                    sys.exit(1)
                else:
                    if os.path.lexists(datadir + '/' + os.path.splitext(mesh_file)[0] + '.osg'):
                        mesh_file = mesh_file.split('.')[0] + '.osg'
                    mesh.set('filename', mesh_file)
            # write uwsim urdf
            insert_header_and_write(uwsim_urdf_xml, gazebo_model_file, uwsim_urdf_file)
        # get nodes to write in gazebo spawner
        vehicle_nodes.append(create_spawner(vehicle, gazebo_model_file))
              
    return vehicle_nodes
from  xml.dom.minidom import parse
from resource_retriever import get
from roscompile.config import CFG
import operator, collections

IGNORE_PACKAGES = ['roslib']
IGNORE_LINES = [s + '\n' for s in get('package://roscompile/data/package.ignore').read().split('\n') if len(s)>0]

ORDERING = ['name', 'version', 'description', 
            ['maintainer', 'license', 'author', 'url'],
            'buildtool_depend', 'build_depend', 'run_depend', 'test_depend', 
            'export']

def get_ordering_index(name):
    for i, o in enumerate(ORDERING):
        if type(o)==list:
            if name in o:
                return i
        elif name==o:
            return i
    if name:        
        print '\tUnsure of ordering for', name
    return len(ORDERING)                

def get_sort_key(node, alphabetize_depends=True):
    if node:
        name = node.nodeName
    else:
        name = None
    
    index = get_ordering_index(name)
        usage=show_usage(),
        epilog=show_epilog(),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('-o',
                        '--option',
                        type=str,
                        default='eof',
                        help='dont care')
    parsed_known_args, unknown_args = parser.parse_known_args(sys.argv[1:])
    print(parsed_known_args)
    usp = None
    try:
        l = rosparam.list_params('')
        models = []
        for p in l:
            v = rosparam.get_param(p)
            if type(v) is str and len(v) > 10000:
                models.append(p)
        r = create_robot_model(get('package://dsr_launcher/rviz/default.rviz'))
        for m in models:
            r.add_model(m, m[0:-18])
        temp = tempfile.NamedTemporaryFile()
        r.write(temp)
        temp.flush()
        args = ['rosrun', 'rviz', 'rviz', '-d', temp.name]
        usp = subprocess.call(args)
        temp.close()
    except KeyboardInterrupt:
        print("Interrupted by user, shutting down...")
Exemple #11
0
def test_invalid_file():
    r.get("file://fail")
Exemple #12
0
def test_http():
    res = r.get("http://packages.ros.org/ros.key")
    assert len(res) > 0
        epilog=show_epilog(),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('-o',
                        '--option',
                        type=str,
                        default='eof',
                        help='dont care')
    parsed_known_args, unknown_args = parser.parse_known_args(sys.argv[1:])
    print(parsed_known_args)
    usp = None
    try:
        l = rosparam.list_params('')
        models = []
        for p in l:
            v = rosparam.get_param(p)
            if type(v) is str and len(v) > 10000:
                models.append(p)
        r = create_robot_model(
            get('package://dsr_launcher/rviz/default_melodic.rviz'))
        for m in models:
            r.add_model(m, m[0:-18])
        temp = tempfile.NamedTemporaryFile()
        r.write(temp)
        temp.flush()
        args = ['rosrun', 'rviz', 'rviz', '-d', temp.name]
        usp = subprocess.call(args)
        temp.close()
    except KeyboardInterrupt:
        print("Interrupted by user, shutting down...")
Exemple #14
0
        epilog=show_epilog(),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('-o',
                        '--option',
                        type=str,
                        default='eof',
                        help='dont care')
    parsed_known_args, unknown_args = parser.parse_known_args(sys.argv[1:])
    print(parsed_known_args)
    usp = None
    try:
        l = rosparam.list_params('')
        models = []
        for p in l:
            v = rosparam.get_param(p)
            if type(v) is str and len(v) > 10000:
                models.append(p)
        r = create_robot_model(
            get('package://dsr_launcher/rviz/default_noetic.rviz'))
        for m in models:
            r.add_model(m, "")
            #r.add_model(m, m[0:-18])
        temp = tempfile.NamedTemporaryFile()
        r.write(temp)
        temp.flush()
        args = ['rosrun', 'rviz', 'rviz', '-d', temp.name]
        usp = subprocess.call(args)
        temp.close()
    except KeyboardInterrupt:
        print("Interrupted by user, shutting down...")
Exemple #15
0
def test_get_by_package():
    res = r.get("package://resource_retriever/test/test.txt")
    assert len(res) == 1
    assert res == 'A'.encode()
Exemple #16
0
def test_invalid_package():
    r.get("package://invalid_package_blah/test.xml")
Exemple #17
0
def test_no_file():
    r.get("package://roscpp")
def process_vehicles(vehicles, datapath):
    '''
    Looks for the vehicle file in datapath
    Resolves corresponding urdf or xacro 
        - convention: uwsim urdf files come from Gazebo urdf files
        - XXX.urdf or XXX.xacro -> XXX_uwsim.urdf
    Creates Gazebo spawner with namespace
    '''
    vehicle_nodes = []
    for vehicle in vehicles:
        name = vehicle.findtext('name')
        uwsim_urdf_file = vehicle.findtext('file')
        # get to Gazebo xacro/urdf file
        gazebo_model_file, datadir = uwsim_to_abspath(uwsim_urdf_file.replace('_uwsim.urdf','.xacro'), datapath)
        if datadir == '':
            gazebo_model_file, datadir = uwsim_to_abspath(uwsim_urdf_file.replace('_uwsim',''), datapath)            
        if datadir == '':
            rospy.loginfo('Could not find original file for ' + uwsim_urdf_file + ' in ' + scene_file)
            sys.exit(1)
        uwsim_urdf_file = gazebo_model_file.replace('.urdf', '_uwsim.urdf').replace('.xacro', '_uwsim.urdf')
            
        # parse Gazebo file (urdf or xacro)
        if 'xacro' in gazebo_model_file:
            uwsim_urdf_xml = subprocess.Popen(['rosrun', 'xacro', 'xacro', gazebo_model_file], stdout=subprocess.PIPE)
            uwsim_urdf_xml = etree.fromstring(uwsim_urdf_xml.stdout.read())
         #   uwsim_urdf_xml = xacro.parse(gazebo_model_file)
         #   xacro.eval_self_contained(uwsim_urdf_xml)
         #   uwsim_urdf_xml = etree.fromstring(uwsim_urdf_xml.toxml())
        else:
            uwsim_urdf_xml = etree.parse(gazebo_model_file).getroot()

        # clean up URDF: keep only joints and links
        for child in uwsim_urdf_xml.getchildren():
            if child.tag not in ('joint', 'link'):
                uwsim_urdf_xml.remove(child)
        # and remove collision / inertial / buoyancy from links
        to_be_removed = ('collision', 'inertial', 'buoyancy')
        for link in uwsim_urdf_xml.findall('link'):
            for tag in to_be_removed:
                for node in link.findall(tag):
                    link.remove(node)
        # change mesh url-filenames to uwsim relative filenames
        meshes = uwsim_urdf_xml.findall('link/visual/geometry/mesh')
        if len(meshes) != 0:
            # create uwsim urdf only if mesh in gazebo urdf, otherwise trust the user 
            for mesh in meshes:
                mesh_file = resource_retriever.get(substitution_args.resolve_args(mesh.get('filename'))).url[7:]
                # get uwsim relative path for mesh
                mesh_file, datadir = abspath_to_uwsim(mesh_file, datapath)
                # if mesh in dae, try to find corresponding osg
                if '.dae' in mesh_file:
                    mesh_osg, datadir_osg = uwsim_to_abspath(mesh_file.replace('.dae','.osg'), datapath)
                    if datadir_osg != '':
                        mesh_file, datadir = abspath_to_uwsim(mesh_osg, datapath)
                if datadir == '':
                    rospy.loginfo('Could not find relative path for ' + mesh_file + ' in ' + gazebo_model_file)
                    sys.exit(1)
                else:
                    if os.path.lexists(datadir + '/' + os.path.splitext(mesh_file)[0] + '.osg'):
                        mesh_file = mesh_file.split('.')[0] + '.osg'
                    mesh.set('filename', mesh_file)
            # write uwsim urdf
            insert_header_and_write(uwsim_urdf_xml, gazebo_model_file, uwsim_urdf_file)
        # get nodes to write in gazebo spawner
        vehicle_nodes.append(create_spawner(vehicle, gazebo_model_file))
              
    return vehicle_nodes
Exemple #19
0
        self.add_display('Robot Footprint', 'rviz/Polygon', topic, color)

    def add_path(self, topic, name, color=None):
        self.add_display(name, 'rviz/Path', topic, color)

    def add_pose(self, topic):
        self.add_display('Current Goal', 'rviz/Pose', topic)

    def set_goal(self, topic):
        self.set_tool_topic('rviz/SetGoal', topic)

    def write(self, f):
        f.write(yaml.dump(self.data, default_flow_style=False))


r = RVizConfig(get('package://navigation_config/config/base.rviz'))
if rospy.has_param('/robot_description'):
    r.add_model()

c = Configuration()
for topic, name in c.maps.iteritems():
    r.add_map(topic, name)

for l in c.laser_scans():
    r.add_laserscan(l)

for topic, name in c.paths.items():
    r.add_path(topic, name)

if c.goal:
    r.add_pose(c.goal)