Skip to content

feat(mit): per-model torque coefficients for effort and command#86

Open
JafarAbdi wants to merge 5 commits into
mainfrom
feature/arm-model-torque-coefficients
Open

feat(mit): per-model torque coefficients for effort and command#86
JafarAbdi wants to merge 5 commits into
mainfrom
feature/arm-model-torque-coefficients

Conversation

@JafarAbdi

Copy link
Copy Markdown
Contributor

Add joint_torque_coefficients(arm_type) with per-model torque constant k and gear ratio b. get_joint_efforts decodes true joint torque (currentkb) instead of the SDK base-piper current*k. direct_scaling_factors takes arm_type and scales commanded torque per model relative to base piper (identity for base, b_base/b on >= S-V1.8-3, 1/b on <= S-V1.8-2).

Add joint_torque_coefficients(arm_type) with per-model torque constant k and gear ratio b. get_joint_efforts decodes true joint torque (current*k*b) instead of the SDK base-piper current*k. direct_scaling_factors takes arm_type and scales commanded torque per model relative to base piper (identity for base, b_base/b on >= S-V1.8-3, 1/b on <= S-V1.8-2).
@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds per-model torque handling for Piper arms. The main changes are:

  • Adds per-joint torque constants and gear ratios by arm model.
  • Decodes feedback effort from raw motor current using model-specific coefficients.
  • Scales gravity-compensation commands by firmware version and arm type.
  • Adds arm-type selection to the gravity-compensation CLI.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
src/piper_control/gravity_compensation.py Adds arm-model-aware torque scaling to gravity compensation.
src/piper_control/piper_interface.py Adds torque coefficient lookup and model-specific effort decoding.
src/piper_control/scripts/run_gravity_compensation.py Adds an arm-type option and passes it to the interface and gravity model.

Reviews (5): Last reviewed commit: "fix(mit): scale commands by per-model k*..." | Re-trigger Greptile

Comment thread src/piper_control/gravity_compensation.py Outdated
Comment thread src/piper_control/gravity_compensation.py Outdated
run_gravity_compensation.py defaulted GravityCompensationModel and PiperInterface to base piper, so a piper_h on >= S-V1.8-3 mis-scaled J5 (1.0 instead of 1/1.7). Add --arm-type and thread it into both.
Comment on lines +643 to +653
k, b = joint_torque_coefficients(self._piper_arm_type)
arm_msgs = self.piper.GetArmHighSpdInfoMsgs()
return [
arm_msgs.motor_1.effort / 1e3,
arm_msgs.motor_2.effort / 1e3,
arm_msgs.motor_3.effort / 1e3,
arm_msgs.motor_4.effort / 1e3,
arm_msgs.motor_5.effort / 1e3,
arm_msgs.motor_6.effort / 1e3,
currents = [
arm_msgs.motor_1.current,
arm_msgs.motor_2.current,
arm_msgs.motor_3.current,
arm_msgs.motor_4.current,
arm_msgs.motor_5.current,
arm_msgs.motor_6.current,
]
return [currents[i] * k[i] * b[i] / 1e3 for i in range(6)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Sample data uses base coefficients

get_joint_efforts() now depends on the configured arm type, but scripts/generate_samples.py still creates PiperInterface(args.can_port) with the implicit PIPER value and has no arm-type option. Recording samples from a Piper H/L/X therefore applies base-Piper coefficients—for example, Piper H J2 uses 1.18125 * 4 instead of 1.65375 * 2.5. The saved effort targets are then wrong for gravity-compensation training, so a correctly configured runner can still deploy a model trained on incorrect torques. Propagate arm type through sample generation.

Fix in Claude Code Fix in Codex

direct_scaling_factors used base(b)/arm(b), which over-scaled joints whose torque constant k also differs from base piper (piper_h J2: 1.6 instead of 1.143). The gravity model is calibrated in the current*k*b feedback frame, so commands must scale by the k*b ratio. J4/J5 are unchanged (equal k); base piper unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant