Exemplo n.º 1
0
def build_single_xacro_file(input_path, output_path):
    try:
        # open and process file
        doc = process_file(input_path)
        # open the output file
        out = open_output(output_path)

    except xml.parsers.expat.ExpatError as e:
        error("XML parsing error: %s" % unicode(e), alt_text=None)
        sys.exit(2) 

    except Exception as e:
        msg = unicode(e)
        if not msg: msg = repr(e)
        error(msg)
        sys.exit(2)  # gracefully exit with error condition

    # write output
    out.write(doc.toprettyxml(indent='  ', **encoding))
    # only close output file, but not stdout
    out.close()



        
Exemplo n.º 2
0
def to_urdf(xacro_path, urdf_path=None):
    # If no URDF path is given, use a temporary file
    if urdf_path is None:
        urdf_path = tempfile.mktemp(prefix='%s_' % os.path.basename(xacro_path))

    # open and process file
    doc = xacro.process_file(xacro_path)
    # open the output file
    print(urdf_path)
    out = xacro.open_output(urdf_path)
    out.write(doc.toprettyxml(indent='  '))

    return urdf_path  # Return path to the urdf file
Exemplo n.º 3
0
def to_urdf(xacro_path, parameters=None):
    """Convert the given xacro file to URDF file.
    * xacro_path -- the path to the xacro file
    * parameters -- to be used when xacro file is parsed.
    """
    urdf_path = tempfile.mktemp(prefix="%s_" % os.path.basename(xacro_path))

    # open and process file
    doc = xacro.process_file(xacro_path, mappings=parameters)
    # open the output file
    out = xacro.open_output(urdf_path)
    out.write(doc.toprettyxml(indent='  '))

    return urdf_path
Exemplo n.º 4
0
 def test_urdf_turtlebot(self):
     """
     Check if check_urdf command passes with the urdf that is generated in
     the .test file this test case is called from.
     """
     resulted_urdf_file_relpath = "./sample_kobuki.urdf"
     kobuki_xacro_file_path = rospkg.RosPack().get_path(
         'openni_description') + "/test/sample_kobuki.urdf.xacro"
     self.assertTrue(os.path.isfile(kobuki_xacro_file_path))
     xacro_output_memory = xacro.process_file(kobuki_xacro_file_path)
     xacro_output_file = xacro.open_output(resulted_urdf_file_relpath)
     xacro_output_file.write(xacro_output_memory.toprettyxml(indent='  '))
     xacro_output_file.close()
     self.assertTrue(os.path.isfile(resulted_urdf_file_relpath))
     self.assertEqual(
         0, subprocess.call(["check_urdf", resulted_urdf_file_relpath]))
def to_urdf(xacro_path, urdf_path=None):
    """Convert the given xacro file to URDF file.
    * xacro_path -- the path to the xacro file
    * urdf_path -- the path to the urdf file
    """
    # If no URDF path is given, use a temporary file
    if urdf_path is None:
        urdf_path = tempfile.mktemp(prefix="%s_" % os.path.basename(xacro_path))

    # open and process file
    doc = xacro.process_file(xacro_path)
    # open the output file
    out = xacro.open_output(urdf_path)
    out.write(doc.toprettyxml(indent='  '))

    return urdf_path  # Return path to the urdf file
Exemplo n.º 6
0
def to_urdf(xacro_path, urdf_path=None, mappings={}):
    """Convert the given xacro file to URDF file.

    * xacro_path -- the path to the xacro file
    * urdf_path -- the path to the urdf file
    """
    # If no URDF path is given, use a temporary file
    if urdf_path is None:
        urdf_path = tempfile.mktemp(prefix='%s_' %
                                    os.path.basename(xacro_path))

    # open and process file
    doc = xacro.process_file(xacro_path, mappings=mappings)
    # open the output file
    out = xacro.open_output(urdf_path)
    out.write(doc.toprettyxml(indent='  '))

    robot_desc = launch.substitutions.Command('xacro %s' % xacro_path)

    return urdf_path, robot_desc  # Return robot description
Exemplo n.º 7
0
AUTHOR_EMAILS = [author.attrib['email'] for author in AUTHORS]

DATA_FILES = [(f'share/{PACKAGE_NAME}', ['package.xml']),
              ('share/ament_index/resource_index/packages/', [f'resources/{PACKAGE_NAME}'])]
DATA_FILES += [(os.path.join('share', PACKAGE_NAME, str(directory)),
                [str(file) for file in directory.rglob(pattern) if not file.is_dir() and file.parent == directory])
               for folder, pattern in SHARE_DIRS for directory in Path(folder).rglob('**')]

BUILD_DIR = next((sys.argv[i + 1] for i, arg in enumerate(sys.argv) if arg == '--build-directory'), None)
if BUILD_DIR:
    os.makedirs(BUILD_DIR, exist_ok=True)
    for path, files in DATA_FILES:
        for file in files:
            if file.endswith('.xacro'):
                new_file = os.path.join(BUILD_DIR, file.replace('.xacro', ''))
                with xacro.open_output(new_file) as fd:
                    fd.write(xacro.process(file))
                files.remove(file)
                files.append(new_file)

INSTALL_REQUIRES = ['setuptools']
if os.path.isfile('requirements.txt'):
    with open('requirements.txt') as file:
        INSTALL_REQUIRES += [line.strip() for line in file.readlines()]

TESTS_REQUIRE = ['pytest']
if os.path.isfile('test-requirements.txt'):
    with open('test-requirements.txt') as file:
        TESTS_REQUIRE += [line.strip() for line in file.readlines()]

setup(