Skip to content

Commit

Permalink
fixes for good sensorless (props to fbeauKmi and nielsvz) (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance committed Dec 19, 2023
1 parent 2455a7e commit 68b0277
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 13 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,33 @@ If I want my printer to light itself on fire, I should be able to make my printe

- [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)

- [homing: min_home_dist](https://github.com/DangerKlippers/danger-klipper/pull/90)

If you're feeling adventurous, take a peek at the extra features in the bleeding-edge branch:

- [dmbutyugin's advanced-features branch](https://github.com/DangerKlippers/danger-klipper/pull/69) [dmbutyugin/advanced-features](https://github.com/dmbutyugin/klipper/commits/advanced-features)
- [dmbutyugin's advanced-features branch](https://github.com/DangerKlippers/danger-klipper/pull/69) [dmbutyugin/advanced-features](https://github.com/dmbutyugin/klipper/commits/advanced-features)

- [stepper: high precision stepping protocol](https://github.com/DangerKlippers/danger-klipper/pull/69)
- [stepper: high precision stepping protocol](https://github.com/DangerKlippers/danger-klipper/pull/69)

- [extruder: sync extruder motion with input shaper](https://github.com/DangerKlippers/danger-klipper/pull/69)
- [extruder: sync extruder motion with input shaper](https://github.com/DangerKlippers/danger-klipper/pull/69)

- [extruder: new print_pa_tower utility](https://github.com/DangerKlippers/danger-klipper/pull/69)
- [extruder: new print_pa_tower utility](https://github.com/DangerKlippers/danger-klipper/pull/69)

- [input_shaper: smooth input shapers](https://github.com/DangerKlippers/danger-klipper/pull/69)
- [input_shaper: smooth input shapers](https://github.com/DangerKlippers/danger-klipper/pull/69)

- [input_shaper: new print_ringing_tower utility](https://github.com/DangerKlippers/danger-klipper/pull/69)
- [input_shaper: new print_ringing_tower utility](https://github.com/DangerKlippers/danger-klipper/pull/69)

## Switch to Danger Klipper

> [!NOTE]
> Any add-on modules you are using will need to be reinstalled after switching to Danger Klipper. This includes things like Beacon support, led-effect, etc.
>
> Any data in ~/printer_data such as printer configs and macros will be unaffected.
### Manually clone the repository

If desired, make a backup copy of your existing Klipper installation by running:

```bash
Expand All @@ -89,6 +95,7 @@ sudo systemctl restart klipper
```

### Using KIAUH

For users that are not comfortable using Git directly, [KIAUH](https://github.com/dw-0/kiauh) is able to use custom repositories.

To do this, add the Danger Klipper repo to KIAUH's repo list and run the script with the following commands:
Expand All @@ -99,6 +106,7 @@ echo "DangerKlippers/danger-klipper" >> ~/kiauh/klipper_repos.txt
```

From the KIAUH menu select:

- 6 ) Settings
- 1 ) Set custom Klipper repository
- Select the number corresponding to DangerKlipper from the list shown
Expand All @@ -107,6 +115,7 @@ From the KIAUH menu select:
- 'Q' to quit

### Adding a git-remote to the existing installation

```bash
cd ~/klipper
git remote add danger https://github.com/DangerKlippers/danger-klipper.git
Expand All @@ -118,6 +127,7 @@ sudo systemctl restart moonraker
```

---

"Dangerous Klipper for dangerous users"

Klipper is a 3d-Printer firmware. It combines the power of a general
Expand Down
21 changes: 21 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ position_max:
# Speed to use on the retract move after homing in case this should
# be different from the homing speed, which is the default for this
# parameter
#min_home_dist:
# Minimum distance (in mm) for toolhead before sensorless homing. If closer
# than `min_home_dist` to endstop, it moves away to this distance, then homes.
# If further, it directly homes and retracts to `homing_retract_dist`.
# The default is equal to `homing_retract_dist`.
#second_homing_speed:
# Velocity (in mm/s) of the stepper when performing the second home.
# The default is homing_speed/2.
Expand Down Expand Up @@ -3481,6 +3486,9 @@ run_current:
#home_current:
# The amount of current (in amps RMS) to configure the driver to use
# during homing procedures. The default is to not reduce the current.
#current_change_dwell_time:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor: 0.110
# The resistance (in ohms) of the motor sense resistor. The default
# is 0.110 ohms.
Expand Down Expand Up @@ -3577,6 +3585,9 @@ run_current:
#home_current:
# The amount of current (in amps RMS) to configure the driver to use
# during homing procedures. The default is to not reduce the current.
#current_change_dwell_time:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor: 0.110
# The resistance (in ohms) of the motor sense resistor. The default
# is 0.110 ohms.
Expand Down Expand Up @@ -3621,6 +3632,7 @@ uart_pin:
run_current:
#hold_current:
#home_current:
#current_change_dwell_time:
#sense_resistor: 0.110
#stealthchop_threshold: 0
# See the "tmc2208" section for the definition of these parameters.
Expand Down Expand Up @@ -3692,6 +3704,9 @@ run_current:
#home_current:
# The amount of current (in amps RMS) to configure the driver to use
# during homing procedures. The default is to not reduce the current.
#current_change_dwell_time:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor:
# The resistance (in ohms) of the motor sense resistor. This
# parameter must be provided.
Expand Down Expand Up @@ -3775,6 +3790,9 @@ run_current:
#home_current:
# The amount of current (in amps RMS) to configure the driver to use
# during homing procedures. The default is to not reduce the current.
#current_change_dwell_time:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#rref: 12000
# The resistance (in ohms) of the resistor between IREF and GND. The
# default is 12000.
Expand Down Expand Up @@ -3899,6 +3917,9 @@ run_current:
#home_current:
# The amount of current (in amps RMS) to configure the driver to use
# during homing procedures. The default is to not reduce the current.
#current_change_dwell_time:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor: 0.075
# The resistance (in ohms) of the motor sense resistor. The default
# is 0.075 ohms.
Expand Down
18 changes: 11 additions & 7 deletions klippy/extras/homing.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def _set_current_homing(self, homing_axes):

for rail in affected_rails:
ch = rail.get_tmc_current_helper()
if ch is not None:
if ch is not None and ch.needs_home_current_change():
ch.set_current_for_homing(print_time)
self.toolhead.dwell(0.5)
self.toolhead.dwell(ch.current_change_dwell_time)

def _set_current_post_homing(self, homing_axes):
print_time = self.toolhead.get_last_move_time()
Expand All @@ -254,9 +254,9 @@ def _set_current_post_homing(self, homing_axes):

for rail in affected_rails:
ch = rail.get_tmc_current_helper()
if ch is not None:
if ch is not None and ch.needs_home_current_change():
ch.set_current_for_normal(print_time)
self.toolhead.dwell(0.5)
self.toolhead.dwell(ch.current_change_dwell_time)

def home_rails(self, rails, forcepos, movepos):
# Notify of upcoming homing operation
Expand Down Expand Up @@ -284,22 +284,25 @@ def home_rails(self, rails, forcepos, movepos):
# Perform second home
if hi.retract_dist:
needs_rehome = False
if any([dist < hi.retract_dist for dist in homing_axis_distances]):
retract_dist = hi.retract_dist
if any(
[abs(dist) < hi.min_home_dist for dist in homing_axis_distances]
):
needs_rehome = True
retract_dist = hi.min_home_dist

logging.info("needs rehome: %s", needs_rehome)
# Retract
startpos = self._fill_coord(forcepos)
homepos = self._fill_coord(movepos)
axes_d = [hp - sp for hp, sp in zip(homepos, startpos)]
move_d = math.sqrt(sum([d * d for d in axes_d[:3]]))
retract_r = min(1.0, hi.retract_dist / move_d)
retract_r = min(1.0, retract_dist / move_d)
retractpos = [
hp - ad * retract_r for hp, ad in zip(homepos, axes_d)
]
self.toolhead.move(retractpos, hi.retract_speed)
if not hi.use_sensorless_homing or needs_rehome:
self.toolhead.dwell(0.5)
# Home again
startpos = [
rp - ad * retract_r for rp, ad in zip(retractpos, axes_d)
Expand All @@ -309,6 +312,7 @@ def home_rails(self, rails, forcepos, movepos):
for endstop in endstops:
# re-querying a tmc endstop seems to reset the state
# otherwise it triggers almost immediately upon second home
# this seems to be an adequate substitute for a 2 second dwell.
endstop[0].query_endstop(print_time)
hmove = HomingMove(self.printer, endstops)
hmove.homing_move(homepos, hi.second_homing_speed)
Expand Down
6 changes: 6 additions & 0 deletions klippy/extras/tmc2130.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ def __init__(self, config, mcu_tmc):
self._home_current = config.getfloat(
"home_current", self.run_current, above=0.0, maxval=MAX_CURRENT
)
self.current_change_dwell_time = config.getfloat(
"current_change_dwell_time", 0.5, above=0.0
)
self.prev_current = self.run_current
self.req_hold_current = self.hold_current
self.sense_resistor = config.getfloat(
Expand All @@ -224,6 +227,9 @@ def __init__(self, config, mcu_tmc):
self.fields.set_field("ihold", ihold)
self.fields.set_field("irun", irun)

def needs_home_current_change(self):
return self._home_current != self.run_current

def set_home_current(self, new_home_current):
self._home_current = min(MAX_CURRENT, new_home_current)

Expand Down
6 changes: 6 additions & 0 deletions klippy/extras/tmc2240.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ def __init__(self, config, mcu_tmc):
self._home_current = config.getfloat(
"home_current", self.run_current, above=0.0, maxval=self.max_cur
)
self.current_change_dwell_time = config.getfloat(
"current_change_dwell_time", 0.5, above=0.0
)
self.prev_current = self.run_current
self.req_hold_current = self.hold_current
current_range = self._calc_current_range(self.run_current)
Expand All @@ -292,6 +295,9 @@ def __init__(self, config, mcu_tmc):
self.fields.set_field("ihold", ihold)
self.fields.set_field("irun", irun)

def needs_home_current_change(self):
return self._home_current != self.run_current

def set_home_current(self, new_home_current):
self._home_current = min(self.max_cur, new_home_current)

Expand Down
6 changes: 6 additions & 0 deletions klippy/extras/tmc2660.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def __init__(self, config, mcu_tmc):
self._home_current = config.getfloat(
"home_current", self.current, above=0.0, maxval=MAX_CURRENT
)
self.current_change_dwell_time = config.getfloat(
"current_change_dwell_time", 0.5, above=0.0
)
self._prev_current = self.current
self.sense_resistor = config.getfloat("sense_resistor")
vsense, cs = self._calc_current(self.current)
Expand All @@ -144,6 +147,9 @@ def __init__(self, config, mcu_tmc):
"idle_timeout:ready", self._handle_ready
)

def needs_home_current_change(self):
return self._home_current != self.current

def set_home_current(self, new_home_current):
self._home_current = min(MAX_CURRENT, new_home_current)

Expand Down
6 changes: 6 additions & 0 deletions klippy/extras/tmc5160.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def __init__(self, config, mcu_tmc):
self._home_current = config.getfloat(
"home_current", self.run_current, above=0.0, maxval=MAX_CURRENT
)
self.current_change_dwell_time = config.getfloat(
"current_change_dwell_time", 0.5, above=0.0
)
self._prev_current = self.run_current
self.req_hold_current = self.hold_current
self.sense_resistor = config.getfloat(
Expand All @@ -277,6 +280,9 @@ def __init__(self, config, mcu_tmc):
self.fields.set_field("ihold", ihold)
self.fields.set_field("irun", irun)

def needs_home_current_change(self):
return self._home_current != self.run_current

def set_home_current(self, new_home_current):
self._home_current = min(MAX_CURRENT, new_home_current)

Expand Down
5 changes: 5 additions & 0 deletions klippy/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ def __init__(
self.use_sensorless_homing = config.getboolean(
"use_sensorless_homing", endstop_is_virtual
)
self.min_home_dist = config.getfloat(
"min_home_dist", self.homing_retract_dist, minval=0.0
)

if self.homing_positive_dir is None:
axis_len = self.position_max - self.position_min
Expand Down Expand Up @@ -493,6 +496,7 @@ def get_homing_info(self):
"positive_dir",
"second_homing_speed",
"use_sensorless_homing",
"min_home_dist",
],
)(
self.homing_speed,
Expand All @@ -502,6 +506,7 @@ def get_homing_info(self):
self.homing_positive_dir,
self.second_homing_speed,
self.use_sensorless_homing,
self.min_home_dist,
)
return homing_info

Expand Down
1 change: 1 addition & 0 deletions test/klippy/tmc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use_sensorless_homing: true
cs_pin: PG2
run_current: .7
home_current: .5
current_change_dwell_time: 1
sense_resistor: 0.220
diag1_pin: !PK7

Expand Down

0 comments on commit 68b0277

Please sign in to comment.