MJCF import: auto-enable actuator *limited flags when *range is specified in MJCF#1504
Conversation
📝 WalkthroughWalkthroughAdds automatic resolution of MuJoCo actuator limited flags (ctrllimited, forcelimited, actlimited) based on corresponding range attributes when the limited flags are not explicitly specified; adds inline MJCF comments and new tests validating this behavior. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… MJCF Implements MuJoCo's auto-inference behavior: if ctrllimited/forcelimited/actlimited is not explicitly set in MJCF but the corresponding range attribute has valid values (range[0] < range[1]), automatically enable the limit flag. This matches native MuJoCo behavior where specifying a range implicitly enables the corresponding limit unless explicitly disabled. Changes: - Add resolution logic in MJCF parser after parsing custom attributes - Add comments to solver_mujoco.py custom attribute definitions Tests: - test_ctrllimited_auto_enabled_when_ctrlrange_specified - test_ctrllimited_not_auto_enabled_without_ctrlrange - test_ctrllimited_explicit_false_not_overridden - test_forcelimited_auto_enabled_when_forcerange_specified - test_actlimited_auto_enabled_when_actrange_specified
e48ebd1 to
3fa2891
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@newton/_src/utils/import_mjcf.py`:
- Around line 1871-1884: The limit auto-enable logic is incorrectly reading
actuator_elem.attrib directly and checking for limited_attr there, which ignores
defaults; update the loop that resolves ("ctrllimited","ctrlrange",...),
("forcelimited","forcerange",...), ("actlimited","actrange",...) to use
merged_attrib for both the presence check and for reading the range string
(i.e., check if limited_attr not in merged_attrib and get range_str =
merged_attrib.get(range_attr, "")), then keep the existing parsing and setting
parsed_attrs[limited_key] = 1 when range_vals[0] < range_vals[1]; this ensures
default-derived range and limited flags are respected for actuator_elem.
In `@newton/tests/test_import_mjcf.py`:
- Around line 4361-4478: The tests in TestMjcfActuatorAutoLimited access
model.mujoco.actuator_* arrays but never call
SolverMuJoCo.register_custom_attributes, so add a registration step before the
tests run (e.g., in a class-level setUpClass or a shared helper invoked at the
top of each test) to ensure MuJoCo actuator custom attributes are registered;
call SolverMuJoCo.register_custom_attributes(...) once before using
ModelBuilder().add_mjcf()/finalize() in tests like
test_ctrllimited_auto_enabled_when_ctrlrange_specified,
test_ctrllimited_not_auto_enabled_without_ctrlrange,
test_ctrllimited_explicit_false_not_overridden,
test_forcelimited_auto_enabled_when_forcerange_specified, and
test_actlimited_auto_enabled_when_actrange_specified.
3dd6c95 to
2583712
Compare
Implements MuJoCo's auto-inference behavior: if ctrllimited/forcelimited/actlimited is not explicitly set in MJCF but the corresponding range attribute has valid values (range[0] < range[1]), automatically enable the limit flag.
This matches native MuJoCo behavior where specifying a range implicitly enables the corresponding limit unless explicitly disabled.
Changes:
Tests:
Before your PR is "Ready for review"
newton/tests/test_examples.py)pre-commit run -aSummary by CodeRabbit
Bug Fixes
Documentation
Tests