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

using coal(hpp-fcl) and pinocchio #2532

Open
viprob-ai opened this issue Dec 29, 2024 · 4 comments
Open

using coal(hpp-fcl) and pinocchio #2532

viprob-ai opened this issue Dec 29, 2024 · 4 comments

Comments

@viprob-ai
Copy link

Bug description

Cannot import coal and pinocchio

I have built coal from source and pinocchio installed using pip install pin

coal : version > 3.0.0
pinocchio : version >2.7.0

import coal
import pinocchio as pin

Error

    from .pinocchio_pywrap import *
AttributeError: 'NoneType' object has no attribute '__dict__'. Did you mean: '__dir__'?

Expected behavior

import coal
import pinocchio as pin

is there any conflict or how to use both if needed ?

Code

import coal
import pinocchio as pin

Error

    from .pinocchio_pywrap import *
AttributeError: 'NoneType' object has no attribute '__dict__'. Did you mean: '__dir__'?

If you revert the order of import then coal throws error

    from .coal_pywrap import *  # noqa
SystemError: initialization of coal_pywrap raised unreported exception

System

  • OS : ubuntu 22.04
  • Pinocchio version: 2.7.0
@nim65s
Copy link
Contributor

nim65s commented Dec 29, 2024

the pin package you installed with pip already comes with hpp-fcl dependency. There is no need to build coal.

@viprob-ai
Copy link
Author

But some of the attributes does not exist under current hpp-fcl like below [code snippet from coal repo]

coal.Transform3s()
contact.getNearestPoint1()

so built the library to make use of that and also to use it as standalone module.

import numpy as np
import coal
# Optional:
# The Pinocchio library is a rigid body algorithms library and has a handy SE3 module.
# It can be installed as simply as `conda -c conda-forge install pinocchio`.
# Installing pinocchio also installs coal.
import pinocchio as pin

def loadConvexMesh(file_name: str):
    loader = coal.MeshLoader()
    bvh: coal.BVHModelBase = loader.load(file_name)
    bvh.buildConvexHull(True, "Qt")
    return bvh.convex

if __name__ == "__main__":
    # Create coal shapes
    shape1 = coal.Ellipsoid(0.7, 1.0, 0.8)
    shape2 = loadConvexMesh("../path/to/mesh/file.obj")

    # Define the shapes' placement in 3D space
    T1 = coal.Transform3s()
    T1.setTranslation(pin.SE3.Random().translation)
    T1.setRotation(pin.SE3.Random().rotation)
    T2 = coal.Transform3s();
    # Using np arrays also works
    T1.setTranslation(np.random.rand(3))
    T2.setRotation(pin.SE3.Random().rotation)

    # Define collision requests and results
    col_req = coal.CollisionRequest()
    col_res = coal.CollisionResult()

    # Collision call
    coal.collide(shape1, T1, shape2, T2, col_req, col_res)

    # Accessing the collision result once it has been populated
    print("Is collision? ", {col_res.isCollision()})
    if col_res.isCollision():
        contact: coal.Contact = col_res.getContact(0)
        print("Penetration depth: ", contact.penetration_depth)
        print("Distance between the shapes including the security margin: ", contact.penetration_depth + col_req.security_margin)
        print("Witness point shape1: ", contact.getNearestPoint1())
        print("Witness point shape2: ", contact.getNearestPoint2())
        print("Normal: ", contact.normal)

    # Before running another collision call, it is important to clear the old one
    col_res.clear()

@nim65s
Copy link
Contributor

nim65s commented Dec 29, 2024

Then you can either:

  1. compile both coal and pinocchio yourself
  2. use a package manager where pinocchio is already using coal (I think the options here are AUR, brew, conda, nix, robotpkg)
  3. wait for pip to provide coal (it's almost done, but I can't finish this during the hollidays)

@viprob-ai
Copy link
Author

@nim65s Thanks for quick response and update.

will try suggested options and yes will wait for pip release 👍 in case could not succeed with other options.

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

No branches or pull requests

2 participants