Browse Source

New Feature: Z_DUAL_ENDSTOPS

Z_DUAL_ENDSTOPS is a feature to enable the use of 2 endstops for both Z
steppers - Let's call them Z stepper and Z2 stepper.
That way the machine is capable to align the bed during home, since both
Z steppers are homed.
There is also an implementation of M666 (software endstops adjustment)
to this feature.
After Z homing, this adjustment is applied to just one of the steppers
in order to align the bed.
One just need to home the Z axis and measure the distance difference
between both Z axis and apply the math: Z adjust = Z - Z2.
If the Z stepper axis is closer to the bed, the measure Z > Z2 (yes, it
is.. think about it) and the Z adjust would be positive.
Play a little bit with small adjustments (0.5mm) and check the
behaviour.
The M119 (endstops report) will start reporting the Z2 Endstop as well.
alexborro 10 years ago
parent
commit
0ce3576685
8 changed files with 228 additions and 19 deletions
  1. 22
    0
      Marlin/ConfigurationStore.cpp
  2. 26
    1
      Marlin/Configuration_adv.h
  3. 2
    0
      Marlin/Marlin.h
  4. 48
    3
      Marlin/Marlin_main.cpp
  5. 1
    0
      Marlin/language.h
  6. 29
    0
      Marlin/pins.h
  7. 94
    15
      Marlin/stepper.cpp
  8. 6
    0
      Marlin/stepper.h

+ 22
- 0
Marlin/ConfigurationStore.cpp View File

67
  *
67
  *
68
  *  filament_size (x4)
68
  *  filament_size (x4)
69
  *
69
  *
70
+ * Z_DUAL_ENDSTOPS
71
+ *  z_endstop_adj
72
+ *
70
  */
73
  */
71
 #include "Marlin.h"
74
 #include "Marlin.h"
72
 #include "language.h"
75
 #include "language.h"
165
     EEPROM_WRITE_VAR(i, delta_radius);              // 1 float
168
     EEPROM_WRITE_VAR(i, delta_radius);              // 1 float
166
     EEPROM_WRITE_VAR(i, delta_diagonal_rod);        // 1 float
169
     EEPROM_WRITE_VAR(i, delta_diagonal_rod);        // 1 float
167
     EEPROM_WRITE_VAR(i, delta_segments_per_second); // 1 float
170
     EEPROM_WRITE_VAR(i, delta_segments_per_second); // 1 float
171
+  #elif defined(Z_DUAL_ENDSTOPS)
172
+    EEPROM_WRITE_VAR(i, z_endstop_adj);            // 1 floats
173
+    dummy = 0.0f;
174
+    for (int q=5; q--;) EEPROM_WRITE_VAR(i, dummy);
168
   #else
175
   #else
169
     dummy = 0.0f;
176
     dummy = 0.0f;
170
     for (int q=6; q--;) EEPROM_WRITE_VAR(i, dummy);
177
     for (int q=6; q--;) EEPROM_WRITE_VAR(i, dummy);
326
       EEPROM_READ_VAR(i, delta_radius);               // 1 float
333
       EEPROM_READ_VAR(i, delta_radius);               // 1 float
327
       EEPROM_READ_VAR(i, delta_diagonal_rod);         // 1 float
334
       EEPROM_READ_VAR(i, delta_diagonal_rod);         // 1 float
328
       EEPROM_READ_VAR(i, delta_segments_per_second);  // 1 float
335
       EEPROM_READ_VAR(i, delta_segments_per_second);  // 1 float
336
+    #elif defined(Z_DUAL_ENDSTOPS)
337
+      EEPROM_READ_VAR(i, z_endstop_adj);
338
+      dummy = 0.0f;
339
+      for (int q=5; q--;) EEPROM_READ_VAR(i, dummy);
329
     #else
340
     #else
341
+      dummy = 0.0f;
330
       for (int q=6; q--;) EEPROM_READ_VAR(i, dummy);
342
       for (int q=6; q--;) EEPROM_READ_VAR(i, dummy);
331
     #endif
343
     #endif
332
 
344
 
459
     delta_diagonal_rod =  DELTA_DIAGONAL_ROD;
471
     delta_diagonal_rod =  DELTA_DIAGONAL_ROD;
460
     delta_segments_per_second =  DELTA_SEGMENTS_PER_SECOND;
472
     delta_segments_per_second =  DELTA_SEGMENTS_PER_SECOND;
461
     recalc_delta_settings(delta_radius, delta_diagonal_rod);
473
     recalc_delta_settings(delta_radius, delta_diagonal_rod);
474
+  #elif defined(Z_DUAL_ENDSTOPS)
475
+    z_endstop_adj = 0;
462
   #endif
476
   #endif
463
 
477
 
464
   #ifdef ULTIPANEL
478
   #ifdef ULTIPANEL
629
     SERIAL_ECHOPAIR(" R", delta_radius );
643
     SERIAL_ECHOPAIR(" R", delta_radius );
630
     SERIAL_ECHOPAIR(" S", delta_segments_per_second );
644
     SERIAL_ECHOPAIR(" S", delta_segments_per_second );
631
     SERIAL_EOL;
645
     SERIAL_EOL;
646
+  #elif defined(Z_DUAL_ENDSTOPS)
647
+    SERIAL_ECHO_START;
648
+    if (!forReplay) {
649
+      SERIAL_ECHOLNPGM("Z2 Endstop adjustement (mm):");
650
+      SERIAL_ECHO_START;
651
+    }
652
+    SERIAL_ECHOPAIR("  M666 Z", z_endstop_adj );
653
+    SERIAL_EOL;  
632
   #endif // DELTA
654
   #endif // DELTA
633
 
655
 
634
   #ifdef PIDTEMP
656
   #ifdef PIDTEMP

+ 26
- 1
Marlin/Configuration_adv.h View File

98
 // Only a few motherboards support this, like RAMPS, which have dual extruder support (the 2nd, often unused, extruder driver is used
98
 // Only a few motherboards support this, like RAMPS, which have dual extruder support (the 2nd, often unused, extruder driver is used
99
 // to control the 2nd Z axis stepper motor). The pins are currently only defined for a RAMPS motherboards.
99
 // to control the 2nd Z axis stepper motor). The pins are currently only defined for a RAMPS motherboards.
100
 // On a RAMPS (or other 5 driver) motherboard, using this feature will limit you to using 1 extruder.
100
 // On a RAMPS (or other 5 driver) motherboard, using this feature will limit you to using 1 extruder.
101
-//#define Z_DUAL_STEPPER_DRIVERS
101
+#define Z_DUAL_STEPPER_DRIVERS
102
+
103
+#ifdef Z_DUAL_STEPPER_DRIVERS
104
+
105
+// Z_DUAL_ENDSTOPS is a feature to enable the use of 2 endstops for both Z steppers - Let's call them Z stepper and Z2 stepper.
106
+// That way the machine is capable to align the bed during home, since both Z steppers are homed. 
107
+// There is also an implementation of M666 (software endstops adjustment) to this feature.
108
+// After Z homing, this adjustment is applied to just one of the steppers in order to align the bed.
109
+// One just need to home the Z axis and measure the distance difference between both Z axis and apply the math: Z adjust = Z - Z2.
110
+// If the Z stepper axis is closer to the bed, the measure Z > Z2 (yes, it is.. think about it) and the Z adjust would be positive.
111
+// Play a little bit with small adjustments (0.5mm) and check the behaviour.
112
+// The M119 (endstops report) will start reporting the Z2 Endstop as well.
113
+
114
+#define Z_DUAL_ENDSTOPS
115
+
116
+#ifdef Z_DUAL_ENDSTOPS
117
+  #define Z2_STEP_PIN E2_STEP_PIN           // Stepper to be used to Z2 axis.
118
+  #define Z2_DIR_PIN E2_DIR_PIN
119
+  #define Z2_ENABLE_PIN E2_ENABLE_PIN
120
+  #define Z2_MAX_PIN 36                     //Endstop used for Z2 axis. In this case I'm using XMAX in a Rumba Board (pin 36)
121
+  const bool Z2_MAX_ENDSTOP_INVERTING = false;
122
+  #define DISABLE_XMAX_ENDSTOP              //Better to disable the XMAX to avoid conflict. Just rename "XMAX_ENDSTOP" by the endstop you are using for Z2 axis.
123
+#endif
124
+
125
+
126
+#endif
102
 
127
 
103
 // Same again but for Y Axis.
128
 // Same again but for Y Axis.
104
 //#define Y_DUAL_STEPPER_DRIVERS
129
 //#define Y_DUAL_STEPPER_DRIVERS

+ 2
- 0
Marlin/Marlin.h View File

242
   extern float delta_diagonal_rod;
242
   extern float delta_diagonal_rod;
243
   extern float delta_segments_per_second;
243
   extern float delta_segments_per_second;
244
   void recalc_delta_settings(float radius, float diagonal_rod);
244
   void recalc_delta_settings(float radius, float diagonal_rod);
245
+#elif defined(Z_DUAL_ENDSTOPS)
246
+extern float z_endstop_adj;
245
 #endif
247
 #endif
246
 #ifdef SCARA
248
 #ifdef SCARA
247
   extern float axis_scaling[3];  // Build size scaling
249
   extern float axis_scaling[3];  // Build size scaling

+ 48
- 3
Marlin/Marlin_main.cpp View File

248
 float home_offset[3] = { 0, 0, 0 };
248
 float home_offset[3] = { 0, 0, 0 };
249
 #ifdef DELTA
249
 #ifdef DELTA
250
   float endstop_adj[3] = { 0, 0, 0 };
250
   float endstop_adj[3] = { 0, 0, 0 };
251
+#elif defined(Z_DUAL_ENDSTOPS)
252
+  float z_endstop_adj = 0;
251
 #endif
253
 #endif
252
 
254
 
253
 float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
255
 float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
973
 
975
 
974
   static float x_home_pos(int extruder) {
976
   static float x_home_pos(int extruder) {
975
     if (extruder == 0)
977
     if (extruder == 0)
976
-      return base_home_pos(X_AXIS) + add_homing[X_AXIS];
978
+    return base_home_pos(X_AXIS) + home_offset[X_AXIS];
977
     else
979
     else
978
       // In dual carriage mode the extruder offset provides an override of the
980
       // In dual carriage mode the extruder offset provides an override of the
979
       // second X-carriage offset when homed - otherwise X2_HOME_POS is used.
981
       // second X-carriage offset when homed - otherwise X2_HOME_POS is used.
1487
       }
1489
       }
1488
     #endif
1490
     #endif
1489
 #endif // Z_PROBE_SLED
1491
 #endif // Z_PROBE_SLED
1492
+    #ifdef Z_DUAL_ENDSTOPS
1493
+      if (axis==Z_AXIS) In_Homing_Process(true);
1494
+    #endif
1490
     destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
1495
     destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
1491
     feedrate = homing_feedrate[axis];
1496
     feedrate = homing_feedrate[axis];
1492
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1497
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1512
 
1517
 
1513
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1518
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1514
     st_synchronize();
1519
     st_synchronize();
1520
+    #ifdef Z_DUAL_ENDSTOPS
1521
+      if (axis==Z_AXIS)
1522
+      {
1523
+        feedrate = homing_feedrate[axis];
1524
+        plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1525
+        if (axis_home_dir > 0)
1526
+        {
1527
+          destination[axis] = (-1) * fabs(z_endstop_adj);
1528
+          if (z_endstop_adj > 0) Lock_z_motor(true); else Lock_z2_motor(true);
1529
+        } else {
1530
+          destination[axis] = fabs(z_endstop_adj);
1531
+          if (z_endstop_adj < 0) Lock_z_motor(true); else Lock_z2_motor(true);        
1532
+        }
1533
+        plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1534
+        st_synchronize();
1535
+        Lock_z_motor(false);
1536
+        Lock_z2_motor(false);
1537
+        In_Homing_Process(false);
1538
+      }
1539
+    #endif
1540
+
1515
 #ifdef DELTA
1541
 #ifdef DELTA
1516
     // retrace by the amount specified in endstop_adj
1542
     // retrace by the amount specified in endstop_adj
1517
     if (endstop_adj[axis] * axis_home_dir < 0) {
1543
     if (endstop_adj[axis] * axis_home_dir < 0) {
1754
 
1780
 
1755
   enable_endstops(true);
1781
   enable_endstops(true);
1756
 
1782
 
1757
-  for (int i = X_AXIS; i <= Z_AXIS; i++) destination[i] = current_position[i];
1783
+  for (int i = X_AXIS; i <= NUM_AXIS; i++) destination[i] = current_position[i];
1758
 
1784
 
1759
   feedrate = 0.0;
1785
   feedrate = 0.0;
1760
 
1786
 
1944
     if (code_seen(axis_codes[Z_AXIS]) && code_value_long() != 0)
1970
     if (code_seen(axis_codes[Z_AXIS]) && code_value_long() != 0)
1945
       current_position[Z_AXIS] = code_value() + home_offset[Z_AXIS];
1971
       current_position[Z_AXIS] = code_value() + home_offset[Z_AXIS];
1946
 
1972
 
1947
-    #ifdef ENABLE_AUTO_BED_LEVELING
1973
+    #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0)
1948
       if (home_all_axis || code_seen(axis_codes[Z_AXIS]))
1974
       if (home_all_axis || code_seen(axis_codes[Z_AXIS]))
1949
         current_position[Z_AXIS] += zprobe_zoffset;  //Add Z_Probe offset (the distance is negative)
1975
         current_position[Z_AXIS] += zprobe_zoffset;  //Add Z_Probe offset (the distance is negative)
1950
     #endif
1976
     #endif
3452
     SERIAL_PROTOCOLPGM(MSG_Z_MAX);
3478
     SERIAL_PROTOCOLPGM(MSG_Z_MAX);
3453
     SERIAL_PROTOCOLLN(((READ(Z_MAX_PIN)^Z_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
3479
     SERIAL_PROTOCOLLN(((READ(Z_MAX_PIN)^Z_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
3454
   #endif
3480
   #endif
3481
+  #if defined(Z2_MAX_PIN) && Z2_MAX_PIN > -1
3482
+    SERIAL_PROTOCOLPGM(MSG_Z2_MAX);
3483
+    SERIAL_PROTOCOLLN(((READ(Z2_MAX_PIN)^Z2_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
3484
+  #endif
3485
+  
3455
 }
3486
 }
3456
 
3487
 
3457
 /**
3488
 /**
3645
       }
3676
       }
3646
     }
3677
     }
3647
   }
3678
   }
3679
+#elif defined(Z_DUAL_ENDSTOPS)
3680
+  /**
3681
+   * M666: For Z Dual Endstop setup, set z axis offset to the z2 axis.
3682
+   */
3683
+  inline void gcode_M666() {
3684
+   if (code_seen('Z')) z_endstop_adj = code_value();
3685
+   SERIAL_ECHOPAIR("Z Endstop Adjustment set to (mm):", z_endstop_adj );
3686
+   SERIAL_EOL;
3687
+  }
3688
+  
3648
 #endif // DELTA
3689
 #endif // DELTA
3649
 
3690
 
3650
 #ifdef FWRETRACT
3691
 #ifdef FWRETRACT
4894
         case 666: // M666 set delta endstop adjustment
4935
         case 666: // M666 set delta endstop adjustment
4895
           gcode_M666();
4936
           gcode_M666();
4896
           break;
4937
           break;
4938
+      #elif defined(Z_DUAL_ENDSTOPS)
4939
+        case 666: // M666 set delta endstop adjustment
4940
+          gcode_M666();
4941
+          break;
4897
       #endif // DELTA
4942
       #endif // DELTA
4898
 
4943
 
4899
       #ifdef FWRETRACT
4944
       #ifdef FWRETRACT

+ 1
- 0
Marlin/language.h View File

128
 #define MSG_Y_MAX                           "y_max: "
128
 #define MSG_Y_MAX                           "y_max: "
129
 #define MSG_Z_MIN                           "z_min: "
129
 #define MSG_Z_MIN                           "z_min: "
130
 #define MSG_Z_MAX                           "z_max: "
130
 #define MSG_Z_MAX                           "z_max: "
131
+#define MSG_Z2_MAX                          "z2_max: "
131
 #define MSG_M119_REPORT                     "Reporting endstop status"
132
 #define MSG_M119_REPORT                     "Reporting endstop status"
132
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
133
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
133
 #define MSG_ENDSTOP_OPEN                    "open"
134
 #define MSG_ENDSTOP_OPEN                    "open"

+ 29
- 0
Marlin/pins.h View File

178
   #define Z_MIN_PIN          -1
178
   #define Z_MIN_PIN          -1
179
 #endif
179
 #endif
180
 
180
 
181
+#ifdef DISABLE_XMAX_ENDSTOP
182
+  #undef X_MAX_PIN
183
+  #define X_MAX_PIN          -1
184
+#endif
185
+
186
+#ifdef DISABLE_XMIN_ENDSTOP
187
+  #undef X_MIN_PIN 
188
+  #define X_MIN_PIN          -1
189
+#endif
190
+
191
+#ifdef DISABLE_YMAX_ENDSTOP
192
+  #define Y_MAX_PIN          -1
193
+#endif
194
+
195
+#ifdef DISABLE_YMIN_ENDSTOP
196
+  #undef Y_MIN_PIN
197
+  #define Y_MIN_PIN          -1
198
+#endif
199
+
200
+#ifdef DISABLE_ZMAX_ENDSTOP
201
+  #undef Z_MAX_PIN
202
+  #define Z_MAX_PIN          -1
203
+#endif
204
+
205
+#ifdef DISABLE_ZMIN_ENDSTOP
206
+  #undef Z_MIN_PIN 
207
+  #define Z_MIN_PIN          -1
208
+#endif
209
+
181
 #define SENSITIVE_PINS { 0, 1, X_STEP_PIN, X_DIR_PIN, X_ENABLE_PIN, X_MIN_PIN, X_MAX_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_ENABLE_PIN, Y_MIN_PIN, Y_MAX_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_ENABLE_PIN, Z_MIN_PIN, Z_MAX_PIN, PS_ON_PIN, \
210
 #define SENSITIVE_PINS { 0, 1, X_STEP_PIN, X_DIR_PIN, X_ENABLE_PIN, X_MIN_PIN, X_MAX_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_ENABLE_PIN, Y_MIN_PIN, Y_MAX_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_ENABLE_PIN, Z_MIN_PIN, Z_MAX_PIN, PS_ON_PIN, \
182
                         HEATER_BED_PIN, FAN_PIN, \
211
                         HEATER_BED_PIN, FAN_PIN, \
183
                         _E0_PINS _E1_PINS _E2_PINS _E3_PINS \
212
                         _E0_PINS _E1_PINS _E2_PINS _E3_PINS \

+ 94
- 15
Marlin/stepper.cpp View File

48
 static unsigned char out_bits;        // The next stepping-bits to be output
48
 static unsigned char out_bits;        // The next stepping-bits to be output
49
 static unsigned int cleaning_buffer_counter;  
49
 static unsigned int cleaning_buffer_counter;  
50
 
50
 
51
+#ifdef Z_DUAL_ENDSTOPS
52
+  static bool performing_homing = false, 
53
+              locked_z_motor = false, 
54
+              locked_z2_motor = false;
55
+#endif
56
+
51
 // Counter variables for the bresenham line tracer
57
 // Counter variables for the bresenham line tracer
52
 static long counter_x, counter_y, counter_z, counter_e;
58
 static long counter_x, counter_y, counter_z, counter_e;
53
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
59
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
84
             old_y_min_endstop = false,
90
             old_y_min_endstop = false,
85
             old_y_max_endstop = false,
91
             old_y_max_endstop = false,
86
             old_z_min_endstop = false,
92
             old_z_min_endstop = false,
93
+            #ifndef Z_DUAL_ENDSTOPS
87
             old_z_max_endstop = false;
94
             old_z_max_endstop = false;
95
+            #else
96
+              old_z_max_endstop = false,
97
+              old_z2_min_endstop = false,
98
+              old_z2_max_endstop = false;
99
+            #endif
88
 
100
 
89
 static bool check_endstops = true;
101
 static bool check_endstops = true;
90
 
102
 
128
 
140
 
129
 #ifdef Z_DUAL_STEPPER_DRIVERS
141
 #ifdef Z_DUAL_STEPPER_DRIVERS
130
   #define Z_APPLY_DIR(v,Q) { Z_DIR_WRITE(v); Z2_DIR_WRITE(v); }
142
   #define Z_APPLY_DIR(v,Q) { Z_DIR_WRITE(v); Z2_DIR_WRITE(v); }
131
-  #define Z_APPLY_STEP(v,Q) { Z_STEP_WRITE(v); Z2_STEP_WRITE(v); }
143
+  #ifdef Z_DUAL_ENDSTOPS
144
+    #define Z_APPLY_STEP(v,Q) \
145
+    if (performing_homing) { \
146
+      if (Z_HOME_DIR > 0) {\
147
+        if (!(old_z_max_endstop && (count_direction[Z_AXIS] > 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
148
+        if (!(old_z2_max_endstop && (count_direction[Z_AXIS] > 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
149
+      } else {\
150
+        if (!(old_z_min_endstop && (count_direction[Z_AXIS] < 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
151
+        if (!(old_z2_min_endstop && (count_direction[Z_AXIS] < 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
152
+      } \
153
+    } else { \
154
+      Z_STEP_WRITE(v); \
155
+      Z2_STEP_WRITE(v); \
156
+    }
157
+  #else
158
+    #define Z_APPLY_STEP(v,Q) Z_STEP_WRITE(v), Z2_STEP_WRITE(v)
159
+  #endif
132
 #else
160
 #else
133
   #define Z_APPLY_DIR(v,Q) Z_DIR_WRITE(v)
161
   #define Z_APPLY_DIR(v,Q) Z_DIR_WRITE(v)
134
   #define Z_APPLY_STEP(v,Q) Z_STEP_WRITE(v)
162
   #define Z_APPLY_STEP(v,Q) Z_STEP_WRITE(v)
465
     }
493
     }
466
 
494
 
467
     if (TEST(out_bits, Z_AXIS)) {   // -direction
495
     if (TEST(out_bits, Z_AXIS)) {   // -direction
468
-      Z_DIR_WRITE(INVERT_Z_DIR);
469
-      #ifdef Z_DUAL_STEPPER_DRIVERS
470
-        Z2_DIR_WRITE(INVERT_Z_DIR);
471
-      #endif
472
-
496
+      Z_APPLY_DIR(INVERT_Z_DIR,0);
473
       count_direction[Z_AXIS] = -1;
497
       count_direction[Z_AXIS] = -1;
474
-      if (check_endstops) {
475
-        #if defined(Z_MIN_PIN) && Z_MIN_PIN >= 0
476
-          UPDATE_ENDSTOP(z, Z, min, MIN);
498
+      if (check_endstops) 
499
+      {
500
+        #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
501
+          #ifndef Z_DUAL_ENDSTOPS
502
+            UPDATE_ENDSTOP(z, Z, min, MIN);
503
+          #else
504
+            bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
505
+            #if defined(Z2_MIN_PIN) && Z2_MIN_PIN > -1
506
+              bool z2_min_endstop=(READ(Z2_MIN_PIN) != Z2_MIN_ENDSTOP_INVERTING);
507
+            #else
508
+              bool z2_min_endstop=z_min_endstop;
509
+            #endif
510
+            if(((z_min_endstop && old_z_min_endstop) || (z2_min_endstop && old_z2_min_endstop)) && (current_block->steps[Z_AXIS] > 0))
511
+            {
512
+              endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
513
+              endstop_z_hit=true;
514
+              if (!(performing_homing) || ((performing_homing)&&(z_min_endstop && old_z_min_endstop)&&(z2_min_endstop && old_z2_min_endstop))) //if not performing home or if both endstops were trigged during homing...
515
+              {
516
+                step_events_completed = current_block->step_event_count;
517
+              } 
518
+            }
519
+            old_z_min_endstop = z_min_endstop;
520
+            old_z2_min_endstop = z2_min_endstop;
521
+          #endif
477
         #endif
522
         #endif
478
       }
523
       }
479
     }
524
     }
480
     else { // +direction
525
     else { // +direction
481
-      Z_DIR_WRITE(!INVERT_Z_DIR);
482
-      #ifdef Z_DUAL_STEPPER_DRIVERS
483
-        Z2_DIR_WRITE(!INVERT_Z_DIR);
484
-      #endif
485
-
526
+      Z_APPLY_DIR(!INVERT_Z_DIR,0);
486
       count_direction[Z_AXIS] = 1;
527
       count_direction[Z_AXIS] = 1;
487
       if (check_endstops) {
528
       if (check_endstops) {
488
         #if defined(Z_MAX_PIN) && Z_MAX_PIN >= 0
529
         #if defined(Z_MAX_PIN) && Z_MAX_PIN >= 0
489
-          UPDATE_ENDSTOP(z, Z, max, MAX);
530
+          #ifndef Z_DUAL_ENDSTOPS
531
+            UPDATE_ENDSTOP(z, Z, max, MAX);
532
+          #else
533
+            bool z_max_endstop=(READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING);
534
+            #if defined(Z2_MAX_PIN) && Z2_MAX_PIN > -1
535
+              bool z2_max_endstop=(READ(Z2_MAX_PIN) != Z2_MAX_ENDSTOP_INVERTING);
536
+            #else
537
+              bool z2_max_endstop=z_max_endstop;
538
+            #endif
539
+            if(((z_max_endstop && old_z_max_endstop) || (z2_max_endstop && old_z2_max_endstop)) && (current_block->steps[Z_AXIS] > 0))
540
+            {
541
+              endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
542
+              endstop_z_hit=true;
543
+
544
+//              if (z_max_endstop && old_z_max_endstop) SERIAL_ECHOLN("z_max_endstop = true");
545
+//              if (z2_max_endstop && old_z2_max_endstop) SERIAL_ECHOLN("z2_max_endstop = true");
546
+
547
+            
548
+              if (!(performing_homing) || ((performing_homing)&&(z_max_endstop && old_z_max_endstop)&&(z2_max_endstop && old_z2_max_endstop))) //if not performing home or if both endstops were trigged during homing...
549
+              {
550
+                step_events_completed = current_block->step_event_count;
551
+              } 
552
+            }
553
+            old_z_max_endstop = z_max_endstop;
554
+            old_z2_max_endstop = z2_max_endstop;
555
+          #endif
490
         #endif
556
         #endif
491
       }
557
       }
492
     }
558
     }
845
     #endif
911
     #endif
846
   #endif
912
   #endif
847
 
913
 
914
+  #if defined(Z2_MAX_PIN) && Z2_MAX_PIN >= 0
915
+    SET_INPUT(Z2_MAX_PIN);
916
+    #ifdef ENDSTOPPULLUP_ZMAX
917
+      WRITE(Z2_MAX_PIN,HIGH);
918
+    #endif
919
+  #endif  
920
+  
848
   #define AXIS_INIT(axis, AXIS, PIN) \
921
   #define AXIS_INIT(axis, AXIS, PIN) \
849
     AXIS ##_STEP_INIT; \
922
     AXIS ##_STEP_INIT; \
850
     AXIS ##_STEP_WRITE(INVERT_## PIN ##_STEP_PIN); \
923
     AXIS ##_STEP_WRITE(INVERT_## PIN ##_STEP_PIN); \
1174
     SERIAL_PROTOCOLLN(digitalRead(E1_MS2_PIN));
1247
     SERIAL_PROTOCOLLN(digitalRead(E1_MS2_PIN));
1175
   #endif
1248
   #endif
1176
 }
1249
 }
1250
+
1251
+#ifdef Z_DUAL_ENDSTOPS
1252
+  void In_Homing_Process(bool state) { performing_homing = state; }
1253
+  void Lock_z_motor(bool state) { locked_z_motor = state; }
1254
+  void Lock_z2_motor(bool state) { locked_z2_motor = state; }
1255
+#endif

+ 6
- 0
Marlin/stepper.h View File

97
 void microstep_init();
97
 void microstep_init();
98
 void microstep_readings();
98
 void microstep_readings();
99
 
99
 
100
+#ifdef Z_DUAL_ENDSTOPS
101
+  void In_Homing_Process(bool state);
102
+  void Lock_z_motor(bool state);
103
+  void Lock_z2_motor(bool state);
104
+#endif
105
+
100
 #ifdef BABYSTEPPING
106
 #ifdef BABYSTEPPING
101
   void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
107
   void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
102
 #endif
108
 #endif

Loading…
Cancel
Save