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

[BUG] Z-Offset Not Working Properly After Upgrading to Marlin 2.1.3-b1: Reported Z Height Inaccuracies #27581

Open
1 task done
Skaifer opened this issue Dec 10, 2024 · 4 comments

Comments

@Skaifer
Copy link

Skaifer commented Dec 10, 2024

Did you test the latest bugfix-2.1.x code?

Yes, and the problem still exists.

Bug Description

Hello,
So, I'm trying to upgrade firmware from old version 2.1.1 to 2.1.3-b1, and stumbled upon an issue, that I think could be a bug.

I can't get Z-offset to work properly. After flashing new firmware, I do as usual and reset EEPROM. Then I do homing, probes the middle of the bed, double-click on knob and adjust babysteps until the nozzle touches the build plate. Then I save settings and run homing to check if Z height is correct or needs further adjusting.

But instead of it being at least close to target height, its final actual Z height always stays approximately at 1.4mm, but the screen reports Z height as whatever negative Z-offset I entered but with a positive value.

Did transfer settings manually from the old configs and Z_AFTER_HOMING is set to 0. I did try latest bugfix, transferred only essential settings and it still behaves this way. Flashed old 2.1.1 back, and there is no problem, so that's not a hardware issue.
Included configuration files from version 2.1.3-b1 and two homing procedures with old Marlin 2.1.1, which preforms as it should and the new version.

Hopefully, I managed to describe my issue across somehow. =)

G28_tests.zip
Configuration.zip

Bug Timeline

New. After upgrade from Marlin 2.1.1 to 2.1.3-b1.

Expected behavior

I expected nozzle with z-offset -10mm to crash into buildplate or to be at Z0 position after homing, with nozzle touching the buildplate, as adjusted to actual z-offset of -1.33mm.

Actual behavior

The nozzle is ~1.4mm above the buildplate, but reported Z height is either 10mm or 1.33mm with z-offset being -10 and -1.33 respectively.

Steps to Reproduce

Steps followed in G28 test files:

  1. Enabled DEBUG_LEVELING_FEATURE and M114_DETAIL, flashed to printer via SD card
  2. Connect my laptop through Pronterface
  3. Reset EEPROM with M502 followed by M500
  4. Enabled maximum logging with M111 S247
  5. Did G28 as a base reference with Z-offset 0
  6. Then I've set Z-offset to insane M851 Z-10 (For demonstration purposes, similarly happens with actual -1.33mm)
  7. Final G28
  8. Following the same commands through LCD gives the same results.

Version of Marlin Firmware

Marlin 2.1.3-b1

Printer model

Creality CR-10S

Electronics

BTT SKRv1.3, BL-Touch v1.2, TMC2208, E3Dv6, DirectDrive

LCD/Controller

Stock

Other add-ons

No response

Bed Leveling

ABL Bilinear mesh

Your Slicer

None

Host Software

Pronterface

Don't forget to include

  • A ZIP file containing your Configuration.h and Configuration_adv.h.

Additional information & file uploads

Did not change any other files except Configuration.h and Configuration_adv.h. Bootscreen and statusscreen files, which should be irrelevant.

@thinkyhead
Copy link
Member

To rule out hard-to-see inaccuracies that can throw things off, I recommend enabling and running the PROBE_OFFSET_WIZARD to get the most accurate nozzle-to-probe Z offset (M851 Z) value. It will help to heat up the nozzle and bed during this procedure, and in general heat things up in future G29 leveling too. Then you should enable X_AXIS_TWIST_COMPENSATION and go through that procedure to see what it reports. With the updated values re-home with G28, do a complete leveling mesh with G29, and run a single layer test print or G26 to see if that improves the result at all.

There are certainly some changes in homing and leveling, so if there is something incompatible with your particular settings we'll want to narrow that down as specifically as we can. If a complete calibration doesn't get you to a better place, we can look at doing a more in depth process to find the specific change.

It would be a good idea for you to look at 2.1.2.5 also. If the problem is not in that version that helps us to narrow down where the problem originates.

@Skaifer
Copy link
Author

Skaifer commented Dec 16, 2024

@thinkyhead
Starting with your recommendations. I can't get firmware 2.1.3-b1 and latest bugfix to compile with X_AXIS_TWIST_COMPENSATION enabled, it's giving error.

Here is the output

sh-5.2$ platformio run --silent -e LPC1768 ; echo "done" >"/tmp/ipc"
Marlin/src/feature/x_twist.cpp:56:61: error: 'float lerp(const_float_t, const_float_t, const_float_t)' conflicts with a previous declaration
   56 | float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
      |                                                             ^
In file included from /home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/math.h:36,
                 from /home/skaifer/.platformio/packages/framework-arduino-lpc176x/cores/arduino/Arduino.h:28,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/../shared/Marduino.h:36,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/HAL.h:37,
                 from Marlin/src/feature/../inc/../HAL/HAL.h:30,
                 from Marlin/src/feature/../inc/MarlinConfigPre-5-post.h:29,
                 from Marlin/src/feature/../inc/MarlinConfigPre-6-type.h:24,
                 from Marlin/src/feature/../inc/MarlinConfig.h:28,
                 from Marlin/src/feature/x_twist.cpp:22:
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1911:3: note: previous declaration 'constexpr float std::lerp(float, float, float)'
 1911 |   lerp(float __a, float __b, float __t) noexcept
      |   ^~~~
Marlin/src/feature/x_twist.cpp: In static member function 'static float XATC::compensation(const xy_pos_t&)':
Marlin/src/feature/x_twist.cpp:64:46: error: call of overloaded 'lerp(float&, float&, float&)' is ambiguous
   64 |   return lerp(t, z_offset[i], z_offset[i + 1]);
      |                                              ^
In file included from /home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/math.h:36,
                 from /home/skaifer/.platformio/packages/framework-arduino-lpc176x/cores/arduino/Arduino.h:28,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/../shared/Marduino.h:36,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/HAL.h:37,
                 from Marlin/src/feature/../inc/../HAL/HAL.h:30,
                 from Marlin/src/feature/../inc/MarlinConfigPre-5-post.h:29,
                 from Marlin/src/feature/../inc/MarlinConfigPre-6-type.h:24,
                 from Marlin/src/feature/../inc/MarlinConfig.h:28,
                 from Marlin/src/feature/x_twist.cpp:22:
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1919:3: note: candidate: 'constexpr long double std::lerp(long double, long double, long double)'
 1919 |   lerp(long double __a, long double __b, long double __t) noexcept
      |   ^~~~
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1915:3: note: candidate: 'constexpr double std::lerp(double, double, double)'
 1915 |   lerp(double __a, double __b, double __t) noexcept
      |   ^~~~
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1911:3: note: candidate: 'constexpr float std::lerp(float, float, float)'
 1911 |   lerp(float __a, float __b, float __t) noexcept
      |   ^~~~
Marlin/src/feature/x_twist.cpp:56:7: note: candidate: 'float lerp(const_float_t, const_float_t, const_float_t)'
   56 | float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
      |       ^~~~
*** [.pio/build/LPC1768/src/src/feature/x_twist.cpp.o] Error 1
============================================================================= [FAILED] Took 5.99 seconds =============================================================================

Environment    Status    Duration
-------------  --------  ------------
LPC1768        FAILED    00:00:05.995
======================================================================= 1 failed, 0 succeeded in 00:00:05.995 =======================================================================
sh-5.2$ 

PROBE_OFFSET_WIZARD is working, and it's a wiser approach overall because the Z offset is set exactly over the probe point, and it has better logic. It appears I've been doing Z-offset, not the best way, the whole time.
You mentioned, that Probe Offset Wizard would preheat nozzle and bed before G28 and G29, but it doesn't in my case. Wouldn't that require PREHEAT_BEFORE_LEVELING to be enabled for this to happen, or is it misbehaving in this aspect?

I checked version 2.1.2.5 and can confirm, that there the z-offset is applied as it used to and Z height after G28 is reported correctly as set in firmware at Z0. Also, the firmware compiles successfully with X_AXIS_TWIST_COMPENSATION being enabled.

Now, with that being said. I assumed, that print would fail, giving that homing resulted in the nozzle being above the build plate with Z_AFTER_HOMING set to 0, but no. Printing from SD card went just fine, with correct Z-offset and babystepping working just fine. And probing wizard gives consistent Z-offset calibration.

So... That makes me conclude, that Z_Offset is working just fine. And that reported Z-height is accurate. It's just that Z position is supposedly wrong, in certain scenarios which do not cause print to fail.

  • G28 ignores Z_AFTER_HOMING 0. Is this zero now relative, meaning without z-offset?
  • Also, I've set PROBE_OFFSET_WIZARD_START_Z to 0, but in my case the starting position is Z10. With that definition commented out, it was Z11.33.

@thinkyhead
Copy link
Member

thinkyhead commented Dec 16, 2024

Thanks for the update. I patched the code so X-twist can build. The code around Z_AFTER_HOMING has some conditions that could prevent the nozzle from moving down below a certain height. You can force a Z move with EVENT_GCODE_AFTER_HOMING if other conditions are superseding Z_AFTER_HOMING.

The logic for upcoming 2.1.3 is likely different from 2.1.2.x. Currently…

  • When Z_AFTER_HOMING is defined it gets assigned to Z_POST_CLEARANCE.
  • After homing Z in G28 there is a call to do_move_after_z_homing().
  • Since Z_POST_CLEARANCE is defined it calls do_z_clearance(Z_POST_CLEARANCE, true, true)
    (with_probe=true, lower_allowed=true).
  • The with_probe flag causes it to add the probe trigger height. This code exists to prevent a deployed probe from hitting obstacles.

If you are certain your probe will be retracted (or if it's a probe that doesn't move) then G28 could call do_z_clearance(Z_POST_CLEARANCE, false, true) instead. Or something more fancy, like…

do_z_clearance(Z_POST_CLEARANCE,
  ALL(HOMING_Z_WITH_PROBE, HAS_STOWABLE_PROBE)
    && TERN0(HAS_BED_PROBE, endstops.z_probe_enabled), true);

@Skaifer
Copy link
Author

Skaifer commented Dec 17, 2024

@thinkyhead
I'm fine with it working this way, without the nozzle reaching bed level, since there is a Probe Wizard, which does the job perfectly. And it's not a bug, which is a good thing.

I patched the code so X-twist can build.

Is this patch already up? I downloaded bugfix 2h ago and tried to compile it with X-twist turned on, and I still get

the error

sh-5.2$ platformio run --silent -e LPC1768 ; echo "done" >"/tmp/ipc"
cc1: warning: command-line option '-Wno-volatile' is valid for C++/ObjC++ but not for C
cc1: warning: command-line option '-Wno-volatile' is valid for C++/ObjC++ but not for C
Marlin/src/feature/x_twist.cpp:56:61: error: 'float lerp(const_float_t, const_float_t, const_float_t)' conflicts with a previous declaration
   56 | float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
      |                                                             ^
In file included from /home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/math.h:36,
                 from /home/skaifer/.platformio/packages/framework-arduino-lpc176x/cores/arduino/Arduino.h:28,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/../shared/Marduino.h:36,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/HAL.h:37,
                 from Marlin/src/feature/../inc/../HAL/HAL.h:30,
                 from Marlin/src/feature/../inc/MarlinConfigPre-5-post.h:29,
                 from Marlin/src/feature/../inc/MarlinConfigPre-6-type.h:24,
                 from Marlin/src/feature/../inc/MarlinConfig.h:28,
                 from Marlin/src/feature/x_twist.cpp:22:
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1911:3: note: previous declaration 'constexpr float std::lerp(float, float, float)'
 1911 |   lerp(float __a, float __b, float __t) noexcept
      |   ^~~~
Marlin/src/feature/x_twist.cpp: In static member function 'static float XATC::compensation(const xy_pos_t&)':
Marlin/src/feature/x_twist.cpp:64:46: error: call of overloaded 'lerp(float&, float&, float&)' is ambiguous
   64 |   return lerp(t, z_offset[i], z_offset[i + 1]);
      |                                              ^
In file included from /home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/math.h:36,
                 from /home/skaifer/.platformio/packages/framework-arduino-lpc176x/cores/arduino/Arduino.h:28,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/../shared/Marduino.h:36,
                 from Marlin/src/feature/../inc/../HAL/../HAL/LPC1768/HAL.h:37,
                 from Marlin/src/feature/../inc/../HAL/HAL.h:30,
                 from Marlin/src/feature/../inc/MarlinConfigPre-5-post.h:29,
                 from Marlin/src/feature/../inc/MarlinConfigPre-6-type.h:24,
                 from Marlin/src/feature/../inc/MarlinConfig.h:28,
                 from Marlin/src/feature/x_twist.cpp:22:
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1919:3: note: candidate: 'constexpr long double std::lerp(long double, long double, long double)'
 1919 |   lerp(long double __a, long double __b, long double __t) noexcept
      |   ^~~~
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1915:3: note: candidate: 'constexpr double std::lerp(double, double, double)'
 1915 |   lerp(double __a, double __b, double __t) noexcept
      |   ^~~~
/home/skaifer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/10.3.1/cmath:1911:3: note: candidate: 'constexpr float std::lerp(float, float, float)'
 1911 |   lerp(float __a, float __b, float __t) noexcept
      |   ^~~~
Marlin/src/feature/x_twist.cpp:56:7: note: candidate: 'float lerp(const_float_t, const_float_t, const_float_t)'
   56 | float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
      |       ^~~~
*** [.pio/build/LPC1768/src/src/feature/x_twist.cpp.o] Error 1
==================================================================================== [FAILED] Took 16.13 seconds ====================================================================================

Environment    Status    Duration
-------------  --------  ------------
LPC1768        FAILED    00:00:16.130
=============================================================================== 1 failed, 0 succeeded in 00:00:16.130 ===============================================================================
sh-5.2$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants