Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gbkwiatt/klipper-idex; br…
Browse files Browse the repository at this point in the history
  • Loading branch information
gbkwiatt committed May 28, 2023
2 parents 3b29aff + 5f0d252 commit 224ae9e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docs/Config_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ All dates in this document are approximate.

## Changes

20230525: `SHAPER_CALIBRATE` command immediately applies input shaper
parameters if `[input_shaper]` was enabled already.

20230407: The `stalled_bytes` counter in the log and in the
`printer.mcu.last_stats` field has been renamed to `upcoming_bytes`.

Expand Down
6 changes: 4 additions & 2 deletions docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ frequency response is calculated (across all probe points) and written into

#### SHAPER_CALIBRATE
`SHAPER_CALIBRATE [AXIS=<axis>] [NAME=<name>] [FREQ_START=<min_freq>]
[FREQ_END=<max_freq>] [HZ_PER_SEC=<hz_per_sec>]
[FREQ_END=<max_freq>] [HZ_PER_SEC=<hz_per_sec>] [CHIPS=<adxl345_chip_name>]
[MAX_SMOOTHING=<max_smoothing>]`: Similarly to `TEST_RESONANCES`, runs
the resonance test as configured, and tries to find the optimal
parameters for the input shaper for the requested axis (or both X and
Expand All @@ -1067,7 +1067,9 @@ frequency responses and the different input shapers values are written
to a CSV file(s) `/tmp/calibration_data_<axis>_<name>.csv`. Unless
specified, NAME defaults to the current time in "YYYYMMDD_HHMMSS"
format. Note that the suggested input shaper parameters can be
persisted in the config by issuing `SAVE_CONFIG` command.
persisted in the config by issuing `SAVE_CONFIG` command, and if
`[input_shaper]` was already enabled previously, these parameters
take effect immediately.

### [respond]

Expand Down
35 changes: 22 additions & 13 deletions klippy/extras/resonance_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,21 @@ def _run_test(self, gcmd, axes, helper, raw_name_suffix=None,
else:
calibration_data[axis].add_data(new_data)
return calibration_data
def _parse_chips(self, accel_chips):
parsed_chips = []
for chip_name in accel_chips.split(','):
if "adxl345" in chip_name:
chip_lookup_name = chip_name.strip()
else:
chip_lookup_name = "adxl345 " + chip_name.strip();
chip = self.printer.lookup_object(chip_lookup_name)
parsed_chips.append(chip)
return parsed_chips
cmd_TEST_RESONANCES_help = ("Runs the resonance test for a specifed axis")
def cmd_TEST_RESONANCES(self, gcmd):
# Parse parameters
axis = _parse_axis(gcmd, gcmd.get("AXIS").lower())
accel_chips = gcmd.get("CHIPS", None)
chips_str = gcmd.get("CHIPS", None)
test_point = gcmd.get("POINT", None)

if test_point:
Expand All @@ -224,15 +234,7 @@ def cmd_TEST_RESONANCES(self, gcmd):
raise gcmd.error("Invalid POINT parameter, must be 'x,y,z'"
" where x, y and z are valid floating point numbers")

if accel_chips:
parsed_chips = []
for chip_name in accel_chips.split(','):
if "adxl345" in chip_name:
chip_lookup_name = chip_name.strip()
else:
chip_lookup_name = "adxl345 " + chip_name.strip();
chip = self.printer.lookup_object(chip_lookup_name)
parsed_chips.append(chip)
accel_chips = self._parse_chips(chips_str) if chips_str else None

outputs = gcmd.get("OUTPUT", "resonances").lower().split(',')
for output in outputs:
Expand All @@ -257,8 +259,7 @@ def cmd_TEST_RESONANCES(self, gcmd):
data = self._run_test(
gcmd, [axis], helper,
raw_name_suffix=name_suffix if raw_output else None,
accel_chips=parsed_chips if accel_chips else None,
test_point=test_point)[axis]
accel_chips=accel_chips, test_point=test_point)[axis]
if csv_output:
csv_name = self.save_calibration_data('resonances', name_suffix,
helper, axis, data,
Expand All @@ -276,6 +277,8 @@ def cmd_SHAPER_CALIBRATE(self, gcmd):
raise gcmd.error("Unsupported axis '%s'" % (axis,))
else:
calibrate_axes = [TestAxis(axis.lower())]
chips_str = gcmd.get("CHIPS", None)
accel_chips = self._parse_chips(chips_str) if chips_str else None

max_smoothing = gcmd.get_float(
"MAX_SMOOTHING", self.max_smoothing, minval=0.05)
Expand All @@ -284,10 +287,13 @@ def cmd_SHAPER_CALIBRATE(self, gcmd):
if not self.is_valid_name_suffix(name_suffix):
raise gcmd.error("Invalid NAME parameter")

input_shaper = self.printer.lookup_object('input_shaper', None)

# Setup shaper calibration
helper = shaper_calibrate.ShaperCalibrate(self.printer)

calibration_data = self._run_test(gcmd, calibrate_axes, helper)
calibration_data = self._run_test(gcmd, calibrate_axes, helper,
accel_chips=accel_chips)

configfile = self.printer.lookup_object('configfile')
for axis in calibrate_axes:
Expand All @@ -302,6 +308,9 @@ def cmd_SHAPER_CALIBRATE(self, gcmd):
"Recommended shaper_type_%s = %s, shaper_freq_%s = %.1f Hz"
% (axis_name, best_shaper.name,
axis_name, best_shaper.freq))
if input_shaper is not None:
helper.apply_params(input_shaper, axis_name,
best_shaper.name, best_shaper.freq)
helper.save_params(configfile, axis_name,
best_shaper.name, best_shaper.freq)
csv_name = self.save_calibration_data(
Expand Down
12 changes: 12 additions & 0 deletions klippy/extras/shaper_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ def save_params(self, configfile, axis, shaper_name, shaper_freq):
configfile.set('input_shaper', 'shaper_freq_'+axis,
'%.1f' % (shaper_freq,))

def apply_params(self, input_shaper, axis, shaper_name, shaper_freq):
if axis == 'xy':
self.apply_params(input_shaper, 'x', shaper_name, shaper_freq)
self.apply_params(input_shaper, 'y', shaper_name, shaper_freq)
return
gcode = self.printer.lookup_object("gcode")
axis = axis.upper()
input_shaper.cmd_SET_INPUT_SHAPER(gcode.create_gcode_command(
"SET_INPUT_SHAPER", "SET_INPUT_SHAPER", {
"SHAPER_TYPE_" + axis: shaper_name,
"SHAPER_FREQ_" + axis: shaper_freq}))

def save_calibration_data(self, output, calibration_data, shapers=None):
try:
with open(output, "w") as csvfile:
Expand Down
6 changes: 5 additions & 1 deletion klippy/kinematics/hybrid_corexy.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def calc_position(self, stepper_positions):
else:
return [pos[0] + pos[1], pos[1], pos[2]]
def update_limits(self, i, range):
self.limits[i] = range
l, h = self.limits[i]
# Only update limits if this axis was already homed,
# otherwise leave in un-homed state.
if l <= h:
self.limits[i] = range
def override_rail(self, i, rail):
self.rails[i] = rail
def set_position(self, newpos, homing_axes):
Expand Down
6 changes: 5 additions & 1 deletion klippy/kinematics/hybrid_corexz.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def calc_position(self, stepper_positions):
else:
return [pos[0] + pos[2], pos[1], pos[2]]
def update_limits(self, i, range):
self.limits[i] = range
l, h = self.limits[i]
# Only update limits if this axis was already homed,
# otherwise leave in un-homed state.
if l <= h:
self.limits[i] = range
def override_rail(self, i, rail):
self.rails[i] = rail
def set_position(self, newpos, homing_axes):
Expand Down

0 comments on commit 224ae9e

Please sign in to comment.