jaxsim icon indicating copy to clipboard operation
jaxsim copied to clipboard

Add mesh support

Open lorycontixd opened this issue 1 year ago • 9 comments

This pull requests aims to extend Jaxsim's parsing functionalities on robot descriptions to meshes. It does so by using third-party library trimesh to parse the mesh file, and custom algorithm create_mesh_collisions to wrap a mesh with collidable points.


📚 Documentation preview 📚: https://jaxsim--156.org.readthedocs.build//156/

lorycontixd avatar May 20 '24 15:05 lorycontixd

@lorycontixd do you prefer a squash and merge or can you please clean the commit history?

flferretti avatar May 20 '24 15:05 flferretti

For the records, this is the function called to load a mesh in trimesh:

https://trimesh.org/trimesh.html#trimesh.load

diegoferigo avatar May 20 '24 16:05 diegoferigo

@diegoferigo before merging this, do we want to set meshes support as default or should it be activated using an environment variable?

flferretti avatar May 21 '24 09:05 flferretti

@diegoferigo before merging this, do we want to set meshes support as default or should it be activated using an environment variable?

Yes I need to properly assess the implications of merging this PR on existing appplications. Automatically adding the collidable points of all meshes is a huge change of behavior and it will make existing simulations unbearably slow.

diegoferigo avatar May 21 '24 09:05 diegoferigo

@diegoferigo @flferretti As of now, random point sampling from a mesh is supported. I think it would be a good idea if I tried to benchmark different values of sampling points and find a good tradeoff between performance and simulation results.

lorycontixd avatar May 21 '24 10:05 lorycontixd

Reminder to myself: bump the version of the ROD dependency before merging this PR.

diegoferigo avatar Jun 11 '24 09:06 diegoferigo

@lorycontixd if you see commits pushed by a bot, don't worry. We can squash those. This should stop as soon as #197 gets merged

flferretti avatar Jul 05 '24 13:07 flferretti

I was wondering 😂 Thanks for letting me know!

lorycontixd avatar Jul 05 '24 13:07 lorycontixd

Must find a way to inject the wrapping method from outside the api (create_mesh_collision func.) for each mesh, if needed.

lorycontixd avatar Jul 18 '24 10:07 lorycontixd

@lorycontixd @flferretti can you please check this together? thanks!

CarlottaSartore avatar Nov 07 '24 14:11 CarlottaSartore

From the last commit, the mesh wrapping algorithms don't follow a class inheritance method anymore, but are defined as simple callables. These may be called from utils.create_mesh_collision() inside the parser which is currently not exposed to the api for the user to modify a mesh. By default, the mesh is wrapper by collision points along all vertices which is the most simple, accurate method but may become computationally expensive for large meshes.

As far as I know, there could be a few ways to achieve this behaviour:

Modify jaxsim api

Modify the api from the rod parser straight to the user interface on jaxsim.model.JaxSimModel.build_from_model_description to allow the user to pass a mesh wrapping algorithm. An idea could be:

model = js.model.JaxSimModel.build_from_model_description(
    model_description=urdf_string,
    model_name="passive_walker",
    terrain=terrain,
    is_urdf=True,
    mesh_wrappers={
        "left_foot" : extract_points_uniform_sampling(...),
    }
)
Advantages:
  • allow the user to modify the mesh to liking straight from the main script
  • most generic & user-intuitive method. one-liner in main script
Disadvantages
  • must modify numerous function to get it done

Move logic to rod

Move the mesh wrapping algorithms to rod as this feature matches the library's goals of building and modifying robot models.

Advantages

?

Disadvantages

?

Leave a default wrapping method

Don't allow the user to modify the mesh wrapping method

Advantages
  • no more implementation needed
Disadvantages
  • no control over collision point creation. collision detection can be slow with large meshes
  • which method as default?

@flferretti

lorycontixd avatar Nov 14 '24 10:11 lorycontixd

For now choosing the 3rd method, which is to leave a default wrapping algorithm for all meshes. For the algorithm, I'd put a collision point on each vertex of the mesh which is probably the most complete method of all despite its computational load for larger meshes.

lorycontixd avatar Nov 14 '24 10:11 lorycontixd

Modify jaxsim api

This is doable, yet to me it looks like an overkill. We should use one single and efficient algorithm for sampling the collidable points, any in-depth modification of the mesh should be done in a different framework and JaxSim is not meant to do that.

Move logic to rod

This is also doable, but in the same fashion of JaxSim, ROD is not meant to be an in-depth mesh editor.

Leave a default wrapping method

This looks like the best option for the time being. and regarding

  • [...] collision detection can be slow with large meshes

This can be considered to be tracked by #283. A smart collidables filtering algorithm like GJK is one of the most effective solution in this case.

WDYT @xela-95 ?

flferretti avatar Nov 14 '24 11:11 flferretti

Modify jaxsim api

This is doable, yet to me it looks like an overkill. We should use one single and efficient algorithm for sampling the collidable points, any in-depth modification of the mesh should be done in a different framework and JaxSim is not meant to do that.

Move logic to rod

This is also doable, but in the same fashion of JaxSim, ROD is not meant to be an in-depth mesh editor.

Leave a default wrapping method

This looks like the best option for the time being. and regarding

  • [...] collision detection can be slow with large meshes

This can be considered to be tracked by #283. A smart collidables filtering algorithm like GJK is one of the most effective solution in this case.

WDYT @xela-95 ?

@flferretti I still have to delve into the details of this PR, but from the latest discussions I've read I fully agree with your comments.

xela-95 avatar Nov 14 '24 16:11 xela-95