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

Cast down NumPy array to float #50

Merged
merged 1 commit into from
Dec 17, 2023
Merged

Cast down NumPy array to float #50

merged 1 commit into from
Dec 17, 2023

Conversation

stephane-caron
Copy link
Contributor

Fixes #49

After upgrading NumPy and SciPy to respectively 1.24.4 and 1.10.1 I started to get the following error when trying to load a robot URDF:

Traceback (most recent call last):
  File "load_in_yourdfpy.py", line 36, in <module>
    robot = load_robot_description(f"{args.name}_description")
  File "/home/user/src/robot_descriptions.py/examples/robot_descriptions/loaders/yourdfpy.py", line 58, in load_robot_description
    return yourdfpy.URDF.load(module.URDF_PATH, mesh_dir=module.PACKAGE_PATH)
  File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 989, in load
    return URDF(robot=URDF._parse_robot(xml_element=xml_root), **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 641, in __init__
    self._scene = self._create_scene(
  File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 1321, in _create_scene
    matrix, _ = self._forward_kinematics_joint(j)
  File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 1072, in _forward_kinematics_joint
    matrix = origin @ tra.rotation_matrix(q, joint.axis)
  File "/home/user/.local/lib/python3.8/site-packages/trimesh/transformations.py", line 361, in rotation_matrix
    M = np.diag([cosa, cosa, cosa, 1.0])
  File "<__array_function__ internals>", line 200, in diag
  File "/home/user/.local/lib/python3.8/site-packages/numpy/lib/twodim_base.py", line 295, in diag
    v = asanyarray(v)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (4,) + inhomogeneous part.

The issue stems from urdf.py where:

matrix = origin @ tra.rotation_matrix(q, joint.axis)

Won't work well by asanyarray (as per the new requirements) if q is a one-dimensional array, which can happen here. I'll suggest a fix in a PR.

Fixes #49

After upgrading NumPy and SciPy to respectively 1.24.4 and 1.10.1 I started to get the following error when trying to load a robot URDF:

    Traceback (most recent call last):
      File "load_in_yourdfpy.py", line 36, in <module>
        robot = load_robot_description(f"{args.name}_description")
      File "/home/user/src/robot_descriptions.py/examples/robot_descriptions/loaders/yourdfpy.py", line 58, in load_robot_description
        return yourdfpy.URDF.load(module.URDF_PATH, mesh_dir=module.PACKAGE_PATH)
      File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 989, in load
        return URDF(robot=URDF._parse_robot(xml_element=xml_root), **kwargs)
      File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 641, in __init__
        self._scene = self._create_scene(
      File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 1321, in _create_scene
        matrix, _ = self._forward_kinematics_joint(j)
      File "/home/user/.local/lib/python3.8/site-packages/yourdfpy/urdf.py", line 1072, in _forward_kinematics_joint
        matrix = origin @ tra.rotation_matrix(q, joint.axis)
      File "/home/user/.local/lib/python3.8/site-packages/trimesh/transformations.py", line 361, in rotation_matrix
        M = np.diag([cosa, cosa, cosa, 1.0])
      File "<__array_function__ internals>", line 200, in diag
      File "/home/user/.local/lib/python3.8/site-packages/numpy/lib/twodim_base.py", line 295, in diag
        v = asanyarray(v)
    ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (4,) + inhomogeneous part.

The issue stems from urdf.py where:

    matrix = origin @ tra.rotation_matrix(q, joint.axis)

Won't work well by asanyarray (as per the new requirements) if q is a one-dimensional array, which can happen here. I'll suggest a fix in a PR.
@blooop
Copy link

blooop commented Nov 20, 2023

I am also getting hit by this error, thanks for the fix.

@abcamiletto
Copy link

this should be merged! also fixes my problem

@clemense clemense merged commit 01f2b81 into clemense:main Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ValueError: setting an array element with a sequence
4 participants