Search code examples
drake

Drake - Rotation of objects appears to be locked even though I did


Image of "Floating" Boxes

I made a simple simulation using custom obj and SDF files for these boxes I made. Hydroelastic contact is enabled (but the same behavior is also seen with point contacts). The boxes have mass and their inertia is a sphere perfectly at their center. I am adding the sdf to the scenario using load_scenario and MakeHardwareStation. I am not locking their rotation or position anywhere. When I run the simulation, why do the boxes "float"? Why do they not tip over and fall? I am not locking their rotation or position anywhere.

This is the bulk of my code:

builder = DiagramBuilder()

### Add Boxes
relative_path_to_gnd = 'Ground.sdf'
absolute_path_to_gnd = os.path.abspath(relative_path_to_gnd)

box_directives = f"""
directives:
- add_model:
    name: Ground
    file: file://{absolute_path_to_gnd}

- add_weld:
    parent: world
    child: Ground::Ground
"""
for i in range(NUM_BOXES):
    relative_path_to_box = 'Box_0_5_0_5_0_5.sdf'
    absolute_path_to_box = os.path.abspath(relative_path_to_box)

    box_pos_x = np.random.uniform(-1.5, 1.5, 1)
    box_pos_y = np.random.uniform(-1, 1, 1)
    box_pos_z = np.random.uniform(0, 5, 1)

    box_directives += f"""
- add_model: 
    name: Box_{i}
    file: file://{absolute_path_to_box}
    default_free_body_pose:
        Box_0_5_0_5_0_5:
            translation: [{box_pos_x[0]}, {box_pos_y[0]}, {box_pos_z[0]}]
            rotation: !Rpy {{ deg: [0, 0, 0] }}
"""

print(f"box_directives: {box_directives}")
    
scenario = load_scenario(data=box_directives)


### Hardware station setup
station = builder.AddSystem(MakeHardwareStation(
    scenario=scenario,
    meshcat=meshcat,
))
scene_graph = station.GetSubsystemByName("scene_graph")
plant = station.GetSubsystemByName("plant")

diagram = builder.Build()
simulator = Simulator(diagram)

####################################
### Running Simulation & Meshcat ###
####################################
simulator.set_target_realtime_rate(1)
simulator.set_publish_every_time_step(True)
plt.show()

meshcat.StartRecording()
simulator.AdvanceTo(box_randomization_runtime)
meshcat.PublishRecording()

I also made this notebook with barebones code replicating the issue: https://deepnote.com/workspace/michael-zengs-workspace-61364779-69ef-470a-9f8e-02bf2b4f369c/project/05-Bin-Picking-Duplicate-472e49aa-3d46-46ad-af7a-54f4c4a4294a/notebook/falling_things_test-ba1ae56fa3ad4ca6b6f3a73652f3d3e0

It appears to me like the rotation of the boxes is locked somehow; when I add the box directives into the scenario at an angle, they remain at the same rotation:

Image of "Floating" Boxes at a Different Rotation

Thank you!


Solution

  • Resolved! Inertia of the box (defined in the SDF file) was huge:

    <inertia>
        <ixx>5208333333333336.0</ixx>
        <ixy>-0.9094947017729282</ixy>
        <ixz>-0.9094947017729282</ixz>
        <iyy>5208333333333336.0</iyy>
        <iyz>-0.9094947017729282</iyz>
        <izz>5208333333333336.0</izz>
    </inertia>
    

    which effectively locked the box's rotation. I just had to make the inertia a reasonable number (changed it to 0.5 * identity matrix, since the box is 0.5 x 0.5 x 0.5 m).