Skip to content

[Question] how can i set different usd in different env #4084

@437142188

Description

@437142188

Question

when i use below code to set my env for parellel training, i cannot get different usd model correctly.

def _setup_scene(self):
        self.robot = Articulation(self.cfg.robot_cfg)
        # add ground plane
        spawn_ground_plane(prim_path="/World/ground", cfg=GroundPlaneCfg())

        map_paths = [
            f"{ISAAC_NUCLEUS_DIR}/Environments/Narrow_gap/localmap_02_collider.usd",
            f"{ISAAC_NUCLEUS_DIR}/Environments/Narrow_gap/localmap_29_collider_1.usd",
        ]
        
        num_envs = self.scene.cfg.num_envs
        
        for env_idx in range(num_envs):
            map_path = map_paths[env_idx % len(map_paths)]
            
            prim_path = f"/World/envs/env_{env_idx}/narrow_gap_localmap"
            
            cfg = sim_utils.UsdFileCfg(
                usd_path=map_path,
                rigid_props=sim_utils.RigidBodyPropertiesCfg(
                    rigid_body_enabled=True,
                    kinematic_enabled=True,
                    disable_gravity=True,
                ),
                collision_props=sim_utils.CollisionPropertiesCfg(
                    collision_enabled=True,
                ),
                activate_contact_sensors=False,
            )
            
            cfg.func(
                prim_path, cfg,
                translation=(-1.0, -1.0, -0.1),
                orientation=(1, 0.0, 0.0, 0)
            )

        # clone and replicate
        self.scene.clone_environments(
            copy_from_source=False,
        )

        # add lights
        light_cfg = sim_utils.DomeLightCfg(intensity=2000.0, color=(0.75, 0.75, 0.75))
        light_cfg.func("/World/Light", light_cfg)
        # add raycaster
        self.lidar_2d = MultiMeshRayCaster(self.cfg.lidar_2d)
        self.scene.sensors["lidar_2d"] = self.lidar_2d
        # add contact
        self.contact_sensor = ContactSensor(self.cfg.contact_sensor)
        self.scene.sensors["contact_sensor"] = self.contact_sensor

        # add articulation to scene
        self.scene.articulations["robot"] = self.robot

        self.scene.filter_collisions(
            global_prim_paths=["/World/ground"],
        )

        self.visualization_markers = define_markers()

        self.up_dir = torch.tensor([0.0, 0.0, 1.0]).cuda()  
        self.yaws = torch.zeros((self.cfg.scene.num_envs, 1)).cuda()
        self.commands = torch.randn((self.cfg.scene.num_envs, 3)).cuda()
        self.commands[:,-1] = 0.0
        self.commands = self.commands/torch.linalg.norm(self.commands, dim=1, keepdim=True)
        
        # offsets to account for atan range and keep things on [-pi, pi]
        ratio = self.commands[:,1]/(self.commands[:,0]+1E-8)
        gzero = torch.where(self.commands > 0, True, False)
        lzero = torch.where(self.commands < 0, True, False)
        plus = lzero[:,0]*gzero[:,1]
        minus = lzero[:,0]*lzero[:,1]
        offsets = torch.pi*plus - torch.pi*minus
        self.yaws = torch.atan(ratio).reshape(-1,1) + offsets.reshape(-1,1)

        self.marker_locations = torch.zeros((self.cfg.scene.num_envs, 3)).cuda()
        self.marker_offset = torch.zeros((self.cfg.scene.num_envs, 3)).cuda()
        self.marker_offset[:,-1] = 0.5
        self.forward_marker_orientations = torch.zeros((self.cfg.scene.num_envs, 4)).cuda()
        self.command_marker_orientations = torch.zeros((self.cfg.scene.num_envs, 4)).cuda()
Image

as the picture shows, all the lidar in different env percept same mesh, although they visual not same type. Beside, all the envs have same collider feature that shows in env0 usd file, maybe i am not use correct usd import function, Thanks for help me!

Build Info

Describe the versions that you are currently using:

  • Isaac Lab Version: 2.2.0
  • Isaac Sim Version: 5.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions