homing: Implement second home from homing.py
Move the logic for performing the second home from the kinematics classes to the generic homing code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
3db483e270
commit
d4bf51231a
|
@ -50,8 +50,10 @@ class PrinterProbe:
|
|||
homing_state = homing.Homing(toolhead)
|
||||
pos = toolhead.get_position()
|
||||
pos[2] = self.z_position
|
||||
endstops = [(self.mcu_probe, "probe")]
|
||||
try:
|
||||
homing_state.probing_move(pos, self.mcu_probe, self.speed)
|
||||
homing_state.homing_move(pos, endstops, self.speed,
|
||||
probe_pos=True, verify_movement=True)
|
||||
except homing.EndstopError as e:
|
||||
reason = str(e)
|
||||
if "Timeout during endstop homing" in reason:
|
||||
|
|
|
@ -27,21 +27,23 @@ class Homing:
|
|||
if coord[i] is not None:
|
||||
thcoord[i] = coord[i]
|
||||
return thcoord
|
||||
def retract(self, newpos, speed):
|
||||
self.toolhead.move(self._fill_coord(newpos), speed)
|
||||
def set_homed_position(self, pos):
|
||||
self.toolhead.set_position(self._fill_coord(pos))
|
||||
def _get_homing_speed(self, speed, endstops):
|
||||
# Round the requested homing speed so that it is an even
|
||||
# number of ticks per step.
|
||||
speed = min(speed, self.toolhead.get_max_velocity()[0])
|
||||
mcu_stepper = endstops[0][0].get_steppers()[0]
|
||||
adjusted_freq = mcu_stepper.get_mcu().get_adjusted_freq()
|
||||
dist_ticks = adjusted_freq * mcu_stepper.get_step_dist()
|
||||
ticks_per_step = math.ceil(dist_ticks / speed)
|
||||
return dist_ticks / ticks_per_step
|
||||
def _homing_move(self, movepos, endstops, speed,
|
||||
def homing_move(self, movepos, endstops, speed, dwell_t=0.,
|
||||
probe_pos=False, verify_movement=False):
|
||||
# Notify endstops of upcoming home
|
||||
for mcu_endstop, name in endstops:
|
||||
mcu_endstop.home_prepare()
|
||||
if dwell_t:
|
||||
self.toolhead.dwell(dwell_t, check_stall=False)
|
||||
# Start endstop checking
|
||||
print_time = self.toolhead.get_last_move_time()
|
||||
start_mcu_pos = [(s, name, s.get_mcu_position())
|
||||
|
@ -53,7 +55,6 @@ class Homing:
|
|||
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
|
||||
min_step_dist / speed)
|
||||
# Issue move
|
||||
movepos = self._fill_coord(movepos)
|
||||
error = None
|
||||
try:
|
||||
self.toolhead.move(movepos, speed)
|
||||
|
@ -85,31 +86,43 @@ class Homing:
|
|||
raise EndstopError("Probe triggered prior to movement")
|
||||
raise EndstopError(
|
||||
"Endstop %s still triggered after retract" % (name,))
|
||||
def probing_move(self, movepos, mcu_probe, speed):
|
||||
mcu_probe.home_prepare()
|
||||
self._homing_move(movepos, [(mcu_probe, "probe")], speed,
|
||||
probe_pos=True, verify_movement=True)
|
||||
def home(self, forcepos, movepos, endstops, speed, second_home=False):
|
||||
if second_home and forcepos == movepos:
|
||||
return
|
||||
def home_rails(self, rails, forcepos, movepos, limit_speed=None):
|
||||
# Alter kinematics class to think printer is at forcepos
|
||||
homing_axes = [axis for axis in range(3) if forcepos[axis] is not None]
|
||||
self.toolhead.set_position(
|
||||
self._fill_coord(forcepos), homing_axes=homing_axes)
|
||||
# Notify endstops of upcoming home
|
||||
for mcu_endstop, name in endstops:
|
||||
mcu_endstop.home_prepare()
|
||||
# Add a CPU delay when homing a large axis
|
||||
if not second_home:
|
||||
est_move_d = sum([abs(forcepos[i]-movepos[i])
|
||||
for i in range(3) if movepos[i] is not None])
|
||||
forcepos = self._fill_coord(forcepos)
|
||||
movepos = self._fill_coord(movepos)
|
||||
self.toolhead.set_position(forcepos, homing_axes=homing_axes)
|
||||
# Determine homing speed
|
||||
endstops = [es for rail in rails for es in rail.get_endstops()]
|
||||
hi = rails[0].get_homing_info()
|
||||
max_velocity = self.toolhead.get_max_velocity()[0]
|
||||
if limit_speed is not None and limit_speed < max_velocity:
|
||||
max_velocity = limit_speed
|
||||
homing_speed = min(hi.speed, max_velocity)
|
||||
homing_speed = self._get_homing_speed(homing_speed, endstops)
|
||||
second_homing_speed = min(hi.second_homing_speed, max_velocity)
|
||||
# Calculate a CPU delay when homing a large axis
|
||||
axes_d = [mp - fp for mp, fp in zip(movepos, forcepos)]
|
||||
est_move_d = abs(axes_d[0]) + abs(axes_d[1]) + abs(axes_d[2])
|
||||
est_steps = sum([est_move_d / s.get_step_dist()
|
||||
for es, n in endstops for s in es.get_steppers()])
|
||||
self.toolhead.dwell(est_steps * HOMING_STEP_DELAY, check_stall=False)
|
||||
speed = self._get_homing_speed(speed, endstops)
|
||||
# Issue homing move
|
||||
self._homing_move(movepos, endstops, speed,
|
||||
verify_movement=second_home and self.verify_retract)
|
||||
dwell_t = est_steps * HOMING_STEP_DELAY
|
||||
# Perform first home
|
||||
self.homing_move(movepos, endstops, homing_speed, dwell_t=dwell_t)
|
||||
# Perform second home
|
||||
if hi.retract_dist:
|
||||
# Retract
|
||||
move_d = math.sqrt(sum([d*d for d in axes_d[:3]]))
|
||||
retract_r = min(1., hi.retract_dist / move_d)
|
||||
retractpos = [mp - ad * retract_r
|
||||
for mp, ad in zip(movepos, axes_d)]
|
||||
self.toolhead.move(retractpos, homing_speed)
|
||||
# Home again
|
||||
forcepos = [rp - ad * retract_r
|
||||
for rp, ad in zip(retractpos, axes_d)]
|
||||
self.toolhead.set_position(forcepos)
|
||||
self.homing_move(movepos, endstops, second_homing_speed,
|
||||
verify_movement=self.verify_retract)
|
||||
def home_axes(self, axes):
|
||||
self.changed_axes = axes
|
||||
try:
|
||||
|
|
|
@ -55,38 +55,24 @@ class CartKinematics:
|
|||
if i in homing_axes:
|
||||
self.limits[i] = rail.get_range()
|
||||
def _home_axis(self, homing_state, axis, rail):
|
||||
# Determine moves
|
||||
# Determine movement
|
||||
position_min, position_max = rail.get_range()
|
||||
hi = rail.get_homing_info()
|
||||
if hi.positive_dir:
|
||||
pos = hi.position_endstop - 1.5*(hi.position_endstop - position_min)
|
||||
rpos = hi.position_endstop - hi.retract_dist
|
||||
r2pos = rpos - hi.retract_dist
|
||||
else:
|
||||
pos = hi.position_endstop + 1.5*(position_max - hi.position_endstop)
|
||||
rpos = hi.position_endstop + hi.retract_dist
|
||||
r2pos = rpos + hi.retract_dist
|
||||
# Initial homing
|
||||
homing_speed = hi.speed
|
||||
second_homing_speed = hi.second_homing_speed
|
||||
if axis == 2:
|
||||
homing_speed = min(homing_speed, self.max_z_velocity)
|
||||
second_homing_speed = min(second_homing_speed, self.max_z_velocity)
|
||||
homepos = [None, None, None, None]
|
||||
homepos[axis] = hi.position_endstop
|
||||
coord = [None, None, None, None]
|
||||
coord[axis] = pos
|
||||
homing_state.home(coord, homepos, rail.get_endstops(), homing_speed)
|
||||
# Retract
|
||||
coord[axis] = rpos
|
||||
homing_state.retract(coord, homing_speed)
|
||||
# Home again
|
||||
coord[axis] = r2pos
|
||||
homing_state.home(coord, homepos, rail.get_endstops(),
|
||||
second_homing_speed, second_home=True)
|
||||
forcepos = list(homepos)
|
||||
if hi.positive_dir:
|
||||
forcepos[axis] -= 1.5 * (hi.position_endstop - position_min)
|
||||
else:
|
||||
forcepos[axis] += 1.5 * (position_max - hi.position_endstop)
|
||||
# Perform homing
|
||||
limit_speed = None
|
||||
if axis == 2:
|
||||
limit_speed = self.max_z_velocity
|
||||
homing_state.home_rails([rail], forcepos, homepos, limit_speed)
|
||||
# Set final homed position
|
||||
coord[axis] = hi.position_endstop + rail.get_homed_offset()
|
||||
homing_state.set_homed_position(coord)
|
||||
forcepos[axis] = hi.position_endstop + rail.get_homed_offset()
|
||||
homing_state.set_homed_position(forcepos)
|
||||
def home(self, homing_state):
|
||||
# Each axis is homed independently and in order
|
||||
for axis in homing_state.get_axes():
|
||||
|
|
|
@ -48,42 +48,25 @@ class CoreXYKinematics:
|
|||
# Each axis is homed independently and in order
|
||||
for axis in homing_state.get_axes():
|
||||
rail = self.rails[axis]
|
||||
# Determine moves
|
||||
# Determine movement
|
||||
position_min, position_max = rail.get_range()
|
||||
hi = rail.get_homing_info()
|
||||
if hi.positive_dir:
|
||||
pos = hi.position_endstop - 1.5*(
|
||||
hi.position_endstop - position_min)
|
||||
rpos = hi.position_endstop - hi.retract_dist
|
||||
r2pos = rpos - hi.retract_dist
|
||||
else:
|
||||
pos = hi.position_endstop + 1.5*(
|
||||
position_max - hi.position_endstop)
|
||||
rpos = hi.position_endstop + hi.retract_dist
|
||||
r2pos = rpos + hi.retract_dist
|
||||
# Initial homing
|
||||
homing_speed = hi.speed
|
||||
second_homing_speed = hi.second_homing_speed
|
||||
if axis == 2:
|
||||
homing_speed = min(homing_speed, self.max_z_velocity)
|
||||
second_homing_speed = min(second_homing_speed,
|
||||
self.max_z_velocity)
|
||||
homepos = [None, None, None, None]
|
||||
homepos[axis] = hi.position_endstop
|
||||
coord = [None, None, None, None]
|
||||
coord[axis] = pos
|
||||
homing_state.home(coord, homepos, rail.get_endstops(), homing_speed)
|
||||
# Retract
|
||||
coord[axis] = rpos
|
||||
homing_state.retract(coord, homing_speed)
|
||||
# Home again
|
||||
coord[axis] = r2pos
|
||||
homing_state.home(coord, homepos, rail.get_endstops(),
|
||||
second_homing_speed, second_home=True)
|
||||
forcepos = list(homepos)
|
||||
if hi.positive_dir:
|
||||
forcepos[axis] -= 1.5 * (hi.position_endstop - position_min)
|
||||
else:
|
||||
forcepos[axis] += 1.5 * (position_max - hi.position_endstop)
|
||||
# Perform homing
|
||||
limit_speed = None
|
||||
if axis == 2:
|
||||
limit_speed = self.max_z_velocity
|
||||
homing_state.home_rails([rail], forcepos, homepos, limit_speed)
|
||||
if axis == 2:
|
||||
# Support endstop phase detection on Z axis
|
||||
coord[axis] = hi.position_endstop + rail.get_homed_offset()
|
||||
homing_state.set_homed_position(coord)
|
||||
forcepos[axis] = hi.position_endstop + rail.get_homed_offset()
|
||||
homing_state.set_homed_position(forcepos)
|
||||
def motor_off(self, print_time):
|
||||
self.limits = [(1.0, -1.0)] * 3
|
||||
for rail in self.rails:
|
||||
|
|
|
@ -97,22 +97,11 @@ class DeltaKinematics:
|
|||
def home(self, homing_state):
|
||||
# All axes are homed simultaneously
|
||||
homing_state.set_axes([0, 1, 2])
|
||||
endstops = [es for rail in self.rails for es in rail.get_endstops()]
|
||||
# Initial homing - assume homing speed same for all steppers
|
||||
hi = self.rails[0].get_homing_info()
|
||||
homing_speed = min(hi.speed, self.max_z_velocity)
|
||||
second_homing_speed = min(hi.second_homing_speed, self.max_z_velocity)
|
||||
homepos = [0., 0., self.max_z, None]
|
||||
coord = list(homepos)
|
||||
coord[2] = -1.5 * math.sqrt(max(self.arm2)-self.max_xy2)
|
||||
homing_state.home(coord, homepos, endstops, homing_speed)
|
||||
# Retract
|
||||
coord[2] = homepos[2] - hi.retract_dist
|
||||
homing_state.retract(coord, homing_speed)
|
||||
# Home again
|
||||
coord[2] -= hi.retract_dist
|
||||
homing_state.home(coord, homepos, endstops,
|
||||
second_homing_speed, second_home=True)
|
||||
forcepos = list(homepos)
|
||||
forcepos[2] = -1.5 * math.sqrt(max(self.arm2)-self.max_xy2)
|
||||
homing_state.home_rails(self.rails, forcepos, homepos,
|
||||
limit_speed=self.max_z_velocity)
|
||||
# Set final homed position
|
||||
spos = [ep + rail.get_homed_offset()
|
||||
for ep, rail in zip(self.abs_endstops, self.rails)]
|
||||
|
|
Loading…
Reference in New Issue