Improve arm control with IK validation, synchronized movements, and vision tracking#3
Open
williankeller wants to merge 11 commits intomainfrom
Open
Improve arm control with IK validation, synchronized movements, and vision tracking#3williankeller wants to merge 11 commits intomainfrom
williankeller wants to merge 11 commits intomainfrom
Conversation
Phase 1 - Bug fixes: - Fix gripper serial command: openGripper() was unreachable (duplicate value==1 check) - Fix moveToPosition(): remove incorrect angle accumulation that double-counted current servo positions and added erroneous +2 offsets - Fix position command parsing: z and gripAngle were parsing the same substring - Add IK reachability validation: solveRZ() now returns bool and checks asin bounds to prevent NaN propagation from unreachable positions - Add PI macro guard to prevent redefinition warnings Phase 2 - Smooth motion: - Replace linear interpolation with smoothStep easing (S-curve) in setServoPosition() for natural acceleration/deceleration instead of constant-velocity jerky starts/stops - Add configurable stepDelayMs parameter for variable movement speeds Phase 3 - Coordinated multi-joint movement: - Add moveJointsSynchronized() for simultaneous multi-servo motion with easing, normalizing travel times so all joints start and finish together - Update moveInitialPosition() to move all 5 joints simultaneously - Rewrite grab() sequence with synchronized multi-joint phases instead of sequential single-servo moves Phase 4 - Cartesian trajectory interpolation: - moveToPosition() now interpolates through 10 waypoints in Cartesian space, solving IK at each point, producing straight-line end-effector paths instead of arc-shaped joint-space paths - Track last commanded position for trajectory continuity between moves Phase 5 - Vision tracking smoothing: - Replace fixed-step increments with proportional control based on pixel error - Add exponential moving average filter (alpha=0.15) for fluid tracking motion - Add dead band thresholds to eliminate jitter near center - Use float precision for sub-degree position tracking - Write servos directly during tracking (skip easing for small continuous moves) - Wrap string literals in F() macro to reduce SRAM usage https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
- Make HuskyLens initialization non-blocking: tries 3 times on boot, then continues in manual mode if not found. Servos attach first so the arm is functional immediately regardless of HuskyLens state. - Add 'tracking on|off' serial command to enable/disable auto tracking at runtime. 'tracking on' retries HuskyLens connection if needed. 'tracking off' returns arm to home position. - Restructure loop() so serial commands are always processed first, independent of HuskyLens connection state. - Extract command handling into handleCommand() and vision tracking into runVisionTracking() for cleaner separation. - Add 'help' command listing all available serial commands. - Add 'tracking' status query (send 'tracking' with no argument). - Reset vision tracking positions on reset/tracking state changes. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
Add command reference tables for joint control, sequences, IK positioning, and vision tracking. Note that HuskyLens is optional and the arm starts in manual mode by default. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
Document servo pin assignments, default angles, power supply requirements (6V/10A for MG996R servos), and HuskyLens I2C connection. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
The wrist min was set to 89° which clamped grab() targets of 60° and 30° to 89°, preventing the gripper from tilting downward to reach objects. Changed to 0° to match the physical clearance of the joint. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
Revert wrist min angle back to 89° (straight position). The wrist cannot physically go below 89° without twisting into the arm frame. Update grab() sequence wrist targets from 60°/80°/30° to 89° so they use the straightest valid position for reaching and dropping objects. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
Higher wrist angles tilt the gripper downward (180° = fully down). Updated grab() wrist targets to point gripper toward objects: - Phase 1 (pre-grab): 150° moderate tilt down - Phase 3 (reach): 170° near-full tilt to reach object - Phase 6 (drop): 160° tilted down for releasing https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
Shoulder 50° was pushing the arm too far down, and elbow 160° exceeded its physical max of 140° (clamped by constrain). Adjusted to shoulder 80°, elbow 130°, wrist 160° for a gentler reach at table level. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
Replace elbow, wrist, and hand PWM servos with daisy-chained LX-1501 bus servos using half-duplex serial protocol. Add teach mode for recording and replaying arm positions by physically moving the bus servos (torque disable + position readback). https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
The BusLinker handles half-duplex conversion between Arduino full-duplex UART and the servo single-wire bus protocol. Servos connect via PH2.0/3P daisy-chain cables to the BusLinker servo interface. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
Includes detailed specifications table (voltage, torque, speed, current, accuracy, connector type) and notes the Hiwonder BusLinker as the recommended controller board. Updated voltage range to 6-8.4V per servo datasheet. https://claude.ai/code/session_01DimPiPhcBhthiP8N3KucLK
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.
Summary
This PR significantly enhances the robotic arm control system by adding inverse kinematics validation, implementing synchronized multi-joint movements, improving vision-based tracking with proportional control and smoothing, and refactoring servo control with easing functions.
Key Changes
Inverse Kinematics & Safety
solveRZ()- now returnsboolto indicate if target position is achievableasin()calls by checking if the ratio is within [-1.0, 1.0] boundsSynchronized Joint Movement
moveJointsSynchronized()function to move multiple joints simultaneously with coordinated timingmoveInitialPosition()andgrab()sequences to use synchronized movements with clear phase commentsServo Control Improvements
setServoPosition()with configurable step delay and smooth easingsmoothStep()S-curve easing function for natural acceleration/decelerationVision Tracking Enhancements
inttofloatfor sub-degree precisionCartesian Trajectory Interpolation
moveToPosition()with linear Cartesian space interpolation (10 waypoints)Code Quality
else if (value == 1)toelse if (value == 0)for open commandImplementation Details