From eecf3b6ea87e7d9d67e26e965ebf2fe58339484d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 7 Nov 2017 12:12:28 -0500 Subject: [PATCH] stepper: Store pointers to step_const and step_delta in PrinterStepper Signed-off-by: Kevin O'Connor --- klippy/cartesian.py | 12 +++++------- klippy/corexy.py | 12 +++++------- klippy/delta.py | 17 +++++++---------- klippy/extruder.py | 12 +++++------- klippy/stepper.py | 10 ++++++---- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/klippy/cartesian.py b/klippy/cartesian.py index edd7519b..685e0c7e 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -107,7 +107,7 @@ class CartKinematics: axis_d = move.axes_d[i] if not axis_d: continue - mcu_stepper = self.steppers[i].mcu_stepper + step_const = self.steppers[i].step_const move_time = print_time start_pos = move.start_pos[i] axis_r = abs(axis_d) / move.move_d @@ -117,19 +117,17 @@ class CartKinematics: # Acceleration steps if move.accel_r: accel_d = move.accel_r * axis_d - mcu_stepper.step_const( - move_time, start_pos, accel_d, move.start_v * axis_r, accel) + step_const(move_time, start_pos, accel_d, + move.start_v * axis_r, accel) start_pos += accel_d move_time += move.accel_t # Cruising steps if move.cruise_r: cruise_d = move.cruise_r * axis_d - mcu_stepper.step_const( - move_time, start_pos, cruise_d, cruise_v, 0.) + step_const(move_time, start_pos, cruise_d, cruise_v, 0.) start_pos += cruise_d move_time += move.cruise_t # Deceleration steps if move.decel_r: decel_d = move.decel_r * axis_d - mcu_stepper.step_const( - move_time, start_pos, decel_d, cruise_v, -accel) + step_const(move_time, start_pos, decel_d, cruise_v, -accel) diff --git a/klippy/corexy.py b/klippy/corexy.py index 561def5f..d459682a 100644 --- a/klippy/corexy.py +++ b/klippy/corexy.py @@ -122,7 +122,7 @@ class CoreXYKinematics: axis_d = axes_d[i] if not axis_d: continue - mcu_stepper = self.steppers[i].mcu_stepper + step_const = self.steppers[i].step_const move_time = print_time start_pos = move_start_pos[i] axis_r = abs(axis_d) / move.move_d @@ -132,19 +132,17 @@ class CoreXYKinematics: # Acceleration steps if move.accel_r: accel_d = move.accel_r * axis_d - mcu_stepper.step_const( - move_time, start_pos, accel_d, move.start_v * axis_r, accel) + step_const(move_time, start_pos, accel_d, + move.start_v * axis_r, accel) start_pos += accel_d move_time += move.accel_t # Cruising steps if move.cruise_r: cruise_d = move.cruise_r * axis_d - mcu_stepper.step_const( - move_time, start_pos, cruise_d, cruise_v, 0.) + step_const(move_time, start_pos, cruise_d, cruise_v, 0.) start_pos += cruise_d move_time += move.cruise_t # Deceleration steps if move.decel_r: decel_d = move.decel_r * axis_d - mcu_stepper.step_const( - move_time, start_pos, decel_d, cruise_v, -accel) + step_const(move_time, start_pos, decel_d, cruise_v, -accel) diff --git a/klippy/delta.py b/klippy/delta.py index 6e04655e..0d9b92ec 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -201,26 +201,23 @@ class DeltaKinematics: vt_startz = origz # Generate steps - mcu_stepper = self.steppers[i].mcu_stepper + step_delta = self.steppers[i].step_delta move_time = print_time if accel_d: - mcu_stepper.step_delta( - move_time, accel_d, move.start_v, accel, - vt_startz, vt_startxy_d, vt_arm_d, movez_r) + step_delta(move_time, accel_d, move.start_v, accel, + vt_startz, vt_startxy_d, vt_arm_d, movez_r) vt_startz += accel_d * movez_r vt_startxy_d -= accel_d * movexy_r move_time += move.accel_t if cruise_d: - mcu_stepper.step_delta( - move_time, cruise_d, cruise_v, 0., - vt_startz, vt_startxy_d, vt_arm_d, movez_r) + step_delta(move_time, cruise_d, cruise_v, 0., + vt_startz, vt_startxy_d, vt_arm_d, movez_r) vt_startz += cruise_d * movez_r vt_startxy_d -= cruise_d * movexy_r move_time += move.cruise_t if decel_d: - mcu_stepper.step_delta( - move_time, decel_d, cruise_v, -accel, - vt_startz, vt_startxy_d, vt_arm_d, movez_r) + step_delta(move_time, decel_d, cruise_v, -accel, + vt_startz, vt_startxy_d, vt_arm_d, movez_r) ###################################################################### diff --git a/klippy/extruder.py b/klippy/extruder.py index 636fed0b..9403ec4f 100644 --- a/klippy/extruder.py +++ b/klippy/extruder.py @@ -189,29 +189,27 @@ class PrinterExtruder: decel_d -= extra_decel_d # Prepare for steps - mcu_stepper = self.stepper.mcu_stepper + step_const = self.stepper.step_const move_time = print_time # Acceleration steps if accel_d: - mcu_stepper.step_const(move_time, start_pos, accel_d, start_v, accel) + step_const(move_time, start_pos, accel_d, start_v, accel) start_pos += accel_d move_time += accel_t # Cruising steps if cruise_d: - mcu_stepper.step_const(move_time, start_pos, cruise_d, cruise_v, 0.) + step_const(move_time, start_pos, cruise_d, cruise_v, 0.) start_pos += cruise_d move_time += cruise_t # Deceleration steps if decel_d: - mcu_stepper.step_const( - move_time, start_pos, decel_d, decel_v, -accel) + step_const(move_time, start_pos, decel_d, decel_v, -accel) start_pos += decel_d move_time += decel_t # Retraction steps if retract_d: - mcu_stepper.step_const( - move_time, start_pos, -retract_d, retract_v, accel) + step_const(move_time, start_pos, -retract_d, retract_v, accel) start_pos -= retract_d self.extrude_pos = start_pos diff --git a/klippy/stepper.py b/klippy/stepper.py index 473a2435..5370c804 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -12,21 +12,23 @@ class PrinterStepper: self.name = config.section if self.name.startswith('stepper_'): self.name = self.name[8:] - - self.step_dist = config.getfloat('step_distance', above=0.) + self.need_motor_enable = True + # Stepper definition self.mcu_stepper = pins.setup_pin( printer, 'stepper', config.get('step_pin')) dir_pin_params = pins.get_printer_pins(printer).parse_pin_desc( config.get('dir_pin'), can_invert=True) self.mcu_stepper.setup_dir_pin(dir_pin_params) + self.step_dist = config.getfloat('step_distance', above=0.) self.mcu_stepper.setup_step_distance(self.step_dist) - + self.step_const = self.mcu_stepper.step_const + self.step_delta = self.mcu_stepper.step_delta + # Enable pin enable_pin = config.get('enable_pin', None) self.mcu_enable = None if enable_pin is not None: self.mcu_enable = pins.setup_pin(printer, 'digital_out', enable_pin) self.mcu_enable.setup_max_duration(0.) - self.need_motor_enable = True def _dist_to_time(self, dist, start_velocity, accel): # Calculate the time it takes to travel a distance with constant accel time_offset = start_velocity / accel