Skip to content

Commit

Permalink
fix: Use backtracking limit in path_finding
Browse files Browse the repository at this point in the history
When `--backtrack` is not infinity (the default), then take it into
account not just when using the backtrack feature but also when doing
path finding.

This fixes #571
  • Loading branch information
eyal0 committed Apr 9, 2021
1 parent 56a6103 commit d729719
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
1 change: 1 addition & 0 deletions integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"am-test-voronoi-front",
"am-test-voronoi-wide-extra-passes",
"backtrack",
"backtrack_0",
"D1MiniGSR",
"edge-cuts-broken-loop",
"edge-cuts-inside-cuts",
Expand Down
3 changes: 3 additions & 0 deletions path_finding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ optional<linestring_type_fp> PathFindingSurface::find_path(
// in_surface builds up some structures that are only efficient if
// we're doing many tries.
return {{start, goal}};
} else {
// If the straight line was too long then there is no way to connect.
return boost::none;
}
}
} catch (GiveUp g) {
Expand Down
17 changes: 14 additions & 3 deletions surface_vectorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,18 @@ Surface_vectorial::PathFinder Surface_vectorial::make_path_finder(
// risetime at G0 + horizontal distance G0 + plunge G1 ==
// travel time at G1
// The horizontal G0 move is for the maximum of the X and Y coordinates.
// We'll assume that G0 Z is 50inches/minute and G0 X or Y is 100 in/min, taken from Nomad Carbide 883.
const auto vertical_distance = mill->zsafe - mill->zwork;
const auto max_manhattan = std::max(std::abs(a.x() - b.x()), std::abs(a.y() - b.y()));
const double horizontalG1speed = mill->feed;
const double vertG1speed = mill->vertfeed;
const double g0_time = vertical_distance/mill->g0_vertical_speed + max_manhattan/mill->g0_horizontal_speed + vertical_distance/vertG1speed;
const double max_g1_distance = g0_time * horizontalG1speed;
// The time saved by milling would be g0_time - g1_distance/g1_horizontal_speed.
// The extra wear on the mill is g1_distance.
// Wear is limited by the backtrack value (in distance/time).
// g1_distance/time_saved < backtrack => g1_distance < backtrack/time_saved
const double max_g1_distance = std::isinf(mill->backtrack) ?
g0_time * horizontalG1speed :
mill->backtrack*g0_time / (1 + mill->backtrack/horizontalG1speed);
return path_finding_surface.find_path(a, b, max_g1_distance, make_optional(mill->path_finding_limit));
};
}
Expand All @@ -736,7 +741,13 @@ Surface_vectorial::PathFinderRingIndices Surface_vectorial::make_path_finder_rin
const double horizontalG1speed = mill->feed;
const double vertG1speed = mill->vertfeed;
const double g0_time = vertical_distance/mill->g0_vertical_speed + max_manhattan/mill->g0_horizontal_speed + vertical_distance/vertG1speed;
const double max_g1_distance = g0_time * horizontalG1speed;
// The time saved by milling would be g0_time - g1_distance/g1_horizontal_speed.
// The extra wear on the mill is g1_distance.
// Wear is limited by the backtrack value (in distance/time).
// g1_distance/time_saved < backtrack => g1_distance < backtrack/time_saved
const double max_g1_distance = std::isinf(mill->backtrack) ?
g0_time * horizontalG1speed :
mill->backtrack*g0_time / (1 + mill->backtrack/horizontalG1speed);
return path_finding_surface.find_path(a, b, max_g1_distance, mill->path_finding_limit, search_key);
};
}
Expand Down
34 changes: 34 additions & 0 deletions testing/gerbv_example/backtrack_0/millproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
mirror-absolute=true
metric=true
metricoutput=true
zchange=10
nog81=true
nog64=true
tsp-2opt=true
vectorial=true
eulerian-paths=true
tile-x=1
tile-y=1
mill-diameters=0.45
isolation-width=0.9mm
tolerance=0.05
zsafe=0.5
milling-overlap=50%
outline=test-Edge.Cuts.gbr
cut-side=front
zcut=-2
cut-infeed=0.7
cut-feed=25
cut-speed=12000
cutter-diameter=1.2
bridgesnum=4
bridges=0.5
zbridges=-0.5
outline-output=test-Edge.Cuts-front-1.2mm.nc
front=test-F.Cu.gbr
front-output=test-F.Cu-front-0.3mm.nc
zwork=-0.15
mill-feed=100
mill-vertfeed=25
mill-speed=12000
backtrack=0
24 changes: 24 additions & 0 deletions testing/gerbv_example/backtrack_0/test-Edge.Cuts.gbr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
G04 #@! TF.GenerationSoftware,KiCad,Pcbnew,5.0.2-bee76a0~70~ubuntu18.04.1*
G04 #@! TF.CreationDate,2020-06-06T15:55:04-04:00*
G04 #@! TF.ProjectId,test,74657374-2e6b-4696-9361-645f70636258,rev?*
G04 #@! TF.SameCoordinates,PX8062360PY5e78920*
G04 #@! TF.FileFunction,Profile,NP*
%FSLAX46Y46*%
G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)*
G04 Created by KiCad (PCBNEW 5.0.2-bee76a0~70~ubuntu18.04.1) date Sat 06 Jun 2020 03:55:04 PM EDT*
%MOMM*%
%LPD*%
G01*
G04 APERTURE LIST*
%ADD10C,0.150000*%
G04 APERTURE END LIST*
D10*
X0Y0D02*
X0Y10160000D01*
X15240000Y0D02*
X0Y0D01*
X15240000Y10160000D02*
X15240000Y0D01*
X0Y10160000D02*
X15240000Y10160000D01*
M02*
77 changes: 77 additions & 0 deletions testing/gerbv_example/backtrack_0/test-F.Cu.gbr
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
G04 #@! TF.GenerationSoftware,KiCad,Pcbnew,5.0.2-bee76a0~70~ubuntu18.04.1*
G04 #@! TF.CreationDate,2020-06-06T15:55:04-04:00*
G04 #@! TF.ProjectId,test,74657374-2e6b-4696-9361-645f70636258,rev?*
G04 #@! TF.SameCoordinates,PX8062360PY5e78920*
G04 #@! TF.FileFunction,Copper,L1,Top*
G04 #@! TF.FilePolarity,Positive*
%FSLAX46Y46*%
G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)*
G04 Created by KiCad (PCBNEW 5.0.2-bee76a0~70~ubuntu18.04.1) date Sat 06 Jun 2020 03:55:04 PM EDT*
%MOMM*%
%LPD*%
G01*
G04 APERTURE LIST*
G04 #@! TA.AperFunction,ViaPad*
%ADD10C,4.000000*%
G04 #@! TD*
G04 #@! TA.AperFunction,NonConductor*
%ADD11C,0.254000*%
G04 #@! TD*
G04 APERTURE END LIST*
D10*
G04 #@! TO.N,*
X7620000Y5080000D03*
G04 #@! TD*
D11*
G36*
X14530001Y710000D02*
X710000Y710000D01*
X710000Y5604134D01*
X4985000Y5604134D01*
X4985000Y4555866D01*
X5386155Y3587392D01*
X6127392Y2846155D01*
X7095866Y2445000D01*
X8144134Y2445000D01*
X9112608Y2846155D01*
X9853845Y3587392D01*
X10255000Y4555866D01*
X10255000Y5604134D01*
X9853845Y6572608D01*
X9112608Y7313845D01*
X8144134Y7715000D01*
X7095866Y7715000D01*
X6127392Y7313845D01*
X5386155Y6572608D01*
X4985000Y5604134D01*
X710000Y5604134D01*
X710000Y9450000D01*
X14530000Y9450000D01*
X14530001Y710000D01*
X14530001Y710000D01*
G37*
X14530001Y710000D02*
X710000Y710000D01*
X710000Y5604134D01*
X4985000Y5604134D01*
X4985000Y4555866D01*
X5386155Y3587392D01*
X6127392Y2846155D01*
X7095866Y2445000D01*
X8144134Y2445000D01*
X9112608Y2846155D01*
X9853845Y3587392D01*
X10255000Y4555866D01*
X10255000Y5604134D01*
X9853845Y6572608D01*
X9112608Y7313845D01*
X8144134Y7715000D01*
X7095866Y7715000D01*
X6127392Y7313845D01*
X5386155Y6572608D01*
X4985000Y5604134D01*
X710000Y5604134D01*
X710000Y9450000D01*
X14530000Y9450000D01*
X14530001Y710000D01*
M02*

0 comments on commit d729719

Please sign in to comment.