From e3d0d1b61e34313aedac0b9310499ecd0275a1a0 Mon Sep 17 00:00:00 2001 From: robsju <61894519+robsju@users.noreply.github.com> Date: Sat, 6 Feb 2021 11:12:58 -0500 Subject: [PATCH 1/7] Update README.md Added a clearer description of nomenclature in BTT documentation. I had trouble at first figuring out what pin was what so thought it would be good to have it right here. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef98cc6..e457bb9 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,12 @@ After installation a restart of Octoprint is recommended. * In [BigTreeTech SmartFilamentSensor Manual](https://github.com/bigtreetech/smart-filament-detection-module/tree/master/manual) on page 12 you can find the functionality of the pins. Please ensure that there is no undocumented twist in your cable * My recommended GPIO pins: 11, 13, 15, 17 (such without any special usage). Please check the [documentation](https://www.raspberrypi.org/documentation/usage/gpio/) of your Raspberry Pi version/model. Also other pins could work, if you know how to configure it on the Raspberry, but it might be tricky and not work out of the box. +Note: The BTT Pins are labeled as follows + +S for SIN <--- signal line (i.e. data source--attach to chosen GPIO pin) +G for GND <--- This is ground +V for VDD <--- +3.3v in + **Attention** There are two different modes for GPIO pins: * BCM (Broadcom SOC channel) - the numbers after the GPIO label @@ -94,4 +100,4 @@ G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed Support of multiple sensors for multiextruders like 4 channel kraken hotend ## Contact -[![PayPal](https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate?hosted_button_id=AHS3MUTFXXMNG "Donate for Octoprint Smart-Filament-Sensor Plugin") \ No newline at end of file +[![PayPal](https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate?hosted_button_id=AHS3MUTFXXMNG "Donate for Octoprint Smart-Filament-Sensor Plugin") From 2faa08dae85b16e21de2b0ab35b8c699cd082221 Mon Sep 17 00:00:00 2001 From: Anni L Date: Fri, 9 Apr 2021 07:02:53 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e457bb9..c99b956 100644 --- a/README.md +++ b/README.md @@ -99,5 +99,8 @@ G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed ## Outlook Support of multiple sensors for multiextruders like 4 channel kraken hotend +## News +Development and support pause till summer 2021 due to a lack of time + ## Contact [![PayPal](https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate?hosted_button_id=AHS3MUTFXXMNG "Donate for Octoprint Smart-Filament-Sensor Plugin") From bc089afb778220cc081631df2e6786e03be1eef5 Mon Sep 17 00:00:00 2001 From: pkasperczyk Date: Wed, 18 Aug 2021 18:42:37 +0200 Subject: [PATCH 3/7] add new detection --- octoprint_smart_filament_sensor/__init__.py | 160 ++++++++++++++++-- .../static/js/smartfilamentsensor_settings.js | 36 ++++ .../smartfilamentsensor_settings.jinja2 | 29 ++++ 3 files changed, 215 insertions(+), 10 deletions(-) diff --git a/octoprint_smart_filament_sensor/__init__.py b/octoprint_smart_filament_sensor/__init__.py index bdd155e..734c222 100644 --- a/octoprint_smart_filament_sensor/__init__.py +++ b/octoprint_smart_filament_sensor/__init__.py @@ -1,3 +1,6 @@ +#Modifications +#2021-08-18 add detection of "sensor physical distance" + # coding=utf-8 from __future__ import absolute_import import octoprint.plugin @@ -5,6 +8,7 @@ import RPi.GPIO as GPIO from time import sleep import flask +from flask import jsonify import json from octoprint_smart_filament_sensor.filament_motion_sensor_timeout_detection import FilamentMotionSensorTimeoutDetection from octoprint_smart_filament_sensor.data import SmartFilamentSensorDetectionData @@ -28,6 +32,8 @@ def initialize(self): self.START_DISTANCE_OFFSET = 7 self.send_code = False self._data = SmartFilamentSensorDetectionData(self.motion_sensor_detection_distance, True, self.updateToUi) + self.lastEHigh = -1 #not set + self.previousState = -1 #not set #Properties @property @@ -69,6 +75,25 @@ def mode(self): #def send_gcode_only_once(self): # return self._settings.get_boolean(["send_gcode_only_once"]) +#Physical distance detection + @property + def motion_sensor_physical_distance(self): + dist = float(self._settings.get(["motion_sensor_physical_distance"])) + return dist + + @property + def motion_sensor_physical_distance_low(self): + return float(self._settings.get(["motion_sensor_physical_distance_low"])) + + @property + def motion_sensor_physical_distance_high(self): + return float(self._settings.get(["motion_sensor_physical_distance_high"])) + + @property + def motion_sensor_physical_distance_tolerance(self): + return float(self._settings.get(["motion_sensor_physical_distance_tolerance"])) + + # Initialization methods def _setup_sensor(self): # Clean up before intializing again, because ports could already be in use @@ -81,10 +106,10 @@ def _setup_sensor(self): self._logger.info("Using BCM Mode") GPIO.setmode(GPIO.BCM) - GPIO.setup(self.motion_sensor_pin, GPIO.IN) + GPIO.setup(self.motion_sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Add reset_distance if detection_method is distance_detection - if (self.detection_method == 1): + if (self.detection_method == 1 or self.detection_method == 2): # Remove event first, because it might been in use already try: GPIO.remove_event_detect(self.motion_sensor_pin) @@ -112,10 +137,10 @@ def on_after_startup(self): def get_settings_defaults(self): return dict( #Motion sensor - mode=0, # Board Mode + mode=1, # Board Mode. Changed to BCM (1) motion_sensor_enabled = True, #Sensor detection is enabled by default - motion_sensor_pin=-1, # Default is no pin - detection_method = 0, # 0 = timeout detection, 1 = distance detection + motion_sensor_pin=17, # Default is no pin(-1). Changed to 17 + detection_method = 2, # 0 = timeout detection, 1 = distance detection, 2 = new detection # Distance detection motion_sensor_detection_distance = 15, # Recommended detection distance from Marlin would be 7 @@ -124,6 +149,12 @@ def get_settings_defaults(self): motion_sensor_max_not_moving=45, # Maximum time no movement is detected - default continously pause_command="M600", #send_gcode_only_once=False, # Default set to False for backward compatibility + + # Physical distance (for sensor) + motion_sensor_physical_distance = -1, + motion_sensor_physical_distance_low = -1, + motion_sensor_physical_distance_high = -1, + motion_sensor_physical_distance_tolerance = 0.6 ) def on_settings_save(self, data): @@ -156,6 +187,55 @@ def start_connection_test(self): self._data.connection_test_running = True self._logger.info("Connection test started") + # Detection of physical distance + def detect_physical_distance(self): + self._logger.info("Physical distance detection started") + startState = GPIO.input(self.motion_sensor_pin) + extruderValue = 0.00 + begin = 1 + end = 1 + secondChange = False + secondChangeValue = 0 + distance = 0 + distanceLow = 0 + distanceHigh = 0 + self._printer.commands("M92 E101.0") + while True: + extruderValue -= 0.1 + self._printer.extrude(-0.1, 200) #relative + sleep(0.5) + state = GPIO.input(self.motion_sensor_pin) + if (state != startState and begin == 1 and not secondChange): + begin = extruderValue + self._logger.info("Step 1, state = "+str(state)+", eV = "+str(extruderValue)) + if (state == startState and begin != 1 and not secondChange): + secondChange = True + secondChangeValue = extruderValue + if (state): + distanceLow = begin - extruderValue + else: + distanceHigh = begin - extruderValue + self._logger.info("Step 2, state = "+str(state)+", eV = "+str(extruderValue)) + if (state != startState and begin != 1 and secondChange): + end = extruderValue + if (state): + distanceLow = secondChangeValue - extruderValue + else: + distanceHigh = secondChangeValue - extruderValue + distance = begin - end + self._logger.info("Step 3, state = "+str(state)+", eV = "+str(extruderValue)) + break + if (extruderValue < -20.00): + self._logger.info("Step 4, state = "+str(state)+", eV = "+str(extruderValue)) + break + self._settings.set(["motion_sensor_physical_distance"], distance) + self._settings.set(["motion_sensor_physical_distance_low"], distanceLow) + self._settings.set(["motion_sensor_physical_distance_high"], distanceHigh) + #self._settings.save(True, True) + self._settings.save(True) + self._logger.info("Physical distance detection ended. Distance is "+str(distance)+", distance low is "+str(distanceLow)+", distance high is "+str(distanceHigh)) + + # Starts the motion sensor if the sensors are enabled def motion_sensor_start(self): self._logger.debug("Sensor enabled: " + str(self.motion_sensor_enabled)) @@ -167,6 +247,11 @@ def motion_sensor_start(self): self._logger.debug("GPIO mode: BCM Mode") self._logger.debug("GPIO pin: " + str(self.motion_sensor_pin)) + # New detection + if (self.detection_method == 2): + self._logger.info("Motion sensor started: New detection") + self._logger.debug("Detection Mode: New detection") + # Distance detection if (self.detection_method == 1): self._logger.info("Motion sensor started: Distance detection") @@ -206,6 +291,14 @@ def printer_change_filament (self): self.send_code = True self._data.filament_moving = False + def handleNewDetection (self): + # Check if stop signal was already sent + if(not self.send_code): + self._logger.debug("Motion sensor detected no movement - New detection") + self._printer.pause_print() + self.send_code = True + self._data.filament_moving = False + # Reset the distance, if the remaining distance is smaller than the new value def reset_distance (self, pPin): self._logger.debug("Motion sensor detected movement") @@ -219,13 +312,15 @@ def init_distance_detection(self): self.lastE = float(-1) self.currentE = float(0) self.reset_remainin_distance() + self.lastEHigh = -1 #not set + self.previousState = GPIO.input(self.motion_sensor_pin) # Reset the remaining distance on start or resume # START_DISTANCE_OFFSET is used for the (re-)start sequence def reset_remainin_distance(self): self._data.remaining_distance = (float(self.motion_sensor_detection_distance) + self.START_DISTANCE_OFFSET) - # Calculate the remaining distance + # Calculate the remaining distance or calculation for EHigh def calc_distance(self, pE): if (self.detection_method == 1): # Only with absolute extrusion the delta distance must be calculated @@ -260,6 +355,43 @@ def calc_distance(self, pE): else: self.printer_change_filament() + if (self.detection_method == 2): + # Only with absolute extrusion the delta distance must be calculated + if (self._data.absolut_extrusion): + # LastE is not used and set to the same value as currentE + if (self.lastE == -1): + self.lastE = pE + else: + self.lastE = self.currentE + self.currentE = pE + + self._logger.debug("LastE: " + str(self.lastE) + "; CurrentE: " + str(self.currentE)) + + # Calculate the remaining distance from detection distance + # currentE - lastE is the delta distance + if(self._data.absolut_extrusion): + deltaDistance = self.currentE - self.lastE + # With relative extrusion the current extrusion value is the delta distance + else: + deltaDistance = float(pE) + + if (deltaDistance > 0 and deltaDistance < 5.9) : + #0.012 - 1 + #0.5 - 5 + # y = + #delta - x + toleranceMultiplier = 1+deltaDistance*8 + tolerance = toleranceMultiplier*self.motion_sensor_physical_distance_tolerance + rDist = self.motion_sensor_physical_distance+tolerance+self.lastEHigh-self.currentE + if (self.lastEHigh != -1 and rDist < 0): + self._logger.info("Detection: CurrentE: "+str(self.currentE)+", EHigh: "+str(self.lastEHigh)+",deltaE: "+str(deltaDistance)+", tolerance: "+str(tolerance)+", rDist: "+str(rDist)) + self.handleNewDetection() + + state = GPIO.input(self.motion_sensor_pin) + if (self.previousState != state and state): + self.lastEHigh = self.currentE + self._logger.info("Change: CurrentE: "+str(self.currentE)+", EHigh: "+str(self.lastEHigh)+",deltaE: "+str(deltaDistance)+", tolerance: "+str(tolerance)+", rDist: "+str(rDist)) + self.previousState = state def updateToUi(self): self._plugin_manager.send_plugin_message(self._identifier, self._data.toJSON()) @@ -279,7 +411,7 @@ def on_event(self, event, payload): if event is Events.PRINT_STARTED: self.stop_connection_test() self.print_started = True - if(self.detection_method == 1): + if(self.detection_method == 1 or self.detection_method == 2): self.init_distance_detection() elif event is Events.PRINT_RESUMED: @@ -322,7 +454,8 @@ def on_event(self, event, payload): def get_api_commands(self): return dict( startConnectionTest=[], - stopConnectionTest=[] + stopConnectionTest=[], + detectPhysicalDistance=[] ) def on_api_command(self, command, data): @@ -333,6 +466,13 @@ def on_api_command(self, command, data): elif(command == "stopConnectionTest"): self.stop_connection_test() return flask.make_response("Stopped connection test", 204) + elif(command == "detectPhysicalDistance"): + self.detect_physical_distance() + return jsonify( + physicalDistance=self.motion_sensor_physical_distance, + physicalDistanceLow=self.motion_sensor_physical_distance_low, + physicalDistanceHigh=self.motion_sensor_physical_distance_high, + ) else: return flask.make_response("Not found", 404) @@ -375,7 +515,7 @@ def update_hook(self): # G0 or G1: Caluclate the remaining distance def distance_detection(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): # Only performed if distance detection is used - if(self.detection_method == 1 and self.motion_sensor_enabled): + if((self.detection_method == 1 or self.detection_method == 2) and self.motion_sensor_enabled): # G0 and G1 for linear moves and G2 and G3 for circle movements if(gcode == "G0" or gcode == "G1" or gcode == "G2" or gcode == "G3"): commands = cmd.split(" ") @@ -388,7 +528,7 @@ def distance_detection(self, comm_instance, phase, cmd, cmd_type, gcode, *args, # G92 reset extruder elif(gcode == "G92"): - if(self.detection_method == 1): + if(self.detection_method == 1 or self.detection_method == 2): self.init_distance_detection() self._logger.debug("G92: Reset Extruders") diff --git a/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js b/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js index e5df87c..b91ac31 100644 --- a/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js +++ b/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js @@ -1,9 +1,13 @@ +// Modifications +// 2021-08-18 add detection of "sensor physical distance" + $(function(){ function SmartFilamentSensorSettingsViewModel(parameters){ var self = this; self.settingsViewModel = parameters[0]; self.printerStateViewModel = parameters[1]; + self.loginStateViewModel = parameters[2]; self.connectionTestDialog = undefined; self.remainingDistance = ko.observable(undefined); @@ -11,6 +15,16 @@ $(function(){ self.isFilamentMoving = ko.observable(undefined); self.isConnectionTestRunning = ko.observable(false); + // https://github.com/jneilliii/OctoPrint-GoogleDriveBackup/blob/master/octoprint_googledrivebackup/static/js/googledrivebackup.js + self.physicalDistance = ko.observable('') + self.physicalDistanceLow = ko.observable('') + self.physicalDistanceHigh = ko.observable('') + self.onBeforeBinding = function() { + self.physicalDistance(self.settingsViewModel.settings.plugins.smartfilamentsensor.motion_sensor_physical_distance()); + self.physicalDistanceLow(self.settingsViewModel.settings.plugins.smartfilamentsensor.motion_sensor_physical_distance_low()); + self.physicalDistanceHigh(self.settingsViewModel.settings.plugins.smartfilamentsensor.motion_sensor_physical_distance_high()); + }; + self.onStartup = function() { self.connectionTestDialog = $("#settings_plugin_smartfilamentsensor_connectiontest"); }; @@ -68,6 +82,28 @@ $(function(){ self.RestSuccess = function(response){ return; } + + self.enableDetectionPhysicalDistance = ko.pureComputed(function() { + return !self.printerStateViewModel.isBusy(); + }); + + self.detectPhysicalDistance = function(){ + $.ajax({ + url: API_BASEURL + "plugin/smartfilamentsensor", + type: "POST", + dataType: "json", + data: JSON.stringify({ "command": "detectPhysicalDistance" }), + contentType: "application/json", + success: self.detectPhysicalDistanceSuccess + }); + }; + + self.detectPhysicalDistanceSuccess = function(response){ + self.physicalDistance(response.physicalDistance) + self.physicalDistanceLow(response.physicalDistanceLow) + self.physicalDistanceHigh(response.physicalDistanceHigh) + return; + } } OCTOPRINT_VIEWMODELS.push({ diff --git a/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 b/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 index e391a34..a359c4f 100644 --- a/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 +++ b/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 @@ -1,3 +1,7 @@ + + + +

{{ _('Smart Filament Sensor') }}

@@ -21,6 +25,7 @@
@@ -84,6 +89,30 @@
+ +
+
{{_('Detect physical distance') }}
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+
+ + mm +
+ +
+
From 7eea9ad656fcf19c256819056643e299ee5b5aab Mon Sep 17 00:00:00 2001 From: pkasperczyk Date: Sat, 18 Sep 2021 09:55:07 +0200 Subject: [PATCH 4/7] improve detection and description, clean up code --- octoprint_smart_filament_sensor/__init__.py | 69 +++++++++---------- .../smartfilamentsensor_settings.jinja2 | 46 ++++++++++--- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/octoprint_smart_filament_sensor/__init__.py b/octoprint_smart_filament_sensor/__init__.py index 734c222..447babd 100644 --- a/octoprint_smart_filament_sensor/__init__.py +++ b/octoprint_smart_filament_sensor/__init__.py @@ -1,5 +1,6 @@ #Modifications #2021-08-18 add detection of "sensor physical distance" +#2021-09-18 improve detection of print problem, clean up code # coding=utf-8 from __future__ import absolute_import @@ -27,12 +28,13 @@ def initialize(self): GPIO.setwarnings(False) # Disable GPIO warnings self.print_started = False + self.preLastE = -1 self.lastE = -1 self.currentE = -1 self.START_DISTANCE_OFFSET = 7 self.send_code = False self._data = SmartFilamentSensorDetectionData(self.motion_sensor_detection_distance, True, self.updateToUi) - self.lastEHigh = -1 #not set + self.lastEStateChange = -1 #not set self.previousState = -1 #not set #Properties @@ -93,6 +95,14 @@ def motion_sensor_physical_distance_high(self): def motion_sensor_physical_distance_tolerance(self): return float(self._settings.get(["motion_sensor_physical_distance_tolerance"])) + @property + def motion_sensor_retraction_distance(self): + return float(self._settings.get(["motion_sensor_retraction_distance"])) + + @property + def motion_sensor_total_distance_detection(self): + return float(self._settings.get(["motion_sensor_total_distance_detection"])) + # Initialization methods def _setup_sensor(self): @@ -140,7 +150,7 @@ def get_settings_defaults(self): mode=1, # Board Mode. Changed to BCM (1) motion_sensor_enabled = True, #Sensor detection is enabled by default motion_sensor_pin=17, # Default is no pin(-1). Changed to 17 - detection_method = 2, # 0 = timeout detection, 1 = distance detection, 2 = new detection + detection_method = 2, # 0 = timeout detection, 1 = distance detection, 2 = distance detection 2 # Distance detection motion_sensor_detection_distance = 15, # Recommended detection distance from Marlin would be 7 @@ -150,11 +160,13 @@ def get_settings_defaults(self): pause_command="M600", #send_gcode_only_once=False, # Default set to False for backward compatibility - # Physical distance (for sensor) + # For distance detection 2 motion_sensor_physical_distance = -1, motion_sensor_physical_distance_low = -1, motion_sensor_physical_distance_high = -1, - motion_sensor_physical_distance_tolerance = 0.6 + motion_sensor_physical_distance_tolerance = 10.0, + motion_sensor_retraction_distance = 6.0, + motion_sensor_total_distance_detection = False ) def on_settings_save(self, data): @@ -199,7 +211,6 @@ def detect_physical_distance(self): distance = 0 distanceLow = 0 distanceHigh = 0 - self._printer.commands("M92 E101.0") while True: extruderValue -= 0.1 self._printer.extrude(-0.1, 200) #relative @@ -228,10 +239,9 @@ def detect_physical_distance(self): if (extruderValue < -20.00): self._logger.info("Step 4, state = "+str(state)+", eV = "+str(extruderValue)) break - self._settings.set(["motion_sensor_physical_distance"], distance) - self._settings.set(["motion_sensor_physical_distance_low"], distanceLow) - self._settings.set(["motion_sensor_physical_distance_high"], distanceHigh) - #self._settings.save(True, True) + self._settings.set(["motion_sensor_physical_distance"], round(distance,1)) + self._settings.set(["motion_sensor_physical_distance_low"], round(distanceLow,1)) + self._settings.set(["motion_sensor_physical_distance_high"], round(distanceHigh,1)) self._settings.save(True) self._logger.info("Physical distance detection ended. Distance is "+str(distance)+", distance low is "+str(distanceLow)+", distance high is "+str(distanceHigh)) @@ -291,14 +301,6 @@ def printer_change_filament (self): self.send_code = True self._data.filament_moving = False - def handleNewDetection (self): - # Check if stop signal was already sent - if(not self.send_code): - self._logger.debug("Motion sensor detected no movement - New detection") - self._printer.pause_print() - self.send_code = True - self._data.filament_moving = False - # Reset the distance, if the remaining distance is smaller than the new value def reset_distance (self, pPin): self._logger.debug("Motion sensor detected movement") @@ -309,10 +311,11 @@ def reset_distance (self, pPin): # Initialize the distance detection values def init_distance_detection(self): + self.preLastE = float(-1) self.lastE = float(-1) self.currentE = float(0) self.reset_remainin_distance() - self.lastEHigh = -1 #not set + self.lastEStateChange = -1 #not set self.previousState = GPIO.input(self.motion_sensor_pin) # Reset the remaining distance on start or resume @@ -359,6 +362,7 @@ def calc_distance(self, pE): # Only with absolute extrusion the delta distance must be calculated if (self._data.absolut_extrusion): # LastE is not used and set to the same value as currentE + self.preLastE = self.lastE if (self.lastE == -1): self.lastE = pE else: @@ -370,27 +374,22 @@ def calc_distance(self, pE): # Calculate the remaining distance from detection distance # currentE - lastE is the delta distance if(self._data.absolut_extrusion): - deltaDistance = self.currentE - self.lastE + deltaDistance = self.lastE - self.preLastE # With relative extrusion the current extrusion value is the delta distance else: - deltaDistance = float(pE) + deltaDistance = float(self.preLastE) - if (deltaDistance > 0 and deltaDistance < 5.9) : - #0.012 - 1 - #0.5 - 5 - # y = - #delta - x - toleranceMultiplier = 1+deltaDistance*8 - tolerance = toleranceMultiplier*self.motion_sensor_physical_distance_tolerance - rDist = self.motion_sensor_physical_distance+tolerance+self.lastEHigh-self.currentE - if (self.lastEHigh != -1 and rDist < 0): - self._logger.info("Detection: CurrentE: "+str(self.currentE)+", EHigh: "+str(self.lastEHigh)+",deltaE: "+str(deltaDistance)+", tolerance: "+str(tolerance)+", rDist: "+str(rDist)) - self.handleNewDetection() - + if (self.preLastE != -1 and deltaDistance > 0 and deltaDistance < self.motion_sensor_retraction_distance): state = GPIO.input(self.motion_sensor_pin) - if (self.previousState != state and state): - self.lastEHigh = self.currentE - self._logger.info("Change: CurrentE: "+str(self.currentE)+", EHigh: "+str(self.lastEHigh)+",deltaE: "+str(deltaDistance)+", tolerance: "+str(tolerance)+", rDist: "+str(rDist)) + rDist = self.motion_sensor_physical_distance_tolerance - (self.lastE-self.lastEStateChange) + if (self.lastEStateChange != -1 and rDist < 0): + self._logger.info("Detection: LastE: "+str(self.lastE)+",deltaE: "+str(deltaDistance)+", state: "+str(state)+", rDist: "+str(rDist)) + self.printer_change_filament() + + + if (self.previousState != state and ((self.motion_sensor_total_distance_detection and state == 1) or not self.motion_sensor_total_distance_detection)): + self.lastEStateChange = self.lastE #lastE is more accurate then currentE + self._logger.info("Change: LastE: "+str(self.lastE)+",deltaE: "+str(deltaDistance)+", state: "+str(state)+", rDist: "+str(rDist)) self.previousState = state def updateToUi(self): diff --git a/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 b/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 index a359c4f..cf4104a 100644 --- a/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 +++ b/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 @@ -1,5 +1,6 @@ +
@@ -25,7 +26,7 @@
@@ -95,22 +96,45 @@
-
- -
-
- -
-
- + E Steps should be calibrated before detection. You can run detection method many times and detected distances may be different. Low state [mm] is distance the filament has moved when the sensor reported Low state. High state [mm] is distance the filament has moved when the sensor reported High state. Total is the sum of Low and High state. Detected values could be helpful to set proper tolerance value, which should be higher than them. +
+ + + + + + + + + + + +
Total [mm]Low state [mm]High state [mm]
+
+ +
+
+ + If this option is set, reference point will be set to these extruder values, when sensor reports High state. If this option is unset, reference point will be set, when sensor changes state. +
- +
mm
- + If "current" extruder value (based on GCode) minus last "reference point" extruder value is higher than tolerance, pause command will be executed. +
+ +
+
+ + mm +
+ Value should be equal to retraction distance in slider, for example Cura. It seems, it should be less than tolerance value.
From 5ea152122ecb07a16cba1c2cca06a8b7976c9333 Mon Sep 17 00:00:00 2001 From: pkasperczyk Date: Thu, 30 Sep 2021 08:20:21 +0200 Subject: [PATCH 5/7] 2021-09-30 remove modification descriptions as these should be stored on github --- octoprint_smart_filament_sensor/__init__.py | 4 ---- .../static/js/smartfilamentsensor_settings.js | 3 --- .../templates/smartfilamentsensor_settings.jinja2 | 5 ----- 3 files changed, 12 deletions(-) diff --git a/octoprint_smart_filament_sensor/__init__.py b/octoprint_smart_filament_sensor/__init__.py index 447babd..7ee8188 100644 --- a/octoprint_smart_filament_sensor/__init__.py +++ b/octoprint_smart_filament_sensor/__init__.py @@ -1,7 +1,3 @@ -#Modifications -#2021-08-18 add detection of "sensor physical distance" -#2021-09-18 improve detection of print problem, clean up code - # coding=utf-8 from __future__ import absolute_import import octoprint.plugin diff --git a/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js b/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js index b91ac31..ac2e1ae 100644 --- a/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js +++ b/octoprint_smart_filament_sensor/static/js/smartfilamentsensor_settings.js @@ -1,6 +1,3 @@ -// Modifications -// 2021-08-18 add detection of "sensor physical distance" - $(function(){ function SmartFilamentSensorSettingsViewModel(parameters){ var self = this; diff --git a/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 b/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 index 616cc9d..e76c052 100644 --- a/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 +++ b/octoprint_smart_filament_sensor/templates/smartfilamentsensor_settings.jinja2 @@ -1,8 +1,3 @@ - - - - -

{{ _('Smart Filament Sensor') }}

From 6b7fada2ba6d765d808c01a208e41d34956e1848 Mon Sep 17 00:00:00 2001 From: pkasperczyk Date: Thu, 30 Sep 2021 08:35:52 +0200 Subject: [PATCH 6/7] 2021-09-30 revert changes in default values --- octoprint_smart_filament_sensor/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/octoprint_smart_filament_sensor/__init__.py b/octoprint_smart_filament_sensor/__init__.py index 7ee8188..3d81473 100644 --- a/octoprint_smart_filament_sensor/__init__.py +++ b/octoprint_smart_filament_sensor/__init__.py @@ -143,9 +143,9 @@ def on_after_startup(self): def get_settings_defaults(self): return dict( #Motion sensor - mode=1, # Board Mode. Changed to BCM (1) + mode=0, # Board Mode motion_sensor_enabled = True, #Sensor detection is enabled by default - motion_sensor_pin=17, # Default is no pin(-1). Changed to 17 + motion_sensor_pin=-1, # Default is no pin detection_method = 2, # 0 = timeout detection, 1 = distance detection, 2 = distance detection 2 # Distance detection @@ -319,7 +319,7 @@ def init_distance_detection(self): def reset_remainin_distance(self): self._data.remaining_distance = (float(self.motion_sensor_detection_distance) + self.START_DISTANCE_OFFSET) - # Calculate the remaining distance or calculation for EHigh + # Calculate the remaining distance or calculation for detection method 2 def calc_distance(self, pE): if (self.detection_method == 1): # Only with absolute extrusion the delta distance must be calculated From fd352cad316e6df26587ba30c51145e23f1ebb19 Mon Sep 17 00:00:00 2001 From: pkasperczyk Date: Thu, 30 Sep 2021 08:37:25 +0200 Subject: [PATCH 7/7] 2021-09-30 revert change in default values --- octoprint_smart_filament_sensor/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_smart_filament_sensor/__init__.py b/octoprint_smart_filament_sensor/__init__.py index 3d81473..5800ab3 100644 --- a/octoprint_smart_filament_sensor/__init__.py +++ b/octoprint_smart_filament_sensor/__init__.py @@ -146,7 +146,7 @@ def get_settings_defaults(self): mode=0, # Board Mode motion_sensor_enabled = True, #Sensor detection is enabled by default motion_sensor_pin=-1, # Default is no pin - detection_method = 2, # 0 = timeout detection, 1 = distance detection, 2 = distance detection 2 + detection_method = 0, # 0 = timeout detection, 1 = distance detection, 2 = distance detection 2 # Distance detection motion_sensor_detection_distance = 15, # Recommended detection distance from Marlin would be 7