Commit f2e387c8 authored by Lars Kruse's avatar Lars Kruse

reduce unnecessary moves to safety height for zigzag patterns

Previously the "TinySidewaysMoveFilter" was used to detect small gaps within
a toolpath that can be removed safely. But the above filter only worked under
the specific conditions that the z levels of both adjacent points are the same.
The new implementation adds another connection line to the motion grid (before
collision tests). Thus now all kind of connections (independent of their length
and position) are possible.
parent 47f67721
......@@ -40,19 +40,11 @@ class ToolParamRadius(pycam.Plugins.PluginBase):
self.core.get("register_parameter")("tool", "radius", self.control)
self.core.register_ui("tool_size", "Tool Diameter",
self.control.get_widget(), weight=10)
self.core.register_chain("toolpath_filters",
self.get_toolpath_filters)
return True
def teardown(self):
self.core.get("unregister_parameter")("tool", "radius")
self.core.unregister_ui("tool_size", self.control.get_widget())
self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters)
@toolpath_filter("tool", "radius")
def get_toolpath_filters(self, radius):
return [pycam.Toolpath.Filters.TinySidewaysMovesFilter(2 * radius)]
class ToolParamTorusRadius(pycam.Plugins.PluginBase):
......
......@@ -185,42 +185,6 @@ class SafetyHeightFilter(BaseFilter):
return new_path
class TinySidewaysMovesFilter(BaseFilter):
PARAMS = ("tolerance", )
WEIGHT = 60
def filter_toolpath(self, toolpath):
new_path = []
last_pos = None
safety_pending = False
for move_type, args in toolpath:
if move_type in (MOVE_STRAIGHT, MOVE_STRAIGHT_RAPID):
if safety_pending and last_pos:
# check if we can skip a possible previous safety move
if (pdist(last_pos, args) <= self.settings["tolerance"]) and \
(abs(last_pos[2] - args[2]) < epsilon):
# same height, within tolerance -> no safety move
pass
elif pnear(last_pos, args, axes=(0, 1)):
# same position (x/y)
pass
else:
# safety move is necessary
new_path.append((MOVE_SAFETY, None))
new_path.append((move_type, args))
safety_pending = False
last_pos = args
elif move_type == MOVE_SAFETY:
safety_pending = True
else:
# all others: keep
new_path.append((move_type, args))
if safety_pending:
new_path.append((MOVE_SAFETY, None))
return new_path
class MachineSetting(BaseFilter):
PARAMS = ("key", "value")
......
......@@ -169,6 +169,25 @@ def get_fixed_grid_layer(minx, maxx, miny, maxy, z, line_distance,
if zigzag:
start, end = end, start
end_position ^= primary_dir
if zigzag and step_width:
# Connect endpoints of zigzag lines (prevent unnecessary safety moves).
# (DropCutter)
zigzag_result = []
for line in result:
zigzag_result.extend(line)
# return a list containing a single chain of lines
result = [zigzag_result]
elif zigzag and step_width is None:
# Add a pair of end_before/start_next points between two lines.
# (PushCutter)
zigzag_result = []
last = None
for (p1, p2) in result:
if last:
zigzag_result.append((last, p1))
zigzag_result.append((p1, p2))
last = p2
result = zigzag_result
return result, end_position
return get_lines(start, end, end_position)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment