Skip to content

Commit

Permalink
sensors: rework temp_ignore_limits (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed May 15, 2024
1 parent b6c3f05 commit eff2f5f
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 67 deletions.
4 changes: 4 additions & 0 deletions docs/Config_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All dates in this document are approximate.

## Changes

20240430: The `adc_ignore_limits` parameter in the `[danger_options]`
config section has been renamed to `temp_ignore_limits` and it now
covers all possible temperature sensors.

20240415: The `on_error_gcode` parameter in the `[virtual_sdcard]`
config section now has a default. If this parameter is not specified
it now defaults to `TURN_OFF_HEATERS`. If the previous behavior is
Expand Down
50 changes: 29 additions & 21 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,6 @@ A collection of DangerKlipper-specific system options
# If an unused config option or section should cause an error
# if False, will warn but allow klipper to still run.
# The default is True.
#log_statistics: True
# If statistics should be logged
# (helpful for keeping the log clean during development)
# The default is True.
#log_config_file_at_startup: True
# If the config file should be logged at startup
# The default is True.
#log_bed_mesh_at_startup: True
# If the bed mesh should be logged on startup
# (helpful for keeping the log clean during development)
# The default is True.
#log_shutdown_info: True
# If we should log detailed crash info when an exception occurs
# Most of it is overly-verbose and fluff and we still get a stack trace
# for normal exceptions, so setting to False can help save time while developing
# The default is True.
#allow_plugin_override: False
# Allows modules in `plugins` to override modules of the same name in `extras`
# The default is False.
Expand All @@ -110,11 +94,11 @@ A collection of DangerKlipper-specific system options
# Tolerance (in mm) for distance moved in the second homing. Ensures the
# second homing distance closely matches the `min_home_dist` when using
# sensorless homing. The default is 0.5mm.
#adc_ignore_limits: False
#temp_ignore_limits: False
# When set to true, this parameter ignores the min_value and max_value
# limits for ADC temperature sensors. It prevents shutdowns due to
# 'ADC out of range' errors by allowing readings outside the specified
# range without triggering a shutdown. Default is False.
# limits for temperature sensors. It prevents shutdowns due to
# 'ADC out of range' and similar errors by allowing readings outside the
# specified range without triggering a shutdown. The default is False.
#autosave_includes: False
# When set to true, SAVE_CONFIG will recursively read [include ...] blocks
# for conflicts to autosave data. Any configurations updated will be backed
Expand All @@ -123,6 +107,30 @@ A collection of DangerKlipper-specific system options
# This allows to set extra flush time (in seconds). Under certain conditions,
# a low value will result in an error if message is not get flushed, a high value
# (0.250) will result in homing/probing latency. The default is 0.250
# Logging options
#minimal_logging: False
# Set all log parameters log options to False. The default is False.
#log_statistics: True
# If statistics should be logged
# (helpful for keeping the log clean during development)
# The default is True.
#log_config_file_at_startup: True
# If the config file should be logged at startup
# The default is True.
#log_bed_mesh_at_startup: True
# If the bed mesh should be logged at startup
# (helpful for keeping the log clean during development)
# The default is True.
#log_shutdown_info: True
# If we should log detailed crash info when an exception occurs
# Most of it is overly-verbose and fluff and we still get a stack trace
# for normal exceptions, so setting to False can help save time while developing
# The default is True.
#log_serial_reader_warnings: True
#log_startup_info: True
#log_webhook_method_register_messages: False
```

## Common kinematic settings
Expand Down Expand Up @@ -2237,7 +2245,7 @@ detach_position: 0,0,0
# the Z axis is not already homed the head is lifted by `z_hop`.
# The default is to not implement Z hop.
#restore_toolhead: True
# While True, the position of the toolhead is restored to the position prior
# While True, the position of the toolhead is restored to the position prior
# to the attach/detach movements.
# The default value is True.
#dock_retries:
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/adc_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def adc_callback(self, read_time, read_value):
self.temperature_callback(read_time + SAMPLE_COUNT * SAMPLE_TIME, temp)

def setup_minmax(self, min_temp, max_temp):
if get_danger_options().adc_ignore_limits:
if get_danger_options().temp_ignore_limits:
danger_check_count = 0
else:
danger_check_count = RANGE_CHECK_COUNT
Expand Down
8 changes: 7 additions & 1 deletion klippy/extras/aht10.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import logging
from . import bus

from extras.danger_options import get_danger_options

######################################################################
# Compatible Sensors:
# AHT10 - Tested w/ BTT GTR 1.0 MCU on i2c3
Expand Down Expand Up @@ -150,7 +152,11 @@ def _sample_aht10(self, eventtime):
self.temp = self.humidity = 0.0
return self.reactor.NEVER

if self.temp < self.min_temp or self.temp > self.max_temp:
if (
self.temp < self.min_temp
or self.temp > self.max_temp
and not get_danger_options().temp_ignore_limits
):
self.printer.invoke_shutdown(
"AHT10 temperature %0.1f outside range of %0.1f:%.01f"
% (self.temp, self.min_temp, self.max_temp)
Expand Down
6 changes: 5 additions & 1 deletion klippy/extras/bme280.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import logging
from . import bus

from extras.danger_options import get_danger_options

REPORT_TIME = 0.8
BME280_CHIP_ADDR = 0x76

Expand Down Expand Up @@ -431,7 +433,9 @@ def _sample_bme280(self, eventtime):
if self.chip_type == "BME280":
humid_raw = (data[6] << 8) | data[7]
self.humidity = self._compensate_humidity_bme280(humid_raw)
if self.temp < self.min_temp or self.temp > self.max_temp:
if (
self.temp < self.min_temp or self.temp > self.max_temp
) and not get_danger_options().temp_ignore_limits:
self.printer.invoke_shutdown(
"BME280 temperature %0.1f outside range of %0.1f:%.01f"
% (self.temp, self.min_temp, self.max_temp)
Expand Down
16 changes: 12 additions & 4 deletions klippy/extras/danger_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,28 @@ def __init__(self, config):
self.error_on_unused_config_options = config.getboolean(
"error_on_unused_config_options", True
)

self.allow_plugin_override = config.getboolean(
"allow_plugin_override", False
)

self.multi_mcu_trsync_timeout = config.getfloat(
"multi_mcu_trsync_timeout", 0.025, minval=0.0
)
self.homing_elapsed_distance_tolerance = config.getfloat(
"homing_elapsed_distance_tolerance", 0.5, minval=0.0
)
self.adc_ignore_limits = config.getboolean("adc_ignore_limits", False)
self.autosave_includes = config.getboolean("autosave_includes", False)

temp_ignore_limits = False
if config.getboolean("temp_ignore_limits", None) is None:
adc_ignore_limits = config.getboolean("adc_ignore_limits", None)
if adc_ignore_limits is not None:
config.deprecate("adc_ignore_limits")
temp_ignore_limits = adc_ignore_limits

self.temp_ignore_limits = config.getboolean(
"temp_ignore_limits", temp_ignore_limits
)

self.autosave_includes = config.getboolean("autosave_includes", False)
self.bgflush_extra_time = config.getfloat(
"bgflush_extra_time", 0.250, minval=0.0
)
Expand Down
14 changes: 10 additions & 4 deletions klippy/extras/ds18b20.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
# Copyright (C) 2020 Alan Lord <alanslists@gmail.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import mcu
import logging, mcu

from extras.danger_options import get_danger_options

DS18_REPORT_TIME = 3.0
# Temperature can be sampled at any time but conversion time is ~750ms, so
Expand Down Expand Up @@ -33,8 +34,13 @@ def __init__(self, config):
def _build_config(self):
sid = "".join(["%02x" % (x,) for x in self.sensor_id])
self._mcu.add_config_cmd(
"config_ds18b20 oid=%d serial=%s max_error_count=%d"
% (self.oid, sid, DS18_MAX_CONSECUTIVE_ERRORS)
"config_ds18b20 oid=%d serial=%s max_error_count=%d ignore_limits=%d"
% (
self.oid,
sid,
DS18_MAX_CONSECUTIVE_ERRORS,
int(get_danger_options().temp_ignore_limits),
)
)

clock = self._mcu.get_query_slot(self.oid)
Expand Down
6 changes: 5 additions & 1 deletion klippy/extras/htu21d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import logging
from . import bus

from extras.danger_options import get_danger_options

######################################################################
# NOTE: The implementation requires write support of length 0
# before reading on the i2c bus of the mcu.
Expand Down Expand Up @@ -242,7 +244,9 @@ def _sample_htu21d(self, eventtime):
self.temp = self.humidity = 0.0
return self.reactor.NEVER

if self.temp < self.min_temp or self.temp > self.max_temp:
if (
self.temp < self.min_temp or self.temp > self.max_temp
) and not get_danger_options().temp_ignore_limits:
self.printer.invoke_shutdown(
"HTU21D temperature %0.1f outside range of %0.1f:%.01f"
% (self.temp, self.min_temp, self.max_temp)
Expand Down
6 changes: 5 additions & 1 deletion klippy/extras/lm75.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import logging
from . import bus

from extras.danger_options import get_danger_options

LM75_CHIP_ADDR = 0x48
LM75_I2C_SPEED = 100000
LM75_REGS = {
Expand Down Expand Up @@ -78,7 +80,9 @@ def _sample_lm75(self, eventtime):
self.temp = 0.0
return self.reactor.NEVER

if self.temp < self.min_temp or self.temp > self.max_temp:
if (
self.temp < self.min_temp or self.temp > self.max_temp
) and not get_danger_options().temp_ignore_limits:
self.printer.invoke_shutdown(
"LM75 temperature %0.1f outside range of %0.1f:%.01f"
% (self.temp, self.min_temp, self.max_temp)
Expand Down
6 changes: 5 additions & 1 deletion klippy/extras/sht3x.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import logging
from . import bus

from extras.danger_options import get_danger_options

######################################################################
# Compatible Sensors:
# SHT31 - Tested on octopus pro and Linux MCU
Expand Down Expand Up @@ -123,7 +125,9 @@ def _sample_sht3x(self, eventtime):
self.temp = self.humidity = 0.0
return self.reactor.NEVER

if self.temp < self.min_temp or self.temp > self.max_temp:
if (
self.temp < self.min_temp or self.temp > self.max_temp
) and not get_danger_options().temp_ignore_limits:
self.printer.invoke_shutdown(
"sht3x: temperature %0.1f outside range of %0.1f:%.01f"
% (self.temp, self.min_temp, self.max_temp)
Expand Down
9 changes: 8 additions & 1 deletion klippy/extras/spi_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import math, logging
from . import bus

from extras.danger_options import get_danger_options

######################################################################
# SensorBase
Expand Down Expand Up @@ -54,6 +55,12 @@ def _build_config(self):
)
clock = self.mcu.get_query_slot(self.oid)
self._report_clock = self.mcu.seconds_to_clock(REPORT_TIME)

if get_danger_options().temp_ignore_limits:
danger_check_count = 0
else:
danger_check_count = MAX_INVALID_COUNT

self.mcu.add_config_cmd(
"query_thermocouple oid=%u clock=%u rest_ticks=%u"
" min_value=%u max_value=%u max_invalid_count=%u"
Expand All @@ -63,7 +70,7 @@ def _build_config(self):
self._report_clock,
self.min_sample_value,
self.max_sample_value,
MAX_INVALID_COUNT,
danger_check_count,
),
is_init=True,
)
Expand Down
6 changes: 5 additions & 1 deletion klippy/extras/temperature_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.

from extras.danger_options import get_danger_options

REPORT_TIME = 0.300


Expand Down Expand Up @@ -75,7 +77,9 @@ def update_temp(self, eventtime):
values.append(sensor_temperature)

# check if values are out of max_deviation range
if (max(values) - min(values)) > self.max_deviation:
if (
max(values) - min(values)
) > self.max_deviation and not get_danger_options().temp_ignore_limits:
self.printer.invoke_shutdown(
"COMBINED SENSOR maximum deviation exceeded limit of %0.1f, "
"max sensor value %0.1f, min sensor value %0.1f."
Expand Down
21 changes: 7 additions & 14 deletions klippy/extras/temperature_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import logging

from extras.danger_options import get_danger_options

HOST_REPORT_TIME = 1.0
RPI_PROC_TEMP_FILE = "/sys/class/thermal/thermal_zone0/temp"

Expand Down Expand Up @@ -58,21 +60,12 @@ def _sample_pi_temperature(self, eventtime):
self.temp = 0.0
return self.reactor.NEVER

if self.temp < self.min_temp:
self.printer.invoke_shutdown(
"HOST temperature %0.1f below minimum temperature of %0.1f."
% (
self.temp,
self.min_temp,
)
)
if self.temp > self.max_temp:
if (
self.temp < self.min_temp or self.temp > self.max_temp
) and not get_danger_options().temp_ignore_limits:
self.printer.invoke_shutdown(
"HOST temperature %0.1f above maximum temperature of %0.1f."
% (
self.temp,
self.max_temp,
)
"HOST temperature %0.1f outside range of %0.1f:%.01f"
% (self.temp, self.min_temp, self.max_temp)
)

mcu = self.printer.lookup_object("mcu")
Expand Down
14 changes: 12 additions & 2 deletions klippy/extras/temperature_mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging

from extras.danger_options import get_danger_options

SAMPLE_TIME = 0.001
SAMPLE_COUNT = 8
REPORT_TIME = 0.300
Expand Down Expand Up @@ -39,10 +41,18 @@ def __init__(self, config):
self.mcu_adc.setup_adc_callback(REPORT_TIME, self.adc_callback)
query_adc = config.get_printer().load_object(config, "query_adc")
query_adc.register_adc(config.get_name(), self.mcu_adc)

if get_danger_options().temp_ignore_limits:
self._danger_check_count = 0
else:
self._danger_check_count = RANGE_CHECK_COUNT

# Register callbacks
if self.printer.get_start_args().get("debugoutput") is not None:
self.mcu_adc.setup_minmax(
SAMPLE_TIME, SAMPLE_COUNT, range_check_count=RANGE_CHECK_COUNT
SAMPLE_TIME,
SAMPLE_COUNT,
range_check_count=self._danger_check_count,
)
return
self.printer.register_event_handler(
Expand Down Expand Up @@ -120,7 +130,7 @@ def _mcu_identify(self):
SAMPLE_COUNT,
minval=min(adc_range),
maxval=max(adc_range),
range_check_count=RANGE_CHECK_COUNT,
range_check_count=self._danger_check_count,
)

def config_unknown(self):
Expand Down
2 changes: 1 addition & 1 deletion klippy/serialhdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def handle_output(self, params):

def handle_default(self, params):
if get_danger_options().log_serial_reader_warnings:
logging.warning("%sgot %s", self.warn_prefix, params)
logging.warning("%s got %s", self.warn_prefix, params)


# Class to send a query command and return the received response
Expand Down
Loading

0 comments on commit eff2f5f

Please sign in to comment.