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

Integrate hand-crafted nice meshes into the repo-pipeline #263

Closed
Nicogene opened this issue Sep 27, 2024 · 29 comments · Fixed by #266
Closed

Integrate hand-crafted nice meshes into the repo-pipeline #263

Nicogene opened this issue Sep 27, 2024 · 29 comments · Fixed by #266
Assignees
Labels
domain-software Related to Software prj-ergocub Related to ErgoCub Project team-fix Related to Team Fix

Comments

@Nicogene
Copy link
Member

Nicogene commented Sep 27, 2024

Task description

This task is probably cross-repository with creo2urdf, @Supermonkey-design did an amazing job on remeshing the the existing URDF mesh, and after a chat w/ @fiorisi @traversaro @GiulioRomualdi and @Supermonkey-design it came out that it would be nice to add them to this repo, alongside the "ugly" ones.

In case these meshes are heavy for the simulation we might think to change creo2urdf in order to make assignedCollisionGeometry handle also complex meshes, and then use the ugly ones for the collisions, keeping the nice one as visual

Definition of Done

We integrated the @Supermonkey-design meshes

cc @maggia80 @pattacini

@Nicogene Nicogene added domain-software Related to Software prj-ergocub Related to ErgoCub Project team-fix Related to Team Fix labels Sep 27, 2024
@Nicogene Nicogene self-assigned this Sep 27, 2024
@Nicogene Nicogene changed the title Integrate nice meshes manually crafted into the repo-pipeline Integrate hand-crafted nice meshes into the repo-pipeline Sep 27, 2024
@Nicogene
Copy link
Member Author

Nicogene commented Oct 2, 2024

As first step I simply added all the new meshes to the repo and find/replace .stl with .obj in the urdf.

I am getting this warning on gazebo side:

[Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[Wrn] [OBJLoader.cc:79] Material file [ ./sim_ecub_1-1_l_hip_1.obj.mtl ] not found in a path : /home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/
Failed to load material file(s). Use default material.
material [ 'material_0' ] not found in .mtl

[Wrn] [OBJLoader.cc:146] Missing material for shape[] in OBJ file[/home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/sim_ecub_l_hip_1.obj]
[Wrn] [OBJLoader.cc:79] Material file [ ./sim_ecub_1-1_r_hip_1.obj.mtl ] not found in a path : /home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/
Failed to load material file(s). Use default material.
material [ 'material_0' ] not found in .mtl

[Wrn] [OBJLoader.cc:146] Missing material for shape[] in OBJ file[/home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/sim_ecub_r_hip_1.obj]
[Wrn] [OBJLoader.cc:79] Material file [ ./sim_ecub_1-1_l_shoulder_1.obj.mtl ] not found in a path : /home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/
Failed to load material file(s). Use default material.
material [ 'material_0' ] not found in .mtl

[Wrn] [OBJLoader.cc:146] Missing material for shape[] in OBJ file[/home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/sim_ecub_l_shoulder_1.obj]
[Wrn] [OBJLoader.cc:79] Material file [ ./sim_ecub_1-1_head_neck_3.obj.mtl ] not found in a path : /home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/
Failed to load material file(s). Use default material.
material [ 'material_0' ] not found in .mtl

[Wrn] [OBJLoader.cc:146] Missing material for shape[] in OBJ file[/home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/sim_ecub_head_neck_3.obj]
[Wrn] [OBJLoader.cc:79] Material file [ ./sim_ecub_1-1_r_shoulder_1.obj.mtl ] not found in a path : /home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/
Failed to load material file(s). Use default material.
material [ 'material_0' ] not found in .mtl

[Wrn] [OBJLoader.cc:146] Missing material for shape[] in OBJ file[/home/ngenesio/robotology/robotology-superbuild/build/install/share/ergoCub/meshes/simmechanics/sim_ecub_r_shoulder_1.obj]

and unfortunately the meshes seems to collapse:

Image

Image

cc @Supermonkey-design

@Supermonkey-design
Copy link

I am getting this warning on gazebo side:

Sorry @Nicogene, I've forgotten to change some of the mtl references. It should be ok now.
For the collapsing, I don't know. To launch gazebo or idyntree, in the urdf I've only ever used the path for the visuals (obj) and left the rest as it was.

@Nicogene
Copy link
Member Author

Nicogene commented Oct 2, 2024

I am getting this warning on gazebo side:

Sorry @Nicogene, I've forgotten to change some of the mtl references. It should be ok now.

The warning are now disappeared thanks!

For the pose of the meshes instead, with stl usually happens when we export them wrt the part csys (that usually is not where is the link csys), but for these obj I don't know how the procedure work.

To launch gazebo or idyntree, in the urdf I've only ever used the path for the visuals (obj) and left the rest as it was.

It is strange indeed that I am experiencing this problem, I just changed the paths too 🤔

@traversaro
Copy link
Member

As first step I simply added all the new meshes to the repo and find/replace .stl with .obj in the urdf.

Did you replace just collision ao also visuals?

@Nicogene
Copy link
Member Author

Nicogene commented Oct 2, 2024

The curious thing is that with the 1.1 meshes this does not happen:
Image

Did you replace just collision ao also visuals?

Yes it should!

The good news is that I didn't see change in the real time factor ~0.98 on my machine.

@traversaro
Copy link
Member

Is anything printed if you run gazebo --verbose ?

@Nicogene
Copy link
Member Author

Nicogene commented Oct 2, 2024

I found out what the problem is.
Preface: The SN001/V1 models have never been created via creo2urdf, they have been built via the old procedure:

Comparing side-by-side the V1 and V1_1 urdf I see an important different on how the meshes are handled:

V1

    <visual>
      <origin xyz="0 0 0.1785" rpy="0 0 1.5707963267948966"/>
      <geometry>
        <mesh filename="package://ergoCub/meshes/simmechanics/sim_ecub_root_link.obj" scale="0.001 0.001 0.001"/>
      </geometry>
      <material name="root_link_color">
        <color rgba="0.9 0.9 0.9 1"/>
      </material>
    </visual>
    <collision>
      <origin xyz="0 0 0.1785" rpy="0 0 1.5707963267948966"/>
      <geometry>
        <mesh filename="package://ergoCub/meshes/simmechanics/sim_ecub_root_link.obj" scale="0.001 0.001 0.001"/>
      </geometry>
    </collision>

V1_1

    <visual>
      <origin xyz="0 0 0" rpy="0 -0 0"/>
      <geometry>
        <mesh filename="package://ergoCub/meshes/simmechanics/sim_ecub_1-1_root_link.obj" scale="0.001 0.001 0.001"/>
      </geometry>
      <material name="">
        <color rgba="0.6 0.6 0.6 1"/>
      </material>
    </visual>
    <collision>
      <origin xyz="0 0 0" rpy="0 -0 0"/>
      <geometry>
        <mesh filename="package://ergoCub/meshes/simmechanics/sim_ecub_1-1_root_link.obj" scale="0.001 0.001 0.001"/>
      </geometry>

Long story short, using the old pipeline we have meshes exported w.r.t the csys and then the pose is adjusted using the origin tag, with the new procedure instead we directly export the meshes respect the correct csys, then the origin tag is simply an identity.

@Supermonkey-design just changed the names of the meshes and changed the color starting from the V1_1 ones, probably the V1 have to be export respect CSYS or as last resort I can change all the origin tags in 000 000 also in V1 (

@GiulioRomualdi
Copy link
Contributor

I was wondering if it makes sense to also update the meshes of the sn000 since it is created with a machinery not supported anymore

@Supermonkey-design
Copy link

As the meshes are basically the same but in different csys, I've made a little definition in Grasshopper to remap the position of V1_1 meshes into the frame of V1 meshes (so without exporting everything again from creo).

Image

It seems to work. This is an overlapping comparison with the actual v1 shrink-wrapped meshes (in red).

Image
Image

The wrists and hand meshes are not visible in the screenshots because I've just made the obj directly from V1 meshes.
I've uploaded stl and obj in the repo already.

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

I was wondering if it makes sense to also update the meshes of the sn000 since it is created with a machinery not supported anymore

You are right, my only fear is that if we want to roll-back to the "ugly" meshes, if we change the urdf the stl meshes have the wrong placement. I quickly tested the impact on the rtf and seems that these new meshes are quite light, but I did not do "complex" task, such as walking grasping etc

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

Instead about the weight of these meshes, I don't know if we might commit them with git lfs or not, until now for using ergocub-software git lfs was not needed and introducing can be considered a breaking change? @traversaro @pattacini

@pattacini
Copy link
Member

pattacini commented Oct 3, 2024

Hi @Nicogene

The main problem with Git LFS is when we aim to apply it to extensions already hosted in the repo1.
Do you know if this is the case here? Do these new meshes have new file extensions that are currently not hosted?

Footnotes

  1. Fixing this would require some Git magic.

@pattacini
Copy link
Member

Also, what file size we're talking about?

@traversaro
Copy link
Member

I've made a little definition in Grasshopper to remap the position of V1_1 meshes into the frame of V1 meshes (so without exporting everything again from creo).

How is this process done? I am always a bit afraid of process that rely on visually checking the aligned of meshes. Did the kinematics changed between ergoCubSN000, 1, 2? If not, we can compute the correct placement from the kinematics, without trying to align the meshes.

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

How is this process done? I am always a bit afraid of process that rely on visually checking the aligned of meshes. Did the kinematics changed between ergoCubSN000, 1, 2? If not, we can compute the correct placement from the kinematics, without trying to align the meshes.

A part of the fingers they should be kinematically identical

The main problem with Git LFS is when we aim to apply it to extensions already hosted in the repo1.
Do you know if this is the case here? Do these new meshes have new file extensions that are currently not hosted?

I would apply in case only to .obj and .obj.mtl that have never committed before

Also, what file size we're talking about?

@pattacini we are passing from 43.8 MB to 96.8 MB, this means we are doubling the size, but still seems a reasonable size

@pattacini
Copy link
Member

I would apply in case only to .obj and .obj.mtl that have never committed before

Good 👍🏻

@pattacini we are passing from 43.8 MB to 96.8 MB, this means we are doubling the size, but still seems a reasonable size

Not really, we're approaching the GH limit of 100 MB per file, hence LFS seems necessary.

@Supermonkey-design
Copy link

How is this process done? I am always a bit afraid of process that rely on visually checking the aligned of meshes.

Me too, honestly, in this case. My idea was also simple: if the meshes are identical, I can read the shrinkwrapped mesh from SN001 and SN000, compute their bounding box centroids, create a vector from these two points, and use it to remap the position of the detailed meshes.
But for example I had to match the rotation of the bound box of the arms and shoulder. I can do a better job and make it automatic by calculating the frame, but as there were only three meshes, I did it manually.

@traversaro
Copy link
Member

Yes, that is exactly what I was afraid of. If the meshes are indeed identical, perhaps to use the V1_1 meshes in V1 we can simply set the origin tag of V1 to <origin xyz="0 0 0" rpy="0 0 0"/>, instead of moving the meshes around?

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

Yes, that is exactly what I was afraid of. If the meshes are indeed identical, perhaps to use the V1_1 meshes in V1 we can simply set the origin tag of V1 to <origin xyz="0 0 0" rpy="0 0 0"/>, instead of moving the meshes around?

My concern about this, is that I have to do it 132 times for each urdf manually(SN000, V1, V1_mincontacts), and then we cannot roll back on the stl without reverting this change, something doable but I am afraid error prone too.

Maybe finding a regex that work can save the day

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

For curiosity I just exported the SN000 urdf using creo2urdf and at first glance seems a well-formed urdf (except that for some reason the feet are flying)

Image

Maybe this is solved:

Because in these months creo2urdf became more robust, my only doubt is if we are leaving some hack we made by hand behind.
In all these months I tried to keep the yamls updated even if not used

@traversaro
Copy link
Member

Yes, that is exactly what I was afraid of. If the meshes are indeed identical, perhaps to use the V1_1 meshes in V1 we can simply set the origin tag of V1 to <origin xyz="0 0 0" rpy="0 0 0"/>, instead of moving the meshes around?

My concern about this, is that I have to do it 132 times for each urdf manually(SN000, V1, V1_mincontacts), and then we cannot roll back on the stl without reverting this change, something doable but I am afraid error prone too.

Maybe finding a regex that work can save the day

Sure, I typically found more useful to do this kind of changes via simple ad-hoc Python scripts rather then manually, especially now that llm can drastically speedup the process of creation of such Python scripts.

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

Yes, that is exactly what I was afraid of. If the meshes are indeed identical, perhaps to use the V1_1 meshes in V1 we can simply set the origin tag of V1 to <origin xyz="0 0 0" rpy="0 0 0"/>, instead of moving the meshes around?

My concern about this, is that I have to do it 132 times for each urdf manually(SN000, V1, V1_mincontacts), and then we cannot roll back on the stl without reverting this change, something doable but I am afraid error prone too.
Maybe finding a regex that work can save the day

Sure, I typically found more useful to do this kind of changes via simple ad-hoc Python scripts rather then manually, especially now that llm can drastically speedup the process of creation of such Python scripts.

Here's a Python script that parses a URDF (Unified Robot Description Format) file, finds all <origin> tags within both <visual> and <collision> elements, and sets the xyz and rpy attributes to 0 0 0. It uses the xml.etree.ElementTree library to manipulate the XML structure of the URDF.

import xml.etree.ElementTree as ET

def set_origin_to_zero(urdf_file, output_file):
    # Parse the URDF file
    tree = ET.parse(urdf_file)
    root = tree.getroot()
    
    # Find all <visual> and <collision> elements
    for element_type in ['visual', 'collision']:
        for elem in root.findall(f".//{element_type}"):
            # Find the <origin> element inside <visual> or <collision>
            origin = elem.find('origin')
            if origin is not None:
                # Set xyz and rpy attributes to '0 0 0'
                origin.set('xyz', '0 0 0')
                origin.set('rpy', '0 0 0')
    
    # Save the modified URDF to a new file
    tree.write(output_file)
    print(f"Updated URDF saved to {output_file}")

# Example usage
urdf_file = 'input.urdf'
output_file = 'output.urdf'
set_origin_to_zero(urdf_file, output_file)

How it works:

  1. The script reads the URDF file and parses it as XML.
  2. It looks for all <visual> and <collision> elements.
  3. For each element, it checks for an <origin> sub-element and sets the xyz and rpy attributes to 0 0 0.
  4. The modified URDF is saved to a new file.

Usage:

  • Replace input.urdf with the path to your URDF file.
  • The script will output the modified URDF to output.urdf.

You can expand this script to handle other attributes or tags as needed.

Let's see if it works :D

@traversaro
Copy link
Member

Note that this may change the formatting of the existing xml if tree.write uses another formatting w.r.t. to the one currently used.

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

Note that this may change the formatting of the existing xml if tree.write uses another formatting w.r.t. to the one currently used.

Yes it works (good job chatGPT), but changes a bit the formatting, in particular it added a space before every /> character, do you know a way to avoid it?

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

@Supermonkey-design Here:

I put all the origin to 000, I can take the old meshes and see if now they work

@Nicogene
Copy link
Member Author

Nicogene commented Oct 3, 2024

Unfortunately setting all the collisions' origin to 000 broke the collision boxes we put in the SN000/V1 soles

Image

I manually put the correct offset and now is fine

Image

@Supermonkey-design is flipping the tight covers meshes, since the V1 is still affected by this:

I hope this is the last step

@Nicogene
Copy link
Member Author

Nicogene commented Oct 4, 2024

Yes, that is exactly what I was afraid of. If the meshes are indeed identical, perhaps to use the V1_1 meshes in V1 we can simply set the origin tag of V1 to <origin xyz="0 0 0" rpy="0 0 0"/>, instead of moving the meshes around?

Unfortunately the meshes for the hands are different, so right now the V1 hands looks like this:

Image

Image

This is due to the fact that the URDF contains the V1 transform between links, but the meshes are the ones of the V1_1, that are longer and have some problems of frame definitions:

"This is not creating problems, just to be aware of it"

Naif me of 2023 :D

So with @Supermonkey-design we decided to:

  • Take the stl of V1 obtained via creo2urdf
  • Convert them to obj

That's it?

Not really, the simulation model of V1 has yet another problem:

That was fixed by @xEnVrE by removing the leverism by hand and committing the stl directly.

So @Supermonkey-design we re-remove those leverism before converting to obj and we should land finally.

@Nicogene
Copy link
Member Author

Nicogene commented Oct 4, 2024

I would apply in case only to .obj and .obj.mtl that have never committed before

Good 👍🏻

@pattacini we are passing from 43.8 MB to 96.8 MB, this means we are doubling the size, but still seems a reasonable size

Not really, we're approaching the GH limit of 100 MB per file, hence LFS seems necessary.

About this point maybe I was not clear, but 96.8 MB is the total of the entire ergocub-software folder, the 100 MB limit seems to be related to a single file:

The limit on the repo seems to be 1 GB.

I would rather avoid using git lfs because this may lead to problems for users, and we should specify to install git lfs both here and in the robotology-superbuild documentation since ergocub-software would be the first repo that requires it.

@Nicogene
Copy link
Member Author

Nicogene commented Oct 7, 2024

We finally landed 🛬

SN000 SN001/2
image image

Thanks @Supermonkey-design !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain-software Related to Software prj-ergocub Related to ErgoCub Project team-fix Related to Team Fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants