Skip to content

BuiltinPdActuator applies swapped pos/vel targets when EntityCfg.sort_actuators=True #1170

Open

Description

@hadelan

When an entity uses EntityCfg(sort_actuators=True), Entity._add_actuators flattens each actuator config to per-target calls: edit_spec(spec, [name]) once per target. BuiltinPdActuator.edit_spec appends one <position> and one <velocity> element per call, so the elements end up interleaved in the compiled model:

sort_actuators=False: [joint1_pd_pos, joint2_pd_pos, joint1_pd_vel, joint2_pd_vel]
sort_actuators=True:  [joint1_pd_pos, joint1_pd_vel, joint2_pd_pos, joint2_pd_vel]

But compute() still returns torch.cat((position_target, velocity_target)) (the [pos..., vel...] block layout), and ctrl_ids are derived from the appended order, so position targets are written to velocity actuators and vice versa. dr.pd_gains slices ctrl_ids[:n] / ctrl_ids[n:] under the same block assumption and randomizes the wrong elements too.

Repro (2-joint robot, kp=100, kd=10, pos target [0.1, 0.2], vel target [1.0, 2.0], joints at rest):

sort_actuators=False: qfrc_actuator = [20.0, 40.0]   # = kp*pos + kd*vel, correct
sort_actuators=True:  qfrc_actuator = [12.0, 120.0]  # scrambled

No test covers the combination: sort_actuators is only exercised with single-ctrl actuators, and the BuiltinPd layout test uses the default unsorted path.

Activity

  1. added
    bug
    on Sep 4, 2026
  2. OrangeScript commented on Nov 27, 2026

    @OrangeScript

    I reproduced this on mjlab 1.6.1. With sort_actuators=True, the two joints produced [12, 120] N·m. I verified that main at d872bfd produces [20, 40] N·m with sorting both on and off.

    I also checked dr.pd_gains. Scaling stiffness by 2 and damping by 3 produced [24, 360] N·m on unpatched 1.6.1 with sorting enabled, and the expected [50, 100] N·m on main. Backporting #1303 to 1.6.1 gave the expected results on both CPU and an RTX 3060 Laptop GPU.

    Thanks @hadelan for the report and @saikishor for the fix. Can this issue be closed as resolved on main?

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