Skip to content

Commit

Permalink
Readd slicing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenJester committed Feb 20, 2024
1 parent 88f472e commit 5b11605
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/test_transition_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,3 +1546,80 @@ def test_single_toggleable_machine_rule_output_object_success():
obj = DatasetObject(**obj_cfg)
og.sim.import_object(obj)
og.sim.step()

@og_test
def test_slicer_volume_sharp_end():
"""
Demo of slicing an apple into two apple slices
"""

# Create the scene config to load -- empty scene with knife and apple

# Grab reference to apple and knife
apple = og.sim.scene.object_registry("name", "apple")
knife = og.sim.scene.object_registry("name", "knife")
place_obj_on_floor_plane(apple)
place_obj_on_floor_plane(knife)


# Let apple settle
for _ in range(50):
og.sim.step()

# knife.keep_still()
knife.set_position_orientation(
position=apple.get_position() + np.array([-0.15, 0.0, 0.2]),
orientation=T.euler2quat([-np.pi / 4, 0, 0]),
)

# Step simulation for a bit so that apple is sliced
for i in range(10000):
og.sim.step()

# Check if apple is sliced
is_empty = len(og.sim.scene.object_registry("category", "half_apple", default_val=[])) == 0
assert not is_empty

# Remove objects
og.sim.remove_object(apple)
og.sim.remove_object(knife)

@og_test
def test_slicer_volume_blunt_end():
"""
Demo of slicing an apple into two apple slices
"""

# Create the scene config to load -- empty scene with knife and apple

# Grab reference to apple and knife
apple = og.sim.scene.object_registry("name", "apple")
knife = og.sim.scene.object_registry("name", "knife")
place_obj_on_floor_plane(apple)
place_obj_on_floor_plane(knife)

# Let apple settle
for _ in range(50):
og.sim.step()

knife.keep_still()
knife.set_position_orientation(
position=apple.get_position() + np.array([-0.15, 0.0, 0.15]),
orientation=T.euler2quat([np.pi / 2, 0, 0]),
)

# Step simulation for a bit so that apple is sliced
for i in range(100):
og.sim.step()


# Check if apple is not sliced
is_sliced = og.sim.scene.object_registry("name", "apple") is None
assert not is_sliced

# Remove objects
og.sim.remove_object(apple)
og.sim.remove_object(knife)

if __name__ == "__main__":
test_slicer_volume_sharp_end()

0 comments on commit 5b11605

Please sign in to comment.