Xingyu-Lin / softgym

SoftGym is a set of benchmark environments for deformable object manipulation.
BSD 3-Clause "New" or "Revised" License
274 stars 62 forks source link

Trying to imitate realistic grasping and sliding of fabric between two fingers #24

Open lpecyna opened 3 years ago

lpecyna commented 3 years ago

I am trying to make a bit different task using SoftGym, instead of picking the cloth by attaching the particle of it to the gripper, I am trying to hold the cloth between two objects (grippers – spheres/fingers) and slide them along the cloth edge (when the other end of the cloth is held in place).

I figure out, and it is quite straightforward, how to control the position of points of the cloth (for example attach one corner to some specified place in space) – I need to set the inverse mass to 0: curr_poss[fixedpoint * 4 + 3] = 0 and the position to a specific value curr_poss[pickedpoint * 4: fixedpoint * 4+3] = and set it pyflex.set_position(curr_pos), this can be done in (but I am making my own environment file): https://github.com/Xingyu-Lin/softgym/blob/27c6cbc69692ce3d1d5095847f0fcca1f8193714/softgym/envs/cloth_flatten.py#L21

(I) Stiffness

The first issue I had was that the cloth seems to be quite elastic - to stretchy (for the task I am doing) and the griper (the ball) even when the cloth was only lying over, was pulling it, elongating the springs inside. I now know how to change the stiffness of the cloth, this can be cone by changing: https://github.com/Xingyu-Lin/softgym/blob/27c6cbc69692ce3d1d5095847f0fcca1f8193714/softgym/envs/cloth_env.py#L100

1) Do you know if there is any limit value that this parameter can take? From my look into helpers.h (where CreateSpring() and CreateSpringGrid() are located) it seems that it can be arbitrary.

(II) Friction

I am also trying to change the friction parameter. I found that this can be done here for the cloth: https://github.com/Xingyu-Lin/softgym/blob/27c6cbc69692ce3d1d5095847f0fcca1f8193714/PyFlex/bindings/softgym_scenes/softgym_cloth.h#L88-L91 This is called by class g_scene from scenes.h <- Init() in main.cpp <- set_scene() in Pyflex.cpp <- set_scene() in cloth.py in SoftGym.

2) I cannot find however if there is a way to change the friction of the gripper itself (I am currently using just original spheres or boxes). Is that possible? I can see that the sphere is made by: https://github.com/Xingyu-Lin/softgym/blob/27c6cbc69692ce3d1d5095847f0fcca1f8193714/PyFlex/bindings/helpers.h#L490-L504 called by pyflex_add_sphere() in pyflex.cpp

In the future, I am planning to use the capsule objects that I found in PyFleX in helpers.h but I have not tried that yet.

(III) Physics of grasping

As I will be trying to close the gap between two fingers (currently spheres) having the cloth between. I am wondering if that task is feasible to do in a way I have in mind.

3) Is there a way to imitate the force and dynamically change its value between these two fingers (so that the cloth is held tighter or looser)? If yes, can you point me out where in code is something that could help me to implement that?

As I am not sure if grasping can be implemented in this more direct way, I am considering calculating the new positions of cloth particles (these between the fingers) based on the forces acting on them and imitate in that function the changing value of friction force from grasping. In that case, I would need to access internal forces in the cloth.

4) Is there an easy way to access them? As I mentioned before I know where the stiffness parameters are defined, I can also get the position of the particles by pyflex.get_positions(), so potentially I can calculate these forces. However, I am wondering if there is an easier and more direct way to obtain them.

5) Would you consider this second approach more appropriate? Or do you think this task could be done in a way I suggested before (simulating both fingers and force between them). I am not sure about that also because the cloth is made of particles, so I do not know how smoothly they could pass by the gap (however, if I can control the force that could be potentially possible, I think).

Sorry for this long post, I was trying to be quite specific and also add some details that might be useful for others if they try to modify and access some parameters in SoftGym. This is also my first issue/question asked at github so if you see that I should have done something in a different, please way let me know.

Thank you for your help:)!

Xingyu-Lin commented 3 years ago

Do you know if there is any limit value that this parameter can take? From my look into helpers.h (where CreateSpring() and CreateSpringGrid() are located) it seems that it can be arbitrary.

You can try increase the stiffness. But the simulation tends to be unstable if the stiffness is too large. You may need to use a smaller dt in that case.

I cannot find however if there is a way to change the friction of the gripper itself (I am currently using just original spheres or boxes). Is that possible?

I think these friction parameters are global parameters that apply to all interactions in one scene. Apart from the dynamic friction and the particle friction you can try setting g_params.staticFriction. Also, I think for grasping, using parallel boxes would be better than spheres.

Is there a way to imitate the force and dynamically change its value between these two fingers (so that the cloth is held tighter or looser)? If yes, can you point me out where in code is something that could help me to implement that? @yufeiwang63 Maybe you can provide some thoughts related to getting the force?

lpecyna commented 3 years ago

@Xingyu-Lin Thank you for you answer.

You can try increase the stiffness. But the simulation tends to be unstable if the stiffness is too large. You may need to use a smaller dt in that case.

I can understand that (higher stiffness often require smaller time step as it causes higher natural frequencies in the system). Is it the g_dt parameter that should be changed? That is set here: https://github.com/Xingyu-Lin/softgym/blob/27c6cbc69692ce3d1d5095847f0fcca1f8193714/PyFlex/bindings/main.cpp#L685

I am also trying to understand the time steps inside SoftGym, from what I see step() from flex_env.py calls 8 times (env.action_repeat times) _step() function from cloth_flatten.py which calls step() from action_space.py and step() from pyflex.cpp. However, there are also two other parameters inside PyFleX, modified in: https://github.com/Xingyu-Lin/softgym/blob/27c6cbc69692ce3d1d5095847f0fcca1f8193714/PyFlex/bindings/softgym_scenes/softgym_cloth.h#L85-L86

Is g_dt time step repeated 8 times (env.action_repeat times) for each step() from flex_env.py (each time step() in pyflex.cpp is called) or this two parameters also have some impact on number of steps? (I am currently not sure how to measure time-lapse inside of the simulation – so that I could empirically quickly check that).

Also, I think for grasping, using parallel boxes would be better than spheres.

We want to use more finger-like gripper as this is the gripper we are planning to use later on a physical robot (that is why I thought to use capsules in the future), however, in a preliminary stage I might try boxes in the simulation.

Looking forward to hear more about the forces (potential force control of the gripper and access to internal forces in the cloth).