Skip to content

Commit

Permalink
black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlottaSartore committed Jun 10, 2024
1 parent c2a8fc2 commit 4e10ef4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/adam/model/std_factories/std_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class URDFModelFactory(ModelFactory):
Args:
ModelFactory: the Model factory
"""
#TODO: path can be either a path and an urdf-string, leaving path for back compatibility, to be changed to meaningfull name

# TODO: path can be either a path and an urdf-string, leaving path for back compatibility, to be changed to meaningfull name
def __init__(self, path: str, math: SpatialMath):
self.math = math
isPath = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def compute_volume(self, length_multiplier):
volume = math.pi * visual_data_new[1] ** 2 * visual_data_new[0]
elif self.geometry_type == Geometry.SPHERE:
visual_data_new = self.visual_data.radius * length_multiplier
volume = 4 * math.pi * visual_data_new ** 3 / 3
volume = 4 * math.pi * visual_data_new**3 / 3
return volume, visual_data_new

def compute_mass(self):
Expand Down Expand Up @@ -235,7 +235,7 @@ def compute_inertia_parametric(self):
I.izz = I.iyy
return I
elif self.geometry_type == Geometry.SPHERE:
I.ixx = 2 * self.mass * self.visual_data_new ** 2 / 5
I.ixx = 2 * self.mass * self.visual_data_new**2 / 5
I.iyy = I.ixx
I.izz = I.ixx
return I
Expand Down
37 changes: 30 additions & 7 deletions src/adam/parametric/model/parametric_factories/parametric_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class URDFParametricModelFactory(ModelFactory):
ModelFactory: the Model factory
"""

# TODO: path can be either a path and an urdf-string, leaving path for back compatibility, to be changed to meaningfull name
def __init__(
self,
path: str,
Expand All @@ -24,10 +25,35 @@ def __init__(
densities,
):
self.math = math
if type(path) is not pathlib.Path:
path = pathlib.Path(path)
if not path.exists():
raise FileExistsError(path)
isPath = False
isUrdf = False
# Checking if it is a path or an urdf
if type(urdf_string) is not (pathlib.Path):
if os.path.exists(urdf_string):
urdf_string = pathlib.Path(urdf_string)
isPath = True
else:
root = ET.fromstring(urdf_string)
robot_el = None
for elem in root.iter():
if elem.tag == "robot":
xml_string = urdf_string
isUrdf = True
elif urdf_string.exists():
isPath = True

if not (isPath) and not (isUrdf):
raise ValueError(
f"Invalid urdf string: {urdf_string}. It is neither a path nor a urdf string"
)

if isPath:
if not (urdf_string.exists()):
raise FileExistsError(path)
urdf_string = pathlib.Path(urdf_string)
xml_file = open(urdf_string, "r")
xml_string = xml_file.read()
xml_file.close()
self.links_name_list = links_name_list

# Read URDF, but before passing it to urdf_parser_py get rid of all sensor tags
Expand All @@ -37,9 +63,6 @@ def __init__(
# to have a useless and noisy warning, let's remove before hands all the sensor elements,
# that anyhow are not parser by urdf_parser_py or adam
# See https://github.com/ami-iit/ADAM/issues/59
xml_file = open(path, "r")
xml_string = xml_file.read()
xml_file.close()
xml_string_without_sensors_tags = urdf_remove_sensors_tags(xml_string)

self.urdf_desc = urdf_parser_py.urdf.URDF.from_xml_string(
Expand Down

0 comments on commit 4e10ef4

Please sign in to comment.