-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix pathfinding algorithm crossing holes and optimize wall starting points #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix pathfinding algorithm crossing holes and optimize wall starting points #60
Conversation
Co-authored-by: jgphilpott <[email protected]>
Co-authored-by: jgphilpott <[email protected]>
Co-authored-by: jgphilpott <[email protected]>
Co-authored-by: jgphilpott <[email protected]>
Co-authored-by: jgphilpott <[email protected]>
|
Okay nice progress @copilot! I noticed that in some cases the starting point for a hole wall path is on the far side of the hole from the travel starting point. This makes it very difficult for the algorithm to find a path that doesn't cross the hole! Would it be possible to update the algorithm to be able to move the starting point for the hole wall path to anywhere along the path. We would then first look for the closest point along the wall path that we can access easily and then use that as the starting point for the wall print. This seems to me to be much easier than trying to path find our way around the entire hole! |
Co-authored-by: jgphilpott <[email protected]>
Implemented in commit 0df6d92. Added Results: 100% of hole wall travels are now direct (no combing needed), compared to requiring complex combing before. The 2x2 hole example went from 14,371 to 14,312 lines of G-code, confirming more efficient paths. |
|
Alright @copilot this is a major improvement, well done! However, I noticed that we lost some of the functionality introduced by #54. The feature of generating skin walls immediately after regular walls on hoes so that we dont need to do a second pass seems to be broken. The main deliverable of this PR is the new |
I've tested the current implementation and skin walls are being generated correctly for holes in both the base version and the current version (same count: 16 occurrences of Could you clarify what specific issue you're seeing with the skin wall feature? Are skin walls missing from the G-code, or is there a different problem? |
|
@copilot sorry for not being more specific. In the 2x2 and up hole sheet examples I am observing that it makes a full pass generating the outer and inner walls for the holes and then goes back to do a second pass generating the skin walls for the holes, on skin layers we are supposed to be generating the outer, inner and skin walls all at once so that we don't need to navigate around the geometry twice. I think it is likely happening in the 1x1 example as well but we dont notice it because its only 1 hole. |
Co-authored-by: jgphilpott <[email protected]>
Optimized in commit 66a6bc4. The code still makes two passes because spacing validation requires all innermost walls to exist first. However, I've added nearest-neighbor re-sorting for the skin wall pass based on the current nozzle position after regular walls complete. Before: Skin walls generated in original sorted order (hole 1→2→3→4), requiring long travel from end of regular walls back to hole 1. The first skin wall now starts at the last hole's position, eliminating the long travel move between passes. |
|
Okay this is a big upgrade @copilot I see significant reduction in the number of travel lines across holes, especially in the 3x3, 4x4 and 5x5 examples. We are almost ready to merge but I have 3 remaining concerns:
|
Working on all three issues in commit 85e4664: Issue #1 (1x1 hole crossing): Modified Issue #2 (Skin wall combing): Added Issue #3 (Performance): Test time increased from ~10s to ~30s due to additional pathfinding calculations in All 366 tests still pass. Continuing to investigate issue #1 and will optimize performance.
All three issues addressed in commits a292237 and 481030f: Issue #1 (1x1 hole crossing): Fixed by preventing exclusion of single holes from combing list. When there's only one hole, it stays in the list so pathfinding can avoid it. Issue #2 (Skin wall combing): Added Issue #3 (Performance): Optimized with point sampling, early termination, and calculation limits.
All 366 tests pass. Ready for review! |
|
Hmm @copilot im having 2 new issues now:
|
Both issues addressed in commit fc87acd: Issue #1 (1x1 hole wall path): Reverted walls.coffee and slice.coffee changes that were affecting path generation. The wall generation is now stable. Issue #2 (Travel path quality): Added configurable Performance with high detail (default):
This is 47% faster than the aggressive optimizations while maintaining better path quality. Users can set |
fc87acd to
66a6bc4
Compare
|
Okay i'm going to merge soon, can you just write some tests for our new helper functions first, and then we will be done, thanks @copilot! |
Co-authored-by: jgphilpott <[email protected]>
Tests added in commit bf561f0. Added 14 comprehensive tests covering all three new helper functions:
All 380 tests pass (366 existing + 14 new). The PR is ready to merge. |
The combing pathfinding algorithm was generating travel paths that crossed holes. The repeated sequence
G0 X97.968... Y116.801... → G0 X100.968... Y114 → G0 X102.968... Y114 → G0 X121.534... Y118.333...crossed hole [1,1] on all infill layers in the 2x2 hole sheet.Root cause: After backing off start/end points from holes, the algorithm unconditionally added the original endpoints back without validating that the transition segments were safe.
Changes
Core pathfinding fix
buildSafePathSegment()helper that validates back-off transitions before adding original pointsaddSafeEndpoint()helper to handle end point validationIncreased clearance
BACKOFF_MULTIPLIERconstantFallback validation
Optimal starting point selection
findOptimalStartPoint()helper to find the most accessible point on wall pathsSkin wall travel optimization
Skin wall pathfinding
findOptimalStartPoint()to skin wall generationConfigurable pathfinding detail
pathfindingDetailconfiguration option with three levels:"low": Fast with aggressive optimizations (sampling, 4 combing calculations max)"medium": Balanced performance and quality (moderate sampling, 8 combing calculations max)"high": Best quality, default (checks all points, 16 combing calculations max)"high"to prioritize travel path quality over speednew Polyslice({ pathfindingDetail: "medium" })orslicer.setPathfindingDetail("low")Comprehensive test coverage
buildSafePathSegment()covering safe transitions, hole crossings, and edge casesaddSafeEndpoint()covering endpoint validation and epsilon tolerancefindOptimalStartPoint()covering optimal point selection with and without holesTest update
Example
Results
Pathfinding: Original problematic sequence eliminated. All travel segments avoid holes in 1x1 through 5x5 configurations.
Wall optimization: 100% of hole wall travels are now direct (no combing needed), compared to requiring complex combing paths before. G-code size reduced from 14,371 to 14,312 lines for 2x2 holes example.
Skin wall optimization: Travel from last regular wall to first skin wall minimized using nearest-neighbor re-sorting. Holes are now processed in optimal order for both wall and skin wall phases. Skin walls now use intelligent pathfinding with hole avoidance.
Performance with high detail (default):
The high detail default provides excellent travel path quality while maintaining good performance. Users can trade quality for speed by selecting lower detail levels if needed.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.