toolhead: Specify maximum acceleration and velocity in toolhead class

Change the config file so the maximum accel and velocity are specified
in the "printer" section instead of the individual "stepper" sections.
The underlying code limits the velocity and accel of the toolhead
relative to the print object, so it makes sense to configure the
system that was as well.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2016-12-01 15:29:26 -05:00
parent fcaf359e89
commit c49d3fdb17
8 changed files with 52 additions and 53 deletions

View File

@@ -13,21 +13,21 @@ class CartKinematics:
self.steppers = [stepper.PrinterStepper(
printer, config.getsection('stepper_' + n), n)
for n in ['x', 'y', 'z']]
self.max_z_velocity = config.getfloat('max_z_velocity', 9999999.9)
self.max_z_accel = config.getfloat('max_z_accel', 9999999.9)
self.need_motor_enable = True
self.limits = [(1.0, -1.0)] * 3
def set_max_jerk(self, max_xy_halt_velocity, max_accel):
self.steppers[0].set_max_jerk(max_xy_halt_velocity, max_accel)
self.steppers[1].set_max_jerk(max_xy_halt_velocity, max_accel)
self.steppers[2].set_max_jerk(0., self.max_z_accel)
def build_config(self):
for stepper in self.steppers[:2]:
stepper.set_max_jerk(0.005 * stepper.max_accel) # XXX
for stepper in self.steppers:
stepper.build_config()
def set_position(self, newpos):
for i in StepList:
s = self.steppers[i]
s.mcu_stepper.set_position(int(newpos[i]*s.inv_step_dist + 0.5))
def get_max_speed(self):
max_xy_speed = min(s.max_velocity for s in self.steppers[:2])
max_xy_accel = min(s.max_accel for s in self.steppers[:2])
return max_xy_speed, max_xy_accel
def get_homed_position(self, homing_state):
pos = [None]*3
for axis in homing_state.get_axes():
@@ -99,13 +99,9 @@ class CartKinematics:
return
# Move with Z - update velocity and accel for slower Z axis
self.check_endstops(move)
axes_d = move.axes_d
move_d = move.move_d
velocity_factor = min([self.steppers[i].max_velocity / abs(axes_d[i])
for i in StepList if axes_d[i]])
accel_factor = min([self.steppers[i].max_accel / abs(axes_d[i])
for i in StepList if axes_d[i]])
move.limit_speed(velocity_factor * move_d, accel_factor * move_d)
z_ratio = move.move_d / abs(move.axes_d[2])
move.limit_speed(
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
def move(self, move_time, move):
if self.need_motor_enable:
self.check_motor_enable(move_time, move)

View File

@@ -28,17 +28,14 @@ class DeltaKinematics:
(cos(210.)*radius, sin(210.)*radius),
(cos(330.)*radius, sin(330.)*radius),
(cos(90.)*radius, sin(90.)*radius)]
def build_config(self):
def set_max_jerk(self, max_xy_halt_velocity, max_accel):
# XXX - this sets conservative values
for stepper in self.steppers:
stepper.set_max_jerk(0.005 * stepper.max_accel) # XXX
stepper.set_max_jerk(max_xy_halt_velocity, max_accel)
def build_config(self):
for stepper in self.steppers:
stepper.build_config()
self.set_position([0., 0., 0.])
def get_max_speed(self):
# XXX - this returns conservative values
max_xy_speed = min(s.max_velocity for s in self.steppers)
max_xy_accel = min(s.max_accel for s in self.steppers)
return max_xy_speed, max_xy_accel
def cartesian_to_actuator(self, coord):
return [int((math.sqrt(self.arm_length2
- (self.towers[i][0] - coord[0])**2

View File

@@ -11,11 +11,13 @@ class PrinterExtruder:
self.heater = heater.PrinterHeater(printer, config)
self.stepper = stepper.PrinterStepper(printer, config, 'extruder')
self.pressure_advance = config.getfloat('pressure_advance', 0.)
self.max_e_velocity = config.getfloat('max_velocity')
self.max_e_accel = config.getfloat('max_accel')
self.need_motor_enable = True
self.extrude_pos = 0.
def build_config(self):
self.heater.build_config()
self.stepper.set_max_jerk(9999999.9)
self.stepper.set_max_jerk(9999999.9, 9999999.9)
self.stepper.build_config()
def motor_off(self, move_time):
self.stepper.motor_enable(move_time, 0)
@@ -28,7 +30,7 @@ class PrinterExtruder:
and not move.axes_d[0] and not move.axes_d[1]
and not move.axes_d[2]):
# Extrude only move - limit accel and velocity
move.limit_speed(self.stepper.max_velocity, self.stepper.max_accel)
move.limit_speed(self.max_e_velocity, self.max_e_accel)
def move(self, move_time, move):
if self.need_motor_enable:
self.stepper.motor_enable(move_time, 1)

View File

@@ -15,9 +15,7 @@ class PrinterStepper:
self.step_dist = config.getfloat('step_distance')
self.inv_step_dist = 1. / self.step_dist
self.max_velocity = config.getfloat('max_velocity')
self.max_accel = config.getfloat('max_accel')
self.max_jerk = 0.
self.min_stop_interval = 0.
self.homing_speed = config.getfloat('homing_speed', 5.0)
self.homing_positive_dir = config.getboolean(
@@ -47,17 +45,16 @@ class PrinterStepper:
self.position_max = config.getfloat('position_max', 0.)
self.need_motor_enable = True
def set_max_jerk(self, max_jerk):
self.max_jerk = max_jerk
def set_max_jerk(self, max_halt_velocity, max_accel):
jc = max_halt_velocity / max_accel
inv_max_step_accel = self.step_dist / max_accel
self.min_stop_interval = (math.sqrt(3.*inv_max_step_accel + jc**2)
- math.sqrt(inv_max_step_accel + jc**2))
def build_config(self):
max_error = self.config.getfloat('max_error', 0.000050)
step_pin = self.config.get('step_pin')
dir_pin = self.config.get('dir_pin')
jc = self.max_jerk / self.max_accel
inv_max_step_accel = self.step_dist / self.max_accel
min_stop_interval = (math.sqrt(3.*inv_max_step_accel + jc**2)
- math.sqrt(inv_max_step_accel + jc**2)) - max_error
min_stop_interval = max(0., min_stop_interval)
min_stop_interval = max(0., self.min_stop_interval - max_error)
mcu = self.printer.mcu
self.mcu_stepper = mcu.create_stepper(
step_pin, dir_pin, min_stop_interval, max_error)

View File

@@ -162,7 +162,8 @@ class ToolHead:
kintypes = {'cartesian': cartesian.CartKinematics,
'delta': delta.DeltaKinematics}
self.kin = config.getchoice('kinematics', kintypes)(printer, config)
self.max_speed, self.max_accel = self.kin.get_max_speed()
self.max_speed = config.getfloat('max_velocity')
self.max_accel = config.getfloat('max_accel')
self.junction_deviation = config.getfloat('junction_deviation', 0.02)
self.move_queue = MoveQueue()
self.commanded_pos = [0., 0., 0., 0.]
@@ -176,6 +177,7 @@ class ToolHead:
self.motor_off_time = self.reactor.NEVER
self.flush_timer = self.reactor.register_timer(self.flush_handler)
def build_config(self):
self.kin.set_max_jerk(0.005 * self.max_accel, self.max_accel) # XXX
self.kin.build_config()
# Print time tracking
def update_move_time(self, movetime):