fix(motion): expose calibration API for mods - #530
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
firmware/host/modules/motion/scservo-driver.ts (1)
18-56: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting shared
setAnglebranching logic to reduce duplication withrs30x-driver.ts.The
setAngleargument-type branching (lines 29–39) and thesetTorque/flashIdpassthroughs are identical tocreateCalibrationServoinrs30x-driver.ts, with the only meaningful difference being the time-unit conversion (motionDurationSecondsToMillisecondsvsmotionDurationSecondsToCentiseconds). A shared factory accepting the servo-specificsetAngle/setAngleInTimemethods 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
📒 Files selected for processing (8)
firmware/host/app/capabilities.tsfirmware/host/app/runtime-context.tsfirmware/host/modules/motion/__tests__/motion-controller.test.tsfirmware/host/modules/motion/motion-controller.tsfirmware/host/modules/motion/rs30x-driver.tsfirmware/host/modules/motion/scservo-driver.tsfirmware/mods/examples/calibration/mod.jsfirmware/mods/examples/setup_rs30x/mod.js

概要
calibration / setup_rs30x MOD が raw driver 内部へ触らないよう、公開 calibration API へ移行します。
変更内容
検証
未実施
リリース影響
patch。公式 MOD の内部 API 依存を解消する互換性改善です。
Closes #507
関連 #399 #515
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation