Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homing Phase for TMC drivers #17299

Merged
merged 24 commits into from
Apr 20, 2020

Conversation

Fabi0San
Copy link
Contributor

Description

Homing phase.
Makes homing super repeatable by retracting from endstop hit back to a very specific stepper coil phase.
TMC Only. Delta Only.

The implementation changes delta homing so when the endstop is hits, the TMC phase is queried and the distance to the next target phase away from endstop is computed and added to endstop trim.

Notes:

  • Trinamic drivers use a stepper phase table with 1024 values which spans 4 full steps
  • with 256 positions each therefore 1024 positions.
  • The full steps (positions 128, 384, 640, 896) have the highest holding torque.
  • The endstop needs to be repeatable to at least half a step.

Benefits

  • Improve homing repeatability.
  • Home is now a position with the highest hold torque.

Related Issues

#16383

@Fabi0San Fabi0San changed the title Pr/tmc end stop phase Homing Phase for TMC drivers Mar 26, 2020
@Strahler85
Copy link

This feature would be also nice also for not Delta 3D-Printer

@extesy
Copy link

extesy commented Mar 26, 2020

@Fabi0San Why is this a delta-only feature? Would you be able to apply it to all types of printers?

@Fabi0San
Copy link
Contributor Author

Fabi0San commented Mar 26, 2020

@Fabi0San Why is this a delta-only feature? Would you be able to apply it to all types of printers?

Deltas use the endstops and endstop trim to get all 3 carriages almost perfectly leveled.
The repeatability error of endstops make them uneven which not only virtually tilts the printing bed but also introduces a compression of horizontal space opposite to the tower that is relatively lower than the other ones, which result in wrong part dimensions, loss of squareness and over-extrusion just to name a few.
People attenuate the bed problem by using grid leveling and other techniques but that does nothing for the horizontal errors introduced by it.

So homing repeatability is a huge deal for deltas.

For cartesians it is not such a big deal, so much so that printers have now been using sensorless homing using TMC's StallGuard feature, and is by far the least repeatable homing method I can think of.
On a 200 step(50 phase cycles) stepper with a 20 tooth gt2 the StallGuard repeatability of one phase cycle is 0.8mm. So what if the print is 0.8mm to right or the left? It doesnt really matter so it can be used that way and having 0,0 be exactly at the same spot is not such a big deal.

@Maeyanie made a good point though, one could benefit from it on a cartesian, by setting the first layer height and the layer height just so it is a multiple of a full step and therefore the z axis would have the highest possible holding torque on every layer. But I'm not sure if holding torque is a big deal, especially given all the Z axis with lead screws and somewhat of a good reduction on them.

All that said, yes anything is possible, we could in theory factor out my code into a method WalkToPhase(axis, phase, direction) and use it on both delta and cartesian. What do you think @thinkyhead ? Any point on doing it?

@Maeyanie
Copy link
Contributor

While I agree it's more useful for deltas, it does have uses for cartesians. Holding torque (more specifically, positioning accuracy) can become a problem when printing extremely thin layers, near the edge of what FDM systems can achieve.

X and Y positioning do tend to be less important, but it would still improve things like power-loss resume accuracy.

@Fabi0San
Copy link
Contributor Author

@Maeyanie , @extesy , @Strahler85
Ok you guys got me convinced, it wasn't too hard, now please help us test this.

@Maeyanie
Copy link
Contributor

Maeyanie commented Mar 27, 2020

Much appreciated. :)
I'm in the middle of a print right now (with ~20 hours left), but will give it a try as soon as I can.

@Strahler85
Copy link

Strahler85 commented Mar 27, 2020

Thank you very much. I'm compiling at the moment. One thing. How to setup this values right?

#define TMC_HOME_PHASE { 896, 896, 896 }

One thing maybe a good improvement (for normal users) that we have a option that home to the next full step and not to select the phase.

@Fabi0San
Copy link
Contributor Author

Thank you very much. I'm compiling at the moment. One thing. How to setup this values right?
#define TMC_HOME_PHASE { 896, 896, 896 }

Yes, un-comment that line and also #define DEBUG_LEVELING_FEATURE on config.h so it can warn you if the phases you picked are too close to the endstops, if so pick other ones.
If you feel extra curious run M111 S38 and see where which phase it is hitting and how repeatable your endstops are between G28 runs and even day to day.
Once G28 throws no more warnings you can comment out DEBUG_LEVELING_FEATURE again.

One thing maybe a good improvement (for normal users) that we have a option that home to the next full step and not to select the phase.

The suggested values are the full step positions, from trinamic datasheet:

Fullstep: Cycles through table positions: 128, 384, 640 and 896 (45°, 135°, 225° and 315° electrical
position, both coils on at identical current). The coil current in each position
corresponds to the RMS-Value (0.71 * amplitude). Step size is 256 (90° electrical)

The phase is tunable for the case where your end stop is too close to the chosen phase and its noise may trigger sometimes before sometimes after the target phase which would make it have a repeatably of 4 full steps.

@Strahler85
Copy link

Okay this mean I uncomment this command, Debug Command and home the printer and if there is no warning it works. If I get a warning I have to change the position and compile the firmware again.
I'm compiling again and than I will flash the firmware on my Ender3

@Strahler85
Copy link

Strahler85 commented Mar 27, 2020

Okay :-) First the good thing. It runs :-). But I'm not sure if it is working at the Z-Axis, because there is no Z- Endstop Hit Debug

Log Output
SENDING:G28
>>> G28
Machine Type: Cartesian
Probe: NONE
Raise Z (before homing) to 4.00
>>> do_blocking_move_to X0.00 Y0.00 Z4.00
<<< do_blocking_move_to
>>> homeaxis(X)
Home 1 Fast:
>>> do_homing_move(X, -352.50, [50.00])
<<< do_homing_move(X)
Move Away:
>>> do_homing_move(X, 5.00, [50.00])
<<< do_homing_move(X)
Home 2 Slow:
>>> do_homing_move(X, -10.00, 25.00)
<<< do_homing_move(X)
**Endstop X hit at Phase:56 Delta:184 Distance:0.14**
>>> do_homing_move(X, 0.14, 25.00)
<<< do_homing_move(X)
>>> set_axis_is_at_home(X)
Axis 88 home_offset = 0.00 position_shift = 0.00
> home_offset[X] = 0.00
  current_position= X0.00 Y0.00 Z4.00 :
<<< set_axis_is_at_home(X)
  current_position= X0.00 Y0.00 Z4.00 : sync_plan_position
  current_position= X0.00 Y0.00 Z4.00 : > AFTER set_axis_is_at_home
<<< homeaxis(X)
>>> homeaxis(Y)
Home 1 Fast:
>>> do_homing_move(Y, -352.50, [50.00])
echo:busy: processing
<<< do_homing_move(Y)
Move Away:
>>> do_homing_move(Y, 5.00, [50.00])
<<< do_homing_move(Y)
Home 2 Slow:
>>> do_homing_move(Y, -10.00, 25.00)
<<< do_homing_move(Y)
**Endstop Y hit at Phase:504 Delta:632 Distance:0.49**
>>> do_homing_move(Y, 0.49, 25.00)
<<< do_homing_move(Y)
>>> set_axis_is_at_home(Y)
Axis 89 home_offset = 0.00 position_shift = 0.00
> home_offset[Y] = 0.00
  current_position= X0.00 Y0.00 Z4.00 :
<<< set_axis_is_at_home(Y)
  current_position= X0.00 Y0.00 Z4.00 : sync_plan_position
  current_position= X0.00 Y0.00 Z4.00 : > AFTER set_axis_is_at_home
<<< homeaxis(Y)
>>> homeaxis(Z)
Home 1 Fast:
>>> do_homing_move(Z, -375.00, [4.00])
<<< do_homing_move(Z)
Move Away:
>>> do_homing_move(Z, 2.00, [4.00])
echo:busy: processing
<<< do_homing_move(Z)
Home 2 Slow:
>>> do_homing_move(Z, -4.00, 1.00)
echo:busy: processing
<<< do_homing_move(Z)
>>> set_axis_is_at_home(Z)
Axis 90 home_offset = 0.00 position_shift = 0.00
> home_offset[Z] = 0.00
  current_position= X0.00 Y0.00 Z0.00 :
<<< set_axis_is_at_home(Z)
  current_position= X0.00 Y0.00 Z0.00 : sync_plan_position
  current_position= X0.00 Y0.00 Z0.00 : > AFTER set_axis_is_at_home
<<< homeaxis(Z)
  current_position= X0.00 Y0.00 Z0.00 : sync_plan_position
<<< G28

@Strahler85
Copy link

Sorry my fault... I replaced the TMC2208 with a LV87XX driver. This is why there is no information at the Z-Axis. I switched back to TMC2208 and compiling marlin again.

@Fabi0San
Copy link
Contributor Author

Sorry my fault... I replaced the TMC2208 with a LV87XX driver. This is why there is no information at the Z-Axis. I switched back to TMC2208 and compiling marlin again.

That is a good test too, I just added the check that doesn't assume all drivers are TMC, it should do just that not look for phase if one of the axis has no TMC on. Tested! Thank you.

@Strahler85
Copy link

Strahler85 commented Mar 27, 2020

Changed to TMC2208
Endstop X hit at Phase:56 Delta:184 Distance:0.14
Endstop Y hit at Phase:488 Delta:616 Distance:0.47

Home phase too close to endstop trigger. Pick a different phase for Z
Endstop Z hit at Phase:632 Delta:264 Distance:0.04

I will change the Phase Z to value 128

But what I found out is:
Home phase too close to endstop trigger. Pick a different phase for Z
Endstop Z hit at Phase:632 Delta:264 Distance:0.04

do_homing_move(Z, 0.04, 1.00)
<<< do_homing_move(Z)
set_axis_is_at_home(Z)

Z moves to 0.04?

@Fabi0San
Copy link
Contributor Author

Endstop Y hit at Phase:504 Delta:632 Distance:0.49
Endstop Y hit at Phase:488 Delta:616 Distance:0.47

You see that Y varied 0.02mm, which is very typical for mechanical ES, which type is it?
With this feature change you should be dead on now, every time.

Note that Z home will be further from the bed now, if you use offset you may have to re-calibrate that or your first layer will get thicker and may run lean.

@teemuatlut
Copy link
Member

I'm not aware of TMC steppers supported by Marlin that do not support the necessary register MSCNT as it its defined in the superclass TMCStepper. So please correct me if I'm wrong.

TMC2660 uses another name.

@Fabi0San
Copy link
Contributor Author

TMC2660 uses another name.

Thank you,
I added the method get_microstep_counter to TMCMarlin and gave TMCMarlin<TMC2660Stepper,...> an implementation reading mstep() instead.

@thinkyhead
Copy link
Member

Looks like progress has been made and testing is going well. I have been attending to other issues, but I will give this a re-review now and get it into final shape for merge.

@thinkyhead thinkyhead merged commit ccfd5c1 into MarlinFirmware:bugfix-2.0.x Apr 20, 2020
@swilkens
Copy link
Contributor

swilkens commented Apr 20, 2020

@Fabi0San tested multiple runs of G28 Z

Endstop Z hit at Phase:472 Delta:424 Distance:0.06
Endstop Z hit at Phase:280 Delta:616 Distance:0.09
Endstop Z hit at Phase:456 Delta:440 Distance:0.07
Endstop Z hit at Phase:8 Delta:888 Distance:0.14
Endstop Z hit at Phase:488 Delta:408 Distance:0.06

Selected home phase 896 too close to endstop trigger phase 872. Pick a different phase for Z
Endstop Z hit at Phase:872 Delta:24 Distance:0.00

If I understand this correctly, there is quite a bit of spread in the activation distance of my Z-endstop relative to the configured phase?

However, i see a huge spread in the trigger phase. 8, 280, 452, 872. How should I evaluate this, or is it time for a better endstop?

@GMagician
Copy link
Contributor

ok discard any previous post from me....I just understood now what you mean (and data you posted)

@swilkens
Copy link
Contributor

swilkens commented Apr 20, 2020

@GMagician basically I'm double checking if this indeed means that my Z-homing varies between 0.06 (I've also seen 0.01) and 0.14 mm relative to the selected phase, indicating a trigger position variation of 0.08 (0.13) mm. Which would be horrible and tells me I need to replace this thing asap.

@Fabi0San
Copy link
Contributor Author

If I understand this correctly, there is quite a bit of spread in the activation distance of my Z-endstop relative to the configured phase?

However, i see a huge spread in the trigger phase. 8, 280, 452, 872. How should I evaluate this, or is it time for a better endstop?

Yes you got it right, your trigger points are all over the place, given phase is between 0-1023 there is no safe place to pick. Ideally you want your endstop to be repeatable within 2 full steps, or 512 uSteps(1/256) which in your case should be about 0.08mm but your trigger seems to have an error at of at least 0.16mm possibly more.

It is hard to say what is adding such noise though, endstop surely is the first suspect but it can be being caused by chassis noise such as from bearings, belts, steppers(current), or electronic noise such as filtering capacitors on endstop pins or FW artifacts such as endstops not using interrupts and the uC missing the edge change by a few steps.

On my machine I have hit all of those and some more, I'm now at about 0.0012mm repeatability which likely is beyond the limit of what I can measure with the tools I can afford.

If you would like some wild guesses tell me about your machine and I can suggest where to look first.

@Fabi0San
Copy link
Contributor Author

maybe you have to choose one of them to get full step alignment...otherwise you align in the middle...and it's the same as before this mod

Not quite. You will always get better repeatability even between full steps, the main difference with that approach is how much torque the motor will have at the homing position.

@swilkens
Copy link
Contributor

If you would like some wild guesses tell me about your machine and I can suggest where to look first.

Thank you for the verification.

I'm relatively sure this is a component quality issue, the endstop is a no-name brand microswitch - the lever also appears to bend during actuation. I'll replace it with a decent omron unit and see if this improves things. I'll also hook up a scope to the endstop and see how noisy the signal is.

Tinker time, perhaps it's even time to install a hall effect sensor on Z.

@Fabi0San
Copy link
Contributor Author

basically I'm double checking if this indeed means that my Z-homing varies between 0.06 (I've also seen 0.01) and 0.14 mm relative to the selected phase, indicating a trigger position variation of 0.08 (0.13) mm. Which would be horrible and tells me I need to replace this thing asap.

Delta of 0 is not good so there will always be some distance, say pick samples:

Endstop Z hit at Phase:472 Delta:424 Distance:0.06
Endstop Z hit at Phase:456 Delta:440 Distance:0.07
Endstop Z hit at Phase:488 Delta:408 Distance:0.06

These are all good, within 0.01mm from each other this would be very typical and workable, all within the fullstep 2(384-640)

But then:

Endstop Z hit at Phase:280 Delta:616 Distance:0.09

Ugh, got to .03 and into the full step1(128-384), still workable

Endstop Z hit at Phase:8 Delta:888 Distance:0.14
Endstop Z hit at Phase:872 Delta:24 Distance:0.00

Now these samples screwed all up, with these we hit full step 3(640-896) and full step 0(896-128).
So that means we have samples peppered across all 4 full steps we can track and cannot assert anything for sure.

I'm relatively sure this is a component quality issue, the endstop is a no-name brand microswitch - the lever also appears to bend during actuation. I'll replace it with a decent omron unit and see if this improves things. I'll also hook up a scope to the endstop and see how noisy the signal is.

Sounds like fun :) Quality is important, but name brands also have their quality issues. In my experimentation, the lever on the endstops were a huge source of noise, take it off if you can.

The most repeatable sensors I could find were inductive and optical, likely because they have no mechanical contact, but both suffered minor drift between machine reboots and changing room conditions.
Single hall seemed to suffer the most as they have an arbitrary flux threshold, I had more luck with dual hall sensors that try to detect the peak magnetic flux instead of arbitrary threshold, but they are expensive and I'm cheap.

On my delta I use optical, but the best compromise is really on mechanical switch especially if you can use this homing phase feature.

Also to clarify, the filter cap was adding a random delay into sinking the pin, so there is a balance there between contact noise and random delay.

Good luck, and have fun.

@Maeyanie
Copy link
Contributor

Optical switches can be very repeatable if you have something good, solid, and flat going into the path of the sensor, and take some steps to prevent foreign light affecting it.

@swilkens
Copy link
Contributor

Good luck, and have fun.

So thanks for this extensive reply with your experiences, I modified the endstop bracket on my printer to allow me to use the endstop without the lever.

Just to remember, this was the result with the lever:

Endstop Z hit at Phase:472 Delta:424 Distance:0.06
Endstop Z hit at Phase:280 Delta:616 Distance:0.09
Endstop Z hit at Phase:456 Delta:440 Distance:0.07
Endstop Z hit at Phase:8 Delta:888 Distance:0.14
Endstop Z hit at Phase:488 Delta:408 Distance:0.06
Endstop Z hit at Phase:872 Delta:24 Distance:0.00

And this is after modifying the printer and removing the lever:

Endstop Z hit at Phase:280 Delta:616 Distance:0.09
Endstop Z hit at Phase:280 Delta:616 Distance:0.09
Endstop Z hit at Phase:280 Delta:616 Distance:0.09
Endstop Z hit at Phase:264 Delta:632 Distance:0.10
Endstop Z hit at Phase:280 Delta:616 Distance:0.09
Endstop Z hit at Phase:296 Delta:600 Distance:0.09

That's pretty crazy.

Naamloos

Can I suggest that this feature is extended with a method to determine the trigger accuracy of the Z endstop (be it microswitch, optical, hall or whatever)? Something that does 5 triggers and outputs the min / max / average perhaps.

@Fabi0San
Copy link
Contributor Author

That is fantastic!
See? the cheapo switch had a <10um repeat on it, you just have to find how to get it out of it. Good job!

I support that idea for a feature request, M48 for any endstop, not just z_min_probe.
Or alternatively G28 repeatability test, G28.1 or something.

@swilkens, feel free to create a [FR] issue and link it here so we can track it.

Cheers.

@sacy80
Copy link

sacy80 commented Jun 30, 2020

@Fabi0San would like to check, are this value look ok? i got repeatable number on every home

Endstop X hit at Phase:252 Delta:900 Distance:-0.7000
Endstop Y hit at Phase:728 Delta:680 Distance:-0.5250
Endstop Z hit at Phase:313 Delta:839 Distance:-0.6500

@Fabi0San Fabi0San deleted the pr/TMCEndStopPhase branch July 12, 2020 14:05
jmp0x0000 pushed a commit to jmp0x0000/Marlin that referenced this pull request Aug 7, 2020
njibhu pushed a commit to njibhu/Marlin that referenced this pull request Aug 24, 2020
strangerok1507 added a commit to strangerok1507/kossel_skr13_marlin_V2 that referenced this pull request Apr 22, 2021
HairingX pushed a commit to HairingX/Marlin that referenced this pull request Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants