Repository navigation
refactor(hero_agent): TDC cleanup, physics tuning, test rewrite - #1
Conversation
…ler and fix 8 bugs Rewrite HeroAgentTDCEnv from RL-integrated gain tuner to standalone classical TDC controller for baseline comparison. Simplify TDC controller, env config, reward system, and agent configs. Add ALBC kinematics module and unit tests. TDC environment changes: - Replace RL gain output (4D) with direct TDC control (no RL actions) - TDC runs at 100Hz (control_decimation=1) for accurate TDE - Remove TDC-specific reward terms and encoder variant - Add console logging for real-time TDC diagnostics Bug fixes from systematic 5-round code review: - Fix buoyancy force sign convention (repulsive, not attractive) - Fix gravity vector initialization (use PhysX gravity, not hardcoded) - Fix CoB/CoG offset handling in restoring torque computation - Fix inertia tensor access for added mass terms - Fix potential reward to use roll/pitch only (exclude yaw) - Fix observation stale _prev_actions_obs after reset - Fix _attitude_error caching for correct logging after reset - Fix TDC buoyancy update to only affect reset environments Other changes: - Add ALBCKinematics class (2-link planar FK/IK/Jacobian) - Add test_tdc_controller.py unit tests - Simplify HeroAgentEnvCfg (remove TDC-specific reward configs) - Clean up agent configs and environment registrations - Remove unused tdc_sweep.py script and actor_critic_encoder_tdc.py Co-Authored-By: Claude Opus 4.6 <[email protected]>
…tests TDC controller cleanup: - Remove unused self._cfg attribute from TDCController - Add F_bu read-only property (replaces private attribute access) - Merge _compute_lambda + _compute_lambda_inv into _compute_lambda_and_inv - Pre-allocate Lambda scratch buffers to avoid per-step allocation - Name magic constant _EPSILON_DET in kinematics.py - Store tdc_dt as self._tdc_dt in tdc_env (eliminates redundant calculation) - Export TDCControllerCfg from controllers/__init__.py and hero_agent/__init__.py Physics tuning: - Disable C_RB (use_full_coriolis=False) to avoid double-counting with PhysX gyroscopic forces - Lower added_mass_stability_factor (0.8->0.5/0.4) for numerical stability - Reduce actuator stiffness/damping (Kp=500->100, Kd=10->3) for softer arm motion - Add explicit added mass force (M_A * v_dot) update in _apply_actions - Set control_decimation=4 for 50Hz TDC matching C++ reference Test rewrite: - Rewrite test_tdc_controller.py for TDCControllerCfg-based constructor - Fix Lambda sign expectations to match corrected physics - Fix IK round-trip test (add current_joint_angles, use small perturbation) - Remove TestUDEMode (UDE mode no longer exists) - Add TestUpdateParams (update_controller_params, update_buoyancy_force, F_bu property) - Improve mock infrastructure for standalone testing without Isaac Sim Co-Authored-By: Claude Opus 4.6 <[email protected]>
📝 WalkthroughWalkthroughThe PR refactors the Hero Agent ALBC system by removing the TDC gain sweep utility, consolidating TDC-encoder training variants into a single unified TDC environment, replacing analytical arm kinematics with a DLS-based Jacobian approach, and redesigning the TDC controller with clearer state management. Configuration updates to hydrodynamics and environment timing support the overhaul. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 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)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In
`@source/isaaclab_tasks/isaaclab_tasks/direct/hero_agent/docs/TDC_LITERATURE_SURVEY.md`:
- Around line 31-33: Add language identifiers to every fenced code block in
TDC_LITERATURE_SURVEY.md that contains equations or plain text (use "math" or
"text"), e.g., change the fence wrapping the equation "M(q)q_ddot + C(q,
q_dot)q_dot + g(q) + f(q_dot) + d(t) = tau" to ```math (or ```text) and do the
same for the other untyped fences that contain equations or math expressions in
the file (the blocks referenced in the review), ensuring each opening
triple-backtick includes the chosen language token.
- Around line 160-167: The table under "### Error Characteristics" has a
misaligned separator row and uses emphasis markers with spaces; update the pipe
count in the separator line so it matches the two columns (e.g.,
"|:-------|:--------------------|") and remove any spaces inside emphasis
markers (change "* text *" or "_ text _" to "*text*" or "_text_") where present
in that section; ensure the table header, separator and rows all have the same
number of columns and no spaced emphasis tokens so the file renders cleanly.
In
`@source/isaaclab_tasks/isaaclab_tasks/direct/hero_agent/docs/tdc-tuning-history-2026-02-09.md`:
- Around line 43-79: Fix spelling typos in the Attempt history blocks: open the
sections headed "Attempt 1: H_hat EMA Filter (alpha=0.05)", "Attempt 2: T_b
Separation (U_hat Only Filtered)", "Attempt 3: Filter Off (alpha=1.0) + 100Hz",
and "Attempt 4: 200Hz + Aggressive PD" and correct misspelled result words
(e.g., change any truncated “stagnatio…” to “stagnation” and ensure
“divergence”/“발산” is consistently and correctly spelled), keep language
consistent across Result lines, and re-run a quick spellcheck to catch any
remaining typos.
In `@source/isaaclab_tasks/test/test_tdc_controller.py`:
- Around line 218-224: In test_lambda_structure_zero_angles, replace the unused
assigned variable Lambda_inv from the call to
controller._compute_lambda_and_inv(roll, pitch) with an underscore (e.g.,
"Lambda, _ = controller._compute_lambda_and_inv(roll, pitch)") so the test still
receives both return values but does not assign the unused one, satisfying the
RUF059 linter rule; update only the assignment in the test function
test_lambda_structure_zero_angles.
🧹 Nitpick comments (3)
source/isaaclab_tasks/isaaclab_tasks/direct/hero_agent/mdp/events.py (1)
237-239: Implementation looks correct; consider encapsulating access to_current_velocity.The logic correctly propagates the randomized current from the main body to the buoy, ensuring physical consistency. However, directly accessing the private
_current_velocityattribute creates tight coupling toHydrodynamicsModelinternals.Consider adding a public property or getter method (e.g.,
current_velocityorget_current_velocity(env_ids)) toHydrodynamicsModelif this access pattern is used elsewhere or expected to grow.source/isaaclab_tasks/isaaclab_tasks/direct/hero_agent/mdp/rewards.py (1)
125-125: Consider addingstrict=Truetozip()for defensive programming.Both lists are populated from the same loop in
__init__, so lengths are guaranteed to match. However, addingstrict=Truedocuments this invariant and would catch any future bugs if the initialization logic changes.🔧 Proposed fix
- for name, term_cfg in zip(self._term_names, self._term_cfgs): + for name, term_cfg in zip(self._term_names, self._term_cfgs, strict=True):source/isaaclab_tasks/test/test_tdc_controller.py (1)
34-40: Rename unusedkwargsto_kwargsto silence the ARG002 lint warning.The
_MockModule.__call__method accepts**kwargsbut doesn't use them. Use the underscore prefix convention to indicate the parameter is intentionally unused.Suggested fix
- def __call__(self, *args, **kwargs): + def __call__(self, *args, **_kwargs):
| ``` | ||
| M(q)q_ddot + C(q, q_dot)q_dot + g(q) + f(q_dot) + d(t) = tau | ||
| ``` |
There was a problem hiding this comment.
Add language identifiers to fenced code blocks (MD040).
Several code fences are untyped; markdownlint flags this. Please add a language (e.g., text, math) to each fence.
Suggested pattern
-```
+```text
M(q)q_ddot + C(q, q_dot)q_dot + g(q) + f(q_dot) + d(t) = tau
</details>
Also applies to: 47-49, 70-73, 100-112, 152-154, 194-196, 278-290
<details>
<summary>🤖 Prompt for AI Agents</summary>
In
@source/isaaclab_tasks/isaaclab_tasks/direct/hero_agent/docs/TDC_LITERATURE_SURVEY.md
around lines 31 - 33, Add language identifiers to every fenced code block in
TDC_LITERATURE_SURVEY.md that contains equations or plain text (use "math" or
"text"), e.g., change the fence wrapping the equation "M(q)q_ddot + C(q,
q_dot)q_dot + g(q) + f(q_dot) + d(t) = tau" to math (or text) and do the
same for the other untyped fences that contain equations or math expressions in
the file (the blocks referenced in the review), ensuring each opening
triple-backtick includes the chosen language token.
</details>
<!-- fingerprinting:phantom:poseidon:eagle -->
<!-- This is an auto-generated comment by CodeRabbit -->
| ### Error Characteristics | ||
|
|
||
| | Factor | Effect on TDE Error | | ||
| |:-------|:--------------------| | ||
| | Smaller L (sampling period) | Smaller error | | ||
| | Faster-changing dynamics | Larger error | | ||
| | Higher accelerations | Larger error (N depends on q_ddot) | | ||
|
|
There was a problem hiding this comment.
Fix markdownlint issues in the “Error Characteristics” table/emphasis (MD056/MD037).
The table alignment row has extra columns and markdownlint also reports spaces inside emphasis markers in this section. Please align the column count and remove spaces inside emphasis markers.
Example table fix
-|:-------|:-----|:-----|
+|:-------|:--------------------|🧰 Tools
🪛 markdownlint-cli2 (0.20.0)
[warning] 160-160: Spaces inside emphasis markers
(MD037, no-space-in-emphasis)
[warning] 160-160: Spaces inside emphasis markers
(MD037, no-space-in-emphasis)
[warning] 160-160: Table column count
Expected: 3; Actual: 5; Too many cells, extra data will be missing
(MD056, table-column-count)
[warning] 163-163: Spaces inside emphasis markers
(MD037, no-space-in-emphasis)
[warning] 163-163: Spaces inside emphasis markers
(MD037, no-space-in-emphasis)
🤖 Prompt for AI Agents
In
`@source/isaaclab_tasks/isaaclab_tasks/direct/hero_agent/docs/TDC_LITERATURE_SURVEY.md`
around lines 160 - 167, The table under "### Error Characteristics" has a
misaligned separator row and uses emphasis markers with spaces; update the pipe
count in the separator line so it matches the two columns (e.g.,
"|:-------|:--------------------|") and remove any spaces inside emphasis
markers (change "* text *" or "_ text _" to "*text*" or "_text_") where present
in that section; ensure the table header, separator and rows all have the same
number of columns and no spaced emphasis tokens so the file renders cleanly.
| ### Attempt 1: H_hat EMA Filter (alpha=0.05) | ||
|
|
||
| **Config**: h_hat_filter_alpha=0.05, 100Hz, Kp=10, Kd=5 | ||
|
|
||
| **Result**: 50도 stagnation (수렴 실패) | ||
|
|
||
| **Root cause**: H_hat 필터에 T_b가 포함되어 있어, delta_T_b = T_b_prev - T_b 취소가 bias를 가짐. 필터가 T_b_prev의 오래된 값을 유지하므로 정적 오프셋 발생. | ||
|
|
||
| --- | ||
|
|
||
| ### Attempt 2: T_b Separation (U_hat Only Filtered) | ||
|
|
||
| **Config**: U_hat만 필터링, T_b는 delta_T_b로 직접 취소 | ||
|
|
||
| **Result**: 동일한 50도 stagnation | ||
|
|
||
| **Root cause**: 필터가 순수 uncertainty에도 여전히 bias를 유발. 근본적으로 필터 접근 자체가 문제. | ||
|
|
||
| --- | ||
|
|
||
| ### Attempt 3: Filter Off (alpha=1.0) + 100Hz | ||
|
|
||
| **Config**: h_hat_filter_alpha=1.0 (필터 비활성화), 100Hz | ||
|
|
||
| **Result**: 발산 (M*nu_dot ~ 29 Nm) | ||
|
|
||
| **Root cause**: 100Hz에서 nu_dot finite difference가 매우 noisy. 필터 없이는 noise가 TDE를 통해 증폭. | ||
|
|
||
| --- | ||
|
|
||
| ### Attempt 4: 200Hz + Aggressive PD | ||
|
|
||
| **Config**: decimation=1 (200Hz), Kp=40, Kd=12, alpha=1.0 | ||
|
|
||
| **Result**: 발산 (M*nu_dot ~ 39 Nm, pEE_raw_r > 1.0) | ||
|
|
||
| **Root cause**: 200Hz로 올려도 nu_dot가 여전히 크고, TDE가 PD의 25배 크기. Workspace saturation → TDE positive feedback. |
There was a problem hiding this comment.
Fix a couple of spelling typos in the Attempt history section.
LanguageTool flagged possible misspellings around the Attempt 1/4 results (e.g., “stagnatio…”). Please verify and correct if present.
🧰 Tools
🪛 LanguageTool
[grammar] ~45-~45: Ensure spelling is correct
Context: ...) Config: h_hat_filter_alpha=0.05, 100Hz, Kp=10, Kd=5 Result: 50도 stagnatio...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~73-~73: Ensure spelling is correct
Context: ...noise가 TDE를 통해 증폭. --- ### Attempt 4: 200Hz + Aggressive PD Config: decimation...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 Prompt for AI Agents
In
`@source/isaaclab_tasks/isaaclab_tasks/direct/hero_agent/docs/tdc-tuning-history-2026-02-09.md`
around lines 43 - 79, Fix spelling typos in the Attempt history blocks: open the
sections headed "Attempt 1: H_hat EMA Filter (alpha=0.05)", "Attempt 2: T_b
Separation (U_hat Only Filtered)", "Attempt 3: Filter Off (alpha=1.0) + 100Hz",
and "Attempt 4: 200Hz + Aggressive PD" and correct misspelled result words
(e.g., change any truncated “stagnatio…” to “stagnation” and ensure
“divergence”/“발산” is consistently and correctly spelled), keep language
consistent across Result lines, and re-run a quick spellcheck to catch any
remaining typos.
| def test_lambda_structure_zero_angles(self, controller): | ||
| """Lambda at zero roll/pitch: lf = F_bu, anti-diagonal [[0,lf],[-lf,0]].""" | ||
| roll = torch.zeros(NUM_ENVS) | ||
| pitch = torch.zeros(NUM_ENVS) | ||
|
|
||
| Lambda, Lambda_inv = controller._compute_lambda_and_inv(roll, pitch) | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, verify the file exists and read the relevant section
if [ -f "source/isaaclab_tasks/test/test_tdc_controller.py" ]; then
echo "=== File exists. Reading lines 215-230 for context ==="
sed -n '215,230p' source/isaaclab_tasks/test/test_tdc_controller.py | cat -n
else
echo "File not found"
find . -name "test_tdc_controller.py" -type f 2>/dev/null | head -5
fiRepository: luckkim123/IsaacLab
Length of output: 986
🏁 Script executed:
#!/bin/bash
# Check RUF059 violations in the file
ruff check source/isaaclab_tasks/test/test_tdc_controller.py --select RUF059 2>&1Repository: luckkim123/IsaacLab
Length of output: 758
🏁 Script executed:
#!/bin/bash
# Search for any usage of Lambda_inv in the entire test function scope around line 218-224
# Get broader context to ensure Lambda_inv is not used elsewhere in that test
sed -n '215,250p' source/isaaclab_tasks/test/test_tdc_controller.py | cat -nRepository: luckkim123/IsaacLab
Length of output: 1910
Replace unused Lambda_inv variable with _ to satisfy RUF059.
The variable is assigned but never used in this test; replace with underscore to keep the test intent while satisfying the linter.
- Lambda, Lambda_inv = controller._compute_lambda_and_inv(roll, pitch)
+ Lambda, _ = controller._compute_lambda_and_inv(roll, pitch)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def test_lambda_structure_zero_angles(self, controller): | |
| """Lambda at zero roll/pitch: lf = F_bu, anti-diagonal [[0,lf],[-lf,0]].""" | |
| roll = torch.zeros(NUM_ENVS) | |
| pitch = torch.zeros(NUM_ENVS) | |
| Lambda, Lambda_inv = controller._compute_lambda_and_inv(roll, pitch) | |
| def test_lambda_structure_zero_angles(self, controller): | |
| """Lambda at zero roll/pitch: lf = F_bu, anti-diagonal [[0,lf],[-lf,0]].""" | |
| roll = torch.zeros(NUM_ENVS) | |
| pitch = torch.zeros(NUM_ENVS) | |
| Lambda, _ = controller._compute_lambda_and_inv(roll, pitch) |
🧰 Tools
🪛 Ruff (0.14.14)
[warning] 223-223: Unpacked variable Lambda_inv is never used
Prefix it with an underscore or any other dummy variable pattern
(RUF059)
🤖 Prompt for AI Agents
In `@source/isaaclab_tasks/test/test_tdc_controller.py` around lines 218 - 224, In
test_lambda_structure_zero_angles, replace the unused assigned variable
Lambda_inv from the call to controller._compute_lambda_and_inv(roll, pitch) with
an underscore (e.g., "Lambda, _ = controller._compute_lambda_and_inv(roll,
pitch)") so the test still receives both return values but does not assign the
unused one, satisfying the RUF059 linter rule; update only the assignment in the
test function test_lambda_structure_zero_angles.
Summary of key analyses: - 24-run retrospective rank: r11_emabias #1, r12_baseline isaac-sim#7 (regression) - Sample-mean divergence hypothesis rejected (baseline and intervention rates match) - r12_baseline config lineage revealed: r11+latent16+k_bias=-1.0 (half strength) - R13_A/B parallel launched with ocean DR DORAEMON integration Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
self._cfgattribute, merge duplicated Lambda computation into single_compute_lambda_and_invwith pre-allocated scratch buffers, addF_buproperty, name magic constant_EPSILON_DET, eliminate redundanttdc_dtcalculation in envuse_full_coriolis=False), lower added mass stability factor, reduce actuator Kp/Kd for softer arm motion, add explicit M_A*v_dot update, setcontrol_decimation=4for 50Hz TDC matching C++ referencetest_tdc_controller.py— updated forTDCControllerCfgconstructor, fixed Lambda sign expectations, fixed IK round-trip test, removed staleTestUDEMode, addedTestUpdateParams, improved mock infrastructure (19/19 tests pass)Test plan
python3 -m pytest source/isaaclab_tasks/test/test_tdc_controller.py -v(19/19 pass)ruff checkon all modified files (all checks passed)ruff formaton all modified files (formatted)./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/train.py --task Isaac-HeroAgent-TDC-v0 --num_envs 16 --headless --max_iterations 1Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Refactor
Tests