Skip to content

Commit

Permalink
danger_options: adc ignore minmax values (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed Jan 16, 2024
1 parent c774626 commit d8faa86
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ If I want my printer to light itself on fire, I should be able to make my printe

- [danger_options: option to configure the homing elapsed distance tolerance](https://github.com/DangerKlippers/danger-klipper/pull/110)

- [danger_options: option to ignore ADC out of range](https://github.com/DangerKlippers/danger-klipper/pull/129)

- [temperature_mcu: add reference_voltage](https://github.com/DangerKlippers/danger-klipper/pull/99) ([klipper#5713](https://github.com/Klipper3d/klipper/pull/5713))

- [stepper: current_change_dwell_time](https://github.com/DangerKlippers/danger-klipper/pull/90)

- [homing: min_home_dist](https://github.com/DangerKlippers/danger-klipper/pull/90)

- [adxl345: improve ACCELEROMETER_QUERY command](https://github.com/DangerKlippers/danger-klipper/pull/124)

If you're feeling adventurous, take a peek at the extra features in the bleeding-edge branch:

- [dmbutyugin's advanced-features branch](https://github.com/DangerKlippers/danger-klipper/pull/69) [dmbutyugin/advanced-features](https://github.com/dmbutyugin/klipper/commits/advanced-features)
Expand All @@ -74,8 +78,6 @@ If you're feeling adventurous, take a peek at the extra features in the bleeding

- [input_shaper: new print_ringing_tower utility](https://github.com/DangerKlippers/danger-klipper/pull/69)

- [adxl345: improve ACCELEROMETER_QUERY command](https://github.com/DangerKlippers/danger-klipper/pull/124)

## Switch to Danger Klipper

> [!NOTE]
Expand Down
5 changes: 5 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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
# 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.
```

## Common kinematic settings
Expand Down
15 changes: 14 additions & 1 deletion klippy/extras/adc_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
REPORT_TIME = 0.300
RANGE_CHECK_COUNT = 4


# Interface between ADC and heater temperature callbacks
class PrinterADCtoTemperature:
def __init__(self, config, adc_convert):
Expand All @@ -24,6 +25,9 @@ def __init__(self, config, adc_convert):
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)
self.danger_options = config.get_printer().lookup_object(
"danger_options"
)

def setup_callback(self, temperature_callback):
self.temperature_callback = temperature_callback
Expand All @@ -36,20 +40,27 @@ 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 self.danger_options.adc_ignore_limits:
danger_check_count = 0
else:
danger_check_count = RANGE_CHECK_COUNT

adc_range = [self.adc_convert.calc_adc(t) for t in [min_temp, max_temp]]

self.mcu_adc.setup_minmax(
SAMPLE_TIME,
SAMPLE_COUNT,
minval=min(adc_range),
maxval=max(adc_range),
range_check_count=RANGE_CHECK_COUNT,
range_check_count=danger_check_count,
)


######################################################################
# Linear interpolation
######################################################################


# Helper code to perform linear interpolation
class LinearInterpolate:
def __init__(self, samples):
Expand Down Expand Up @@ -98,6 +109,7 @@ def reverse_interpolate(self, value):
# Linear voltage to temperature converter
######################################################################


# Linear style conversion chips calibrated from temperature measurements
class LinearVoltage:
def __init__(self, config, params):
Expand Down Expand Up @@ -146,6 +158,7 @@ def create(self, config):
# Linear resistance to temperature converter
######################################################################


# Linear resistance calibrated from temperature measurements
class LinearResistance:
def __init__(self, config, samples):
Expand Down
1 change: 1 addition & 0 deletions klippy/extras/danger_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, config):
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)


def load_config(config):
Expand Down
14 changes: 8 additions & 6 deletions src/adccmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ analog_in_event(struct timer *timer)
a->timer.waketime += a->sample_time;
return SF_RESCHEDULE;
}
if (likely(a->value >= a->min_value && a->value <= a->max_value)) {
a->invalid_count = 0;
} else {
a->invalid_count++;
if (a->invalid_count >= a->range_check_count) {
try_shutdown("ADC out of range");
if (a->range_check_count > 0) {
if (likely(a->value >= a->min_value && a->value <= a->max_value)) {
a->invalid_count = 0;
} else {
a->invalid_count++;
if (a->invalid_count >= a->range_check_count) {
try_shutdown("ADC out of range");
a->invalid_count = 0;
}
}
}
sched_wake_task(&analog_wake);
Expand Down
1 change: 1 addition & 0 deletions test/klippy/danger_options.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ log_bed_mesh_at_startup: False
log_shutdown_info: False
allow_plugin_override: True
multi_mcu_trsync_timeout: 0.05
adc_ignore_limits: True

[stepper_x]
step_pin: PF0
Expand Down

0 comments on commit d8faa86

Please sign in to comment.