Skip to content

Commit

Permalink
rework sensorless rehome; check traveled distance (with tolerance (#110)
Browse files Browse the repository at this point in the history
config)

Co-authored-by: Brandon Nance <[email protected]>
  • Loading branch information
rogerlz and bwnance authored Dec 20, 2023
1 parent 17c6d64 commit 544e3ee
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 42 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ If I want my printer to light itself on fire, I should be able to make my printe

- [danger_options: expose the multi mcu homing timeout as a parameter](https://github.com/DangerKlippers/danger-klipper/pull/93)

- [danger_options: option to configure the homing elapsed distance tolerance](https://github.com/DangerKlippers/danger-klipper/pull/110)

- [temperature_mcu: add reference_voltage](https://github.com/DangerKlippers/danger-klipper/pull/99) ([klipper#5713](https://github.com/Klipper3d/klipper/pull/5713))

- [stepper: current_change_dwell_time](https://github.com/DangerKlippers/danger-klipper/pull/90)
Expand Down
78 changes: 44 additions & 34 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,43 @@ pins such as "extra_mcu:ar9" may then be used elsewhere in the config
[mcu my_extra_mcu]
# See the "mcu" section for configuration parameters.
```

## ⚠️ Danger Options

A collection of DangerKlipper-specific system options

```
[danger_options]
# If an unused config option or section should cause an error
# if False, will warn but allow klipper to still run
error_on_unused_config_options: True
# If statistics should be logged
# (helpful for keeping the log clean during development)
log_statistics: True
# If the config file should be logged at startup
log_config_file_at_startup: True
# If the bed mesh should be logged on startup
# (helpful for keeping the log clean during development)
log_bed_mesh_at_startup: True
# If we should log detailed crash info when an exception occurs
# Most of it is overly-verbose and fluff and we still get a stack trace
# for normal exceptions, so setting to False can help save time while developing
log_shutdown_info: True
# Allows modules in `plugins` to override modules of the same name in `extras`
allow_plugin_override: False
# The timeout (in seconds) for MCU synchronization during the homing process when multiple MCUs are in use.
multi_mcu_trsync_timeout: 0.025
#error_on_unused_config_options: True
# If an unused config option or section should cause an error
# if False, will warn but allow klipper to still run.
# The default is True.
#log_statistics: True
# If statistics should be logged
# (helpful for keeping the log clean during development)
# The default is True.
#log_config_file_at_startup: True
# If the config file should be logged at startup
# The default is True.
#log_bed_mesh_at_startup: True
# If the bed mesh should be logged on startup
# (helpful for keeping the log clean during development)
# The default is True.
#log_shutdown_info: True
# If we should log detailed crash info when an exception occurs
# Most of it is overly-verbose and fluff and we still get a stack trace
# for normal exceptions, so setting to False can help save time while developing
# The default is True.
#allow_plugin_override: False
# Allows modules in `plugins` to override modules of the same name in `extras`
# The default is False.
#multi_mcu_trsync_timeout: 0.025
# The timeout (in seconds) for MCU synchronization during the homing process when
# multiple MCUs are in use. The default is 0.025
#homing_elapsed_distance_tolerance: 0.5
# Tolerance (in mm) for distance moved in the second homing. Ensures the
# second homing distance closely matches the `min_home_dist` when using
# sensorless homing. The default is 0.5mm.
```

## Common kinematic settings
Expand Down Expand Up @@ -365,7 +372,7 @@ example deltesian kinematics config file.

Only parameters specific to deltesian printers are described here - see
[common kinematic settings](#common-kinematic-settings) for available
parameters.
parameters.

```
[printer]
Expand Down Expand Up @@ -914,6 +921,7 @@ See the [bed mesh guide](Bed_Mesh.md) and
[command reference](G-Codes.md#bed_mesh) for additional information.

Visual Examples:

```
rectangular bed, probe_count = 3, 3:
x---x---x (max_point)
Expand Down Expand Up @@ -1241,7 +1249,6 @@ extended [G-Code command](G-Codes.md#z_tilt) becomes available.
# The default is conservative.
```


### [quad_gantry_level]

Moving gantry leveling using 4 independently controlled Z motors.
Expand All @@ -1251,6 +1258,7 @@ WARNING: Using this on a moving bed may lead to undesirable results.
If this section is present then a QUAD_GANTRY_LEVEL extended G-Code
command becomes available. This routine assumes the following Z motor
configuration:

```
----------------
|Z1 Z2|
Expand All @@ -1261,6 +1269,7 @@ configuration:
|Z Z3|
----------------
```

Where x is the 0, 0 point on the bed

```
Expand Down Expand Up @@ -1669,6 +1678,7 @@ Enable the "M118" and "RESPOND" extended
```

### [exclude_object]

Enables support to exclude or cancel individual objects during the printing
process.

Expand Down Expand Up @@ -1885,7 +1895,7 @@ aliases_<name>:

Include file support. One may include additional config file from the
main printer config file. Wildcards may also be used (eg,
"configs/*.cfg").
"configs/\*.cfg").

```
[include my_other_config.cfg]
Expand Down Expand Up @@ -4890,8 +4900,8 @@ Octoprint as they will conflict, and 1 will fail to initialize
properly likely aborting your print.

If you use Octoprint and stream gcode over the serial port instead of
printing from virtual_sd, then remo **M1** and **M0** from *Pausing commands*
in *Settings > Serial Connection > Firmware & protocol* will prevent
printing from virtual_sd, then remo **M1** and **M0** from _Pausing commands_
in _Settings > Serial Connection > Firmware & protocol_ will prevent
the need to start print on the Palette 2 and unpausing in Octoprint
for your print to begin.

Expand All @@ -4914,7 +4924,7 @@ serial:
### [angle]

Magnetic hall angle sensor support for reading stepper motor angle
shaft measurements using a1333, as5047d, or tle5012b SPI chips. The
shaft measurements using a1333, as5047d, or tle5012b SPI chips. The
measurements are available via the [API Server](API_Server.md) and
[motion analysis tool](Debugging.md#motion-analysis-and-data-logging).
See the [G-Code reference](G-Codes.md#angle) for available commands.
Expand Down Expand Up @@ -4982,8 +4992,8 @@ It is generally recommended to only use I2C devices that are on the
same printed circuit board as the micro-controller.

Most Klipper micro-controller implementations only support an
`i2c_speed` of 100000 (*standard mode*, 100kbit/s). The Klipper "Linux"
micro-controller supports a 400000 speed (*fast mode*, 400kbit/s), but it must be
`i2c_speed` of 100000 (_standard mode_, 100kbit/s). The Klipper "Linux"
micro-controller supports a 400000 speed (_fast mode_, 400kbit/s), but it must be
[set in the operating system](RPi_microcontroller.md#optional-enabling-i2c)
and the `i2c_speed` parameter is otherwise ignored. The Klipper
"RP2040" micro-controller and ATmega AVR family support a rate of 400000
Expand Down
3 changes: 3 additions & 0 deletions klippy/extras/danger_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def __init__(self, config):
self.multi_mcu_trsync_timeout = config.getfloat(
"multi_mcu_trsync_timeout", 0.025, minval=0.0
)
self.homing_elapsed_distance_tolerance = config.getfloat(
"homing_elapsed_distance_tolerance", 0.5, minval=0.0
)


def load_config(config):
Expand Down
40 changes: 32 additions & 8 deletions klippy/extras/homing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, printer, endstops, toolhead=None):
self.toolhead = toolhead
self.stepper_positions = []
self.distance_elapsed = []
self.danger_options = printer.lookup_object("danger_options")

def get_mcu_endstops(self):
return [es for es, name in self.endstops]
Expand Down Expand Up @@ -197,6 +198,25 @@ def check_no_movement(self):
return sp.endstop_name
return None

def moved_less_than_dist(self, min_dist, homing_axes):
homing_axis_distances = [
dist
for i, dist in enumerate(self.distance_elapsed)
if i in homing_axes
]
distance_tolerance = (
self.danger_options.homing_elapsed_distance_tolerance
)
if any(
[
abs(dist) < min_dist
and min_dist - abs(dist) >= distance_tolerance
for dist in homing_axis_distances
]
):
return True
return False


# State tracking of homing requests
class Homing:
Expand Down Expand Up @@ -275,18 +295,12 @@ def home_rails(self, rails, forcepos, movepos):

hmove.homing_move(homepos, hi.speed)

homing_axis_distances = [
dist
for i, dist in enumerate(hmove.distance_elapsed)
if i in homing_axes
]
needs_rehome = False
retract_dist = hi.retract_dist
if any(
[abs(dist) < hi.min_home_dist for dist in homing_axis_distances]
):
if hmove.moved_less_than_dist(hi.min_home_dist, homing_axes):
needs_rehome = True
retract_dist = hi.min_home_dist

# Perform second home
if retract_dist:
logging.info("needs rehome: %s", needs_rehome)
Expand Down Expand Up @@ -319,6 +333,16 @@ def home_rails(self, rails, forcepos, movepos):
"Endstop %s still triggered after retract"
% (hmove.check_no_movement(),)
)
if (
hi.use_sensorless_homing
and needs_rehome
and hmove.moved_less_than_dist(
hi.min_home_dist, homing_axes
)
):
raise self.printer.command_error(
"Early homing trigger on second home!"
)
if hi.retract_dist:
# Retract (again)
startpos = self._fill_coord(forcepos)
Expand Down

0 comments on commit 544e3ee

Please sign in to comment.