Skip to content

DynamixelドライバーのESP-IDF5対応#342

Merged
meganetaaan merged 3 commits intostack-chan:dev/v1.0from
stc1988:faeture/rt_version
Nov 6, 2025
Merged

DynamixelドライバーのESP-IDF5対応#342
meganetaaan merged 3 commits intostack-chan:dev/v1.0from
stc1988:faeture/rt_version

Conversation

@stc1988
Copy link
Copy Markdown
Contributor

@stc1988 stc1988 commented Oct 19, 2025

ESP-IDF5系以降でDynamixelドライバーが動作しなくなる問題があるため、RT版からの更新内容の取り込みとなります。
合わせてCoreS3のサーボの設定をRT版に合わせています。

一方で、#307 の問題は未解決のため、CoreS3で動作させるためにはPSRAMを無効にする必要があります。

Summary by CodeRabbit

  • Bug Fixes

    • Improved motor positioning accuracy with automatic offset detection and application to eliminate positioning drift.
  • Chores

    • Switched the motor driver configuration from PWM to Dynamixel-compatible control and updated serial pin assignments for the ESP32 target.
    • Adjusted serial communication defaults to improve connectivity and stability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 19, 2025

Walkthrough

Introduces a 4096-step offset in PControl to adjust goal/present positions, changes default Dynamixel serial pin/port values and baud handling, and replaces PWM-based pan/tilt configuration with a Dynamixel driver and new ID/pin mappings in the manifest.

Changes

Cohort / File(s) Summary
PControl offset logic
firmware/stackchan/drivers/dynamixel-driver.ts
Adds _offset: number and initializes it to 0; on init reads present position and sets _offset = 4096 if value > 4096; applies _offset when writing goal position and subtracts it when computing presentPosition and current.
Dynamixel transport defaults
firmware/stackchan/drivers/dynamixel.ts
Adjusts default UART pins and port used when packetHandler is null (receive: 166, transmit: 177, port: 21); updates baud handling at initialization sites.
Platform driver config
firmware/stackchan/manifest.json
Replaces PWM pan/tilt driver with a dynamixel type for esp32/m5stack_cores3, adds panId/tiltId, and updates serial TX/RX pins from (14,13) to (7,6).

Sequence Diagram(s)

sequenceDiagram
    participant Init as PControl.init
    participant Servo as Dynamixel
    participant HW as Motor HW

    Note over Init,Servo: PControl initialization flow (new)
    Init->>Servo: readPresentPosition()
    alt read OK and value > 4096
        Servo-->>Init: present = value
        Init->>Init: set _offset = 4096
    else read OK and value <= 4096
        Servo-->>Init: present = value
        Init->>Init: _offset = 0
    else read FAIL
        Servo-->>Init: error
        Init-->>Init: log trace, _offset = 0
    end
Loading
sequenceDiagram
    participant App as Controller
    participant P as PControl
    participant D as Dynamixel
    participant M as Motor HW

    Note over App,P: Setting a new goal (changed)
    App->>P: setGoal(goalPosition)
    P->>P: goalWithOffset = goalPosition + _offset
    P->>D: writeGoalPosition(goalWithOffset)
    D->>M: sendGoal()
    M-->>D: ack
    D-->>P: write result
    P->>D: readPresentPosition()
    D-->>P: rawPresent
    P->>P: present = rawPresent - _offset
    P->>P: compute current = f(goalPosition, present, gain, saturation)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰

I nudge the gears with gentle hops,
Four thousand ninety-six tiny stops,
Pins realigned, the bytes converse,
Motors hum a brand new verse,
A rabbit cheers — code all set, full props!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "DynamixelドライバーのESP-IDF5対応" (Dynamixel driver ESP-IDF5 support) directly aligns with the PR's primary objective as stated in the PR objectives: addressing the issue where the Dynamixel driver doesn't work with ESP-IDF5 and later. All three modified files—the driver source files (dynamixel-driver.ts and dynamixel.ts) with their offset handling and serial communication parameter changes, plus the manifest.json configuration updates—serve the overarching goal of achieving ESP-IDF5 compatibility. The title is concise, specific, and conveys the main purpose clearly enough for a developer scanning the history to understand the PR is about making the Dynamixel driver compatible with ESP-IDF5.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3557b5 and 0936211.

📒 Files selected for processing (3)
  • firmware/stackchan/drivers/dynamixel-driver.ts (4 hunks)
  • firmware/stackchan/drivers/dynamixel.ts (2 hunks)
  • firmware/stackchan/manifest.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
firmware/stackchan/manifest.json (2)
firmware/stackchan/drivers/rs30x-driver.ts (1)
  • RS30XDriver (10-56)
firmware/stackchan/drivers/rs30x.ts (1)
  • RS30X (172-310)
firmware/stackchan/drivers/dynamixel.ts (2)
firmware/stackchan/drivers/rs30x.ts (3)
  • PacketHandler (86-165)
  • constructor (92-155)
  • PacketHandler (93-145)
firmware/stackchan/drivers/scservo.ts (1)
  • PacketHandler (61-139)
firmware/stackchan/drivers/dynamixel-driver.ts (1)
firmware/stackchan/drivers/sg90-driver.ts (1)
  • PWMServoDriver (17-97)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (6)
firmware/stackchan/drivers/dynamixel-driver.ts (3)

17-17: LGTM: Offset field initialization.

The offset mechanism is properly initialized to handle servos with extended position ranges.

Also applies to: 27-27


45-45: LGTM: Offset applied to goal position.

The offset is correctly added to the goal position when writing to the servo, maintaining symmetry with the read operation.


54-56: LGTM: Offset correctly applied in control calculations.

The present position is properly adjusted by subtracting the offset, and the normalized position is used in the control calculation. This maintains consistency between goal and present positions in the same coordinate space.

firmware/stackchan/drivers/dynamixel.ts (1)

232-235: LGTM: Serial configuration updated for ESP-IDF 5.

The PacketHandler initialization now uses the correct default pins (receive: 6, transmit: 7) and port (1), aligning with the manifest.json configuration for CoreS3. These changes are consistent across both initialization sites (setBaud and constructor).

firmware/stackchan/manifest.json (2)

113-115: LGTM: CoreS3 driver configuration migrated to Dynamixel.

The configuration correctly switches from PWM-based servo control to Dynamixel protocol with appropriate servo IDs. This aligns with the DynamixelDriverProps type defined in dynamixel-driver.ts and matches the RT version configuration mentioned in the PR objectives.


121-122: LGTM: Serial pins updated for CoreS3 Dynamixel communication.

The serial pin configuration (transmit: 7, receive: 6) is correctly updated and consistent with the defaults in dynamixel.ts. This ensures proper communication with Dynamixel servos on the CoreS3 hardware under ESP-IDF 5.

Comment thread firmware/stackchan/drivers/dynamixel-driver.ts
Comment thread firmware/stackchan/drivers/dynamixel.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
firmware/stackchan/drivers/dynamixel-driver.ts (1)

32-37: Error handling for failed offset detection already flagged.

The initialization continues even if the position read fails, potentially leaving _offset at 0 for servos that require it. This concern has been thoroughly analyzed in the previous review, which recommends mirroring the error-handling pattern from update() and aborting initialization on read failure.

🧹 Nitpick comments (1)
firmware/stackchan/drivers/dynamixel-driver.ts (1)

56-58: Consider simplifying the local variable usage.

The position variable on line 57 is only used once on line 58. While the current code is readable, you could simplify slightly by using this.presentPosition directly in the calculation:

 this.presentPosition = result.value - this._offset
-const position = this.presentPosition
-const current = Math.min(Math.abs(this.goalPosition - position) * this.gain, this.saturation)
+const current = Math.min(Math.abs(this.goalPosition - this.presentPosition) * this.gain, this.saturation)

However, the current approach is also perfectly acceptable and may improve readability by keeping the calculation line shorter.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0936211 and 27bf4c2.

📒 Files selected for processing (2)
  • firmware/stackchan/drivers/dynamixel-driver.ts (4 hunks)
  • firmware/stackchan/drivers/dynamixel.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • firmware/stackchan/drivers/dynamixel.ts
🧰 Additional context used
🧬 Code graph analysis (1)
firmware/stackchan/drivers/dynamixel-driver.ts (1)
firmware/stackchan/drivers/sg90-driver.ts (1)
  • PWMServoDriver (17-97)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (2)
firmware/stackchan/drivers/dynamixel-driver.ts (2)

17-17: LGTM: Clean addition of offset tracking field.

The _offset field is properly declared and initialized to a sensible default of 0 before detection occurs during init().

Also applies to: 27-27


47-47: LGTM: Offset correctly applied to goal position.

Adding _offset when setting the goal position correctly maps the logical [0, 4096) range to the servo's actual position range for multi-turn servos.

@stc1988
Copy link
Copy Markdown
Contributor Author

stc1988 commented Oct 19, 2025

@meganetaaan さん、ご確認おねがいします

Copy link
Copy Markdown
Collaborator

@meganetaaan meganetaaan left a comment

Choose a reason for hiding this comment

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

CoreS3(RT Version)で動作することを確認しました。
素の状態で書き込むとmanifest_local.jsonのdriverの設定で上書きされてしまうのを対処しないとですね。別途issueを立てます。
ありがとうございます!

@meganetaaan meganetaaan merged commit 85bfa33 into stack-chan:dev/v1.0 Nov 6, 2025
3 checks passed
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.

2 participants