Skip to content

[Question] Unable to reset the position of an object fixed in the world #4147

@seanxd0727

Description

@seanxd0727

Question

Hello, I want to randomize the state of an object during training and add a platform fixed in the world coordinate system below the object. But write_root_link_pose_to_sim is not work. Platform always initialized in the default position.

Here is my randomization code:

def reset_object_state_with_platform_uniform(
    env: ManagerLocoManipRLEnv,
    env_ids: torch.Tensor,
    pose_range: dict[str, tuple[float, float]],
    velocity_range: dict[str, tuple[float, float]],
    object_cfg: SceneEntityCfg = SceneEntityCfg("object"),
    platform_cfg: SceneEntityCfg = SceneEntityCfg("platform"),
):
    # extract the used quantities (to enable type-hinting)
    object: RigidObject | Articulation = env.scene[object_cfg.name]
    platform: RigidObject = env.scene[platform_cfg.name]
    # get default root state
    root_states = object.data.default_root_state[env_ids].clone()
    # poses
    range_list = [pose_range.get(key, (0.0, 0.0)) for key in ["x", "y", "z", "roll", "pitch", "yaw"]]
    ranges = torch.tensor(range_list, device=object.device)
    rand_samples = math_utils.sample_uniform(ranges[:, 0], ranges[:, 1], (len(env_ids), 6), device=object.device)

    if env.object_aabb_local_cache is None:
        prim_paths = sim_utils.find_matching_prim_paths(object.cfg.prim_path)
        cache = bounds_utils.create_bbox_cache()
        aabb_list = [bounds_utils.compute_aabb(cache, prim_path=path) for path in prim_paths]
        aabb_np = np.stack(aabb_list, axis=0)  # (N,6)
        size_np = aabb_np[:, 3:] - aabb_np[:, :3]  # (N,3)
        env.object_aabb_local_cache = torch.from_numpy(size_np).to(env.device).to(torch.float32)  # (N,3)

    positions = root_states[:, 0:3] + env.scene.env_origins[env_ids] + rand_samples[:, 0:3]
    platform_pos_z = positions[:, 2] - 0.5 * env.object_aabb_local_cache[env_ids, 2] - 0.01
    platform_pos = torch.cat([positions[:, :2], platform_pos_z.unsqueeze(-1)], dim=-1)
    orientations_delta = math_utils.quat_from_euler_xyz(rand_samples[:, 3], rand_samples[:, 4], rand_samples[:, 5])
    orientations = math_utils.quat_mul(root_states[:, 3:7], orientations_delta)
    # velocities
    range_list = [velocity_range.get(key, (0.0, 0.0)) for key in ["x", "y", "z", "roll", "pitch", "yaw"]]
    ranges = torch.tensor(range_list, device=object.device)
    rand_samples = math_utils.sample_uniform(ranges[:, 0], ranges[:, 1], (len(env_ids), 6), device=object.device)

    velocities = root_states[:, 7:13] + rand_samples

    # set into the physics simulation
    object.write_root_pose_to_sim(torch.cat([positions, orientations], dim=-1), env_ids=env_ids)
    object.write_root_velocity_to_sim(velocities, env_ids=env_ids)
    platform.write_root_link_pose_to_sim(torch.cat([platform_pos, orientations], dim=-1), env_ids=env_ids)
PLATFORM_CFG = RigidObjectCfg(
    spawn=sim_utils.UrdfFileCfg(
        asset_path=f"{XD_LAB_DESCRIPTION_DIR}/objects/platform/platform0.urdf",
        usd_dir=f"{XD_LAB_DESCRIPTION_DIR}/objects/platform/usd",
        usd_file_name="platform0.usd",
        fix_base=True,
        activate_contact_sensors=False,
        articulation_props=sim_utils.ArticulationRootPropertiesCfg(articulation_enabled=False),
        rigid_props=sim_utils.RigidBodyPropertiesCfg(),
        joint_drive=sim_utils.UrdfConverterCfg.JointDriveCfg(
            gains=sim_utils.UrdfConverterCfg.JointDriveCfg.PDGainsCfg(
                stiffness=0,
                damping=0,
            ),
        ),
    ),
    init_state=RigidObjectCfg.InitialStateCfg(),
)

Build Info

  • Isaac Lab Version: [e.g. 2.3.0]
  • Isaac Sim Version: [e.g. 5.1]

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