-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OSError when creating RobotModel
#21
Comments
Try to modify: with: def get_xml_string(path: str | pathlib.Path):
isPath = isinstance(path, pathlib.Path)
isUrdf = False
# Checking if it is a path or an urdf
try:
from ctypes.wintypes import MAX_PATH
except ValueError:
MAX_PATH = os.pathconf("/", "PC_PATH_MAX")
if not isPath:
if len(path) <= MAX_PATH and os.path.exists(path):
path = pathlib.Path(path)
isPath = True
else:
root = ET.fromstring(path)
for elem in root.iter():
if elem.tag == "robot":
xml_string = path
isUrdf = True
elif path.exists():
isPath = True
if not (isPath) and not (isUrdf):
raise ValueError(
f"Invalid urdf string: {path}. It is neither a path nor a urdf string"
)
if isPath:
if not (path.exists()):
raise FileExistsError(path)
path = pathlib.Path(path)
with open(path, "r") as xml_file:
xml_string = xml_file.read()
xml_file.close()
return xml_string If it works, I'll open a PR to |
Thanks a lot @flferretti! It worked like a charm 👌🏻 ✨ I was not able to complete the run of the notebook for some other downstream errors, but this patch fixes that exception. |
Every notebook is failing with the same error: Error Log -- Before the Fix
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
Cell In[6], line 5
3 urdf_robot_string = create_urdf_instance.write_urdf_to_file()
4 create_urdf_instance.reset_modifications()
----> 5 robot_model_init = RobotModel(urdf_robot_string, "stickBot", joint_name_list)
6 s_des, xyz_rpy, H_b = robot_model_init.compute_desired_position_walking()
7 robot_model_init.set_foot_corner(np.asarray([0.1, 0.05, 0.0]),np.asarray([0.1, -0.05, 0.0]),np.asarray([-0.1, -0.05, 0.0]),np.asarray([-0.1, 0.05, 0.0]))
File ~/git/comodo/src/comodo/robotModel/robotModel.py:64, in RobotModel.__init__(self, urdfstring, robot_name, joint_name_list, base_link, left_foot, right_foot, torso, right_foot_rear_link_name, right_foot_front_link_name, left_foot_rear_link_name, left_foot_front_link_name, kp_pos_control, kd_pos_control)
62 self.gravity.setVal(2, -9.81)
63 self.H_b = iDynTree.Transform()
---> 64 super().__init__(urdfstring, self.joint_name_list, self.base_link)
65 self.H_left_foot = self.forward_kinematics_fun(self.left_foot_frame)
66 self.H_right_foot = self.forward_kinematics_fun(self.right_foot_frame)
File ~/git/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:35, in KinDynComputations.__init__(self, urdfstring, joints_name_list, root_link, gravity, f_opts)
28 """
29 Args:
30 urdfstring (str): path of the urdf
31 joints_name_list (list): list of the actuated joints
32 root_link (str, optional): the first link. Defaults to 'root_link'.
33 """
34 math = SpatialMath()
---> 35 factory = URDFModelFactory(path=urdfstring, math=math)
36 model = Model.build(factory=factory, joints_name_list=joints_name_list)
37 self.rbdalgos = RBDAlgorithms(model=model, math=math)
File ~/git/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:37, in URDFModelFactory.__init__(self, path, math)
35 if type(path) is not pathlib.Path:
36 path = pathlib.Path(path)
---> 37 if not path.exists():
38 raise FileExistsError(path)
40 # Read URDF, but before passing it to urdf_parser_py get rid of all sensor tags
41 # sensor tags are valid elements of URDF (see ),
42 # but they are ignored by urdf_parser_py, that complains every time it sees one.
(...)
45 # that anyhow are not parser by urdf_parser_py or adam
46 # See https://github.com/ami-iit/ADAM/issues/59
File ~/git/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1290, in Path.exists(self)
1286 """
1287 Whether this path exists.
1288 """
1289 try:
-> 1290 self.stat()
1291 except OSError as e:
1292 if not _ignore_error(e):
File ~/git/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1097, in Path.stat(self, follow_symlinks)
1092 def stat(self, *, follow_symlinks=True):
1093 """
1094 Return the result of the stat() system call on this path, like
1095 os.stat() does.
1096 """
-> 1097 return self._accessor.stat(self, follow_symlinks=follow_symlinks)
OSError: [Errno 36] File name too long: ' \n<robot name="stickBot">\n <link name="root_link">\n <inertial>\n
# [...] After the fix in ami-iit/adam@2f2b8d2 the error is solved. |
I had the same problem last week on my setup when I first attempted to run code from #20, but then I postponed since there were still comodo-related problems to fix first on that PR. Thanks @flferretti for proposing the fix in ADAM. |
I'm testing the example notebook introduced in #20 on a Ubuntu server (
Ubuntu 22.04.5 LTS
) and there my notebook fails at the following line:with the following traceback:
The error seems to be coming from adam. There I'm using version
0.3.0
from conda-forge.Note: I'm not getting this error on my machine (
Ubuntu 24.04.1 LTS
)CC @flferretti @CarlottaSartore @Giulero
The text was updated successfully, but these errors were encountered: