fix(motion): expose calibration API for mods by meganetaaan · Pull Request #530 · stack-chan/stack-chan · GitHub
Skip to content

fix(motion): expose calibration API for mods - #530

Draft
meganetaaan wants to merge 3 commits into
developfrom
fix/issue-507-calibration-mods
Draft

fix(motion): expose calibration API for mods#530
meganetaaan wants to merge 3 commits into
developfrom
fix/issue-507-calibration-mods

Conversation

@meganetaaan

@meganetaaan meganetaaan commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

概要

calibration / setup_rs30x MOD が raw driver 内部へ触らないよう、公開 calibration API へ移行します。

変更内容

  • motion.calibration API を追加
  • RS30X / SCServo driver に calibration wrapper を追加
  • calibration と setup_rs30x MOD から _driver 参照を削除
  • optional button capability を安全に扱うよう修正
  • motion-controller test を追加

検証

  • cd firmware && npm run lint: pass
  • cd firmware && npm run test:unit: pass, 31 tests
  • cd firmware && npm run check:architecture: pass, 13 tests
  • git diff --check: pass

未実施

  • 実機サーボでの較正動作確認
  • test:moddable / build

リリース影響

patch。公式 MOD の内部 API 依存を解消する互換性改善です。

Closes #507
関連 #399 #515

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added motion calibration support across the runtime and motion drivers.
    • Calibration data is now available through the motion control interface for supported hardware.
  • Bug Fixes

    • Improved handling when calibration features aren’t supported, avoiding failures and stopping unsupported reads gracefully.
    • Updated example behavior to use safer checks before accessing motion and button controls.
  • Documentation

    • Updated sample workflows to reflect the new calibration-based motion controls.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@meganetaaan

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meganetaaan

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
firmware/host/modules/motion/scservo-driver.ts (1)

18-56: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider extracting shared setAngle branching logic to reduce duplication with rs30x-driver.ts.

The setAngle argument-type branching (lines 29–39) and the setTorque/flashId passthroughs are identical to createCalibrationServo in rs30x-driver.ts, with the only meaningful difference being the time-unit conversion (motionDurationSecondsToMilliseconds vs motionDurationSecondsToCentiseconds). A shared factory accepting the servo-specific setAngle/setAngleInTime methods and a time-conversion function would eliminate this duplication and prevent future divergence.

♻️ Example shared helper
// In a shared module, e.g. motion/calibration-servo.ts
export function createSetAngle(
  setAngle: (angle: number, callback?: MotionCompletion) => void,
  setAngleInTime: (angle: number, time: number, callback?: MotionCompletion) => void,
  convertTime: (duration: MotionDurationSeconds) => number,
): MotionCalibrationServo['setAngle'] {
  return (angle: number, timeOrCallback?: MotionDurationSeconds | MotionCompletion, callback?: MotionCompletion) => {
    if (typeof timeOrCallback === 'function') {
      setAngle(angle, timeOrCallback)
      return
    }
    if (timeOrCallback == null) {
      setAngle(angle, callback)
      return
    }
    setAngleInTime(angle, convertTime(timeOrCallback), callback)
  }
}

Then in each driver:

// scservo-driver.ts
setAngle: createSetAngle(
  (a, cb) => servo.setAngle(a, cb),
  (a, t, cb) => servo.setAngleInTime(a, t, cb),
  motionDurationSecondsToMilliseconds,
),
// rs30x-driver.ts
setAngle: createSetAngle(
  (a, cb) => servo.setAngle(a, cb),
  (a, t, cb) => servo.setAngleInTime(a, t, cb),
  motionDurationSecondsToCentiseconds,
),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@firmware/host/modules/motion/scservo-driver.ts` around lines 18 - 56, The
createCalibrationServo implementation in scservo-driver.ts duplicates the same
setAngle branching and passthrough behavior already present in rs30x-driver.ts,
so extract the shared calibration-servo factory into a common helper and reuse
it here. Make the helper accept the servo-specific setAngle and setAngleInTime
methods plus a duration conversion function, then wire scservo-driver.ts to use
motionDurationSecondsToMilliseconds while rs30x-driver.ts uses its existing
centisecond conversion. Keep the existing readAngle, setTorque, flashId,
readOffsetAngle, setOffsetAngle, and saveSettings behavior intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@firmware/host/modules/motion/scservo-driver.ts`:
- Around line 18-56: The createCalibrationServo implementation in
scservo-driver.ts duplicates the same setAngle branching and passthrough
behavior already present in rs30x-driver.ts, so extract the shared
calibration-servo factory into a common helper and reuse it here. Make the
helper accept the servo-specific setAngle and setAngleInTime methods plus a
duration conversion function, then wire scservo-driver.ts to use
motionDurationSecondsToMilliseconds while rs30x-driver.ts uses its existing
centisecond conversion. Keep the existing readAngle, setTorque, flashId,
readOffsetAngle, setOffsetAngle, and saveSettings behavior intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 29dd0f8f-65c2-4794-81a5-7aacf344f377

📥 Commits

Reviewing files that changed from the base of the PR and between 092e56a and 93c0c44.

📒 Files selected for processing (8)
  • firmware/host/app/capabilities.ts
  • firmware/host/app/runtime-context.ts
  • firmware/host/modules/motion/__tests__/motion-controller.test.ts
  • firmware/host/modules/motion/motion-controller.ts
  • firmware/host/modules/motion/rs30x-driver.ts
  • firmware/host/modules/motion/scservo-driver.ts
  • firmware/mods/examples/calibration/mod.js
  • firmware/mods/examples/setup_rs30x/mod.js

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.

サーボ較正系MOD(setup_rs30x / calibration)が旧 _driver 直参照のまま動作しない

1 participant