Skip to content

Commit

Permalink
relative Z box
Browse files Browse the repository at this point in the history
  • Loading branch information
paukstelis committed Jan 19, 2025
1 parent 2e87ed4 commit b1989c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 3 additions & 2 deletions octoprint_gcode_ripper/G_Code_Rip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,8 +1613,8 @@ def generategcode(self,side,z_safe=.5,
D2 = line[2][2]-line[1][2]
D012 = sqrt((D0+0j).real**2+(D1+0j).real**2+(D2+0j).real**2)

coordA=[ line[1][0], line[1][1], line[1][2] ]
coordB=[ line[2][0], line[2][1], line[2][2] ]
coordA=[ line[1][0], line[1][1], line[1][2] ] #this is previous
coordB=[ line[2][0], line[2][1], line[2][2] ] #this is current
if Wrap == "Y2A" or Wrap == "Y2B":
#if line[1][1].imag == 0:
if (not isinstance(line[1][1], complex)):
Expand All @@ -1630,6 +1630,7 @@ def generategcode(self,side,z_safe=.5,
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
12 changes: 10 additions & 2 deletions octoprint_gcode_ripper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self):
self.min_seg = 1.0
self.datafolder = None
self.template_name = None
self.zrelative = False
#self.watched_path = self._settings.global_get_basefolder("watched")
##~~ SettingsPlugin mixin
def initialize(self):
Expand Down Expand Up @@ -77,7 +78,7 @@ def _get_templates(self):
def generate_name(self):
#abbreviate origin
ori = self.origin[0].upper()
wrapdiam = self.start_diameter + 2*(self.currentZ)
wrapdiam = self.calc_diameter()
output_name = f"D{int(wrapdiam)}_R{int(self.rotation)}_Ori{ori}_"
return output_name

Expand All @@ -87,7 +88,7 @@ def generate_gcode(self):
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)
wrapdiam = self.calc_diameter()
output_name = self.generate_name()
output_path = output_name+self.template_name
path_on_disk = "{}/{}".format(self._settings.getBaseFolder("watched"), output_path)
Expand Down Expand Up @@ -145,6 +146,12 @@ def generate_gcode(self):
FSCALE="None"):
newfile.write(f"\n{line}")

def calc_diameter(self):
if self.zrelative:
return self.start_diameter + 2*(self.currentZ)
else:
return self.start_diameter

def update_image(self):
self._file_manager.set_additional_metadata("local",self.selected_file,"bgs_imgurl",self.selected_image,overwrite=True)

Expand All @@ -169,6 +176,7 @@ def on_api_command(self, command, data):
self.mapping = "Y2A"
self.split_moves = bool(data["split_moves"])
self.min_seg = float(data["min_seg"])
self.zrelative = bool(data["zrelative"])
self.generate_gcode()

if command == "editmeta":
Expand Down
9 changes: 8 additions & 1 deletion octoprint_gcode_ripper/static/js/gcode_ripper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $(function() {
self.newimage = ko.observable("");
self.thumbnail_url = ko.observable('/static/img/tentacle-20x20.png');
self.zPos = ko.observable("");
self.zrelative = ko.observable(0);


tab = document.getElementById("tab_plugin_gcode_ripper_link");
Expand Down Expand Up @@ -129,6 +130,7 @@ $(function() {
split_moves: self.split_moves(),
min_seg: self.min_seg_length(),
origin: self.origin(),
zrelative: self.zrelative()
};

OctoPrint.simpleApiCommand("gcode_ripper", "write_gcode", data)
Expand Down Expand Up @@ -197,7 +199,12 @@ $(function() {
self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin == 'gcode_ripper' && data.type == 'grbl_state') {
self.zPos(Number.parseFloat(data.z).toFixed(2));
self.calc_diameter = (Number.parseFloat(self.diameter()) + (self.zPos()*2));

if (self.zrelative) {
self.calc_diameter = (Number.parseFloat(self.diameter()) + (self.zPos()*2));
} else {
self.calc_diameter = self.diameter;
}
//console.log(newDiam);
}
}
Expand Down
7 changes: 7 additions & 0 deletions octoprint_gcode_ripper/templates/gcode_ripper_tab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
<input id="scale_factor_input" type="number" value="1" step="any" class="span4" data-bind="value: scaleFactor">
</div>

<div class="row">
<label for="zrelative">Reference Diam.
<i class="icon icon-info-sign" title="When checked, the input diameter is a reference diameter at Z=0. The current work position Z value is added to this value to calculate the diameter." data-toggle="tooltip"></i>
<input id="zrelative" type="checkbox" unchecked data-bind="checked: zrelative">
</label>
</div>

<div class="row" style="padding-left: 20px; padding-bottom: 10px;">
<div class="span12">
<label for="gcode_file_select">Select GCode File:</label>
Expand Down

0 comments on commit b1989c7

Please sign in to comment.