cartesian: Rename CartKinematics class to ToolHead

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-07-07 14:23:48 -04:00
parent b3e8b430e5
commit 20ae4e5d98
4 changed files with 40 additions and 40 deletions

View File

@ -13,8 +13,8 @@ import lookahead, stepper, homing
StepList = (0, 1, 2, 3)
class Move:
def __init__(self, kin, pos, move_d, axes_d, speed, accel):
self.kin = kin
def __init__(self, toolhead, pos, move_d, axes_d, speed, accel):
self.toolhead = toolhead
self.pos = tuple(pos)
self.axes_d = axes_d
self.move_d = move_d
@ -34,9 +34,9 @@ class Move:
return
junction_cos_theta = max(junction_cos_theta, -0.999999)
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)
self.junction_start_max = min(
R * self.kin.max_xy_accel, self.junction_max, prev_move.junction_max)
R = self.toolhead.junction_deviation * sin_theta_d2 / (1. - sin_theta_d2)
self.junction_start_max = min(R * self.toolhead.max_xy_accel,
self.junction_max, prev_move.junction_max)
def process(self, junction_start, junction_end):
# Determine accel, cruise, and decel portions of the move
junction_cruise = self.junction_max
@ -64,19 +64,19 @@ class Move:
# , next_move_time, accel_r, cruise_r))
# 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:
new_step_pos = int(self.pos[i]*self.kin.steppers[i].inv_step_dist
+ 0.5)
steps = new_step_pos - self.kin.stepper_pos[i]
new_step_pos = int(
self.pos[i]*self.toolhead.steppers[i].inv_step_dist + 0.5)
steps = new_step_pos - self.toolhead.stepper_pos[i]
if not steps:
continue
self.kin.stepper_pos[i] = new_step_pos
self.toolhead.stepper_pos[i] = new_step_pos
sdir = 0
if steps < 0:
sdir = 1
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)
step_dist = self.move_d / steps
@ -107,11 +107,11 @@ class Move:
so.step_sqrt(
decel_steps, step_offset, clock_offset + decel_clock_offset
, 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
class CartKinematics:
class ToolHead:
def __init__(self, printer, config):
self.printer = printer
self.reactor = printer.reactor

View File

@ -25,7 +25,7 @@ class GCodeParser:
self.gcode_handlers = {}
self.is_shutdown = 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.speed = 1.0
self.absolutecoord = self.absoluteextrude = True
@ -34,7 +34,7 @@ class GCodeParser:
self.homing_add = [0.0, 0.0, 0.0, 0.0]
self.axis2pos = {'X': 0, 'Y': 1, 'Z': 2, 'E': 3}
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_bed = self.printer.objects.get('heater_bed')
self.fan = self.printer.objects.get('fan')
@ -62,7 +62,7 @@ class GCodeParser:
self.reactor.run()
def finish(self):
self.reactor.end()
self.kin.motor_off()
self.toolhead.motor_off()
logging.debug('Completed translation by klippy')
def stats(self, eventtime):
return "gcodein=%d" % (self.bytes_read,)
@ -103,8 +103,8 @@ class GCodeParser:
# Check if machine can process next command or must stall input
if self.busy_state is not None:
break
if self.kin.check_busy(eventtime):
self.set_busy(self.kin)
if self.toolhead.check_busy(eventtime):
self.set_busy(self.toolhead)
break
self.ack()
del self.input_commands[:i+1]
@ -142,7 +142,7 @@ class GCodeParser:
def busy_handler(self, eventtime):
busy = self.busy_state.check_busy(eventtime)
if busy:
self.kin.reset_motor_off_time(eventtime)
self.toolhead.reset_motor_off_time(eventtime)
return eventtime + self.RETRY_TIME
self.busy_state = None
self.ack()
@ -179,7 +179,7 @@ class GCodeParser:
return
self.set_busy(temp_busy_handler_wrapper())
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'))
heater.set_temp(print_time, temp)
if wait:
@ -209,14 +209,14 @@ class GCodeParser:
self.last_position[p] = v + self.base_position[p]
if 'F' in params:
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):
# Dwell
if 'S' in params:
delay = float(params['S'])
else:
delay = float(params.get('P', '0')) / 1000.
self.kin.dwell(delay)
self.toolhead.dwell(delay)
def cmd_G20(self, params):
# Set units to inches
self.movemult = 25.4
@ -231,9 +231,9 @@ class GCodeParser:
axis.append(self.axis2pos[a])
if not axis:
axis = [0, 1, 2]
busy_handler = self.kin.home(axis)
busy_handler = self.toolhead.home(axis)
def axis_update(axis):
newpos = self.kin.get_position()
newpos = self.toolhead.get_position()
for a in axis:
self.last_position[a] = newpos[a]
self.base_position[a] = -self.homing_add[a]
@ -262,10 +262,10 @@ class GCodeParser:
self.absoluteextrude = False
def cmd_M18(self, params):
# Turn off motors
self.kin.motor_off()
self.toolhead.motor_off()
def cmd_M84(self, params):
# Stop idle hold
self.kin.motor_off()
self.toolhead.motor_off()
def cmd_M105(self, params):
# Get Extruder Temperature
self.ack(self.get_temp())
@ -280,7 +280,7 @@ class GCodeParser:
pass
def cmd_M114(self, params):
# 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.last_position[0], self.last_position[1],
self.last_position[2], self.last_position[3],
@ -293,11 +293,11 @@ class GCodeParser:
self.set_temp(self.heater_bed, params, wait=True)
def cmd_M106(self, params):
# 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.)
def cmd_M107(self, params):
# 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)
def cmd_M206(self, params):
# Set home offset

View File

@ -7,8 +7,8 @@
import logging
class Homing:
def __init__(self, kin, steppers):
self.kin = kin
def __init__(self, toolhead, steppers):
self.toolhead = toolhead
self.steppers = steppers
self.states = []
@ -48,27 +48,27 @@ class Homing:
def do_move(self, axis_pos, speed):
# Issue a move command to axis_pos
newpos = self.kin.get_position()
newpos = self.toolhead.get_position()
for axis, pos in axis_pos.items():
newpos[axis] = pos
self.kin.move(newpos, speed)
self.toolhead.move(newpos, speed)
return False
def do_home(self, axis_pos, speed):
# Alter kinematics class to think printer is at axis_pos
newpos = self.kin.get_position()
newpos = self.toolhead.get_position()
forcepos = list(newpos)
for axis, pos in axis_pos.items():
newpos[axis] = self.steppers[axis].position_endstop
forcepos[axis] = pos
self.kin.set_position(forcepos)
self.toolhead.set_position(forcepos)
# 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:
hz = speed * self.steppers[axis].inv_step_dist
es = self.steppers[axis].enable_endstop_checking(print_time, hz)
self.endstops.append(es)
self.kin.move(newpos, speed)
self.kin.reset_print_time()
self.toolhead.move(newpos, speed)
self.toolhead.reset_print_time()
for es in self.endstops:
es.home_finalize()
return False

View File

@ -58,13 +58,13 @@ class Printer:
if self.fileconfig.has_section('heater_bed'):
self.objects['heater_bed'] = heater.PrinterHeater(
self, ConfigWrapper(self, 'heater_bed'))
self.objects['kinematics'] = cartesian.CartKinematics(
self.objects['toolhead'] = cartesian.ToolHead(
self, self._pconfig)
def stats(self, eventtime):
out = []
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))
logging.info("Stats %.0f: %s" % (eventtime, ' '.join(out)))
return eventtime + 1.