resonance_tester: Set max_accel ignoring the limit from the config (#4174)

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
Dmitry Butyugin 2021-06-06 19:04:53 +02:00 committed by GitHub
parent e0e8615aaf
commit 4596a244e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 26 deletions

View File

@ -139,17 +139,7 @@ noisy imbalanced fans on a 3D printer.
## Measuring the resonances ## Measuring the resonances
Now you can run some real-life tests. In `printer.cfg` add or replace the Now you can run some real-life tests. Run the following command:
following values:
```
[printer]
max_accel: 10000
max_accel_to_decel: 10000
```
(after you are done with the measurements, revert these values to their old,
or the newly suggested values).
Run the following command:
``` ```
TEST_RESONANCES AXIS=X TEST_RESONANCES AXIS=X
``` ```

View File

@ -32,25 +32,30 @@ class VibrationPulseTest:
return ['x', 'y'] return ['x', 'y']
def get_start_test_points(self): def get_start_test_points(self):
return self.probe_points return self.probe_points
def prepare_test(self, toolhead, gcmd): def prepare_test(self, gcmd):
self.freq_start = gcmd.get_float("FREQ_START", self.min_freq, minval=1.) self.freq_start = gcmd.get_float("FREQ_START", self.min_freq, minval=1.)
self.freq_end = gcmd.get_float("FREQ_END", self.max_freq, self.freq_end = gcmd.get_float("FREQ_END", self.max_freq,
minval=self.freq_start, maxval=200.) minval=self.freq_start, maxval=200.)
self.hz_per_sec = gcmd.get_float("HZ_PER_SEC", self.hz_per_sec, self.hz_per_sec = gcmd.get_float("HZ_PER_SEC", self.hz_per_sec,
above=0., maxval=2.) above=0., maxval=2.)
# Attempt to adjust maximum acceleration and acceleration to def run_test(self, axis, gcmd):
# deceleration based on the maximum test frequency. toolhead = self.printer.lookup_object('toolhead')
max_accel = self.freq_end * self.accel_per_hz
toolhead.cmd_SET_VELOCITY_LIMIT(self.gcode.create_gcode_command(
"SET_VELOCITY_LIMIT", "SET_VELOCITY_LIMIT",
{"ACCEL": max_accel, "ACCEL_TO_DECEL": max_accel}))
def run_test(self, toolhead, axis, gcmd):
X, Y, Z, E = toolhead.get_position() X, Y, Z, E = toolhead.get_position()
if axis not in self.get_supported_axes(): if axis not in self.get_supported_axes():
raise gcmd.error("Test axis '%s' is not supported", axis) raise gcmd.error("Test axis '%s' is not supported", axis)
vib_dir = (1, 0) if axis == 'x' else (0., 1.) vib_dir = (1, 0) if axis == 'x' else (0., 1.)
sign = 1. sign = 1.
freq = self.freq_start freq = self.freq_start
# Override maximum acceleration and acceleration to
# deceleration based on the maximum test frequency
systime = self.printer.get_reactor().monotonic()
toolhead_info = toolhead.get_status(systime)
old_max_accel = toolhead_info['max_accel']
old_max_accel_to_decel = toolhead_info['max_accel_to_decel']
max_accel = self.freq_end * self.accel_per_hz
self.gcode.run_script_from_command(
"SET_VELOCITY_LIMIT ACCEL=%.3f ACCEL_TO_DECEL=%.3f" % (
max_accel, max_accel))
input_shaper = self.printer.lookup_object('input_shaper', None) input_shaper = self.printer.lookup_object('input_shaper', None)
if input_shaper is not None and not gcmd.get_int('INPUT_SHAPING', 0): if input_shaper is not None and not gcmd.get_int('INPUT_SHAPING', 0):
input_shaper.disable_shaping() input_shaper.disable_shaping()
@ -58,23 +63,26 @@ class VibrationPulseTest:
else: else:
input_shaper = None input_shaper = None
gcmd.respond_info("Testing frequency %.0f Hz" % (freq,)) gcmd.respond_info("Testing frequency %.0f Hz" % (freq,))
_, max_accel = toolhead.get_max_velocity()
while freq <= self.freq_end + 0.000001: while freq <= self.freq_end + 0.000001:
t_seg = .25 / freq t_seg = .25 / freq
accel = min(self.accel_per_hz * freq, max_accel) accel = self.accel_per_hz * freq
V = accel * t_seg max_v = accel * t_seg
toolhead.cmd_M204(self.gcode.create_gcode_command( toolhead.cmd_M204(self.gcode.create_gcode_command(
"M204", "M204", {"S": accel})) "M204", "M204", {"S": accel}))
L = .5 * accel * t_seg**2 L = .5 * accel * t_seg**2
nX = X + sign * vib_dir[0] * L nX = X + sign * vib_dir[0] * L
nY = Y + sign * vib_dir[1] * L nY = Y + sign * vib_dir[1] * L
toolhead.move([nX, nY, Z, E], V) toolhead.move([nX, nY, Z, E], max_v)
toolhead.move([X, Y, Z, E], V) toolhead.move([X, Y, Z, E], max_v)
sign = -sign sign = -sign
old_freq = freq old_freq = freq
freq += 2. * t_seg * self.hz_per_sec freq += 2. * t_seg * self.hz_per_sec
if math.floor(freq) > math.floor(old_freq): if math.floor(freq) > math.floor(old_freq):
gcmd.respond_info("Testing frequency %.0f Hz" % (freq,)) gcmd.respond_info("Testing frequency %.0f Hz" % (freq,))
# Restore the original acceleration values
self.gcode.run_script_from_command(
"SET_VELOCITY_LIMIT ACCEL=%.3f ACCEL_TO_DECEL=%.3f" % (
old_max_accel, old_max_accel_to_decel))
# Restore input shaper if it was disabled for resonance testing # Restore input shaper if it was disabled for resonance testing
if input_shaper is not None: if input_shaper is not None:
input_shaper.enable_shaping() input_shaper.enable_shaping()
@ -116,7 +124,7 @@ class ResonanceTester:
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
calibration_data = {axis: None for axis in axes} calibration_data = {axis: None for axis in axes}
self.test.prepare_test(toolhead, gcmd) self.test.prepare_test(gcmd)
test_points = self.test.get_start_test_points() test_points = self.test.get_start_test_points()
for point in test_points: for point in test_points:
toolhead.manual_move(point, self.move_speed) toolhead.manual_move(point, self.move_speed)
@ -133,7 +141,7 @@ class ResonanceTester:
if axis in chip_axis or chip_axis in axis: if axis in chip_axis or chip_axis in axis:
chip.start_measurements() chip.start_measurements()
# Generate moves # Generate moves
self.test.run_test(toolhead, axis, gcmd) self.test.run_test(axis, gcmd)
raw_values = [] raw_values = []
for chip_axis, chip in self.accel_chips: for chip_axis, chip in self.accel_chips:
if axis in chip_axis or chip_axis in axis: if axis in chip_axis or chip_axis in axis: