This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix M909 (set microstepping) and M92 (set steps per mm)
- remove Printer.steps_pr_meter because it's redundant with Stepper.microsteps - remove callback from Stepper to Printer to update steps_pr_meter - remove redundant microstepping bounds check from M909 - the Steppers can do this themselves - add microstepping bounds check to B-series Steppers to match the A-series - update steps per mm in M92 correctly (instead of restarting the path planner, which doesn't help) - add tests for M909 and M92 - revise PathPlanner::setAxisStepsPerMeter to preserve the current location of the printer Validated on the hardware - you can now change microstepping settings without losing printer positioning. If no one objects I'd like to take an IOU on test coverage for the PathPlanner bits - that interface is about to be significantly refactored anyway to make probing more flexible. Fixes #188
- Loading branch information
1 parent
d08cc19
commit 4b0a83f
Showing
10 changed files
with
170 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from __future__ import absolute_import | ||
|
||
from .MockPrinter import MockPrinter | ||
from numpy.testing import assert_array_equal | ||
import numpy | ||
import mock | ||
|
||
|
||
class M909_Tests(MockPrinter): | ||
def setUp(self): | ||
self.steps_pr_mm = {} | ||
self.microstep_configs = {} | ||
|
||
for axis, stepper in self.printer.steppers.items(): | ||
self.steps_pr_mm[axis] = stepper.steps_pr_mm | ||
self.microstep_configs[axis] = stepper.microstepping | ||
|
||
self.printer.path_planner.update_steps_pr_meter = mock.Mock() | ||
|
||
def _check_microsteps_pr_meter(self): | ||
# first we check just the microstep configs because this makes failures easier to diagnose | ||
printer_microstep_configs = numpy.ones(self.printer.num_axes) | ||
expected_microstep_configs = numpy.ones(self.printer.num_axes) | ||
for axis, stepper in self.printer.steppers.items(): | ||
index = self.printer.axis_to_index(axis) | ||
printer_microstep_configs[index] = stepper.microstepping | ||
expected_microstep_configs[index] = self.microstep_configs[axis] | ||
|
||
assert_array_equal(expected_microstep_configs, printer_microstep_configs) | ||
|
||
# next check the final multiplied microsteps per mm | ||
printer_microsteps = [val / 1000.0 for val in self.printer.get_steps_pr_meter()] | ||
expected_microsteps = [] | ||
|
||
for axis_num in range(self.printer.num_axes): | ||
axis = self.printer.index_to_axis(axis_num) | ||
expected_microsteps.append(self.steps_pr_mm[axis] * | ||
self.microstep_config_to_multiplier[self.microstep_configs[axis]]) | ||
|
||
assert_array_equal(expected_microsteps, printer_microsteps) | ||
|
||
def test_gcodes_M909_noop(self): | ||
self.printer.path_planner.update_steps_pr_meter.assert_not_called() | ||
self._check_microsteps_pr_meter() | ||
self.execute_gcode("M909") | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M909_X0_Y1_E2(self): | ||
self.execute_gcode("M909 X0 Y1 E2") | ||
self.microstep_configs['X'] = 0 | ||
self.microstep_configs['Y'] = 1 | ||
self.microstep_configs['E'] = 2 | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M909_H5_E4_Z2(self): | ||
self.execute_gcode("M909 H5 E4 Z2") | ||
self.microstep_configs['H'] = 5 | ||
self.microstep_configs['E'] = 4 | ||
self.microstep_configs['Z'] = 2 | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M909_X20(self): | ||
self.execute_gcode("M909 X20") | ||
# should be a no-op | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M909_Xneg(self): | ||
self.execute_gcode("M909 X-1") | ||
# should be a no-op | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from __future__ import absolute_import | ||
|
||
from .MockPrinter import MockPrinter | ||
from numpy.testing import assert_array_equal | ||
import mock | ||
|
||
|
||
class M92_Tests(MockPrinter): | ||
def setUp(self): | ||
self.steps_pr_mm = {} | ||
|
||
for axis, stepper in self.printer.steppers.items(): | ||
self.steps_pr_mm[axis] = stepper.steps_pr_mm | ||
stepper.set_microstepping(0) | ||
|
||
self.printer.path_planner.update_steps_pr_meter = mock.Mock() | ||
|
||
def _check_microsteps_pr_meter(self): | ||
# to make the test output easier to read, we actually convert from meters to millimeters | ||
printer_microsteps = [val / 1000.0 for val in self.printer.get_steps_pr_meter()] | ||
expected_microsteps = [ | ||
self.steps_pr_mm[self.printer.index_to_axis(axis_num)] | ||
for axis_num in range(self.printer.num_axes) | ||
] | ||
|
||
assert_array_equal(expected_microsteps, printer_microsteps) | ||
|
||
def test_gcodes_M92_noop(self): | ||
self.printer.path_planner.update_steps_pr_meter.assert_not_called() | ||
self._check_microsteps_pr_meter() | ||
self.execute_gcode("M92") | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M92_X5_Z200_H50000(self): | ||
self.execute_gcode("M92 X5 Z200.0 H50000.0000") | ||
self.steps_pr_mm['X'] = 5.0 | ||
self.steps_pr_mm['Z'] = 200.0 | ||
self.steps_pr_mm['H'] = 50000.0 | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M92_E0_001_H0_0050(self): | ||
self.execute_gcode("M92 E0.001 H0.0050") | ||
self.steps_pr_mm['E'] = 0.001 | ||
self.steps_pr_mm['H'] = 0.0050 | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M92_Yneg_Zneg(self): | ||
self.execute_gcode("M92 Y-0.05 Z-2") | ||
# should be a no-op | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() | ||
|
||
def test_gcodes_M92_Xneg_Y8_44(self): | ||
self.execute_gcode("M92 X-22 Y8.44") | ||
# negative X is ignored | ||
self.steps_pr_mm['Y'] = 8.44 | ||
self._check_microsteps_pr_meter() | ||
self.printer.path_planner.update_steps_pr_meter.assert_called_once() |