cartesian: Rename CartKinematics class to ToolHead
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
b3e8b430e5
commit
20ae4e5d98
|
@ -13,8 +13,8 @@ import lookahead, stepper, homing
|
||||||
StepList = (0, 1, 2, 3)
|
StepList = (0, 1, 2, 3)
|
||||||
|
|
||||||
class Move:
|
class Move:
|
||||||
def __init__(self, kin, pos, move_d, axes_d, speed, accel):
|
def __init__(self, toolhead, pos, move_d, axes_d, speed, accel):
|
||||||
self.kin = kin
|
self.toolhead = toolhead
|
||||||
self.pos = tuple(pos)
|
self.pos = tuple(pos)
|
||||||
self.axes_d = axes_d
|
self.axes_d = axes_d
|
||||||
self.move_d = move_d
|
self.move_d = move_d
|
||||||
|
@ -34,9 +34,9 @@ class Move:
|
||||||
return
|
return
|
||||||
junction_cos_theta = max(junction_cos_theta, -0.999999)
|
junction_cos_theta = max(junction_cos_theta, -0.999999)
|
||||||
sin_theta_d2 = math.sqrt(0.5*(1.0-junction_cos_theta));
|
sin_theta_d2 = math.sqrt(0.5*(1.0-junction_cos_theta));
|
||||||
R = self.kin.junction_deviation * sin_theta_d2 / (1.0 - sin_theta_d2)
|
R = self.toolhead.junction_deviation * sin_theta_d2 / (1. - sin_theta_d2)
|
||||||
self.junction_start_max = min(
|
self.junction_start_max = min(R * self.toolhead.max_xy_accel,
|
||||||
R * self.kin.max_xy_accel, self.junction_max, prev_move.junction_max)
|
self.junction_max, prev_move.junction_max)
|
||||||
def process(self, junction_start, junction_end):
|
def process(self, junction_start, junction_end):
|
||||||
# Determine accel, cruise, and decel portions of the move
|
# Determine accel, cruise, and decel portions of the move
|
||||||
junction_cruise = self.junction_max
|
junction_cruise = self.junction_max
|
||||||
|
@ -64,19 +64,19 @@ class Move:
|
||||||
# , next_move_time, accel_r, cruise_r))
|
# , next_move_time, accel_r, cruise_r))
|
||||||
|
|
||||||
# Calculate step times for the move
|
# Calculate step times for the move
|
||||||
next_move_time = self.kin.get_next_move_time()
|
next_move_time = self.toolhead.get_next_move_time()
|
||||||
for i in StepList:
|
for i in StepList:
|
||||||
new_step_pos = int(self.pos[i]*self.kin.steppers[i].inv_step_dist
|
new_step_pos = int(
|
||||||
+ 0.5)
|
self.pos[i]*self.toolhead.steppers[i].inv_step_dist + 0.5)
|
||||||
steps = new_step_pos - self.kin.stepper_pos[i]
|
steps = new_step_pos - self.toolhead.stepper_pos[i]
|
||||||
if not steps:
|
if not steps:
|
||||||
continue
|
continue
|
||||||
self.kin.stepper_pos[i] = new_step_pos
|
self.toolhead.stepper_pos[i] = new_step_pos
|
||||||
sdir = 0
|
sdir = 0
|
||||||
if steps < 0:
|
if steps < 0:
|
||||||
sdir = 1
|
sdir = 1
|
||||||
steps = -steps
|
steps = -steps
|
||||||
clock_offset, clock_freq, so = self.kin.steppers[i].prep_move(
|
clock_offset, clock_freq, so = self.toolhead.steppers[i].prep_move(
|
||||||
sdir, next_move_time)
|
sdir, next_move_time)
|
||||||
|
|
||||||
step_dist = self.move_d / steps
|
step_dist = self.move_d / steps
|
||||||
|
@ -107,11 +107,11 @@ class Move:
|
||||||
so.step_sqrt(
|
so.step_sqrt(
|
||||||
decel_steps, step_offset, clock_offset + decel_clock_offset
|
decel_steps, step_offset, clock_offset + decel_clock_offset
|
||||||
, decel_sqrt_offset, -accel_multiplier)
|
, decel_sqrt_offset, -accel_multiplier)
|
||||||
self.kin.update_move_time(accel_t + cruise_t + decel_t)
|
self.toolhead.update_move_time(accel_t + cruise_t + decel_t)
|
||||||
|
|
||||||
STALL_TIME = 0.100
|
STALL_TIME = 0.100
|
||||||
|
|
||||||
class CartKinematics:
|
class ToolHead:
|
||||||
def __init__(self, printer, config):
|
def __init__(self, printer, config):
|
||||||
self.printer = printer
|
self.printer = printer
|
||||||
self.reactor = printer.reactor
|
self.reactor = printer.reactor
|
||||||
|
|
|
@ -25,7 +25,7 @@ class GCodeParser:
|
||||||
self.gcode_handlers = {}
|
self.gcode_handlers = {}
|
||||||
self.is_shutdown = False
|
self.is_shutdown = False
|
||||||
self.need_ack = False
|
self.need_ack = False
|
||||||
self.kin = self.heater_nozzle = self.heater_bed = self.fan = None
|
self.toolhead = self.heater_nozzle = self.heater_bed = self.fan = None
|
||||||
self.movemult = 1.0
|
self.movemult = 1.0
|
||||||
self.speed = 1.0
|
self.speed = 1.0
|
||||||
self.absolutecoord = self.absoluteextrude = True
|
self.absolutecoord = self.absoluteextrude = True
|
||||||
|
@ -34,7 +34,7 @@ class GCodeParser:
|
||||||
self.homing_add = [0.0, 0.0, 0.0, 0.0]
|
self.homing_add = [0.0, 0.0, 0.0, 0.0]
|
||||||
self.axis2pos = {'X': 0, 'Y': 1, 'Z': 2, 'E': 3}
|
self.axis2pos = {'X': 0, 'Y': 1, 'Z': 2, 'E': 3}
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
self.kin = self.printer.objects['kinematics']
|
self.toolhead = self.printer.objects['toolhead']
|
||||||
self.heater_nozzle = self.printer.objects.get('heater_nozzle')
|
self.heater_nozzle = self.printer.objects.get('heater_nozzle')
|
||||||
self.heater_bed = self.printer.objects.get('heater_bed')
|
self.heater_bed = self.printer.objects.get('heater_bed')
|
||||||
self.fan = self.printer.objects.get('fan')
|
self.fan = self.printer.objects.get('fan')
|
||||||
|
@ -62,7 +62,7 @@ class GCodeParser:
|
||||||
self.reactor.run()
|
self.reactor.run()
|
||||||
def finish(self):
|
def finish(self):
|
||||||
self.reactor.end()
|
self.reactor.end()
|
||||||
self.kin.motor_off()
|
self.toolhead.motor_off()
|
||||||
logging.debug('Completed translation by klippy')
|
logging.debug('Completed translation by klippy')
|
||||||
def stats(self, eventtime):
|
def stats(self, eventtime):
|
||||||
return "gcodein=%d" % (self.bytes_read,)
|
return "gcodein=%d" % (self.bytes_read,)
|
||||||
|
@ -103,8 +103,8 @@ class GCodeParser:
|
||||||
# Check if machine can process next command or must stall input
|
# Check if machine can process next command or must stall input
|
||||||
if self.busy_state is not None:
|
if self.busy_state is not None:
|
||||||
break
|
break
|
||||||
if self.kin.check_busy(eventtime):
|
if self.toolhead.check_busy(eventtime):
|
||||||
self.set_busy(self.kin)
|
self.set_busy(self.toolhead)
|
||||||
break
|
break
|
||||||
self.ack()
|
self.ack()
|
||||||
del self.input_commands[:i+1]
|
del self.input_commands[:i+1]
|
||||||
|
@ -142,7 +142,7 @@ class GCodeParser:
|
||||||
def busy_handler(self, eventtime):
|
def busy_handler(self, eventtime):
|
||||||
busy = self.busy_state.check_busy(eventtime)
|
busy = self.busy_state.check_busy(eventtime)
|
||||||
if busy:
|
if busy:
|
||||||
self.kin.reset_motor_off_time(eventtime)
|
self.toolhead.reset_motor_off_time(eventtime)
|
||||||
return eventtime + self.RETRY_TIME
|
return eventtime + self.RETRY_TIME
|
||||||
self.busy_state = None
|
self.busy_state = None
|
||||||
self.ack()
|
self.ack()
|
||||||
|
@ -179,7 +179,7 @@ class GCodeParser:
|
||||||
return
|
return
|
||||||
self.set_busy(temp_busy_handler_wrapper())
|
self.set_busy(temp_busy_handler_wrapper())
|
||||||
def set_temp(self, heater, params, wait=False):
|
def set_temp(self, heater, params, wait=False):
|
||||||
print_time = self.kin.get_last_move_time()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
temp = float(params.get('S', '0'))
|
temp = float(params.get('S', '0'))
|
||||||
heater.set_temp(print_time, temp)
|
heater.set_temp(print_time, temp)
|
||||||
if wait:
|
if wait:
|
||||||
|
@ -209,14 +209,14 @@ class GCodeParser:
|
||||||
self.last_position[p] = v + self.base_position[p]
|
self.last_position[p] = v + self.base_position[p]
|
||||||
if 'F' in params:
|
if 'F' in params:
|
||||||
self.speed = float(params['F']) / 60.
|
self.speed = float(params['F']) / 60.
|
||||||
self.kin.move(self.last_position, self.speed, sloppy)
|
self.toolhead.move(self.last_position, self.speed, sloppy)
|
||||||
def cmd_G4(self, params):
|
def cmd_G4(self, params):
|
||||||
# Dwell
|
# Dwell
|
||||||
if 'S' in params:
|
if 'S' in params:
|
||||||
delay = float(params['S'])
|
delay = float(params['S'])
|
||||||
else:
|
else:
|
||||||
delay = float(params.get('P', '0')) / 1000.
|
delay = float(params.get('P', '0')) / 1000.
|
||||||
self.kin.dwell(delay)
|
self.toolhead.dwell(delay)
|
||||||
def cmd_G20(self, params):
|
def cmd_G20(self, params):
|
||||||
# Set units to inches
|
# Set units to inches
|
||||||
self.movemult = 25.4
|
self.movemult = 25.4
|
||||||
|
@ -231,9 +231,9 @@ class GCodeParser:
|
||||||
axis.append(self.axis2pos[a])
|
axis.append(self.axis2pos[a])
|
||||||
if not axis:
|
if not axis:
|
||||||
axis = [0, 1, 2]
|
axis = [0, 1, 2]
|
||||||
busy_handler = self.kin.home(axis)
|
busy_handler = self.toolhead.home(axis)
|
||||||
def axis_update(axis):
|
def axis_update(axis):
|
||||||
newpos = self.kin.get_position()
|
newpos = self.toolhead.get_position()
|
||||||
for a in axis:
|
for a in axis:
|
||||||
self.last_position[a] = newpos[a]
|
self.last_position[a] = newpos[a]
|
||||||
self.base_position[a] = -self.homing_add[a]
|
self.base_position[a] = -self.homing_add[a]
|
||||||
|
@ -262,10 +262,10 @@ class GCodeParser:
|
||||||
self.absoluteextrude = False
|
self.absoluteextrude = False
|
||||||
def cmd_M18(self, params):
|
def cmd_M18(self, params):
|
||||||
# Turn off motors
|
# Turn off motors
|
||||||
self.kin.motor_off()
|
self.toolhead.motor_off()
|
||||||
def cmd_M84(self, params):
|
def cmd_M84(self, params):
|
||||||
# Stop idle hold
|
# Stop idle hold
|
||||||
self.kin.motor_off()
|
self.toolhead.motor_off()
|
||||||
def cmd_M105(self, params):
|
def cmd_M105(self, params):
|
||||||
# Get Extruder Temperature
|
# Get Extruder Temperature
|
||||||
self.ack(self.get_temp())
|
self.ack(self.get_temp())
|
||||||
|
@ -280,7 +280,7 @@ class GCodeParser:
|
||||||
pass
|
pass
|
||||||
def cmd_M114(self, params):
|
def cmd_M114(self, params):
|
||||||
# Get Current Position
|
# Get Current Position
|
||||||
kinpos = self.kin.get_position()
|
kinpos = self.toolhead.get_position()
|
||||||
self.respond("X:%.3f Y:%.3f Z:%.3f E:%.3f Count X:%.3f Y:%.3f Z:%.3f" % (
|
self.respond("X:%.3f Y:%.3f Z:%.3f E:%.3f Count X:%.3f Y:%.3f Z:%.3f" % (
|
||||||
self.last_position[0], self.last_position[1],
|
self.last_position[0], self.last_position[1],
|
||||||
self.last_position[2], self.last_position[3],
|
self.last_position[2], self.last_position[3],
|
||||||
|
@ -293,11 +293,11 @@ class GCodeParser:
|
||||||
self.set_temp(self.heater_bed, params, wait=True)
|
self.set_temp(self.heater_bed, params, wait=True)
|
||||||
def cmd_M106(self, params):
|
def cmd_M106(self, params):
|
||||||
# Set fan speed
|
# Set fan speed
|
||||||
print_time = self.kin.get_last_move_time()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
self.fan.set_speed(print_time, float(params.get('S', '255')) / 255.)
|
self.fan.set_speed(print_time, float(params.get('S', '255')) / 255.)
|
||||||
def cmd_M107(self, params):
|
def cmd_M107(self, params):
|
||||||
# Turn fan off
|
# Turn fan off
|
||||||
print_time = self.kin.get_last_move_time()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
self.fan.set_speed(print_time, 0)
|
self.fan.set_speed(print_time, 0)
|
||||||
def cmd_M206(self, params):
|
def cmd_M206(self, params):
|
||||||
# Set home offset
|
# Set home offset
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
class Homing:
|
class Homing:
|
||||||
def __init__(self, kin, steppers):
|
def __init__(self, toolhead, steppers):
|
||||||
self.kin = kin
|
self.toolhead = toolhead
|
||||||
self.steppers = steppers
|
self.steppers = steppers
|
||||||
|
|
||||||
self.states = []
|
self.states = []
|
||||||
|
@ -48,27 +48,27 @@ class Homing:
|
||||||
|
|
||||||
def do_move(self, axis_pos, speed):
|
def do_move(self, axis_pos, speed):
|
||||||
# Issue a move command to axis_pos
|
# Issue a move command to axis_pos
|
||||||
newpos = self.kin.get_position()
|
newpos = self.toolhead.get_position()
|
||||||
for axis, pos in axis_pos.items():
|
for axis, pos in axis_pos.items():
|
||||||
newpos[axis] = pos
|
newpos[axis] = pos
|
||||||
self.kin.move(newpos, speed)
|
self.toolhead.move(newpos, speed)
|
||||||
return False
|
return False
|
||||||
def do_home(self, axis_pos, speed):
|
def do_home(self, axis_pos, speed):
|
||||||
# Alter kinematics class to think printer is at axis_pos
|
# Alter kinematics class to think printer is at axis_pos
|
||||||
newpos = self.kin.get_position()
|
newpos = self.toolhead.get_position()
|
||||||
forcepos = list(newpos)
|
forcepos = list(newpos)
|
||||||
for axis, pos in axis_pos.items():
|
for axis, pos in axis_pos.items():
|
||||||
newpos[axis] = self.steppers[axis].position_endstop
|
newpos[axis] = self.steppers[axis].position_endstop
|
||||||
forcepos[axis] = pos
|
forcepos[axis] = pos
|
||||||
self.kin.set_position(forcepos)
|
self.toolhead.set_position(forcepos)
|
||||||
# Start homing and issue move
|
# Start homing and issue move
|
||||||
print_time = self.kin.get_last_move_time()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
for axis in axis_pos:
|
for axis in axis_pos:
|
||||||
hz = speed * self.steppers[axis].inv_step_dist
|
hz = speed * self.steppers[axis].inv_step_dist
|
||||||
es = self.steppers[axis].enable_endstop_checking(print_time, hz)
|
es = self.steppers[axis].enable_endstop_checking(print_time, hz)
|
||||||
self.endstops.append(es)
|
self.endstops.append(es)
|
||||||
self.kin.move(newpos, speed)
|
self.toolhead.move(newpos, speed)
|
||||||
self.kin.reset_print_time()
|
self.toolhead.reset_print_time()
|
||||||
for es in self.endstops:
|
for es in self.endstops:
|
||||||
es.home_finalize()
|
es.home_finalize()
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -58,13 +58,13 @@ class Printer:
|
||||||
if self.fileconfig.has_section('heater_bed'):
|
if self.fileconfig.has_section('heater_bed'):
|
||||||
self.objects['heater_bed'] = heater.PrinterHeater(
|
self.objects['heater_bed'] = heater.PrinterHeater(
|
||||||
self, ConfigWrapper(self, 'heater_bed'))
|
self, ConfigWrapper(self, 'heater_bed'))
|
||||||
self.objects['kinematics'] = cartesian.CartKinematics(
|
self.objects['toolhead'] = cartesian.ToolHead(
|
||||||
self, self._pconfig)
|
self, self._pconfig)
|
||||||
|
|
||||||
def stats(self, eventtime):
|
def stats(self, eventtime):
|
||||||
out = []
|
out = []
|
||||||
out.append(self.gcode.stats(eventtime))
|
out.append(self.gcode.stats(eventtime))
|
||||||
out.append(self.objects['kinematics'].stats(eventtime))
|
out.append(self.objects['toolhead'].stats(eventtime))
|
||||||
out.append(self.mcu.stats(eventtime))
|
out.append(self.mcu.stats(eventtime))
|
||||||
logging.info("Stats %.0f: %s" % (eventtime, ' '.join(out)))
|
logging.info("Stats %.0f: %s" % (eventtime, ' '.join(out)))
|
||||||
return eventtime + 1.
|
return eventtime + 1.
|
||||||
|
|
Loading…
Reference in New Issue