Skip to content

Commit

Permalink
sensor_ldc1612: Halt homing if sensor reports a warning
Browse files Browse the repository at this point in the history
Explicitly check for sensor warnings during homing and report an error
code back to the host.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed May 22, 2024
1 parent 3748217 commit 4a92727
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
9 changes: 5 additions & 4 deletions klippy/extras/ldc1612.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _build_config(self):
oid=self.oid, cq=cmdqueue)
self.ldc1612_setup_home_cmd = self.mcu.lookup_command(
"ldc1612_setup_home oid=%c clock=%u threshold=%u"
" trsync_oid=%c trigger_reason=%c", cq=cmdqueue)
" trsync_oid=%c trigger_reason=%c error_reason=%c", cq=cmdqueue)
self.query_ldc1612_home_state_cmd = self.mcu.lookup_query_command(
"query_ldc1612_home_state oid=%c",
"ldc1612_home_state oid=%c homing=%c trigger_clock=%u",
Expand All @@ -138,13 +138,14 @@ def set_reg(self, reg, val, minclock=0):
def add_client(self, cb):
self.batch_bulk.add_client(cb)
# Homing
def setup_home(self, print_time, trigger_freq, trsync_oid, reason):
def setup_home(self, print_time, trigger_freq,
trsync_oid, hit_reason, err_reason):
clock = self.mcu.print_time_to_clock(print_time)
tfreq = int(trigger_freq * (1<<28) / float(LDC1612_FREQ) + 0.5)
self.ldc1612_setup_home_cmd.send(
[self.oid, clock, tfreq, trsync_oid, reason])
[self.oid, clock, tfreq, trsync_oid, hit_reason, err_reason])
def clear_home(self):
self.ldc1612_setup_home_cmd.send([self.oid, 0, 0, 0, 0])
self.ldc1612_setup_home_cmd.send([self.oid, 0, 0, 0, 0, 0])
if self.mcu.is_fileoutput():
return 0.
params = self.query_ldc1612_home_state_cmd.send([self.oid])
Expand Down
9 changes: 6 additions & 3 deletions klippy/extras/probe_eddy_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def cmd_EDDY_CALIBRATE(self, gcmd):

# Helper for implementing PROBE style commands
class EddyEndstopWrapper:
REASON_SENSOR_ERROR = mcu.MCU_trsync.REASON_COMMS_TIMEOUT + 1
def __init__(self, config, sensor_helper, calibration):
self._printer = config.get_printer()
self._sensor_helper = sensor_helper
Expand Down Expand Up @@ -236,16 +237,18 @@ def home_start(self, print_time, sample_time, sample_count, rest_time,
trigger_completion = self._dispatch.start(print_time)
self._sensor_helper.setup_home(
print_time, trigger_freq, self._dispatch.get_oid(),
mcu.MCU_trsync.REASON_ENDSTOP_HIT)
mcu.MCU_trsync.REASON_ENDSTOP_HIT, self.REASON_SENSOR_ERROR)
return trigger_completion
def home_wait(self, home_end_time):
self._dispatch.wait_end(home_end_time)
trigger_time = self._sensor_helper.clear_home()
self._stop_measurements(is_home=True)
res = self._dispatch.stop()
if res >= mcu.MCU_trsync.REASON_COMMS_TIMEOUT:
raise self._printer.command_error(
"Communication timeout during homing")
if res == mcu.MCU_trsync.REASON_COMMS_TIMEOUT:
raise self._printer.command_error(
"Communication timeout during homing")
raise self._printer.command_error("Eddy current sensor error")
if res != mcu.MCU_trsync.REASON_ENDSTOP_HIT:
return 0.
if self._mcu.is_fileoutput():
Expand Down
11 changes: 9 additions & 2 deletions src/sensor_ldc1612.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct ldc1612 {
// homing
struct trsync *ts;
uint8_t homing_flags;
uint8_t trigger_reason;
uint8_t trigger_reason, error_reason;
uint32_t trigger_threshold;
uint32_t homing_clock;
};
Expand Down Expand Up @@ -95,11 +95,12 @@ command_ldc1612_setup_home(uint32_t *args)
ld->homing_clock = args[1];
ld->ts = trsync_oid_lookup(args[3]);
ld->trigger_reason = args[4];
ld->error_reason = args[5];
ld->homing_flags = LH_AWAIT_HOMING | LH_CAN_TRIGGER;
}
DECL_COMMAND(command_ldc1612_setup_home,
"ldc1612_setup_home oid=%c clock=%u threshold=%u"
" trsync_oid=%c trigger_reason=%c");
" trsync_oid=%c trigger_reason=%c error_reason=%c");

void
command_query_ldc1612_home_state(uint32_t *args)
Expand All @@ -118,6 +119,12 @@ check_home(struct ldc1612 *ld, uint32_t data)
uint8_t homing_flags = ld->homing_flags;
if (!(homing_flags & LH_CAN_TRIGGER))
return;
if (data > 0x0fffffff) {
// Sensor reports an issue - cancel homing
ld->homing_flags = 0;
trsync_do_trigger(ld->ts, ld->error_reason);
return;
}
uint32_t time = timer_read_time();
if ((homing_flags & LH_AWAIT_HOMING)
&& timer_is_before(time, ld->homing_clock))
Expand Down

0 comments on commit 4a92727

Please sign in to comment.