homing: Create Homing class from gcode
Create the Homing class in the gcode handler instead of in the kinematic classes. This will make it easier to pass error messages back to the user. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
9e1059afb4
commit
781cf608d7
|
@ -31,10 +31,9 @@ class CartKinematics:
|
||||||
def get_homed_position(self):
|
def get_homed_position(self):
|
||||||
return [s.position_endstop + s.get_homed_offset()*s.step_dist
|
return [s.position_endstop + s.get_homed_offset()*s.step_dist
|
||||||
for s in self.steppers]
|
for s in self.steppers]
|
||||||
def home(self, toolhead, axes):
|
def home(self, homing_state):
|
||||||
# Each axis is homed independently and in order
|
# Each axis is homed independently and in order
|
||||||
homing_state = homing.Homing(toolhead, axes)
|
for axis in homing_state.get_axes():
|
||||||
for axis in axes:
|
|
||||||
s = self.steppers[axis]
|
s = self.steppers[axis]
|
||||||
self.limits[axis] = (s.position_min, s.position_max)
|
self.limits[axis] = (s.position_min, s.position_max)
|
||||||
# Determine moves
|
# Determine moves
|
||||||
|
@ -60,7 +59,6 @@ class CartKinematics:
|
||||||
# Home again
|
# Home again
|
||||||
coord[axis] = r2pos
|
coord[axis] = r2pos
|
||||||
homing_state.plan_home(list(coord), homepos, [s], s.homing_speed/2.0)
|
homing_state.plan_home(list(coord), homepos, [s], s.homing_speed/2.0)
|
||||||
return homing_state
|
|
||||||
def motor_off(self, move_time):
|
def motor_off(self, move_time):
|
||||||
self.limits = [(1.0, -1.0)] * 3
|
self.limits = [(1.0, -1.0)] * 3
|
||||||
for stepper in self.steppers:
|
for stepper in self.steppers:
|
||||||
|
|
|
@ -83,9 +83,9 @@ class DeltaKinematics:
|
||||||
* self.steppers[i].step_dist
|
* self.steppers[i].step_dist
|
||||||
for i in StepList]
|
for i in StepList]
|
||||||
return self.actuator_to_cartesian(pos)
|
return self.actuator_to_cartesian(pos)
|
||||||
def home(self, toolhead, axes):
|
def home(self, homing_state):
|
||||||
# All axes are homed simultaneously
|
# All axes are homed simultaneously
|
||||||
homing_state = homing.Homing(toolhead, [0, 1, 2])
|
homing_state.set_axes([0, 1, 2])
|
||||||
s = self.steppers[0] # Assume homing parameters same for all steppers
|
s = self.steppers[0] # Assume homing parameters same for all steppers
|
||||||
self.limit_xy2 = self.max_xy2
|
self.limit_xy2 = self.max_xy2
|
||||||
# Initial homing
|
# Initial homing
|
||||||
|
@ -101,7 +101,6 @@ class DeltaKinematics:
|
||||||
coord[2] -= s.homing_retract_dist
|
coord[2] -= s.homing_retract_dist
|
||||||
homing_state.plan_home(list(coord), homepos, self.steppers
|
homing_state.plan_home(list(coord), homepos, self.steppers
|
||||||
, s.homing_speed/2.0)
|
, s.homing_speed/2.0)
|
||||||
return homing_state
|
|
||||||
def motor_off(self, move_time):
|
def motor_off(self, move_time):
|
||||||
self.limit_xy2 = -1.
|
self.limit_xy2 = -1.
|
||||||
for stepper in self.steppers:
|
for stepper in self.steppers:
|
||||||
|
|
|
@ -250,14 +250,15 @@ class GCodeParser:
|
||||||
axes.append(self.axis2pos[axis])
|
axes.append(self.axis2pos[axis])
|
||||||
if not axes:
|
if not axes:
|
||||||
axes = [0, 1, 2]
|
axes = [0, 1, 2]
|
||||||
busy_handler = self.toolhead.home(axes)
|
homing_state = homing.Homing(self.toolhead, axes)
|
||||||
def axes_update(axes):
|
self.toolhead.home(homing_state)
|
||||||
|
def axes_update(homing_state):
|
||||||
newpos = self.toolhead.get_position()
|
newpos = self.toolhead.get_position()
|
||||||
for axis in axes:
|
for axis in homing_state.get_axes():
|
||||||
self.last_position[axis] = newpos[axis]
|
self.last_position[axis] = newpos[axis]
|
||||||
self.base_position[axis] = -self.homing_add[axis]
|
self.base_position[axis] = -self.homing_add[axis]
|
||||||
busy_handler.plan_axes_update(axes_update)
|
homing_state.plan_axes_update(axes_update)
|
||||||
self.set_busy(busy_handler)
|
self.set_busy(homing_state)
|
||||||
def cmd_G90(self, params):
|
def cmd_G90(self, params):
|
||||||
# Use absolute coordinates
|
# Use absolute coordinates
|
||||||
self.absolutecoord = True
|
self.absolutecoord = True
|
||||||
|
|
|
@ -14,13 +14,17 @@ class Homing:
|
||||||
self.eventtime = 0.
|
self.eventtime = 0.
|
||||||
self.states = []
|
self.states = []
|
||||||
self.endstops = []
|
self.endstops = []
|
||||||
|
def set_axes(self, axes):
|
||||||
|
self.changed_axes = axes
|
||||||
|
def get_axes(self):
|
||||||
|
return self.changed_axes
|
||||||
def plan_home(self, forcepos, movepos, steppers, speed):
|
def plan_home(self, forcepos, movepos, steppers, speed):
|
||||||
self.states.append((self.do_home, (forcepos, movepos, steppers, speed)))
|
self.states.append((self.do_home, (forcepos, movepos, steppers, speed)))
|
||||||
self.states.append((self.do_wait_endstop, ()))
|
self.states.append((self.do_wait_endstop, ()))
|
||||||
def plan_move(self, newpos, speed):
|
def plan_move(self, newpos, speed):
|
||||||
self.states.append((self.do_move, (newpos, speed)))
|
self.states.append((self.do_move, (newpos, speed)))
|
||||||
def plan_axes_update(self, callback):
|
def plan_axes_update(self, callback):
|
||||||
self.states.append((callback, (self.changed_axes,)))
|
self.states.append((callback, (self,)))
|
||||||
def check_busy(self, eventtime):
|
def check_busy(self, eventtime):
|
||||||
self.eventtime = eventtime
|
self.eventtime = eventtime
|
||||||
while self.states:
|
while self.states:
|
||||||
|
|
|
@ -259,16 +259,15 @@ class ToolHead:
|
||||||
self.extruder.check_move(move)
|
self.extruder.check_move(move)
|
||||||
self.commanded_pos[:] = newpos
|
self.commanded_pos[:] = newpos
|
||||||
self.move_queue.add_move(move)
|
self.move_queue.add_move(move)
|
||||||
def home(self, axes):
|
def home(self, homing_state):
|
||||||
homing = self.kin.home(self, axes)
|
self.kin.home(homing_state)
|
||||||
def axes_update(axes):
|
def axes_update(homing_state):
|
||||||
pos = self.get_position()
|
pos = self.get_position()
|
||||||
homepos = self.kin.get_homed_position()
|
homepos = self.kin.get_homed_position()
|
||||||
for axis in axes:
|
for axis in homing_state.get_axes():
|
||||||
pos[axis] = homepos[axis]
|
pos[axis] = homepos[axis]
|
||||||
self.set_position(pos)
|
self.set_position(pos)
|
||||||
homing.plan_axes_update(axes_update)
|
homing_state.plan_axes_update(axes_update)
|
||||||
return homing
|
|
||||||
def dwell(self, delay):
|
def dwell(self, delay):
|
||||||
self.get_last_move_time()
|
self.get_last_move_time()
|
||||||
self.update_move_time(delay)
|
self.update_move_time(delay)
|
||||||
|
|
Loading…
Reference in New Issue