Skip to content

Commit c7a50d1

Browse files
committed
fix: default HW sometimes using wrong mj joint ids
1 parent 1b1cc9a commit c7a50d1

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Loading and reset times are reported in the server debug log. All plugin stats c
1111

1212
### Fixed
1313
* Added missing call to render callbacks in viewer. While the callbacks were still being run for offscreen rendering, the viewer did not render additional geoms added by plugins.
14+
* *mujoco_ros_control*: fixed sometimes using wrong joint id in default hardware interface (would only be correct, if the joints appear first and in the same order in the compiled MuJoCo model).
1415

1516
### Changed
1617
* Moved `mujoco_ros::Viewer::Clock` definition to `mujoco_ros::Clock` (into common_types.h).

mujoco_ros_control/src/default_robot_hw_sim.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ void DefaultRobotHWSim::writeSim(ros::Time time, ros::Duration period)
269269
for (unsigned int j = 0; j < n_dof_; j++) {
270270
switch (joint_control_methods_[j]) {
271271
case EFFORT: {
272-
const double effort = e_stop_active_ ? 0 : joint_effort_command_[j];
273-
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[j]] = effort;
272+
const double effort = e_stop_active_ ? 0 : joint_effort_command_[j];
273+
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = effort;
274274
break;
275275
}
276276

277277
case POSITION: {
278-
d_ptr_->qpos[m_ptr_->jnt_dofadr[j]] = joint_position_command_[j];
279-
d_ptr_->qvel[m_ptr_->jnt_dofadr[j]] = 0.;
280-
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[j]] = 0.;
278+
d_ptr_->qpos[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = joint_position_command_[j];
279+
d_ptr_->qvel[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = 0.;
280+
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = 0.;
281281
break;
282282
}
283283

@@ -299,13 +299,13 @@ void DefaultRobotHWSim::writeSim(ros::Time time, ros::Duration period)
299299

300300
const double effort_limit = joint_effort_limits_[j];
301301
const double effort = clamp(pid_controllers_[j].computeCommand(error, period), -effort_limit, effort_limit);
302-
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[j]] = effort;
302+
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = effort;
303303
break;
304304
}
305305

306306
case VELOCITY: {
307-
d_ptr_->qvel[m_ptr_->jnt_dofadr[j]] = e_stop_active_ ? 0. : joint_velocity_command_[j];
308-
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[j]] = 0.;
307+
d_ptr_->qvel[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = e_stop_active_ ? 0. : joint_velocity_command_[j];
308+
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = 0.;
309309
break;
310310
}
311311

@@ -318,7 +318,7 @@ void DefaultRobotHWSim::writeSim(ros::Time time, ros::Duration period)
318318
error = joint_velocity_command_[j] - joint_velocity_[j];
319319
const double effort_limit = joint_effort_limits_[j];
320320
const double effort = clamp(pid_controllers_[j].computeCommand(error, period), -effort_limit, effort_limit);
321-
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[j]] = effort;
321+
d_ptr_->qfrc_applied[m_ptr_->jnt_dofadr[mujoco_joint_ids_[j]]] = effort;
322322
break;
323323
}
324324
}

0 commit comments

Comments
 (0)