Skip to content

[Bug Report] set the initial joint state of articulation, but it doesn't work. #2663

Closed

Description

@wghou

Describe the bug

I create a manager-based task and add a robot(articulation) into the scene, and set the initial joint state of the robot(articulation). But the joint state always be ZERO when I run the simulation.

I review the source code and try to figure out the flow of setting initial joint state of articulation, as following:

  1. the initial joint state is usually store in ArticulationCfg, i.e. FRANKA_PANDA_CFG;
  2. then it is store in ArticulationData.default_joint_pos;
  3. Call Articulation.write_joint_state_to_sim(joint_pos, joint_vel), we can set the joint state based on the initial joint pos;
  4. Call Articulation.set_joint_position_target(ArticulationData.default_joint_pos), we can set the joint target pos based the initial joint pos.

For example, the event function randomize_joint_by_gaussian_offset, it set the joint current pos and joint target pos based on default_joint_pos (initial joint state), as following:

def randomize_joint_by_gaussian_offset(
    env: ManagerBasedEnv,
    env_ids: torch.Tensor,
    mean: float,
    std: float,
    asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"),
):
    asset: Articulation = env.scene[asset_cfg.name]

    # Add gaussian noise to joint states
    joint_pos = asset.data.default_joint_pos[env_ids].clone()
    joint_vel = asset.data.default_joint_vel[env_ids].clone()
    joint_pos += math_utils.sample_gaussian(mean, std, joint_pos.shape, joint_pos.device)

    # Clamp joint pos to limits
    joint_pos_limits = asset.data.soft_joint_pos_limits[env_ids]
    joint_pos = joint_pos.clamp_(joint_pos_limits[..., 0], joint_pos_limits[..., 1])

    # Don't noise the gripper poses
    joint_pos[:, -2:] = asset.data.default_joint_pos[env_ids, -2:]

    # Set into the physics simulation
    asset.set_joint_position_target(joint_pos, env_ids=env_ids)
    asset.set_joint_velocity_target(joint_vel, env_ids=env_ids)
    asset.write_joint_state_to_sim(joint_pos, joint_vel, env_ids=env_ids)

BUT, in the event function reset_scene_to_default, it only reset the joint current pos. The joint target pos would be zero. When I run the simulation, the joint position would goes to zero, rather than the initial state we already set.

def reset_scene_to_default(env: ManagerBasedEnv, env_ids: torch.Tensor):
    """Reset the scene to the default state specified in the scene configuration."""
    # rigid bodies
    for rigid_object in env.scene.rigid_objects.values():
        # obtain default and deal with the offset for env origins
        default_root_state = rigid_object.data.default_root_state[env_ids].clone()
        default_root_state[:, 0:3] += env.scene.env_origins[env_ids]
        # set into the physics simulation
        rigid_object.write_root_pose_to_sim(default_root_state[:, :7], env_ids=env_ids)
        rigid_object.write_root_velocity_to_sim(default_root_state[:, 7:], env_ids=env_ids)
    # articulations
    for articulation_asset in env.scene.articulations.values():
        # obtain default and deal with the offset for env origins
        default_root_state = articulation_asset.data.default_root_state[env_ids].clone()
        default_root_state[:, 0:3] += env.scene.env_origins[env_ids]
        # set into the physics simulation
        articulation_asset.write_root_pose_to_sim(default_root_state[:, :7], env_ids=env_ids)
        articulation_asset.write_root_velocity_to_sim(default_root_state[:, 7:], env_ids=env_ids)
        # obtain default joint positions
        default_joint_pos = articulation_asset.data.default_joint_pos[env_ids].clone()
        default_joint_vel = articulation_asset.data.default_joint_vel[env_ids].clone()
        # set into the physics simulation
        articulation_asset.write_joint_state_to_sim(default_joint_pos, default_joint_vel, env_ids=env_ids)
    # deformable objects
    for deformable_object in env.scene.deformable_objects.values():
        # obtain default and set into the physics simulation
        nodal_state = deformable_object.data.default_nodal_state_w[env_ids].clone()
        deformable_object.write_nodal_state_to_sim(nodal_state, env_ids=env_ids)

Steps to reproduce

We can reproduce the situtation described above based on task Isaac-Stack-Cube-Franka-IK-Rel-v0, as following:

In file isaaclab_tasks/manager_based/manipulation/stack/franka/stack_joint_pos_env_cfg.py, remove the randomize_franka_joint_state term in the EnvCfg:

@configclass
class EventCfg:
    """Configuration for events."""

    init_franka_arm_pose = EventTerm(
        func=franka_stack_events.set_default_joint_pose,
        mode="startup",
        params={
            "default_pose": [0.0444, -0.1894, -0.1107, -2.5148, 0.0044, 2.3775, 0.6952, 0.0400, 0.0400],
        },
    )

    #randomize_franka_joint_state = EventTerm(
    #    func=franka_stack_events.randomize_joint_by_gaussian_offset,
    #    mode="reset",
    #    params={
    #        "mean": 0.0,
    #        "std": 0.02,
    #        "asset_cfg": SceneEntityCfg("robot"),
    #    },
    #)

    randomize_cube_positions = EventTerm(
        func=franka_stack_events.randomize_object_pose,
        mode="reset",
        params={
            "pose_range": {"x": (0.4, 0.6), "y": (-0.10, 0.10), "z": (0.0203, 0.0203), "yaw": (-1.0, 1, 0)},
            "min_separation": 0.1,
            "asset_cfgs": [SceneEntityCfg("cube_1"), SceneEntityCfg("cube_2"), SceneEntityCfg("cube_3")],
        },
    )

The result is as following:

Image

Activity

  1. RandomOakForest commented on Jun 12, 2025

    @RandomOakForest
    Collaborator

    Thank you for posting this. The issue arises from how joint target positions are handled during scene resets in Isaac Lab. When setting initial joint states for articulations, both the current joint state and target positions must be configured to prevent unexpected behavior with implicit PD controllers.

    The reset_scene_to_default event function only sets current joint positions/velocities via write_joint_state_to_sim(), but doesn't configure target positions. This causes position-controlled articulations to revert to default (zero) targets during simulation (see ref.).

    Try modifying the reset function to include target position configuration:

    def reset_scene_to_default(...):
        # Existing root/joint state code
        articulation_asset.write_joint_state_to_sim(...)
        
        # Add target position configuration
        articulation_asset.set_joint_position_target(
            default_joint_pos, 
            env_ids=env_ids
        )
  2. wghou commented on Jun 13, 2025

    @wghou
    ContributorAuthor

    Thank you for posting this. The issue arises from how joint target positions are handled during scene resets in Isaac Lab. When setting initial joint states for articulations, both the current joint state and target positions must be configured to prevent unexpected behavior with implicit PD controllers.

    The reset_scene_to_default event function only sets current joint positions/velocities via write_joint_state_to_sim(), but doesn't configure target positions. This causes position-controlled articulations to revert to default (zero) targets during simulation (see ref.).

    Try modifying the reset function to include target position configuration:

    def reset_scene_to_default(...):
    # Existing root/joint state code
    articulation_asset.write_joint_state_to_sim(...)

    # Add target position configuration
    articulation_asset.set_joint_position_target(
        default_joint_pos, 
        env_ids=env_ids
    )
    

    Thanks for your reply. Yes, your are right. We have to set both the default_joint_state and joint_position_target.

    But, in the source file of IsaacLab https://github.com/isaac-sim/IsaacLab/blob/main/source/isaaclab/isaaclab/envs/mdp/events.py , line 1137, it doesn't set the joint_position_target. It would cause bug, as i described above.

    I have fix this bug, as described in #2692 , could you please help to review it.

    Thanks.

  3. RandomOakForest commented on Jun 13, 2025

    @RandomOakForest
    Collaborator

    Thanks for adding the PR. The team will review it.

  4. added
    bug
    on Jun 13, 2025
  5. kellyguo11 commented on Jun 25, 2025

    @kellyguo11
    Contributor

    Fixed in #2692

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions