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

Soft bodies collisions #39

Open
lorenzominotti opened this issue Nov 11, 2019 · 1 comment
Open

Soft bodies collisions #39

lorenzominotti opened this issue Nov 11, 2019 · 1 comment

Comments

@lorenzominotti
Copy link

Good afternoon,

I am trying to import a soft body in AMBF and make it interact with a PSM. AMBF is used on Ubuntu 18.04 with ROS melodic. I have been facing however some problems with the interaction between soft bodies and the PSM, and in general between soft bodies/rigid bodies and between soft bodies/soft bodies.
To get started with soft bodies I imported the cloth example in the folder ambf/ambf_models/descriptions/multi-bodies/sb into the framework. To make things easier, I constrained the cloth in 4 points at the corners so that it was fixed horizontally.

PSM_cloth_horizontal

Then, I wrote a simple python client code for the PSM to make it collide with the cloth (just moving down the main insertion link). What happens is that:

  1. Changing the value of different parameters in the yaml file of both the cloth and the PSM (like collision margin for example), in some cases collision does not occur at all and the PSM penetrates into the cloth, sometimes collision occur for a certain part of the robotic arm but not for others.

  2. Simulation in any case slows down too much when the collision occurs and the Phx frequency dramatically decreases using a variable time-step.

  3. If the PSM and the cloth are in the same scene and using a variable time-step, and I try to run the python client code for the PSM so that they collide, the PSM does not work properly but has a completely unpredictable behaviour with random movements and thus it is impossible to control.

About points 2 and 3, I noticed that using a fixed physics time-step (with the –t true option) things improve but are anyway not optimal and the Sim time is slower. The Phx frequency increases a little and if I run the python client, the PSM seems to do its job, even if random oscillations are still present and the simulation is not stable.
I also tried to change the position of the cloth for example by constraining it into 2 points only and making then the PSM interact with it. The PSM penetrates sometimes the tissue with certain parts and the simulation is, again, not stable at all.

PSM_through_cloth_vertical

Both the previous images represent a simulation done with fixed time-step for physics, otherwise, as said previously, it would have been impossible to move the PSM with the python client.

I found similar issues in collisions even with other bodies, for instance with a rigid box and a soft sphere (they completely penetrate), or the same with a soft sphere and a soft torus. It is a problem that could be related to the Bullet physics engine behind the framework.
It would be really helpful for me to have some more examples of soft bodies to understand better how these objects work in this simulation environment.

I hope you can help me to solve these issues.

@adnanmunawar
Copy link
Member

Thanks for creating this issue. Based on our discussion in the email I hope things are moving in a better direction. I shall paste the major points here for reference and then hopefully, very soon, I can create a new section in the WIKI detailing the scope and limitations of softbody simulations.

  1. As you rightly noticed, there are some flags that we can play with to improve the simulation. I would recommend using the following flags (-l , -p and -t) for soft-body simulation. As an example,

./ambf_simulation -l 22 -t 1 -p 60

These flags are defined as -l (L not I) as the index of the body to load. The 22 index is a primitive ''box'' shape acting as the ground rather than the default ''plane'' primitive shape. I find that the box primitive shape has better SB collision as it reduces ''tunneling'' for bodies that are freely moving in the simulation. The -t flag is to disable dynamic stepping and the -p flag is the frequency of the physics loop. The -t and -p flags are not necessary, but unless you want to do a real-time interaction with the soft-body, I would suggest that you use them, as they give much better solution convergence by not forcing the soft-body solver to terminate to match real-time stepping.

Now you can simply run your softbody example as:
./ambf_simulation -l 22 -t 1 -p 60 -a <path + filename to your .yaml file>
You can even add more bodies to the simulation by adding more indexes to the -l flag.

You can also use the -h flag to list all the command-line options.

I am attaching some examples of softbody examples as well.
softbody_examples.zip

  1. With the example of the cloth that you shared, it is indeed true that the collision is weird. This is because Bullet only handles the collisions at the vertices (softbody nodes) by default. As the cloth is made up of sparse and finite vertices, the PSM's tip just passes through the cloth. Now all hope is not lost. One option is to increase the collision "margin" parameter in the softbody which increases the collision radius of softbody nodes. As you can see, this is not ideal if your vertices are sparsely populated as it ends up giving thickness to the cloth, which might not be desirable.
    So what else can we do? Well, the best solution so far is to use clustering. In a nutshell, clustering essentially forms deformable primitives from a sparse softbody mesh for collision purposes and enables whole body collision and even self collision. To do so, you can play around with some flags in a softbody. I need to document them better, but here is an example.
 soft bodies: [BODY Cheese]
joints: []
high resolution path: ./high_res/
low resolution path: ./low_res/
ignore inter-collision: false
namespace: /ambf/env/cheese/
BODY Cheese:
  name: Cheese
  mesh: Cheese.STL
  mass: 10.0
  collision margin: 0.001
  scale: 1.0
  location:
    orientation: {p: -0.0, r: 0.0, y: 0.0}
    position: {x: -1.3, y: 0.0, z: -1.0}
  color components:
    ambient: {level: 1.0}
    diffuse: {b: 0.0, g: 0.4941, r: 0.8}
    specular: {b: 1.0, g: 1.0, r: 1.0}
    transparency: 1.0
  config: {
    kDP: 0.001, # damping
    kDF: 10.0,  #
    kMT: 0.001,
    clusters: 0,
    flags: 18,
    }

The fields clusters (integer) and flags (integer converted to hex) are the relevant fields and they are internal parameters of Bullet. Based on the clustering, one requires appropriate collision flags. Again, we need to better document the meaning of these numbers in the wiki but this should be a good starting point.

  1. I would also suggest modifying the collision shapes of the PSM's links. You may use the newer version of the Blender Addon at https://github.com/WPI-AIM/ambf_addon to visually generate and place the collision shapes (Tutorial Comming Out Soon). For the moment, all the PSM collision shapes are meshes rather than primitives which isn't ideal. I do plan on addressing this myself and I shall update you once I have done so.

Finally, thanks for your patience. I am finally going to be working on improving the soft-body support and feature set as part of my new job so stay tuned :).

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