hall_filament_width_sensor: Added virtual runout sensor (#2535)

Signed-off-by: Denis Ignatenko deniss979@gmail.com
This commit is contained in:
Denis Ignatenko 2020-03-02 05:05:12 +02:00 committed by GitHub
parent 26523d77ba
commit f84542cd20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 6 deletions

View File

@ -1891,7 +1891,35 @@
#measurement_interval: 10
# The approximate distance (in mm) between sensor readings. The
# default is 10mm.
#Virtual filament_switch_sensor support. Create sensor named hall_filament_width_sensor.
#min_diameter:1.0
#Minimal diameter for trigger virtual filament_switch_sensor.
#Values from filament_switch_sensor.
#See [filament_switch_sensor] for a description of these parameters.
#pause_on_runout: True
# When set to True, a PAUSE will execute immediately after a runout
# is detected. Note that if pause_on_runout is False and the
# runout_gcode is omitted then runout detection is disabled. Default
# is True.
#runout_gcode:
# A list of G-Code commands to execute after a filament runout is
# detected. See docs/Command_Templates.md for G-Code format. If
# pause_on_runout is set to True this G-Code will run after the
# PAUSE is complete. The default is not to run any G-Code commands.
#insert_gcode:
# A list of G-Code commands to execute after a filament insert is
# detected. See docs/Command_Templates.md for G-Code format. The
# default is not to run any G-Code commands, which disables insert
# detection.
#event_delay: 3.0
# The minimum amount of time in seconds to delay between events.
# Events triggered during this time period will be silently
# ignored. The default is 3 seconds.
#pause_delay: 0.5
# The amount of time to delay, in seconds, between the pause command
# dispatch and execution of the runout_gcode. It may be useful to
# increase this delay if Octoprint exhibits strange pause behavior.
# Default is 0.5 seconds.
######################################################################
# Board specific hardware support

View File

@ -48,6 +48,19 @@ Sensor generates two analog output based on calculated filament width. Sum of ou
# measurement_interval:10
# Sensor readings done with 10 mm intervals by default. If necessary you are free to change this setting
#Virtual filament_switch_sensor suppurt. Create sensor named hall_filament_width_sensor.
#
#min_diameter:1.0
#Minimal diameter for trigger virtual filament_switch_sensor.
#
#Values from filament_switch_sensor. See the "filament_switch_sensor" section for information on these parameters.
#
#pause_on_runout: True
#runout_gcode:
#insert_gcode:
#event_delay: 3.0
#pause_delay: 0.5
## Commands
**QUERY_FILAMENT_WIDTH** - Return the current measured filament width as result

View File

@ -3,6 +3,7 @@
# Copyright (C) 2019 Mustafa YILDIZ <mydiz@hotmail.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import filament_switch_sensor
ADC_REPORT_TIME = 0.500
ADC_SAMPLE_TIME = 0.001
@ -29,6 +30,7 @@ class HallFilamentWidthSensor:
- self.measurement_max_difference)
self.diameter =self.nominal_filament_dia
self.is_active =config.getboolean('enable', False)
self.runout_dia=config.getfloat('min_diameter', 1.0)
# filament array [position, filamentWidth]
self.filament_array = []
self.lastFilamentWidthReading = 0
@ -57,6 +59,7 @@ class HallFilamentWidthSensor:
self.cmd_M405)
self.gcode.register_command('QUERY_RAW_FILAMENT_WIDTH',
self.cmd_Get_Raw_Values)
self.runout_helper = filament_switch_sensor.RunoutHelper(config)
# Initialization
def handle_ready(self):
# Load printer objects
@ -73,17 +76,17 @@ class HallFilamentWidthSensor:
def adc2_callback(self, read_time, read_value):
# read sensor value
self.lastFilamentWidthReading2 = round(read_value * 10000)
# calculate diameter
self.diameter = round((self.dia2 - self.dia1)/
(self.rawdia2-self.rawdia1)*
((self.lastFilamentWidthReading+self.lastFilamentWidthReading2)
-self.rawdia1)+self.dia1,2)
def update_filament_array(self, last_epos):
# Fill array
if len(self.filament_array) > 0:
# Get last reading position in array & calculate next
# reading position
self.diameter = round((self.dia2 - self.dia1)/
(self.rawdia2-self.rawdia1)*
((self.lastFilamentWidthReading+self.lastFilamentWidthReading2)
-self.rawdia1)+self.dia1,2)
next_reading_position = (self.filament_array[-1][0] +
self.MEASUREMENT_INTERVAL_MM)
if next_reading_position <= (last_epos + self.measurement_delay):
@ -100,6 +103,9 @@ class HallFilamentWidthSensor:
last_epos = pos[3]
# Update filament array for lastFilamentWidthReading
self.update_filament_array(last_epos)
# Check runout
self.runout_helper.note_filament_present(
self.diameter > self.runout_dia)
# Does filament exists
if self.lastFilamentWidthReading > 0.5:
if len(self.filament_array) > 0: