Commit e93e4e3f authored by Nicholas Gar Hei Chan's avatar Nicholas Gar Hei Chan
Browse files

Added layer sampling functionality

parent ca4b6ff5
......@@ -9,7 +9,6 @@ from __future__ import absolute_import
#
# Take a look at the documentation on what other plugin mixins are available.
import wiringpi
import subprocess
import octoprint.plugin
......@@ -31,9 +30,6 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
# Implement custom logic and driving code here #
# ------------------------------------------------------------------------- #
def startup_actions(self, **kwargs):
wiringpi.
def send_layer(self, layer):
""" Sends a layer to the Octoprint client
......@@ -57,15 +53,24 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
File selected payload from the on-event handler.
"""
full_path = os.path.expanduser("~/.octoprint/uploads/{}".format(payload['name']))
self.model = gcp.parse_gcode(full_path)
self.model = gcp.parse_gcode(full_path,5,10)
self.num_layers = len(self.model.layers)
self.curr_layer = 0;
def sample_layer(self):
def sample_layer(self, current_layer):
""" Sample a layer
"""
return True
layer = self.model.layers[current_layer]
if len(layer.sample_points['x']):
result = 0
for point in zip(layer.sample_points['x'], layer.sample_points['y']):
if probe_point(point[0], point[1], layer.z_height):
return True
else:
return False
else:
return True
def probe_point(self, x, y, z):
"""
......@@ -77,14 +82,18 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
probe_y = y - self.offsets['y']
probe_z = z + self.offsets['z']
if (probe_x < 0) or (probe_y < 0) or (probe_z < 0):
self._logger.info('Sample point outside of printer bounds. Assuming good')
return True
# Go to 2mm above the sample position, accounting for tool offset
self._printer.commands('G0 X{} Y{} Z{}'.format(x+self.offsets['x'],
y+self.offsets['y'],
z+self.offsets['z']))
self._printer.commands('G0 X{} Y{} Z{}'.format(probe_x,
probe_y,
probe_z)
reading = subprocess.run("./sample.sh", capture_output=True).stdout.decode("utf-8").strip() == '1'
return reading
return True #RETURN ALL TRUE FOR NOW
# ------------------------------------------------------------------------- #
# OCTOPRINT DEFINED FUNCTIONS #
......@@ -124,17 +133,13 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
self.process_gcode(payload)
self._logger.info('GCODE Processed: {} layers'.format(self.num_layers))
self.send_layer(0)
if event == 'Dwelling': #G4 command received
self._logger.info('Dwell, sending a test command...')
self._printer.commands('G0 X10 Y10')
if event == 'Waiting': #M0, M1, M226 received
self._logger.info('Waiting')
if event == 'ZChange':
data = self._printer.get_current_data()
currentZ = data['currentZ']
try:
current_layer = self.model.layer_heights.index(currentZ)
self._logger.info('Current layer: {}'.format(current_layer))
self.sample_layer(current_layer)
except:
self._logger.info('Not a valid layer at z = {}'.format(currentZ))
......
Supports Markdown
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