def update_stepper(self, stepper, is_rail): stepper_name = stepper.get_name() if stepper_name not in self.tracking: info = self.lookup_stepper(stepper, stepper_name) self.tracking[stepper_name] = info info = self.tracking[stepper_name] if info is None: return if is_rail: info["is_rail"] = True get_phase = info["get_phase"] if get_phase is None: return try: driver_phase, driver_phases = get_phase() except: logging.exception("Error in EndstopPhases get_phase") return phase_history = info["phase_history"] phase = convert_phase(driver_phase, driver_phases, len(phase_history)) phase_history[phase] += 1 self.last_home_info[stepper.get_name()] = { 'phase': phase, 'phases': len(phase_history), 'mcu_position': stepper.get_mcu_position() }
def handle_home_rails_end(self, homing_state, rails): for rail in rails: is_primary = True for stepper in rail.get_steppers(): sname = stepper.get_name() trig_mcu_pos = homing_state.get_trigger_position(sname) self.update_stepper(stepper, trig_mcu_pos, is_primary) is_primary = False
def handle_home_rails_end(self, homing_state, rails): for rail in rails: stepper = rail.get_steppers()[0] stepper_name = stepper.get_name() if stepper_name not in self.tracking: info = self.lookup_rail(stepper, stepper_name) self.tracking[stepper_name] = info self.update_rail(self.tracking[stepper_name], stepper)
def handle_home_rails_end(self, homing_state, rails): for rail in rails: stepper = rail.get_steppers()[0] if stepper.get_name() == self.name: trig_mcu_pos = homing_state.get_trigger_position(self.name) align = self.align_endstop(rail) offset = self.get_homed_offset(stepper, trig_mcu_pos) homing_state.set_stepper_adjustment(self.name, align + offset) return
def handle_home_rails_end(self, homing_state, rails): kin_spos = homing_state.get_stepper_trigger_positions() orig_pos = kin_spos.get(self.name) if orig_pos is None: return for rail in rails: stepper = rail.get_steppers()[0] if stepper.get_name() == self.name: offset = self.get_homed_offset(stepper) kin_spos[self.name] = self.align_endstop(orig_pos) + offset return
def handle_home_rails_end(self, homing_state, rails): for rail in rails: stepper = rail.get_steppers()[0] if stepper.get_name() != self.name: continue orig_pos = rail.get_tag_position() offset = self.get_homed_offset(stepper) pos = self.align_endstop(orig_pos) + offset if pos == orig_pos: return False rail.set_tag_position(pos) return True
def _handle_sync_mcu_pos(self, stepper): if stepper.get_name() != self.stepper_name: return try: driver_phase = self._query_phase() except self.printer.command_error as e: logging.info("Unable to obtain tmc %s phase", self.stepper_name) self.mcu_phase_offset = None enable_line = self.stepper_enable.lookup_enable(self.stepper_name) if enable_line.is_motor_enabled(): raise return if not stepper.is_dir_inverted(): driver_phase = 1023 - driver_phase phases = self._get_phases() phase = int(float(driver_phase) / 1024 * phases + .5) % phases moff = (phase - stepper.get_mcu_position()) % phases if self.mcu_phase_offset is not None and self.mcu_phase_offset != moff: logging.warning("Stepper %s phase change (was %d now %d)", self.stepper_name, self.mcu_phase_offset, moff) self.mcu_phase_offset = moff
def update_stepper(self, stepper, trig_mcu_pos, is_primary): stepper_name = stepper.get_name() phase_calc = self.tracking.get(stepper_name) if phase_calc is None: # Check if stepper has an endstop_phase config section defined mod_name = "endstop_phase %s" % (stepper_name, ) m = self.printer.lookup_object(mod_name, None) if m is not None: phase_calc = m.phase_calc else: # Create new PhaseCalc tracker phase_calc = PhaseCalc(self.printer, stepper_name) phase_calc.stats_only = True phase_calc.lookup_tmc() self.tracking[stepper_name] = phase_calc if phase_calc.phase_history is None: return if is_primary: phase_calc.is_primary = True if phase_calc.stats_only: phase_calc.calc_phase(stepper, trig_mcu_pos)