Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove THRESHOLD_TEST #82

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 0 additions & 160 deletions scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
class ThresholdResults:
def __init__(
self,
max_value,

Check warning on line 66 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of parameter "max_value" is unknown (reportUnknownParameterType)

Check warning on line 66 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type annotation is missing for parameter "max_value" (reportMissingParameterType)
min_value,

Check warning on line 67 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of parameter "min_value" is unknown (reportUnknownParameterType)

Check warning on line 67 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type annotation is missing for parameter "min_value" (reportMissingParameterType)
range_value,

Check warning on line 68 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of parameter "range_value" is unknown (reportUnknownParameterType)

Check warning on line 68 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type annotation is missing for parameter "range_value" (reportMissingParameterType)
avg_value,

Check warning on line 69 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of parameter "avg_value" is unknown (reportUnknownParameterType)

Check warning on line 69 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type annotation is missing for parameter "avg_value" (reportMissingParameterType)
median,

Check warning on line 70 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of parameter "median" is unknown (reportUnknownParameterType)

Check warning on line 70 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type annotation is missing for parameter "median" (reportMissingParameterType)
sigma,
in_range,
early,
Expand Down Expand Up @@ -325,11 +325,6 @@
self.cmd_SCANNER_CALIBRATE,
desc=self.cmd_SCANNER_CALIBRATE_help,
)
self.gcode.register_command(
sensor_name + "_THRESHOLD_TEST",
self.cmd_SCANNER_THRESHOLD_TEST,
desc=self.cmd_SCANNER_THRESHOLD_TEST_help,
)
self.gcode.register_command(
sensor_name + "_THRESHOLD_SCAN",
self.cmd_SCANNER_THRESHOLD_SCAN,
Expand Down Expand Up @@ -1772,7 +1767,7 @@
model_name = gcmd.get("MODEL_NAME", "default")

toolhead = self.toolhead
curtime = self.reactor.monotonic()

Check failure on line 1770 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

scanner.py:1770:9: F841 Local variable `curtime` is assigned to but never used
toolhead.wait_moves()

if manual_mode:
Expand Down Expand Up @@ -1804,14 +1799,14 @@
try:
self._start_streaming()
self._sample_printtime_sync(50)
with self.streaming_session(cb) as ss:

Check failure on line 1802 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

scanner.py:1802:48: F841 Local variable `ss` is assigned to but never used
self._sample_printtime_sync(50)
toolhead.dwell(0.250)
curpos[2] = cal_min_z
toolhead.manual_move(curpos, cal_speed)
toolhead.dwell(0.250)
self._sample_printtime_sync(50)
except:

Check failure on line 1809 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E722)

scanner.py:1809:9: E722 Do not use bare `except`
self.trigger_method = 0
self._zhop()
finally:
Expand Down Expand Up @@ -2206,161 +2201,6 @@
configfile.set("scanner", "scanner_touch_threshold", "%d" % int(threshold))
configfile.set("scanner", "scanner_touch_speed", "%d" % int(speed))

cmd_SCANNER_THRESHOLD_TEST_help = (
"Home using touch and check with coil to see how consistent it is"
)

def cmd_SCANNER_THRESHOLD_TEST(self, gcmd):
threshold = gcmd.get_int("THRESHOLD", self.detect_threshold_z)
sample_count = gcmd.get_int("SAMPLES", 5, minval=1)
skip_samples = gcmd.get_int("SKIP", 1)
lift_speed = self.get_lift_speed(gcmd)
touch_location_x = gcmd.get_float(
"TOUCH_LOCATION_X", float(self.touch_location[0])
)
touch_location_y = gcmd.get_float(
"TOUCH_LOCATION_Y", float(self.touch_location[1])
)
accel = gcmd.get_float("ACCEL", self.scanner_touch_config["accel"], minval=1)
curtime = self.printer.get_reactor().monotonic()
max_accel = self.toolhead.get_status(curtime)["max_accel"]
self._move([touch_location_x, touch_location_y, None], 40)
gcmd.respond_info(
"Threshold Testing"
" (samples=%d threshold=%d skip=%d)\n"
% (sample_count, threshold, skip_samples)
)

original_trigger_method = self.trigger_method
original_threshold = self.detect_threshold_z
self.toolhead.wait_moves()
self.check_temp(gcmd)
try:
self.set_accel(accel)
self.trigger_method = 1
self.detect_threshold_z = threshold
result = self._probe_accuracy_check(
self.scanner_touch_config["speed"],
skip_samples,
sample_count,
5,
False,
lift_speed,
)

gcmd.respond_info(
"scanner threshold results: threshold quality: %r, maximum %.6f, minimum %.6f, range %.6f, "
"average %.6f, median %.6f, standard deviation %.6f, %d/%d within 0.1 range, %d early, %d late, %d skipped"
% (
# self._get_threshold_quality(result.range_value),
"Unknown",
result.max_value,
result.min_value,
result.range_value,
result.avg_value,
result.median,
result.sigma,
result.in_range,
sample_count,
result.early,
result.late,
skip_samples,
)
)
finally:
self._zhop()
self.detect_threshold_z = original_threshold
self.trigger_method = original_trigger_method
self.set_accel(max_accel)

def _test_threshold(self, threshold, sample_count):
toolhead = self.printer.lookup_object("toolhead")
curtime = self.printer.get_reactor().monotonic()
if "z" not in toolhead.get_status(curtime)["homed_axes"]:
raise self.printer.command_error("Must home before probe")

original_trigger_method = self.trigger_method
original_threshold = self.detect_threshold_z

try:
self.detect_threshold_z = threshold

positions = []
while len(positions) < sample_count:
# Change method to touch
self.trigger_method = 1
# home
self.gcode.run_script_from_command("G28 Z")
# Change method to scan
# Move to Z = 2 to get some solid data
self.toolhead.manual_move([None, None, 2], 1500)
self.toolhead.wait_moves()
self.trigger_method = 0
# probe to get position
(dist, samples) = self._sample(self.z_settling_time, 10)
# Reset the trigger method
positions.append(dist)
self.toolhead.manual_move([None, None, 10], 1500)
self.toolhead.wait_moves()

zs = positions
max_value = max(zs)
min_value = min(zs)
range_value = max_value - min_value
avg_value = sum(zs) / len(positions)
median_ = median(zs)
in_range = 0
early = 0
late = 0

for sampl in zs:
if abs(median_ - sampl) < 0.05:
in_range += 1
elif sampl > median_:
early += 1
else:
late += 1

deviation_sum = 0
for i in range(len(zs)):
deviation_sum += pow(zs[i] - avg_value, 2.0)
sigma = (deviation_sum / len(zs)) ** 0.5

return ThresholdResults(
max_value,
min_value,
range_value,
avg_value,
median_,
sigma,
in_range,
early,
late,
len(zs),
)
except:
self.trigger_method = 0
self.gcode.run_script_from_command("G28")
return ThresholdResults(
float("inf"),
float("inf"),
float("inf"),
float("inf"),
float("inf"),
float("inf"),
0,
0,
0,
0,
)
finally:
# Change method to scan
self.trigger_method = 0
self.gcode.run_script_from_command("G28 Z")

self.detect_threshold_z = original_threshold
self.trigger_method = original_trigger_method

cmd_SCANNER_ESTIMATE_BACKLASH_help = "Estimate Z axis backlash"

def cmd_SCANNER_ESTIMATE_BACKLASH(self, gcmd):
Expand Down Expand Up @@ -2682,7 +2522,7 @@
"printer config file and restart the printer."
)
else:
old_offset = self.model.offset

Check failure on line 2525 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

scanner.py:2525:13: F841 Local variable `old_offset` is assigned to but never used
self.model.offset += offset
self.model.save(self, False)
gcmd.respond_info(
Expand Down Expand Up @@ -2878,7 +2718,7 @@
return a * x + b

def compensate(self, freq, temp_source, temp_target, tctl=None):
if self.a_a == None or self.a_b == None or self.b_a == None or self.b_b == None:

Check failure on line 2721 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

scanner.py:2721:24: E711 Comparison to `None` should be `cond is None`

Check failure on line 2721 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

scanner.py:2721:44: E711 Comparison to `None` should be `cond is None`

Check failure on line 2721 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

scanner.py:2721:64: E711 Comparison to `None` should be `cond is None`

Check failure on line 2721 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

scanner.py:2721:84: E711 Comparison to `None` should be `cond is None`
return freq
A = (
4 * (temp_source * self.a_a) ** 2
Expand Down Expand Up @@ -3019,7 +2859,7 @@
self.tl = None

def update(self, time, measurement):
if self.xl == None:

Check failure on line 2862 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

scanner.py:2862:23: E711 Comparison to `None` should be `cond is None`
self.xl = measurement
if self.tl is not None:
dt = time - self.tl
Expand Down Expand Up @@ -3416,7 +3256,7 @@
def query_endstop(self, print_time):
if self.scanner.model is None:
return 1
clock = self._mcu.print_time_to_clock(print_time)

Check failure on line 3259 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

scanner.py:3259:9: F841 Local variable `clock` is assigned to but never used
sample = self.scanner._sample_async()
if self.scanner.trigger_freq <= sample["freq"]:
return 1
Expand Down