Skip to content

Support for different control modes with mujoco by defining PIDs - #5

Merged
saikishor merged 49 commits into
ros-controls:jazzy-develfrom
pal-robotics-forks:feature-mujoco-control-mode-dependence
Dec 3, 2025
Merged

saikishor merged 49 commits into
ros-controls:jazzy-develfrom
pal-robotics-forks:feature-mujoco-control-mode-dependence

Conversation

@saikishor

@saikishor saikishor commented Nov 24, 2025 •

Copy link
Copy Markdown
Member

Hello!

We added a new feature here. If you define the PIDs via an argument, then you can utilize different control modes. For instance, with a standard MuJoCo actuator, after defining gains of position and velocity PIDs, you can control the robot in position, velocity or effort.

We also added an example test case, so you can try it out

Kudos to @Ortisa

Similar to NASA-JSC-Robotics/mujoco_ros2_simulation#38

@eholum-nasa eholum-nasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here, @saikishor! The changes look great. Thanks for your efforts there.

Just the one, very, very nit comment but IMO we should ship this and keep moving forward.

Comment thread README.md Outdated
Comment thread src/mujoco_system_interface.cpp
Comment thread src/mujoco_system_interface.cpp
Comment thread src/mujoco_system_interface.cpp Outdated
last_joint_state.is_position_control_enabled = true;
last_joint_state.position_command =
should_override_start_position ? mj_data_->ctrl[joint_state.mj_actuator_id] : last_joint_state.position;
if (last_joint_state.actuator_type == ActuatorType::VELOCITY ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The comments and the table in the README are also super helpful here.

ros__parameters:
pid_gains:
position:
joint1:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could probably tweak these to work in a more stable fashion but I'm also not sure what I was thinking when I made these links 27 kg each...

Fun to play with these though!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might as well update these to real values as a part of this PR so it is reasonable to test? Bc at the moment, it is hard to verify functionality with those values

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can do it. Give us sometime

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think mainly just so that the default gains work well in test space. To get something relatively reasonable I was ending up with some pretty strange gains 0.o

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh blah. Yeah I was thinking we should consolidate the example models into a single file and maybe xacro out the driver specifics. When we do that we should not have 27 kg links and pick something a little more reasonable that is easier to tune with "normal" gains.

Thoughts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I have some more reasonable gains.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @saikishor! I just tried it and things look great, though we might have to add i_clamp values to accommodate this... silly timing...

ros-controls/control_toolbox#515

Which looks like it just got released and picked up locally... Here's the config that worked for me:

/**:
  ros__parameters:
    pid_gains:
      position:
        joint1:
          p: 200.0
          i: 0.005
          d: 50.0
          u_clamp_max: 100.0
          u_clamp_min: -100.0
          i_clamp_max: 10.0
          i_clamp_min: -10.0
        joint2:
          p: 200.0
          i: 0.005
          d: 50.0
          u_clamp_max: 100.0
          u_clamp_min: -100.0
          i_clamp_max: 10.0
          i_clamp_min: -10.0
    pid_gains:
      velocity:
        joint1:
          p: 100.0
          i: 0.001
          d: 5.0
          u_clamp_max: 100.0
          u_clamp_min: -100.0
          i_clamp_max: 10.0
          i_clamp_min: -10.0
        joint2:
          p: 100.0
          i: 0.001
          d: 5.0
          u_clamp_max: 100.0
          u_clamp_min: -100.0
          i_clamp_max: 10.0
          i_clamp_min: -10.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh whoops... mixing work and non-work accounts again...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha. Thanks. I just updated the gains

@eholum-nasa eholum-nasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I was going to apply and merge that line fix but don't have access... if you modify it I think this is GTG!

Co-authored-by: Erik Holum <erik.holum@nasa.gov>

@eholum-nasa eholum-nasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it!

Comment thread src/mujoco_system_interface.cpp Outdated
joint.name.c_str());
}
}
else if (last_joint_state.actuator_type == ActuatorType::POSITION)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we somehow warn the user if they specified PID gains, but the position control actuator is actually used instead? I think power users would probably understand the implication of mixing and matching mujoco actuator types with pid actuator types, but I think relatively newer users might just assume that adding their own pid gains and including that file in the ros2 control tag would mean that those would be the default behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not the default behaviour. I've added a table in the README to explain the same
image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use effort and then PIDs of the position and velocity, you should be able to switch between them at runtime

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess that is fair. I think maybe just adding a comment that the mujoco actuator of a specific type will be preferred if both that mujoco actuator and the pid of that type is specified.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@saikishor

Copy link
Copy Markdown
Member Author

@ndunkelb-nasa I've addressed your comments

@eholum-nasa eholum-nasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the right account!

@ndunkelb-nasa

Copy link
Copy Markdown
Collaborator

@ndunkelb-nasa I've addressed your comments

Thanks, I think it looks good!

@saikishor
saikishor merged commit fb9d346 into ros-controls:jazzy-devel Dec 3, 2025
5 checks passed
@saikishor
saikishor deleted the feature-mujoco-control-mode-dependence branch December 3, 2025 17:06
saikishor added a commit to pal-robotics-forks/mujoco_ros2_control that referenced this pull request Dec 3, 2025
…-controls#5)

---------

Co-authored-by: Ortisa Poci <ortisa.poci@studenti.unipd.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants