Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions jun25_dwell_rook_toolpath/toolpath_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def shift_time(layer, new_start_time, eps=1e-12):
return new_layer

def add_power_off_entry(layer, eps=1e-10):
new_layer = [(layer[0][0], layer[0][1], 0.0)]
# New layer initial dwell - slightly perturb x position to ensure unique value
new_layer_position = (layer[0][1][0] + eps, layer[0][1][1], layer[0][1][2])
new_layer = [(layer[0][0], new_layer_position, 0.0)]
new_layer = new_layer + [(layer[0][0]+ eps, layer[0][1], layer[0][2])]
new_layer = new_layer + layer[1:]

Expand Down Expand Up @@ -154,12 +156,26 @@ def flatten_layer_z(layer, reference_index=0):

return new_layer

def strip_duplicate_locations(time_position_power):
def strip_duplicate_locations(time_position_power, eps=1e-10):
out = []
for entry in reversed(time_position_power):
if len(out) > 0:
# Check whether this entry is at the same position as the one after it
if entry[1] != out[-1][1]:
# This entry is at a new position - append this event
out.append(entry)
else:
# This entry is at the same position as the one after it
# If both entries are dwells, they can be combined
# Otherwise, combining entries will change the scan path itself
# To avoid this, slightly perturb the position rather than combining entries
# This is necessary as adamantine cannot handle consecutive entries with the same position
if entry[2] != 0 or out[-1][2] != 0:
# Slightly perturb x position
modified_position = (entry[1][0] + eps, entry[1][1], entry[1][2])
modified_entry = (entry[0], modified_position, entry[2])
# Append this modified event
out.append(modified_entry)
Comment on lines +167 to +178
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because duplicates are resolved in a single reverse pass, perturbing an entry to avoid a scan/dwell collision can prevent earlier consecutive dwells from being combined. Example pattern: dwell@P, dwell@P, scan@P will perturb the second dwell (to avoid matching the scan) and then the first dwell no longer matches it, so the two dwells are not combined and an extra micro-move is introduced during power-off time. To ensure only consecutive dwells are combined, consider collapsing adjacent dwell runs (power==0) at identical positions before applying the non-dwell perturbation rule (or do a forward pass that handles dwell/dwell first).

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A situation where multiple consecutive segments at the same location occur with non-zero and zero power would be rare, and whether or not the dwells are combined in such a case won't affect the overall result as the applied perturbation to the location is minor to begin with

else:
out.append(entry)

Expand Down