From 6c252d30f5530982db0986b79f8eb1895f7d48f0 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <kevin@koconnor.net>
Date: Fri, 22 Dec 2017 21:44:56 -0500
Subject: [PATCH] delta: Allow the user to specify a minimum z position

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
 config/example-delta.cfg | 3 +++
 klippy/delta.py          | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/config/example-delta.cfg b/config/example-delta.cfg
index bd2859c1b..3ae4c3120 100644
--- a/config/example-delta.cfg
+++ b/config/example-delta.cfg
@@ -99,6 +99,9 @@ max_z_velocity: 150
 #   maximum speed of up/down moves (which require a higher step rate
 #   than other moves on a delta printer). The default is to use
 #   max_velocity for max_z_velocity.
+#minimum_z_position: 0
+#   The minimum Z position that the user may command the head to move
+#   to.  The default is 0.
 delta_radius: 174.75
 #   Radius (in mm) of the horizontal circle formed by the three linear
 #   axis towers. This parameter may also be calculated as:
diff --git a/klippy/delta.py b/klippy/delta.py
index c0e5ef288..5014fe017 100644
--- a/klippy/delta.py
+++ b/klippy/delta.py
@@ -33,6 +33,7 @@ class DeltaKinematics:
                          for s, arm2 in zip(self.steppers, self.arm2)]
         self.limit_xy2 = -1.
         self.max_z = min([s.position_endstop for s in self.steppers])
+        self.min_z = config.getfloat('minimum_z_position', 0, maxval=self.max_z)
         self.limit_z = min([ep - arm
                             for ep, arm in zip(self.endstops, arm_lengths)])
         logging.info(
@@ -148,7 +149,7 @@ class DeltaKinematics:
         limit_xy2 = self.max_xy2
         if end_pos[2] > self.limit_z:
             limit_xy2 = min(limit_xy2, (self.max_z - end_pos[2])**2)
-        if xy2 > limit_xy2 or end_pos[2] < 0. or end_pos[2] > self.max_z:
+        if xy2 > limit_xy2 or end_pos[2] < self.min_z or end_pos[2] > self.max_z:
             raise homing.EndstopMoveError(end_pos)
         if move.axes_d[2]:
             move.limit_speed(self.max_z_velocity, move.accel)