I use python to use GeometryPrim. Here is my code " def add_table(self,table_position=np.array([[0.7,0.2,1.03]]),
hole_translation= np.array([[-0.06, -0.1, 0.0]]),
hole_orientation= None,
peg_translation= np.array([[-0.1, -0.15, 0.0]]),
peg_orientation= None):
# 创建桌子
# hole and peg will seted in their parent frame, just use translation
# position is relative to the world frame,so just translation
table_path = self.assets_root_path + “/Isaac/Props/Mounts/textured_table.usd”
add_reference_to_stage(usd_path=table_path, prim_path=“/World/table”)
self.table = RigidPrim(prim_paths_expr=“/World/table”,name=“table_0”,
positions=table_position / get_stage_units(),
)
self.world.scene.add(self.table)
self.world.reset()
hole_path = self.assets_root_path + “/Isaac/IsaacLab/Factory/factory_hole_8mm.usd”
peg_path = self.assets_root_path + “/Isaac/IsaacLab/Factory/factory_peg_8mm.usd”
add_reference_to_stage(usd_path=hole_path,prim_path=“/World/table/hole”)
add_reference_to_stage(usd_path=peg_path,prim_path=“/World/table/peg”)
self.hole = GeometryPrim(prim_paths_expr=“/World/table/hole”,name=“hole_0”,
translations=hole_translation / get_stage_units(),
orientations=hole_orientation,
)
# add_reference_to_stage(usd_path=hole_path,prim_path=“/World/hole”)
# self.hole = RigidPrim(prim_paths_expr=“/World/hole”,name=“hole_0”,
# positions=np.array([[0.64, 0.1 , 1.03]])
# )
self.world.scene.add(self.hole)
self.world.reset()
self.peg = GeometryPrim(prim_paths_expr="/World/table/peg",name="peg_0",
translations=peg_translation / get_stage_units(),
orientations=peg_orientation,
)
# add_reference_to_stage(usd_path=peg_path,prim_path="/World/peg")
# self.peg = RigidPrim(prim_paths_expr="/World/peg",name="peg_0",
# positions=np.array([[0.59999996, 0.05 , 1.03 ]])
# )
self.world.scene.add(self.peg)
self.world.reset()
import numpy as np
import gymnasium as gym
import sys
import cv2 # 用于图像处理
import carb
from isaacsim.core.api import World
from isaacsim.robot.manipulators.examples.franka import Franka
from isaacsim.robot.manipulators.examples.franka import KinematicsSolver
from isaacsim.core.utils.stage import add_reference_to_stage, get_stage_units
from isaacsim.storage.native import get_assets_root_path
from isaacsim.core.utils.viewports import set_camera_view
from isaacsim.core.utils.rotations import matrix_to_euler_angles, euler_angles_to_quat
from isaacsim.core.api.objects import VisualSphere, VisualCylinder
from isaacsim.core.prims import GeometryPrim,RigidPrim
from omni.isaac.sensor import Camera
from pxr import UsdLux, Gf
class FrankaGym(gym.Env):
metadata = {‘render.modes’: [‘human’]}
def init(self, max_steps=1000, stage_units =1.0, render=True, render_mode=‘human’,task_message=None):
self.max_steps = max_steps
self.episode_steps = 0
self.render = render
self.render_mode = render_mode
self.action_space = gym.spaces.Box(low=-1.0, high=1.0, shape=(7,))
self.observation_space = gym.spaces.Box(low=-np.inf, high=np.inf, shape=(10,))
self.world = World(stage_units_in_meters=stage_units)
self.world.scene.add_default_ground_plane()
set_camera_view(
eye=[1.3, 0.,1.6], target=[0.00, 0.00, 0.9], camera_prim_path="/OmniverseKit_Persp") # set camera view
self.stage = self.world.stage
self.assets_root_path = get_assets_root_path()
if self.assets_root_path is None:
carb.log_error("Could not find Isaac Sim assets folder")
self.simulation_app.close()
sys.exit()
self.add_franka()
self.add_sphere_light()
self.add_table()
self.world.step(render=self.render)
self.camera_world = Camera(prim_path="/World/CameraWorld",
name="camera_1",
resolution=(256,256),
frequency=20,
orientation=np.array([0.,0.,0.,-1.]),
position=np.array([1,0.0,1.2]),
)
self.camera_world.set_clipping_range(0.01, 10.0)
self.camera_world.set_focal_length(1)
self.world.scene.add(self.camera_world)
self.world.reset()
print("peg_offsets:",self.peg.get_rest_offsets())
print("peg_contact_offsets:",self.peg.get_contact_offsets())
"
The two prints have the same question.