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

Feature: pass params from calibrate to touch #120

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

temp_sensor_override = config.get("temp_sensor_override", None)
if temp_sensor_override is not None:
self.thermistor_override = config.printer.load_object(

Check warning on line 103 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "thermistor_override" is unknown (reportUnknownMemberType)
config, "temperature_sensor " + temp_sensor_override
)
else:
Expand Down Expand Up @@ -130,7 +130,7 @@
)

atypes = {"median": "median", "average": "average"}
self.samples_config = {

Check warning on line 133 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "samples_config" is partially unknown   Type of "samples_config" is "dict[str, Unknown]" (reportUnknownMemberType)
"samples": config.getfloat("samples", 5, above=0.0),
"retract_dist": config.getfloat("samples_retract_dist", 5, above=0.0),
"tolerance": config.getfloat("samples_tolerance", 0.2, minval=0.0),
Expand Down Expand Up @@ -174,7 +174,7 @@
"scanner_touch_max_speed", 10, above=0, maxval=30
)
## NEW VARIABLES HERE
self.scanner_touch_config = {

Check warning on line 177 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "scanner_touch_config" is partially unknown   Type of "scanner_touch_config" is "dict[str, Unknown]" (reportUnknownMemberType)
"accel": config.getfloat("scanner_touch_accel", 100, above=0, minval=100),
"max_speed": max_speed_value,
"speed": config.getfloat("scanner_touch_speed", 3, maxval=max_speed_value),
Expand All @@ -199,7 +199,7 @@
raise self.printer.command_error(
"Please change detect_threshold_z to scanner_touch_threshold in printer.cfg"
)
self.detect_threshold_z = self.scanner_touch_config["threshold"]

Check warning on line 202 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "detect_threshold_z" is unknown (reportUnknownMemberType)

Check warning on line 202 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "scanner_touch_config" is partially unknown   Type of "scanner_touch_config" is "dict[str, Unknown]" (reportUnknownMemberType)
self.previous_probe_success = None

self.cal_config = {
Expand All @@ -213,7 +213,7 @@
# Load models
self.model = None
self.models: dict[str, ScannerModel] = {}
self.model_temp_builder = ScannerTempModelBuilder.load(config)

Check warning on line 216 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "load" is partially unknown   Type of "load" is "(config: Unknown) -> ScannerTempModelBuilder" (reportUnknownMemberType)
self.model_temp = None
self.fmin = None
self.default_model_name = config.get("default_model_name", "default")
Expand All @@ -228,16 +228,16 @@
self.last_received_sample = None
self.hardware_failure = None

self.mesh_helper = ScannerMeshHelper.create(self, config)

Check warning on line 231 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "create" is partially unknown   Type of "create" is "(scanner: Unknown, config: Unknown) -> (ScannerMeshHelper | None)" (reportUnknownMemberType)

self._stream_en = 0
self._stream_timeout_timer = self.reactor.register_timer(self._stream_timeout)

Check warning on line 234 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "_stream_timeout" is partially unknown   Type of "_stream_timeout" is "(eventtime: Unknown) -> float" (reportUnknownMemberType)

Check warning on line 234 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Argument type is partially unknown   Argument corresponds to parameter "callback" in function "register_timer"   Argument type is "(eventtime: Unknown) -> float" (reportUnknownArgumentType)
self._stream_callbacks = {}
self._stream_latency_requests = {}
self._stream_buffer = []
self._stream_buffer_limit = STREAM_BUFFER_LIMIT_DEFAULT
self._stream_buffer_limit_new = self._stream_buffer_limit
self._stream_samples_queue = queue.Queue()

Check warning on line 240 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Type of "_stream_samples_queue" is partially unknown   Type of "_stream_samples_queue" is "Queue[Unknown]" (reportUnknownMemberType)
self._stream_flush_event = threading.Event()
self._log_stream = None
self._data_filter = AlphaBetaFilter(
Expand Down Expand Up @@ -338,13 +338,17 @@
cmd_SCANNER_CALIBRATE_help = "Calibrate scanner response curve"

def cmd_SCANNER_CALIBRATE(self, gcmd: GCodeCommand):
orig_params = gcmd.get_command_parameters()
if self.calibration_method != "scan":
cmd = self.sensor_name + "_TOUCH"
params = {}
params: dict[str, str] = {}
if gcmd.get("METHOD", "None").lower() == "manual":
params["METHOD"] = "manual"
else:
params["CALIBRATE"] = "1"

params.update(orig_params)

cmd = self.gcode.create_gcode_command(cmd, cmd, params)
self.cmd_SCANNER_TOUCH(cmd)
else:
Expand Down Expand Up @@ -1523,7 +1527,7 @@
model_name = gcmd.get("MODEL_NAME", "default")

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

Check failure on line 1530 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

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

if manual_mode:
Expand Down Expand Up @@ -1555,7 +1559,7 @@
try:
self._start_streaming()
self._sample_printtime_sync(50)
with self.streaming_session(cb) as ss:

Check failure on line 1562 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

scanner.py:1562: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
Expand Down Expand Up @@ -2496,7 +2500,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 2503 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

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

Check failure on line 2503 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

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

Check failure on line 2503 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

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

Check failure on line 2503 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

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

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

Check failure on line 2644 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E711)

scanner.py:2644: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 @@ -2974,7 +2978,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 2981 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

scanner.py:2981: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 Expand Up @@ -3157,7 +3161,7 @@
pa = (begin_a, pos_p) if even else (end_a, pos_p)
pb = (end_a, pos_p) if even else (begin_a, pos_p)

l = (pa, pb)

Check failure on line 3164 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (E741)

scanner.py:3164:13: E741 Ambiguous variable name: `l`

if len(points) > 0 and corner_radius > 0:
# We need to insert an overscan corner. Basically we insert
Expand Down Expand Up @@ -3322,7 +3326,7 @@
# Calculate original step size and apply the new bounds
orig_span_x = self.max_x - self.min_x
orig_span_y = self.max_y - self.min_y
orig_step_x = orig_span_x / (self.res_x - 1)

Check failure on line 3329 in scanner.py

View workflow job for this annotation

GitHub Actions / checks

Ruff (F841)

scanner.py:3329:9: F841 Local variable `orig_step_x` is assigned to but never used
orig_step_y = orig_span_y / (self.res_y - 1)

if bound_min_x >= self.min_x:
Expand Down
3 changes: 3 additions & 0 deletions typings/gcode.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Callable, NamedTuple, final, overload
# Types for https://github.com/Klipper3d/klipper/blob/master/klippy/gcode.py

@final
class CommandError(Exception):
Expand All @@ -14,6 +15,8 @@ class GCodeCommand:
pass
def respond_info(self, msg: str, log: bool = True) -> None:
pass
def get_command_parameters(self) -> dict[str, str]:
pass

@overload
def get(
Expand Down