Skip to content
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

Closed
xela-95 opened this issue Oct 11, 2024 · 4 comments · Fixed by ami-iit/adam#100
Closed

OSError when creating RobotModel #21

xela-95 opened this issue Oct 11, 2024 · 4 comments · Fixed by ami-iit/adam#100
Labels
bug Something isn't working

Comments

@xela-95
Copy link
Member

xela-95 commented Oct 11, 2024

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:

robot_model_init = RobotModel(urdf_robot_string, "stickBot", joint_names)

with the following traceback:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[2], [line 42](vscode-notebook-cell:?execution_count=2&line=42)
     [18](vscode-notebook-cell:?execution_count=2&line=18) joint_names = [
     [19](vscode-notebook-cell:?execution_count=2&line=19)     "r_shoulder_pitch",  # 0
     [20](vscode-notebook-cell:?execution_count=2&line=20)     "r_shoulder_roll",  # 1
   (...)
     [38](vscode-notebook-cell:?execution_count=2&line=38)     "l_ankle_roll",  # 19
     [39](vscode-notebook-cell:?execution_count=2&line=39) ]
     [41](vscode-notebook-cell:?execution_count=2&line=41) urdf_robot_string = create_urdf_instance.write_urdf_to_file()
---> [42](vscode-notebook-cell:?execution_count=2&line=42) robot_model_init = RobotModel(urdf_robot_string, "stickBot", joint_names)

File ~/repos/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](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/src/comodo/robotModel/robotModel.py:62) self.gravity.setVal(2, -9.81)
     [63](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/src/comodo/robotModel/robotModel.py:63) self.H_b = iDynTree.Transform()
---> [64](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/src/comodo/robotModel/robotModel.py:64) super().__init__(urdfstring, self.joint_name_list, self.base_link)
     [65](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/src/comodo/robotModel/robotModel.py:65) self.H_left_foot = self.forward_kinematics_fun(self.left_foot_frame)
     [66](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/src/comodo/robotModel/robotModel.py:66) self.H_right_foot = self.forward_kinematics_fun(self.right_foot_frame)

File ~/repos/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](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:28) """
     [29](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:29) Args:
     [30](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:30)     urdfstring (str): path of the urdf
     [31](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:31)     joints_name_list (list): list of the actuated joints
     [32](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:32)     root_link (str, optional): the first link. Defaults to 'root_link'.
     [33](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:33) """
     [34](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:34) math = SpatialMath()
---> [35](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:35) factory = URDFModelFactory(path=urdfstring, math=math)
     [36](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:36) model = Model.build(factory=factory, joints_name_list=joints_name_list)
     [37](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/casadi/computations.py:37) self.rbdalgos = RBDAlgorithms(model=model, math=math)

File ~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:37, in URDFModelFactory.__init__(self, path, math)
     [35](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:35) if type(path) is not pathlib.Path:
     [36](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:36)     path = pathlib.Path(path)
---> [37](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:37) if not path.exists():
     [38](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:38)     raise FileExistsError(path)
     [40](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:40) # Read URDF, but before passing it to urdf_parser_py get rid of all sensor tags
     [41](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:41) # sensor tags are valid elements of URDF (see ),
     [42](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:42) # but they are ignored by urdf_parser_py, that complains every time it sees one.
   (...)
     [45](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:45) # that anyhow are not parser by urdf_parser_py or adam
     [46](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/site-packages/adam/model/std_factories/std_model.py:46) # See https://github.com/ami-iit/ADAM/issues/59

File ~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1290, in Path.exists(self)
   [1286](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1286) """
   [1287](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1287) Whether this path exists.
   [1288](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1288) """
   [1289](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1289) try:
-> [1290](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1290)     self.stat()
   [1291](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1291) except OSError as e:
   [1292](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1292)     if not _ignore_error(e):

File ~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1097, in Path.stat(self, follow_symlinks)
   [1092](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1092) def stat(self, *, follow_symlinks=True):
   [1093](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1093)     """
   [1094](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1094)     Return the result of the stat() system call on this path, like
   [1095](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1095)     os.stat() does.
   [1096](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1096)     """
-> [1097](https://vscode-remote+ssh-002dremote-002biitbmp014srv002-002eiit-002elocal.vscode-resource.vscode-cdn.net/home/acroci-iit.local/repos/comodo/examples/~/repos/comodo/.pixi/envs/default/lib/python3.10/pathlib.py:1097)     return self._accessor.stat(self, follow_symlinks=follow_symlinks)

OSError: [Errno 36] File name too long: '  \n<robot name="stickBot <OMITTED>

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

@xela-95 xela-95 added the bug Something isn't working label Oct 11, 2024
@flferretti
Copy link
Contributor

flferretti commented Oct 11, 2024

Try to modify:

https://github.com/ami-iit/adam/blob/7c855ca5466e385caae188d50b964ef34fb4b089/src/adam/model/std_factories/std_model.py#L30-L56

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 adam

@xela-95
Copy link
Member Author

xela-95 commented Oct 11, 2024

If it works, I'll open a PR to adam

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.

@flferretti
Copy link
Contributor

flferretti commented Oct 11, 2024

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.

@diegoferigo
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants