Restitution in rigid collisions #1090
-
Hi, thank you for the great work on Genesis! I have a question regarding rigid body collisions. Specifically, how can we control the restitution (bounciness) between two rigid bodies — for example, when a rigid sphere drops and collides with a table? I noticed that in the material definition for rigid bodies, there is a Admittedly, I can use In comparison, the Kubric (based on PyBullet) allows setting restitution at the rigid body level, which directly affects bounce. See this line in Kubric’s object definition. Here’s a minimal example. Even when I set all import genesis as gs
import numpy as np
def main():
gs.init(backend=gs.gpu)
scene = gs.Scene(
sim_options=gs.options.SimOptions(
dt=5e-3,
substeps=16,
),
vis_options=gs.options.VisOptions(
show_world_frame=False,
plane_reflection=True,
ambient_light=(0.5, 0.5, 0.5),
),
show_viewer=False,
)
# All objects are set as rigid bodies with coup_restituion=1
general_rigid = gs.materials.Rigid(
coup_friction=0.1,
coup_restitution=1.0,
)
plane = scene.add_entity(
material=general_rigid,
morph=gs.morphs.Plane(),
)
# Put a fixed table underneath
table = scene.add_entity(
morph=gs.morphs.Mesh(
file="assets/table/meshes/CoffeeTable.obj",
scale=0.02,
fixed=True,
),
material=general_rigid,
surface=gs.surfaces.Rough(),
)
# Put a ball on it and let it fall freely
sphere = scene.add_entity(
material=general_rigid,
morph=gs.morphs.Sphere(
pos=(0.0, 0.0, 1.8),
radius=0.1,
),
)
cam = scene.add_camera(
res=(720, 480),
fov=45,
GUI=False,
)
# Build the scene
scene.build()
# Added a little lens rotation
horizon = 500
center = np.array([0.0, 0.0, 1.0])
radius = 3.0
height = 2.5
start_angle = -np.pi / 6
end_angle = np.pi / 6
cam.start_recording()
for i in range(horizon):
scene.step()
# Camera operation
t = i / horizon
angle = start_angle + t * (end_angle - start_angle)
x = center[0] + radius * np.cos(angle)
y = center[1] + radius * np.sin(angle)
z = height
cam.set_pose(
pos=(x, y, z),
lookat=(center[0], center[1], center[2]),
)
cam.render()
cam.stop_recording(save_to_filename="video.mp4", fps=video_fps)
if __name__ == "__main__":
main() Is there a way to achieve this kind of rigid body bounce within Genesis? Or is restitution only meaningful when using deformable objects? Any guidance would be greatly appreciated! video.mp4 |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 7 replies
-
@duburcqa It would be also nice if we can expose the restitution for domain randomization in RL. |
Beta Was this translation helpful? Give feedback.
-
Actually, that is not how it works for Rigid Body Dynamics. The contact dynamics relies on the impedance model that was introduced by Mujoco. here is the official documentation. The behaviour of this model is specified by the vector parameters |
Beta Was this translation helpful? Give feedback.
-
@duburcqa thanks for the explanation — is it possible to set sol_params individually for each rigid body (or per object-pair contact), and if so, where exactly should this be done? |
Beta Was this translation helpful? Give feedback.
-
@duburcqa Thank you for correcting my misunderstanding of Rigid Body Dynamics. I noticed that during collision computation, the solver uses the average of the two objects’ In addition, the Genesis/genesis/engine/solvers/rigid/rigid_solver_decomp.py Lines 4027 to 4039 in a0eeddd By default, the solver parameters for rigid bodies are initialized via the following method: Lines 1146 to 1153 in a0eeddd My question is whether Genesis provides a higher-level API that supports either of the following functionalities:
I'm planning to use Genesis for rigid body simulation involving some predefined basic shapes such as cubes and spheres. If the current implementation supports either of the functionalities above, could you kindly point me to how it's done? If not, would it be possible to consider adding such features in a future release? Alternatively, would you consider updating the collision section of the user guide to cover this? |
Beta Was this translation helpful? Give feedback.
-
@gleitn96 I found that using MuJoCo xml for file description can achieve this task. According to the concept given in Solver Parameter, we can directly set <mujoco model="ball_drop">
<compiler angle="degree" coordinate="local"/>
<option timestep="0.002" gravity="0 0 -9.81" iterations="50" integrator="RK4"/>
<!-- Default settings for all geoms -->
<default>
<geom solref="0.005 0.3" friction="0.5 0.1 0.0" density="1000"/>
</default>
<asset>
<texture name="grid" type="2d" builtin="checker" width="512" height="512"
rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3"/>
<material name="mat_ground" texture="grid" texrepeat="4 4" reflectance="0.2"/>
</asset>
<worldbody>
<!-- Static ground plane -->
<geom name="floor" type="plane" pos="0 0 0" size="5 5 0.1" material="mat_ground" rgba="0.8 0.8 0.8 1" solref="0.005 0.3"/>
<!-- Falling ball -->
<body name="ball_0" pos="0.2 0 1">
<freejoint/>
<geom name="ball_geom_0" type="sphere" size="0.04" rgba="1 0 0 1" solref="0.005 0.9"/>
</body>
<body name="ball_1" pos="0.1 0 1">
<freejoint/>
<geom name="ball_geom_1" type="sphere" size="0.04" rgba="1 0 0 1" solref="0.005 0.09"/>
</body>
<body name="ball_2" pos="0 0 1">
<freejoint/>
<geom name="ball_geom_2" type="sphere" size="0.04" rgba="1 0 0 1" solref="0.005 0.009"/>
</body>
<body name="ball_3" pos="-0.1 0 1">
<freejoint/>
<geom name="ball_geom_3" type="sphere" size="0.04" rgba="1 0 0 1" solref="0.005 0.0009"/>
</body>
<body name="ball_4" pos="-0.2 0 1">
<freejoint/>
<geom name="ball_geom_4" type="sphere" size="0.04" rgba="1 0 0 1" solref="0.005 0.00009"/>
</body>
</worldbody>
<actuator/>
</mujoco> video.mp4 |
Beta Was this translation helpful? Give feedback.
-
I added the low-level API to set the solver parameters independently for each geometry in this PR#1131: For now it is only available at rigid solver-level, but it should be exposed at joint, geom, and equality-levels soon! |
Beta Was this translation helpful? Give feedback.
Here it is: #1173