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 06bc145
Show file tree
Hide file tree
Showing 3 changed files with 18 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

0 comments on commit 06bc145

Please sign in to comment.