Skip to content

Commit 894af33

Browse files
committed
Keep lockstep compatible with ROS 2 Humble
Signed-off-by: Lionel Gulich <lgulich@nvidia.com>
1 parent 3ea51de commit 894af33

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎mujoco_ros2_control/src/mujoco_system_interface.cpp‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,28 @@ MujocoSystemInterface::on_init(const hardware_interface::HardwareComponentInterf
395395
}
396396
else
397397
{
398+
#if ROS_DISTRO_HUMBLE
399+
// Humble's HardwareInfo does not expose the controller read/write rate.
400+
// A caller can still select a different ratio with lockstep_steps_per_update.
401+
lockstep_steps_per_update_ = 1;
402+
#else
398403
const double controller_period = 1.0 / static_cast<double>(get_hardware_info().rw_rate);
399-
lockstep_steps_per_update_ =
400-
std::max<uint32_t>(1, static_cast<uint32_t>(std::round(controller_period / simulation_->model()->opt.timestep)));
404+
lockstep_steps_per_update_ = std::max<uint32_t>(
405+
1, static_cast<uint32_t>(std::round(controller_period / simulation_->model()->opt.timestep)));
406+
#endif
401407
}
402408

403409
const double lockstep_period =
404410
static_cast<double>(lockstep_steps_per_update_) * simulation_->model()->opt.timestep;
405411
RCLCPP_INFO(get_logger(),
406412
"MuJoCo lockstep uses %u physics step(s) per ros2_control update: timestep %.6f s, effective period %.6f s",
407413
lockstep_steps_per_update_, simulation_->model()->opt.timestep, lockstep_period);
414+
#if !ROS_DISTRO_HUMBLE
415+
const double controller_period = 1.0 / static_cast<double>(get_hardware_info().rw_rate);
416+
RCLCPP_WARN_EXPRESSION(get_logger(), std::abs(lockstep_period - controller_period) > 1e-9,
417+
"MuJoCo lockstep period %.6f s does not match controller period %.6f s.", lockstep_period,
418+
controller_period);
419+
#endif
408420
}
409421

410422
// Time publisher will be pushed from the simulation wrapper.

0 commit comments

Comments
 (0)