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

Springs in pybullet #2100

Closed
krasin opened this issue Feb 6, 2019 · 7 comments
Closed

Springs in pybullet #2100

krasin opened this issue Feb 6, 2019 · 7 comments

Comments

@krasin
Copy link

krasin commented Feb 6, 2019

I would like to use springs to define a complex body that consists of multiple parts. In the C++ land, there's btGeneric6DofSpring2Constraint. Unfortunately, I can't find a way to use it from pybullet.

Would it be a correct guess that pybullet is missing plumbing for this constraint? How hard it would be to add?

I am willing to take on that, but will appreciate some guidance, as I am relatively new to the Bullet / pybullet code.

Thank you in advance.

@erwincoumans
Copy link
Member

erwincoumans commented Feb 7, 2019

By default, PyBullet uses btMultiBody reduced coordinate articulated bodies. Joints in articulated bodies are not implemented as constraints, but handled through the Featherstone articulated body algorithm. We have special btMultiBody constraints, exposed through PyBullet.createConstraint. We could re-implement parts of btGeneric6DofSpring2Constraint for the btMultiBody case.

btGeneric6DofSpring2Constraint is only implemented for btRigidBody.
You can loadURDF using the useMaximalCoordinates=True flag, and in that case, joints are implemented as btGeneric6DofSpring2Constraint. So we could add some API that lets you configure existing btRigidBody joints that way.

One way would be to implement it in the 'changeDynamics' API, only in case we have btRigidBody. This is still complicated, since we don't have all links/other rigid bodies readily available there.
https://github.com/bulletphysics/bullet3/blob/master/examples/SharedMemory/PhysicsServerCommandProcessor.cpp#L7763

Notice that useMaximalCoordinates is not well supported in PyBullet, since most users use the default reduced coordinate methods.

@krasin
Copy link
Author

krasin commented Feb 7, 2019

Hi Erwin,

thank you very much for your throughout reply.

Using useMaximalCoordinates and exposing necessary APIs might be the way to go, and I would be happy to code that, but before we dive into the implementation details, let me take a step back and explain the higher-level issue I am trying to solve.

We aim to learn how to optimize gripper shapes and for that we will need to have a better idea which parts of the gripper are affected by the contact when an object is grasped. It's great that pybullet has getContactPoints, but it will only give surface-level contact points. We would like to have deeper insights and the approach we currently explore is to make grippers out of voxels connected with pretty stiff springs organized in a cubic crystal.

That way, after an object is grasped, the points of immediate contact will get highest displacement values, while their neighbors will get lower, and the voxels which don't participate in the contact at all will get ~zeros.

Given that we seem to be outside of the regular pybullet use cases, I wonder if the same problem could be solved by other means. Realistically, we don't care if it's displacements or some other measure of importance for a specific contact event. What we care is that this information is spreaded among higher number of voxels so that we can make better decisions on how to optimize the shape.

Let me know, if that makes sense to you. :)

@erwincoumans
Copy link
Member

erwincoumans commented Feb 7, 2019

How about using a fixed constraint with a very limited force? That will act like a spring, and you can read the applied forces. This works with regular reduced coordinates.
See attached example. You can add a whole bunch of spheres/boxes next to each other, and use fixed constraint (PyBullet.createConstraint) to keep them there. Then use PyBullet.changeConstraint(cid,maxForce=...) to limit the constraint force.
constraint.zip

I think the fixed constraint also works between reduced and maximal coordinate objects, so you can use maximal coordinate spheres for the surfaces and reduced coordinate for the gripper.

@krasin
Copy link
Author

krasin commented Feb 8, 2019

Hi Erwin,

that sounds really great! I will spend some time tomorrow to see how many voxels it will be possible to simulate with a reasonable simulation speed.

Will report back.

@erwincoumans
Copy link
Member

It sounds a bit like this (thanks Yunfei Bai for the link)
https://www.cc.gatech.edu/graphics/projects/Sumit/homepage/projects/softcontacts/index.html

@erwincoumans
Copy link
Member

Assuming this works, let's close the issue. Please re-open if not.

@horuswoo
Copy link

Is it possible to add a spring (possibly implemented with a bunch of spheres/boxes with constraint, like @erwincoumans mentioned above) as a convenience feature? Also wondering if @krasin was able to get it working, as I'm seeing other issues following this approach facing other issues like #3047

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

3 participants