Hi Everyone,
I am following the Isaac Sim Example menu, where we create our own example in the menu and add a franka robot pick-and-place a cube (available on the website).
What I tried to is to do the pick-and-place of a deformable cube instead. My code is as follows. The cube is successfully created, can be seen dropping on the floor in scene and also in the stage tree under WORLD, and also verified by the print commands in deformable cube creation function. But as soon as the SETUP_POST_LOAD function calls
“self._deformable_cube = self._world.scene.get_object(“world/deformable_cube”)”,
error comes up, I guess comes as NONE or empty. I feel the reason is that it is wrong way to get a deformable object, but what should I use then instead ?
Any help is highly appreciated.
######### CODE #################
Blockquote
from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.franka import Franka
from omni.isaac.franka.controllers import PickPlaceController
import numpy as np
import omni.usd
from omni.physx.scripts import deformableUtils, physicsUtils
from pxr import UsdGeom, Gf
from omni.isaac.kit import SimulationApp
from omni.isaac.core import SimulationContext
from omni.isaac.core.physics_context.physics_context import PhysicsContext
import asyncio
class HelloWorld(BaseSample):
def init(self) → None:
super().init()
return
def create_deformable_cube(self, stage, target_path):
# Function to create deformable cube
_, tmp_path = omni.kit.commands.execute("CreateMeshPrim", prim_type="Cube", select_new_prim=False)
omni.kit.commands.execute("MovePrim", path_from=tmp_path, path_to=target_path)
# Debugging output
print(f"Creating deformable cube at {target_path}")
# Set cube mesh attributes
cube_mesh = UsdGeom.Mesh.Get(stage, target_path)
if cube_mesh:
print("Cube mesh found, setting attributes...")
cube_mesh.GetPrim().GetAttribute("xformOp:translate").Set(Gf.Vec3f(0.3, 0.3, 0.3)) # Set initial position
cube_mesh.GetPrim().GetAttribute("xformOp:scale").Set(Gf.Vec3f(0.05, 0.05, 0.05)) # Small scale for the cube
# Apply PhysX deformable body settings
deformableUtils.add_physx_deformable_body(
stage,
cube_mesh.GetPath(),
collision_simplification=True,
simulation_hexahedral_resolution=10,
self_collision=False,
)
print("Deformable body added successfully.")
else:
print("Error: Deformable cube not created.")
return cube_mesh
def setup_scene(self):
# Initialize the physics context and configure settings
self._scene = PhysicsContext()
self._scene.set_solver_type("TGS") # Set solver type to TGS
self._scene.set_broadphase_type("GPU") # Set broadphase type to GPU
self._scene.enable_gpu_dynamics(flag=True) # Enable GPU dynamics
world = self.get_world()
stage = omni.usd.get_context().get_stage()
# Add ground plane and Franka robot
world.scene.add_default_ground_plane()
franka = world.scene.add(Franka(prim_path="/World/Fancy_Franka", name="fancy_franka"))
# Create a deformable cube as a target for pick-and-place
deformable_cube_path = "/World/deformable_cube"
deformable_cube = self.create_deformable_cube(stage, deformable_cube_path)
# List all prims in the scene for debugging
print("Current prims in the scene:")
for prim in stage.Traverse():
print(f"- {prim.GetPath()}")
# Set up deformable material and apply it
deformable_material_path = omni.usd.get_stage_next_free_path(stage, "/World/deformableBodyMaterial", True)
deformableUtils.add_deformable_body_material(
stage,
deformable_material_path,
youngs_modulus=10000.0,
poissons_ratio=0.49,
damping_scale=0.0,
dynamic_friction=0.5,
)
physicsUtils.add_physics_material_to_prim(stage, deformable_cube.GetPrim(), deformable_material_path)
return
async def setup_post_load(self):
self._world = self.get_world()
self._franka = self._world.scene.get_object("fancy_franka")
print(self._franka)
#await asyncio.sleep(3)
# Check if the deformable cube exists
self._deformable_cube = self._world.scene.get_object("world/deformable_cube")
if self._deformable_cube:
print(f"Found deformable cube at: {self._deformable_cube.get_path()}")
else:
print("Deformable cube not found. Please check the cube creation logic.")
# Initialize pick and place controller
self._controller = PickPlaceController(
name="pick_place_controller",
gripper=self._franka.gripper,
robot_articulation=self._franka,
)
self._world.add_physics_callback("sim_step", callback_fn=self.physics_step)
await self._world.play_async()
return
async def setup_post_reset(self):
self._controller.reset()
self._franka.gripper.set_joint_positions(self._franka.gripper.joint_opened_positions)
await self._world.play_async()
return
def physics_step(self, step_size):
# Ensure the deformable cube has a world pose
if self._deformable_cube is None:
print("Deformable cube is not initialized.")
return
cube_position, _ = self._deformable_cube.get_world_pose()
goal_position = np.array([-0.3, -0.3, 0.025]) # Adjusted for the height of the cube
current_joint_positions = self._franka.get_joint_positions()
actions = self._controller.forward(
picking_position=cube_position,
placing_position=goal_position,
current_joint_positions=current_joint_positions,
)
self._franka.apply_action(actions)
# Check if the pick and place operation is done
if self._controller.is_done():
self._world.pause()
return
Please provide all relevant details below before submitting your post. This will help the community provide more accurate and timely assistance. After submitting, you can check the appropriate boxes. Remember, you can always edit your post later to include additional information if needed.
Isaac Sim Version
4.2.0
4.1.0
4.0.0
2023.1.1
2023.1.0-hotfix.1
Other (please specify):
Isaac Lab Version (if applicable)
1.2
1.1
1.0
Other (please specify):
Operating System
Ubuntu 22.04
Ubuntu 20.04
Windows 11
Windows 10
Other (please specify):