diff options
author | Mikkel Schmidt <mikkel.schmidt@gmail.com> | 2022-05-24 01:56:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-23 19:56:58 -0400 |
commit | af38d708cb3fad993422b8cf6bf4880acda568a3 (patch) | |
tree | 4f91fad6a1379511f0975a0a934bc494a490278f /klippy/extras | |
parent | c7e0372c5de4680760721674dc86959dc5d239ec (diff) | |
download | kutter-af38d708cb3fad993422b8cf6bf4880acda568a3.tar.gz kutter-af38d708cb3fad993422b8cf6bf4880acda568a3.tar.xz kutter-af38d708cb3fad993422b8cf6bf4880acda568a3.zip |
adxl345: Support recording data from multiple ADXL345's in one run, and more. (#5224)
Add PROBE and CHIP to TEST_RESONANCES
Since it's possible to specify more than one chip
in TEST_RESONANCES the CHIP parameter has been
renamed to CHIPS
Signed-off-by: Mikkel Schmidt <mikkel.schmidt@gmail.com>
Diffstat (limited to 'klippy/extras')
-rw-r--r-- | klippy/extras/resonance_tester.py | 77 |
1 files changed, 60 insertions, 17 deletions
diff --git a/klippy/extras/resonance_tester.py b/klippy/extras/resonance_tester.py index 00797156..db03e320 100644 --- a/klippy/extras/resonance_tester.py +++ b/klippy/extras/resonance_tester.py @@ -147,15 +147,21 @@ class ResonanceTester: (chip_axis, self.printer.lookup_object(chip_name)) for chip_axis, chip_name in self.accel_chip_names] - def _run_test(self, gcmd, axes, helper, raw_name_suffix=None): + def _run_test(self, gcmd, axes, helper, raw_name_suffix=None, + accel_chips=None, test_point=None): toolhead = self.printer.lookup_object('toolhead') calibration_data = {axis: None for axis in axes} self.test.prepare_test(gcmd) - test_points = self.test.get_start_test_points() + + if test_point is not None: + test_points = [test_point] + else: + test_points = self.test.get_start_test_points() + for point in test_points: toolhead.manual_move(point, self.move_speed) - if len(test_points) > 1: + if len(test_points) > 1 or test_point is not None: gcmd.respond_info( "Probing point (%.3f, %.3f, %.3f)" % tuple(point)) for axis in axes: @@ -165,29 +171,36 @@ class ResonanceTester: gcmd.respond_info("Testing axis %s" % axis.get_name()) raw_values = [] - for chip_axis, chip in self.accel_chips: - if axis.matches(chip_axis): + if accel_chips is None: + for chip_axis, chip in self.accel_chips: + if axis.matches(chip_axis): + aclient = chip.start_internal_client() + raw_values.append((chip_axis, aclient, chip.name)) + else: + for chip in accel_chips: aclient = chip.start_internal_client() - raw_values.append((chip_axis, aclient)) + raw_values.append((axis, aclient, chip.name)) + # Generate moves self.test.run_test(axis, gcmd) - for chip_axis, aclient in raw_values: + for chip_axis, aclient, chip_name in raw_values: aclient.finish_measurements() if raw_name_suffix is not None: raw_name = self.get_filename( 'raw_data', raw_name_suffix, axis, - point if len(test_points) > 1 else None) + point if len(test_points) > 1 else None, + chip_name if accel_chips is not None else None,) aclient.write_to_file(raw_name) gcmd.respond_info( "Writing raw accelerometer data to " "%s file" % (raw_name,)) if helper is None: continue - for chip_axis, aclient in raw_values: + for chip_axis, aclient, chip_name in raw_values: if not aclient.has_valid_samples(): raise gcmd.error( - "%s-axis accelerometer measured no data" % ( - chip_axis,)) + "accelerometer '%s' measured no data" % ( + chip_name,)) new_data = helper.process_accelerometer_data(aclient) if calibration_data[axis] is None: calibration_data[axis] = new_data @@ -198,6 +211,28 @@ class ResonanceTester: def cmd_TEST_RESONANCES(self, gcmd): # Parse parameters axis = _parse_axis(gcmd, gcmd.get("AXIS").lower()) + accel_chips = gcmd.get("CHIPS", None) + test_point = gcmd.get("POINT", None) + + if test_point: + test_coords = test_point.split(',') + if len(test_coords) != 3: + raise gcmd.error("Invalid POINT parameter, must be 'x,y,z'") + try: + test_point = [float(p.strip()) for p in test_coords] + except ValueError: + 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) outputs = gcmd.get("OUTPUT", "resonances").lower().split(',') for output in outputs: @@ -221,10 +256,13 @@ class ResonanceTester: data = self._run_test( gcmd, [axis], helper, - raw_name_suffix=name_suffix if raw_output else None)[axis] + raw_name_suffix=name_suffix if raw_output else None, + accel_chips=parsed_chips if accel_chips else None, + test_point=test_point)[axis] if csv_output: csv_name = self.save_calibration_data('resonances', name_suffix, - helper, axis, data) + helper, axis, data, + point=test_point) gcmd.respond_info( "Resonances data written to %s file" % (csv_name,)) cmd_SHAPER_CALIBRATE_help = ( @@ -287,7 +325,8 @@ class ResonanceTester: for chip_axis, aclient in raw_values: if not aclient.has_valid_samples(): raise gcmd.error( - "%s-axis accelerometer measured no data" % (chip_axis,)) + "%s-axis accelerometer measured no data" % ( + chip_axis,)) data = helper.process_accelerometer_data(aclient) vx = data.psd_x.mean() vy = data.psd_y.mean() @@ -299,18 +338,22 @@ class ResonanceTester: def is_valid_name_suffix(self, name_suffix): return name_suffix.replace('-', '').replace('_', '').isalnum() - def get_filename(self, base, name_suffix, axis=None, point=None): + def get_filename(self, base, name_suffix, axis=None, + point=None, chip_name=None): name = base if axis: name += '_' + axis.get_name() + if chip_name: + name += '_' + chip_name.replace(" ", "_") if point: name += "_%.3f_%.3f_%.3f" % (point[0], point[1], point[2]) name += '_' + name_suffix return os.path.join("/tmp", name + ".csv") def save_calibration_data(self, base_name, name_suffix, shaper_calibrate, - axis, calibration_data, all_shapers=None): - output = self.get_filename(base_name, name_suffix, axis) + axis, calibration_data, + all_shapers=None, point=None): + output = self.get_filename(base_name, name_suffix, axis, point) shaper_calibrate.save_calibration_data(output, calibration_data, all_shapers) return output |