hall_filament_width_sensor: Add option to enable or disable flow compensation, add command descriptions, and improve query command output#7210
Conversation
|
Let's not limit the scope to said printers: I added a reliable Hall sensor to mine but I don't want it enabled when I use soft filaments, while I still need the runout switch to operate! I totally approve the idea behind this change. |
|
FWIW, I have tested this code on my Qidi Q1 Pro printer and can confirm:
|
|
I am not a coder, but I can understand code to some degree and the topic.
|
I was on the fence with resetting to 100%. I was trying to modify as little as possible but actually I agree with you. I have added
I've added
I believe that this is now consistent as the flow will be reset to 100% if flow compensation is disabled. I have updated the documentation to explicitly state when the flow rate is reset to 100%. While I was doing this I also added some command help for all the commands (not just the ones I added) and improved the formatting the output of the |
|
Also look at CONTRIBUTING.md regarding the formation of commits. |
51fd34f to
4414917
Compare
Thanks for the feedback (and your time). I have reorganized the changes into three distinct commits. Hopefully this is better? I also updated the PR description to better reflect all of the proposed changes. |
|
You have to add "Signed-off-by" to every commit (doc). Otherwise everything is probably fine. |
4414917 to
8a2bfb5
Compare
All done. Thanks again for your feedback. |
|
I can not verify this is working for me on the Plus4 and I didnt found any issues at this hall_filament_width_sensor.py 👍 |
Phil1988
left a comment
There was a problem hiding this comment.
Properly coded and documentation added - looking good to me and could be merged
|
Some remarks Disabling compensation does not clear queued diameter readings cmd_flow_comp_disable() resets M221 S100, but does not clear filament_array. This allows to briefly disable and then re-enable and use already-queued values, but re-enabling later could immediately apply an “old” diameter value. Maybe just clear up the queue and that's it, or let's think to a use case where the user disabled the compensation, and re-enables it without touching the filament in between. I can't find any. Division by zero There’s no guard for calibration division-by-zero: (self.rawdia2 - self.rawdia1) could be zero if misconfigured, leading to a crash in adc2_callback(). It was there also in the original module. Indentation The update_filament_array() block uses inconsistent indentation for several lines—e.g. next_reading_position = ..., the following if, and the append(...) are indented differently than the surrounding code (they don’t line up with the usual 4-spaces-per-level style). |
I don't think this is a problem. We're only disabling compensation - the filament width readings are still being taken while compensation is disabled, so the queue will contain current values to be used if/when compensation is re-enabled. Disabling the sensor does clear the readings.
I've added a new commit to eliminate that and another potential div-by-zero in
There's a few spacing and indentation issues throughout the module. The contributing guidelines say: "Whitespace changes should not be mixed with functional changes. In general, gratuitous whitespace changes are not accepted unless they are from the established "owner" of the code being modified." So I'm going to leave that as-is unless I get direction to clean it up. |
|
Perfect then, no further comments on my side. |
|
Thanks. In general it seems fine to me. I'd ask for a change to the g-code commands though. This module is an "old school" module in that it defines a lot of g-code commands. For the last several years, however, we've been reluctant to add lots of new G-Code commands. The issue is, each time we add a new command it risks conflicting with other modules and user defined macros. This PR adds 3 new commands. Would it be possible to just add new parameters to the existing commands? For example, instead of adding a new QUERY_FILAMENT_WIDTH_COMPENSATION could the info just be displayed in the existing QUERY_FILAMENT_WIDTH command? Instead of addding new ENABLE/DISABLE_FILAMENT_WIDTH_COMPENSATION commands, could a new parameter "FLOW_COMPENSATION=[0|1]" be added to the existing ENABLE_FILAMENT_WIDTH_SENSOR command? Cheers, |
Adds a toggle to enable or disable flow compensation based on the filament width sensor readings without disabling the sensor entirely. Useful on printers where the hall effect sensor is too inaccurate to helpfully adjust the extrusion multiplier, but is good enough to act as a filament runout sensor. The new setting defaults to true to preserve the existing sensor behavior. Existing width sensor G-Code commands are updated to optionally enable and disable flow compensation and to show the state of the sensor and command outputs are normalized. Also includes updates to the relevant doc pages. Signed-off-by: Ben Lye ben@lye.co.nz
Signed-off-by: Ben Lye ben@lye.co.nz
Adds two checks to prevent config settings which could lead to div-by-zero errors in specific circumstances: - `raw_dia1` and `raw_dia2` must be different to prevent a possible exception in `adc2_callback` - `max_difference` must be less than `default_nominal_filament_diameter` to prevent a possible exception in `extrude_factor_update_event` Doc is also updated. Signed-off-by: Ben Lye ben@lye.co.nz
Keeps the width sensor state in sync with the associated runout sensor and normalizes the output when the width sensor is disabled. When the width sensor was disabled the associated filament sensor remained enabled but was no longer updated so would be 'stuck' in the last state it was in before the width sensor was disabled. The toggle switch and readings in the web interface could also be out of sync with the actual sensor and filament states, misleading the user. Now, when the width sensor is disabled: - The filament sensor is disabled - The reported filament state is 'present' - The reported filament diameter is the nominal diameter When the width sensor is enabled: - The filament sensor is enabled - The reported filament state is the derived state - The reported filament diameter is the measured value Finally, `min_diameter` is now used to determine the runout state rather than a fixed value of `0.5`. Signed-off-by: Ben Lye ben@lye.co.nz
Race conditions exist when `M221 S100` commands are sent outside the timer, while the sensor is active. This intermittently prevents the flow multiplier resetting to 100% when either flow compensation or the width sensor are changed to disabled. We can avoid this by moving the diable actions, including the `M221 S100` commands, inside the timer loop and only using `M221` outside the timer while the sensor is disabled. Signed-off-by: Ben Lye ben@lye.co.nz
8c592ee to
ae65444
Compare
Ah, I see. Thanks for the explanation. I have refactored the changes to use the existing commands instead of adding new ones, and made some other improvements:
I've force-pushed to the PR branch. If it's better to close this PR and open a new one for a fresh review, please let me know. |
This PR proposes several changes to the hall_filament_width_sensor.
The primary change is to add a configuration option to enable or disable the flow compensation element of the hall_filament_width_sensor.
Some printers, including several models from Qidi such as the Q1 Pro and Plus4, have a hall effect sensor which is too inaccurate to helpfully adjust the extrusion multiplier, but is good enough to act as a filament runout sensor. By having the option to enable the width sensor but disable flow compensation, the width sensor can still be used as a runout sensor.
The PR adds a new config option
enable_flow_compensationtohall_filament_width_sensorwhich enables this choice. The option defaults toTrue, ensuring that the existing default behavior is not affected.Three new commands are also added, which can be used to enable or disable flow compensation and check the current state:
ENABLE_FILAMENT_WIDTH_COMPENSATION: Turn on flow compensation based on filament width sensor readings.DISABLE_FILAMENT_WIDTH_COMPENSATION: Turn off flow compensation based on filament width sensor readings. Does not disable the sensor itself or the filament runout switch.QUERY_FILAMENT_WIDTH_COMPENSATION: Report the current state of flow compensation.Note that while flow compensation can also be disabled by setting
max_differenceto 0, this forces the extrusion multiplier to 100% and prevents the user from changing it to any other value.Additional changes:
QUERYcommands is improved:QUERY_FILAMENT_WIDTHoutput is limited to four decimal placesQUERY_RAW_FILAMENT_WIDTHCurrent query command outputs:
New query command outputs
The documentation is updated to reflect the changes.
Signed-off-by: Ben Lye ben@lye.co.nz