diff --git a/config/example-delta.cfg b/config/example-delta.cfg index 777f7dc2..5954be68 100644 --- a/config/example-delta.cfg +++ b/config/example-delta.cfg @@ -16,8 +16,6 @@ step_pin: ar54 dir_pin: ar55 enable_pin: !ar38 step_distance: .01 -max_velocity: 200 -max_accel: 3000 endstop_pin: ^ar2 homing_speed: 50.0 position_endstop: 297.05 @@ -30,8 +28,6 @@ step_pin: ar60 dir_pin: ar61 enable_pin: !ar56 step_distance: .01 -max_velocity: 200 -max_accel: 3000 endstop_pin: ^ar15 position_endstop: 297.05 @@ -42,8 +38,6 @@ step_pin: ar46 dir_pin: ar48 enable_pin: !ar62 step_distance: .01 -max_velocity: 200 -max_accel: 3000 endstop_pin: ^ar19 position_endstop: 297.05 @@ -85,6 +79,8 @@ pin_map: arduino [printer] kinematics: delta # This option must be "delta" for linear delta printers +max_velocity: 200 +max_accel: 3000 delta_arm_length: 333.0 # Length (in mm) of the diagonal rods that connect the linear axes # to the print head diff --git a/config/example.cfg b/config/example.cfg index 1bc1dd59..c1807581 100644 --- a/config/example.cfg +++ b/config/example.cfg @@ -26,10 +26,6 @@ enable_pin: !ar25 # Enable pin (default is enable high; use ! to indicate enable low) step_distance: .0225 # Distance in mm that each step causes the axis to travel -max_velocity: 500 -# Maximum velocity (in mm/s) of the stepper -max_accel: 3000 -# Maximum acceleration (in mm/s^2) of the stepper endstop_pin: ^ar0 # Endstop switch detection pin homing_speed: 50.0 @@ -75,8 +71,6 @@ step_pin: ar27 dir_pin: ar26 enable_pin: !ar25 step_distance: .0225 -max_velocity: 500 -max_accel: 3000 endstop_pin: ^ar1 position_min: -0.25 position_endstop: 0 @@ -90,8 +84,6 @@ step_pin: ar23 dir_pin: !ar22 enable_pin: !ar25 step_distance: .005 -max_velocity: 250 -max_accel: 30 endstop_pin: ^ar2 position_min: 0.1 position_endstop: 0.5 @@ -108,7 +100,12 @@ dir_pin: ar18 enable_pin: !ar25 step_distance: .004242 max_velocity: 200000 +# Maximum velocity (in mm/s) of the extruder motor for extrude only +# moves. max_accel: 3000 +# Maximum acceleration (in mm/s^2) of the extruder motor for extrude +# only moves. +# # The remaining variables describe the extruder heater pressure_advance: 0.0 # The amount of raw filament to push into the extruder during @@ -191,6 +188,20 @@ custom: [printer] kinematics: cartesian # This option must be "cartesian" for cartesian printers +max_velocity: 500 +# Maximum velocity (in mm/s) of the toolhead (relative to the +# print) +max_accel: 3000 +# Maximum acceleration (in mm/s^2) of the toolhead (relative to the +# print) +max_z_velocity: 250 +# For cartesian printers this sets the maximum velocity (in mm/s) of +# movement along the z axis. This setting can be used to restrict +# the maximum speed of the z stepper motor on cartesian printers. +max_z_accel: 30 +# For cartesian printers this sets the maximum acceleration (in +# mm/s^2) of movement along the z axis. It limits the acceleration +# of the z stepper motor on cartesian printers. motor_off_time: 60 # Time (in seconds) of idle time before the printer will try to # disable active motors. diff --git a/config/makergear-m2-2012.cfg b/config/makergear-m2-2012.cfg index 5634c580..c89f6714 100644 --- a/config/makergear-m2-2012.cfg +++ b/config/makergear-m2-2012.cfg @@ -8,8 +8,6 @@ step_pin: PC0 dir_pin: !PL1 enable_pin: !PA7 step_distance: .0225 -max_velocity: 500 -max_accel: 3000 endstop_pin: ^!PB6 homing_speed: 50.0 homing_stepper_phases: 32 @@ -23,8 +21,6 @@ step_pin: PC1 dir_pin: PL0 enable_pin: !PA6 step_distance: .0225 -max_velocity: 500 -max_accel: 3000 endstop_pin: ^!PB5 homing_speed: 50.0 homing_stepper_phases: 32 @@ -38,8 +34,6 @@ step_pin: PC2 dir_pin: !PL2 enable_pin: !PA5 step_distance: .005 -max_velocity: 250 -max_accel: 30 endstop_pin: ^!PB4 homing_speed: 4.0 homing_retract_dist: 2.0 @@ -105,4 +99,8 @@ custom: [printer] kinematics: cartesian +max_velocity: 500 +max_accel: 3000 +max_z_velocity: 250 +max_z_accel: 30 motor_off_time: 600 diff --git a/klippy/cartesian.py b/klippy/cartesian.py index 09a2a094..50946f03 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -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) diff --git a/klippy/delta.py b/klippy/delta.py index 27290aac..3b2ad674 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -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 diff --git a/klippy/extruder.py b/klippy/extruder.py index 0ca57eba..7d5a952d 100644 --- a/klippy/extruder.py +++ b/klippy/extruder.py @@ -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) diff --git a/klippy/stepper.py b/klippy/stepper.py index f770afdb..71a5c8c6 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -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) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index e173f279..ec215d6b 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -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):