Skip to content

fix for machines with z_min end-stops + probes#28350

Closed
12oclocker wants to merge 1 commit intoMarlinFirmware:bugfix-2.1.xfrom
12oclocker:BLTouch+Endstop_LevelingFix
Closed

fix for machines with z_min end-stops + probes#28350
12oclocker wants to merge 1 commit intoMarlinFirmware:bugfix-2.1.xfrom
12oclocker:BLTouch+Endstop_LevelingFix

Conversation

@12oclocker
Copy link
Contributor

fix for machines with z_min endstops + probes

Description

fix for machines with z_min endstops + probes, which are independent of each other.
When using AUTO_BED_LEVELING_BILINEAR the Z homing must be zeroed before creating the bed meshes; otherwise the bed mesh never subtracts the Z offset during creation.
Currently the Z position is only zeroed when using a probe to home. Now it will be zeroed when using a mechanical endstop to home, or a probe to home. The fix is a single line of code.

Related Issues

fixes all these issues...
#27680
#22653
#21727
#21833

fix for machines with z_min endstops + probes
@Nuck-TH
Copy link

Nuck-TH commented Feb 24, 2026

will this work if Z home offset is not 0?

@12oclocker
Copy link
Contributor Author

will this work if Z home offset is not 0?

yes

@Nuck-TH
Copy link

Nuck-TH commented Feb 26, 2026

no, it doesn't. home offset stops to have effect on Z

@12oclocker
Copy link
Contributor Author

12oclocker commented Feb 26, 2026

Can you describe exactly what settings are you changing and having an issue with? GUI Z home offset through LCD, or #define Z offsets. Also what machine are you using? Please let me know... ALSO does your machine home using Endstop or Probe? The machine I am testing with homes with endstop, but uses probe. If your machine is homing with probe and not endstop, then the line of code I have submitted is not active for your machine and does not effect your machine. Also what version of marlin did you test with, the latest bugfix 2.1.x or 2.1.2.7 ?

I tested it and found it to have no ill effect on offsets. Are you having a problem? If you are can you describe in more detail the problem you are having?... The line of code I submitted was "missing"... the effect is the same as "position.z -= probe.offset.z" when homing with a probe. (4 lines above in the code) which subtracts probe offset and makes net zero, except you are homing with endstop sensor, and nozzle touches instead of probe, nozzle touching the bed is net zero... So "position.z -= probe.offset.z" and "position.z = 0" both do not have any ill effect on the offsets... Offsets are applied after this code at a later time. Without this code fix, it is impossible for machines that require Z endstops to use a probe, the probe will "float" above the bed by the Z offset amount, because Z was never initialized during endstop homing.

 // Z Probe Z Homing? Account for the probe's Z offset.
  #if HAS_BED_PROBE && Z_HOME_TO_MIN
    if (axis == Z_AXIS) {
      #if HOMING_Z_WITH_PROBE
        #if ENABLED(BD_SENSOR)
          safe_delay(100);
          position.z = bdl.read();
        #else
          position.z -= probe.offset.z; // <---NET RESULT IS A ZERO POSITION, because Z nozzle will be ABOVE the bed by the amount of probe.offset.z
        #endif
        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z homed with PROBE" TERN_(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, " (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)") " ***\n> (M851 Z", probe.offset.z, ")");
      #else
        position.z -= probe.offset.z; // <---NET RESULT IS A ZERO POSITION, because Z nozzle is touches the bed as endstop triggers, this line of code was missing
        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z homed to ENDSTOP ***");
      #endif
    }
  #endif

@Nuck-TH
Copy link

Nuck-TH commented Feb 27, 2026

bugfix-2.1.x, specifically updated yesterday to test this. endstop and probe. Home offset is set via M206 Z, idk about screen. to test i probe reference point on bed with G30. Without change from this PR it works correctly and offset applied both to probed point and bed mesh. With change setting any home offset have no effect on point or mesh values.

@12oclocker
Copy link
Contributor Author

12oclocker commented Feb 27, 2026

bugfix-2.1.x, specifically updated yesterday to test this. endstop and probe. Home offset is set via M206 Z, idk about screen. to test i probe reference point on bed with G30. Without change from this PR it works correctly and offset applied both to probed point and bed mesh. With change setting any home offset have no effect on point or mesh values.

thanks, are you using UBL bed leveling or bilinear? I am assuming UBL since bilinear is what this fix is targeting. If you are using bilinear can you post your config.h file.... I will test with your config settings.

@Nuck-TH
Copy link

Nuck-TH commented Feb 27, 2026

bilinear. but choice of leveling system shouldn't affect G30.

@12oclocker
Copy link
Contributor Author

12oclocker commented Mar 1, 2026

I will test this today and find the cause

I suspect the problem may be "current_position[axis] = base_home_pos(axis);" is not working correctly, because
current_position.z = 0; that I added (which should actually be current_position.z = Z_MIN_POS;) is compensating for current_position[axis] = base_home_pos(axis); not working. This only seems to occur when AUTO_BED_LEVELING_BILINEAR is enabled, a probe exist, and HOMING_Z_WITH_PROBE is not enabled.
Are you not printing from SDCARD and just controlling the machine though a PC to print?
I am trying to figure out how you are not having these issues... (Can you post a link to your config files?)
#27680
#22653
#21727
#21833

  #if ANY(MORGAN_SCARA, AXEL_TPARA)
    scara_set_axis_is_at_home(axis);
  #elif ENABLED(DELTA)
    current_position[axis] = (axis == Z_AXIS) ? DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) : base_home_pos(axis);
  #else
    current_position[axis] = base_home_pos(axis); //why is this not working for Z when BILINEAR is enabled and homing with endstop?
    DEBUG_ECHOLNPGM("*** base_home_pos = ", base_home_pos(axis)); //monitor if this is working
  #endif

  /**
   * Z Probe Z Homing? Account for the probe's Z offset.
   */
  #if HAS_BED_PROBE && Z_HOME_TO_MIN
    if (axis == Z_AXIS) {
      #if HOMING_Z_WITH_PROBE
        #error "Yes HOMING_Z_WITH_PROBE"
        current_position.z -= probe.offset.z;
        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z);
      #else
        current_position.z = Z_MIN_POS; //this fixes a bug with BILINEAR, but why is "current_position[axis] = base_home_pos(axis)" above not working?
        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED TO ENDSTOP, current_position.z = ", current_position.z);
      #endif
    }
  #endif

@Nuck-TH
Copy link

Nuck-TH commented Mar 2, 2026

It works but not always and very finicky. For one, i have to rescan mesh after any probe offset change and reboot printer for good measure or things get funky.
Conf.zip

@12oclocker
Copy link
Contributor Author

Yes, re-scan of mesh after any probe offset change is because of the way marlin was written. That occurs because you are probing the mesh, but homing with endstop. the probe is subtracted from the mesh during creation, so if you change probe offset, you must re-make the mesh to apply it to the mesh. When homing with probe you obviously don't have to remake the mesh. I have several ideas on how to solve that, but have not coded it yet... I will examine your config today

@12oclocker
Copy link
Contributor Author

It works but not always and very finicky. For one, i have to rescan mesh after any probe offset change and reboot printer for good measure or things get funky. Conf.zip

I am canceling this pull request, the problem is a bug in marlin, after setting Z probe offset, the machine must be rebooted before MESH can be created, otherwise mesh is built with Z offset NOT subtracted from the mesh.

@12oclocker 12oclocker closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants