feat(microduck): port BAM xl330-m6 voltage actuator model (issue #1474) - #1475
Merged
TATP-233 merged 2 commits intoSep 3, 2026
Merged
Conversation
NumPy port of the upstream bam.mjlab.BamActuator (xl330-m6 voltage servo) as a task-owned action term on the Manager-Based runtime, recomputing motor torque every physics substep through the SimBackend set_pre_step_control contract (go2w precedent): LIFO command-delay ring buffer (lag 3-6 substeps), per-env battery model (vin 6.5-8.2 V startup DR with load-dependent drop), firmware P law with current-limit duty window and PWM clip, back-EMF torque equation, and the m6 friction budget (Coulomb + Stribeck + directional load + quadratic) under per-env friction_scale reset DR. Approximation boundaries vs upstream (documented in the module docstring): the friction budget is folded into the output torque with a torque-domain stiction clip because the SimBackend contract has no per-substep dof_frictionloss/dof_damping write channel, and the external torque is a finite-difference estimate since qfrc_* is not exposed. New task MicroduckVelocityBamFlat (mujoco owner only; the mjwarp host_numpy profile rejects pre-step control) reuses the PD recipe's reward/obs/curriculum verbatim so the actuator model is the only delta. Probe cross-check vs upstream (64 envs, seed 42): zero-action falls 356/64 envs with mean first fall at 64.1 steps (upstream 383, 64), knee-step t90 403 ms (upstream ~370 ms), steady-state error overall 0.036 rad / knee 0.118 rad (upstream 0.049 / 0.148; stiffer by ~25% from the torque-domain friction approximation).
Collaborator
Author
BAM 训练对齐结果(seed42,4096 envs × 2000 iter,mjwarp 两侧)修复内容:将 microduck 执行器从 PD 配方改为上游原版 BAM(BLDC + 母线电流环,substep 电压积分),对应 #1464 根因分析的原因 1(执行器模型不同)。 总览(终段窗口均值,UniLab vs 上游)
Reward term 对比(BAM vs 上游)
终止占比:tilt 10.1% vs 11.3%,无 NaN。 结论
产物
Validation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1474
背景
#1452 对齐对比的根因分析(#1464 评论区)确认:microduck 与上游 microduck_rl 的剩余训练差距主因是执行器模型不同(原因 1)——UniLab 用 XML position PD(kp=50/kv=0.5),上游用 BAM xl330-m6 电压舵机。本 PR 把 BAM 模型移植到 UniLab 侧,使执行器动力学不再是对齐差距的来源。
实现
BamVoltageAction(src/unilab/tasks/locomotion/microduck/bam_action.py):task-owned action term,requires_substep_state_feedback=True,经 SimBackend 已声明的set_pre_step_control契约在每个物理 substep 重算力矩(go2w 先例),零 SimBackend / unisim-core 契约变更。逐 substep 管线与上游bam.mjlab.BamActuator逐项对应:<motor>截断新 task
MicroduckVelocityBamFlat(仅 mujoco owner;mjwarp host_numpy profile 显式拒绝 pre-step control,fail-closed)复用 PD 配方的 reward/obs/curriculum/commands/terminations 逐项不变(owner 契约测试断言相等),执行器模型是唯一变量。与上游的近似边界(模块 docstring 同步记录)
dof_frictionloss/dof_damping由求解器做静摩擦 clip;UniLab SimBackend 契约无逐 substep 写这两个字段的通道,故预算折算进输出力矩,stiction clip 在力矩域复刻。I_eff·a_fd − τ_applied_prev(I_eff=名义 dof_armature)。稳态无差,快速暂态略低估惯性反作用。探针对拍(64 envs,seed 42,UniLab BAM/mujoco vs 上游 BAM/mjwarp 既有探针参照值)
含延迟、电压 sag、限幅的动态指标(A/B)几乎复刻;静态误差(C)偏硬约 25%,来源于上述力矩域摩擦近似——已在代码与本文档记录。
Validation
make test-all于最终 head 8371566 通过(2583 passed;benchmark module/script-mode 仅 platform-optional mlx 跳过)。训练对比
BAM task 修复验证训练(mujoco CPU,4096 envs × 2000 iter,seed 42)进行中,结果以本 PR 评论跟进(上游 seed42 run 复用 #1452 既有数据)。