Skip to content

Commit

Permalink
Add chord length (#3)
Browse files Browse the repository at this point in the history
* chord testing

* remove polar, add chord

* remove accordian

* version bump
  • Loading branch information
paukstelis authored Nov 26, 2024
1 parent df79098 commit a880ecb
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
13 changes: 11 additions & 2 deletions octoprint_gcode_ripper/G_Code_Rip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,7 @@ def generategcode(self,side,z_safe=.5,
Wrap="XYZ",
preamble="",
postamble="",
chord=False,
gen_rapids=False,
PLACES_L=4,
PLACES_R=3,
Expand Down Expand Up @@ -1617,10 +1618,18 @@ def generategcode(self,side,z_safe=.5,
if Wrap == "Y2A" or Wrap == "Y2B":
#if line[1][1].imag == 0:
if (not isinstance(line[1][1], complex)):
coordA[1]=sign*degrees(line[1][1]/Rstock)
#Use chord length
if chord:
coordA[1]=sign*degrees(2*asin(line[1][1]/(2*Rstock)))
else:
coordA[1]=sign*degrees(line[1][1]/Rstock)
#if line[2][1].imag == 0:
if (not isinstance(line[2][1], complex)):
coordB[1]=sign*degrees(line[2][1]/Rstock)
#Use chord length
if chord:
coordB[1]=sign*degrees(2*asin(line[2][1]/(2*Rstock)))
else:
coordB[1]=sign*degrees(line[2][1]/Rstock)
elif Wrap == "X2B" or Wrap == "X2A":
#if line[1][0].imag == 0:
if (not isinstance(line[1][0], complex)):
Expand Down
34 changes: 25 additions & 9 deletions octoprint_gcode_ripper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self):
self.scalefactor = float(1)
self.origin = "center"
self.mapping = "Y2A"
self.chord = False
self.split_moves = True
self.min_seg = 1.0
self.datafolder = None
Expand Down Expand Up @@ -73,14 +74,21 @@ def _get_templates(self):
if file.endswith('.gcode'):
self.template_gcode.append(file)

def generate_name(self):
#abbreviate origin
ori = self.origin[0].upper()
wrapdiam = self.start_diameter + 2*(self.currentZ)
output_name = f"D{int(wrapdiam)}_R{int(self.rotation)}_Ori{ori}_"
return output_name

def generate_gcode(self):
gcr = G_Code_Rip.G_Code_Rip()
gcode_file = self.selected_file
gcr.Read_G_Code("{}/{}".format(self._settings.getBaseFolder("uploads"), gcode_file), XYarc2line=True, units="mm")
self.mapping = "Y2A"
polar = False
wrapdiam = self.start_diameter + 2*(self.currentZ)
output_name = "D{0}_R{1}_".format(int(wrapdiam), int(self.rotation))
output_name = self.generate_name()
output_path = output_name+self.template_name
path_on_disk = "{}/{}".format(self._settings.getBaseFolder("watched"), output_path)
sf = self.scalefactor
Expand All @@ -99,13 +107,13 @@ def generate_gcode(self):
y_zero = midy

#Refactor for polar coordinate case
if self.start_diameter < maxx:
output_name = "POLAR_R{0}_".format(int(self.rotation))
output_path = output_name+self.template_name
path_on_disk = "{}/{}".format(self._settings.getBaseFolder("watched"), output_path)
self.mapping = "Polar"
polar = True
wrapdiam=0.5
#if self.start_diameter < maxx:
# output_name = "POLAR_R{0}_".format(int(self.rotation))
# output_path = output_name+self.template_name
# path_on_disk = "{}/{}".format(self._settings.getBaseFolder("watched"), output_path)
# self.mapping = "Polar"
# polar = True
# wrapdiam=0.5

temp = gcr.scale_translate(temp,translate=[x_zero,y_zero,0.0])
gcr.scaled_trans = temp
Expand All @@ -123,7 +131,14 @@ def generate_gcode(self):
pre = pre + "DOMODA\nMAXARC {0:.3f}".format(maxarc)

with open(path_on_disk,"w") as newfile:
for line in gcr.generategcode(temp, Rstock=wrapdiam/2, no_variables=True, Wrap=self.mapping, preamble=pre, postamble="STOPBANGLE", FSCALE="None"):
for line in gcr.generategcode(temp,
Rstock=wrapdiam/2,
no_variables=True,
Wrap=self.mapping,
preamble=pre,
chord=self.chord,
postamble="STOPBANGLE",
FSCALE="None"):
newfile.write(f"\n{line}")

def update_image(self):
Expand All @@ -144,6 +159,7 @@ def on_api_command(self, command, data):
self.start_diameter = float(data["diameter"])
self.rotation = float(data["rotationAngle"])
self.modifyA = bool(data["modifyA"])
self.chord = bool(data["chord"])
self.scalefactor = float(data["scalefactor"])
self.origin = data["origin"]
self.mapping = "Y2A"
Expand Down
2 changes: 2 additions & 0 deletions octoprint_gcode_ripper/static/js/gcode_ripper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $(function() {
self.rotationAngle = ko.observable(0);
self.scaleFactor = ko.observable(1.0);
self.modifyA = ko.observable(1);
self.chord = ko.observable(1);
self.split_moves = ko.observable(1);
self.min_seg_length = ko.observable(1.0);
self.origin = ko.observable("center");
Expand Down Expand Up @@ -123,6 +124,7 @@ $(function() {
filename: self.selectedGCodeFile,
rotationAngle: self.rotationAngle(),
modifyA: self.modifyA(),
chord: self.chord(),
scalefactor: self.scaleFactor(),
split_moves: self.split_moves(),
min_seg: self.min_seg_length(),
Expand Down
33 changes: 17 additions & 16 deletions octoprint_gcode_ripper/templates/gcode_ripper_tab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,43 @@
</div>

</div>
<div class="row" style="padding-left: 20px; padding-bottom: 10px;">
<div class="accordian-group" id="extra_options">
<div class="accordian-heading">
<a class="accordian-toggle" data-toggle="collapse" href="#extra_options_collapse">Extra options</a>
</div>
<div id="extra_options_collapse" class="accordian-body collapse">
<div class="span12">
<div class="row" style="padding-left: 30px; padding-bottom: 10px;">

<div id="extra_options">
<div>
<label for="modifyA_input">Flat pockets:
<i class="icon icon-info-sign" title="Extra Z-depth at cut origin. Uncheck for objects that are not simple pockets." data-toggle="tooltip"></i>
<i class="icon icon-info-sign" title="Extra Z-depth at cut origin. Uncheck for objects that are not simple pockets. Must also be on when cutting near-polar coordinates (B~=+/-90)" data-toggle="tooltip"></i>
<input id="modifyA_input" type="checkbox" checked data-bind="checked: modifyA">
</label>
</div>
<div class="span12">
<div>
<label for="chord_input">Use chord length:
<i class="icon icon-info-sign" title="Calculates A axis values as the chord length, rather than arc length. Increases A rotations slightly." data-toggle="tooltip"></i>
<input id="chord_input" type="checkbox" checked data-bind="checked: chord">
</label>
</div>
<div>
<label for="split_input">Split moves:
<i class="icon icon-info-sign" title="Split moves into smaller moves defined by minimum segment length. Need for flat pockets and some other features." data-toggle="tooltip"></i>
<i class="icon icon-info-sign" title="Split moves into smaller moves defined by minimum segment length. Needed for flat pockets and near-polar coordinate cutting." data-toggle="tooltip"></i>
<input id="split_input" type="checkbox" checked data-bind="checked: split_moves">
</label>
</div>

<div class="span12">
<div>
<label for="min_seg_input">Minimum segment length (mm):
<input id="min_seg_input" type="number" value="1" step="any" data-bind="value: min_seg_length">
<input id="min_seg_input" type="number" min="0.1" value="1" step="0.1" data-bind="value: min_seg_length">
</label>
</div>
<div class="span12">
<div>
<label for="origin_sel">Origin:
<select class="span4" id="origin_sel" name="origin_sel" data-bind="value: origin">
<select id="origin_sel" name="origin_sel" data-bind="value: origin">
<option value="center">Center</option>
<option value="left">Left</option>
<option value="right">Right</option>
</select>
</label>
</div>
</div>

</div>
</div>
<hr>
<div>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-Gcode_ripper"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.1.7"
plugin_version = "0.1.8"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit a880ecb

Please sign in to comment.