diff --git a/phobos/ci/model_testing.py b/phobos/ci/model_testing.py index 9b399f12..f38b3902 100644 --- a/phobos/ci/model_testing.py +++ b/phobos/ci/model_testing.py @@ -25,15 +25,15 @@ def __init__(self, new_model, compare_model=None): self.old_hyrodyn = None self.new_hml_test = get_load_report(self.new.robot.xmlfile, self.new.robot.submechanisms_file) self.new_sm_hml_test = [] - if len([x for x in self.new.robot.submodel_defs if not x["name"].startswith("#submech#")]) > 0: + if len([x for x in self.new.robot.submodel_defs if not x.startswith("#submech#")]) > 0: sm_path = os.path.join(self.new.exportdir, "submodels") for au in self.new.robot.submodel_defs: - if au["name"].startswith("#submech#"): + if au.startswith("#submech#"): continue self.new_sm_hml_test += [{ - "name": au["name"], - "urdf": os.path.join(sm_path, au["name"], "urdf", au["name"] + ".urdf"), - "submech": os.path.normpath(os.path.join(sm_path, au["name"], "smurf", au["name"] + "_submechanisms.yml")) + "name": au, + "urdf": os.path.join(sm_path, au, "urdf", au + ".urdf"), + "submech": os.path.normpath(os.path.join(sm_path, au, "smurf", au + "_submechanisms.yml")) }] self.new_sm_hml_test[-1]["report"] = get_load_report( self.new_sm_hml_test[-1]["urdf"], @@ -267,10 +267,11 @@ def test_compare_amount_joints(self): return len(self.new.robot.joints) == len(self.old.joints) def test_load_in_pybullet(self): - if not PYBULLET_AVAILABLE: + if not check_pybullet_available(): log.warning('Pybullet not present') return True try: + import pybullet as pb client = pb.connect(pb.DIRECT) pb.loadURDF(os.path.join(self.new.robot.xmlfile), physicsClientId=client) pb.disconnect(client) diff --git a/phobos/core/robot.py b/phobos/core/robot.py index 3b4f0096..975cd0bb 100755 --- a/phobos/core/robot.py +++ b/phobos/core/robot.py @@ -258,7 +258,8 @@ def export_xml(self, outputdir=None, format="urdf", filename=None, float_fmt_dic def export_smurf(self, outputdir=None, outputfile=None, robotfile=None, check_submechs=True, with_submodel_defs=False, - with_meshes=True, mesh_format=None, additional_meshes=None, rel_mesh_pathes=None): + with_meshes=True, mesh_format=None, additional_meshes=None, rel_mesh_pathes=None, + submodels=None): """ Export self and all annotations inside a given folder with structure """ assert self.check_linkage() @@ -355,9 +356,14 @@ def export_smurf(self, outputdir=None, outputfile=None, robotfile=None, # submodel list if with_submodel_defs and len(self.submodel_defs) > 0: out_submodel_defs = {} - for name, definition in self.submodel_defs.items(): - out_submodel_defs[name] = deepcopy(definition) - out_submodel_defs[name]["export_dir"] = os.path.relpath(out_submodel_defs[name]["export_dir"], smurf_dir) + if submodels is not None: + for name in submodels: + out_submodel_defs[name] = deepcopy(self.submodel_defs[name]) + out_submodel_defs[name]["export_dir"] = os.path.relpath(out_submodel_defs[name]["export_dir"], smurf_dir) + else: + for name, definition in self.submodel_defs.items(): + out_submodel_defs[name] = deepcopy(definition) + out_submodel_defs[name]["export_dir"] = os.path.relpath(out_submodel_defs[name]["export_dir"], smurf_dir) with open(os.path.join(smurf_dir, "{}_submodels.yml".format(self.name.replace('/','_'))), "w+") as stream: stream.write(dump_json({"submodels": out_submodel_defs}, default_style=False)) export_files.append(os.path.split(stream.name)[-1]) @@ -722,7 +728,7 @@ def export(self, outputdir, export_config=None, rel_mesh_pathes=None, ros_pkg_na name=export["name"], start=export.get("start", None), stop=export.get("stop", None), - include_unstopped_branches=export.get("include_unstopped_branches", None), + include_unstopped_branches=export.get("include_unstopped_branches", False), no_submechanisms=export.get("no_submechanisms", False), abstract_model=export.get("abstract_model", False), remove_fixed=export.get("remove_fixed", False), @@ -785,7 +791,8 @@ def export(self, outputdir, export_config=None, rel_mesh_pathes=None, ros_pkg_na robotfile=xml_file_in_smurf, check_submechs=check_submechs, with_submodel_defs=True, - with_meshes=False # has been done before + with_meshes=False, # has been done before + submodels=[filtered_item['name'] for filtered_item in filter(lambda item: item["type"] == "submodel", export_config)] ) # export ros package files if ros_pkg and not ros_pkg_later: diff --git a/phobos/io/xmlrobot.py b/phobos/io/xmlrobot.py index fb70c9dc..32d80e6a 100644 --- a/phobos/io/xmlrobot.py +++ b/phobos/io/xmlrobot.py @@ -27,7 +27,8 @@ def __init__(self, name=None, version=None, links: List[representation.Link] = N materials: List[representation.Material] = None, transmissions: List[representation.Transmission] = None, sensors=None, motors=None, plugins=None, root=None, - is_human=False, urdf_version=None, xmlfile=None, _xmlfile=None): + is_human=False, urdf_version=None, xmlfile=None, _xmlfile=None, + sensors_that_dont_belong_to_links_or_joints=None): self._related_robot_instance = self super().__init__() self.joints = [] @@ -65,10 +66,13 @@ def __init__(self, name=None, version=None, links: List[representation.Link] = N self.materials = materials if materials is not None else [] self.transmissions = transmissions if transmissions is not None else [] self.sensors = sensors if sensors is not None else [] + if sensors_that_dont_belong_to_links_or_joints is not None: + self.sensors_that_dont_belong_to_links_or_joints = sensors_that_dont_belong_to_links_or_joints self.motors = motors if motors is not None else [] if plugins is not None: self.motors += [m for m in _plural(plugins) if isinstance(m, representation.Motor)] + if is_human: self.annotate_as_human()