Browse Source

Cleanup for dual endstops homing

Scott Lahteine 6 years ago
parent
commit
ad8d3150aa

+ 1
- 2
Marlin/src/module/endstops.cpp View File

@@ -396,7 +396,6 @@ void Endstops::M119() {
396 396
 // Check endstops - Could be called from ISR!
397 397
 void Endstops::update() {
398 398
 
399
-  #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
400 399
   // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
401 400
   #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
402 401
   // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
@@ -590,7 +589,7 @@ void Endstops::update() {
590 589
     if (dual_hit) { \
591 590
       _ENDSTOP_HIT(AXIS1, MINMAX); \
592 591
       /* if not performing home or if both endstops were trigged during homing... */ \
593
-      if (!stepper.performing_homing || dual_hit == 0x3) \
592
+      if (!stepper.homing_dual_axis || dual_hit == 0x3) \
594 593
         planner.endstop_triggered(_AXIS(AXIS1)); \
595 594
     } \
596 595
   }while(0)

+ 45
- 39
Marlin/src/module/motion.cpp View File

@@ -1052,9 +1052,14 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
1052 1052
     if (DEBUGGING(LEVELING)) {
1053 1053
       SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]);
1054 1054
       SERIAL_ECHOPAIR(", ", distance);
1055
-      SERIAL_ECHOPAIR(", ", fr_mm_s);
1056
-      SERIAL_ECHOPAIR(" [", fr_mm_s ? fr_mm_s : homing_feedrate(axis));
1057
-      SERIAL_ECHOLNPGM("])");
1055
+      SERIAL_ECHOPGM(", ");
1056
+      if (fr_mm_s)
1057
+        SERIAL_ECHO(fr_mm_s);
1058
+      else {
1059
+        SERIAL_ECHOPAIR("[", homing_feedrate(axis));
1060
+        SERIAL_CHAR(']');
1061
+      }
1062
+      SERIAL_ECHOLNPGM(")");
1058 1063
     }
1059 1064
   #endif
1060 1065
 
@@ -1262,11 +1267,12 @@ void homeaxis(const AxisEnum axis) {
1262 1267
     }
1263 1268
   #endif
1264 1269
 
1265
-  const int axis_home_dir =
1270
+  const int axis_home_dir = (
1266 1271
     #if ENABLED(DUAL_X_CARRIAGE)
1267
-      (axis == X_AXIS) ? x_home_dir(active_extruder) :
1272
+      axis == X_AXIS ? x_home_dir(active_extruder) :
1268 1273
     #endif
1269
-    home_dir(axis);
1274
+    home_dir(axis)
1275
+  );
1270 1276
 
1271 1277
   // Homing Z towards the bed? Deploy the Z probe or endstop.
1272 1278
   #if HOMING_Z_WITH_PROBE
@@ -1274,14 +1280,20 @@ void homeaxis(const AxisEnum axis) {
1274 1280
   #endif
1275 1281
 
1276 1282
   // Set flags for X, Y, Z motor locking
1277
-  #if ENABLED(X_DUAL_ENDSTOPS)
1278
-    if (axis == X_AXIS) stepper.set_homing_flag_x(true);
1279
-  #endif
1280
-  #if ENABLED(Y_DUAL_ENDSTOPS)
1281
-    if (axis == Y_AXIS) stepper.set_homing_flag_y(true);
1282
-  #endif
1283
-  #if ENABLED(Z_DUAL_ENDSTOPS)
1284
-    if (axis == Z_AXIS) stepper.set_homing_flag_z(true);
1283
+  #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
1284
+    switch (axis) {
1285
+      #if ENABLED(X_DUAL_ENDSTOPS)
1286
+        case X_AXIS:
1287
+      #endif
1288
+      #if ENABLED(Y_DUAL_ENDSTOPS)
1289
+        case Y_AXIS:
1290
+      #endif
1291
+      #if ENABLED(Z_DUAL_ENDSTOPS)
1292
+        case Z_AXIS:
1293
+      #endif
1294
+      stepper.set_homing_dual_axis(true);
1295
+      default: break;
1296
+    }
1285 1297
   #endif
1286 1298
 
1287 1299
   // Fast move towards endstop until triggered
@@ -1321,37 +1333,32 @@ void homeaxis(const AxisEnum axis) {
1321 1333
     const bool pos_dir = axis_home_dir > 0;
1322 1334
     #if ENABLED(X_DUAL_ENDSTOPS)
1323 1335
       if (axis == X_AXIS) {
1324
-        const bool lock_x1 = pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0);
1325
-        float adj = ABS(endstops.x_endstop_adj);
1326
-        if (pos_dir) adj = -adj;
1327
-        if (lock_x1) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
1328
-        do_homing_move(axis, adj);
1329
-        if (lock_x1) stepper.set_x_lock(false); else stepper.set_x2_lock(false);
1330
-        stepper.set_homing_flag_x(false);
1336
+        const float adj = ABS(endstops.x_endstop_adj);
1337
+        if (pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
1338
+        do_homing_move(axis, pos_dir ? adj : -adj);
1339
+        stepper.set_x_lock(false);
1340
+        stepper.set_x2_lock(false);
1331 1341
       }
1332 1342
     #endif
1333 1343
     #if ENABLED(Y_DUAL_ENDSTOPS)
1334 1344
       if (axis == Y_AXIS) {
1335
-        const bool lock_y1 = pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0);
1336
-        float adj = ABS(endstops.y_endstop_adj);
1337
-        if (pos_dir) adj = -adj;
1338
-        if (lock_y1) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
1339
-        do_homing_move(axis, adj);
1340
-        if (lock_y1) stepper.set_y_lock(false); else stepper.set_y2_lock(false);
1341
-        stepper.set_homing_flag_y(false);
1345
+        const float adj = ABS(endstops.y_endstop_adj);
1346
+        if (pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
1347
+        do_homing_move(axis, pos_dir ? adj : -adj);
1348
+        stepper.set_y_lock(false);
1349
+        stepper.set_y2_lock(false);
1342 1350
       }
1343 1351
     #endif
1344 1352
     #if ENABLED(Z_DUAL_ENDSTOPS)
1345 1353
       if (axis == Z_AXIS) {
1346
-        const bool lock_z1 = pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0);
1347
-        float adj = ABS(endstops.z_endstop_adj);
1348
-        if (pos_dir) adj = -adj;
1349
-        if (lock_z1) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
1350
-        do_homing_move(axis, adj);
1351
-        if (lock_z1) stepper.set_z_lock(false); else stepper.set_z2_lock(false);
1352
-        stepper.set_homing_flag_z(false);
1354
+        const float adj = ABS(endstops.z_endstop_adj);
1355
+        if (pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0)) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
1356
+        do_homing_move(axis, pos_dir ? adj : -adj);
1357
+        stepper.set_z_lock(false);
1358
+        stepper.set_z2_lock(false);
1353 1359
       }
1354 1360
     #endif
1361
+    stepper.set_homing_dual_axis(false);
1355 1362
   #endif
1356 1363
 
1357 1364
   #if IS_SCARA
@@ -1393,10 +1400,9 @@ void homeaxis(const AxisEnum axis) {
1393 1400
     if (axis == Z_AXIS && STOW_PROBE()) return;
1394 1401
   #endif
1395 1402
 
1396
-  // Clear z_lift if homing the Z axis
1403
+  // Clear retracted status if homing the Z axis
1397 1404
   #if ENABLED(FWRETRACT)
1398
-    if (axis == Z_AXIS)
1399
-      fwretract.hop_amount = 0.0;
1405
+    if (axis == Z_AXIS) fwretract.hop_amount = 0.0;
1400 1406
   #endif
1401 1407
 
1402 1408
   #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -1470,7 +1476,7 @@ void homeaxis(const AxisEnum axis) {
1470 1476
     #endif
1471 1477
 
1472 1478
     #if ENABLED(DELTA)
1473
-      switch(axis) {
1479
+      switch (axis) {
1474 1480
         #if HAS_SOFTWARE_ENDSTOPS
1475 1481
           case X_AXIS:
1476 1482
           case Y_AXIS:

+ 7
- 10
Marlin/src/module/stepper.cpp View File

@@ -87,7 +87,7 @@ Stepper stepper; // Singleton
87 87
 block_t* Stepper::current_block = NULL;  // A pointer to the block currently being traced
88 88
 
89 89
 #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
90
-  bool Stepper::performing_homing = false;
90
+  bool Stepper::homing_dual_axis = false;
91 91
 #endif
92 92
 
93 93
 #if HAS_MOTOR_CURRENT_PWM
@@ -166,7 +166,7 @@ bool Stepper::all_steps_done = false;
166 166
 uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
167 167
 
168 168
 volatile int32_t Stepper::count_position[NUM_AXIS] = { 0 };
169
-volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
169
+int8_t Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
170 170
 
171 171
 #if ENABLED(MIXING_EXTRUDER)
172 172
   int32_t Stepper::counter_m[MIXING_STEPPERS];
@@ -183,7 +183,7 @@ volatile int32_t Stepper::endstops_trigsteps[XYZ];
183 183
 
184 184
 #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
185 185
   #define DUAL_ENDSTOP_APPLY_STEP(A,V)                                                                                        \
186
-    if (performing_homing) {                                                                                                  \
186
+    if (homing_dual_axis) {                                                                                                   \
187 187
       if (A##_HOME_DIR < 0) {                                                                                                 \
188 188
         if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V);    \
189 189
         if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
@@ -1144,7 +1144,6 @@ void Stepper::set_directions() {
1144 1144
 HAL_STEP_TIMER_ISR {
1145 1145
   HAL_timer_isr_prologue(STEP_TIMER_NUM);
1146 1146
 
1147
-  // Call the ISR
1148 1147
   Stepper::isr();
1149 1148
 
1150 1149
   HAL_timer_isr_epilogue(STEP_TIMER_NUM);
@@ -1175,7 +1174,7 @@ void Stepper::isr() {
1175 1174
   // We need this variable here to be able to use it in the following loop
1176 1175
   hal_timer_t min_ticks;
1177 1176
   do {
1178
-    // Enable ISRs so the USART processing latency is reduced
1177
+    // Enable ISRs to reduce USART processing latency
1179 1178
     ENABLE_ISRS();
1180 1179
 
1181 1180
     // Run main stepping pulse phase ISR if we have to
@@ -1193,11 +1192,9 @@ void Stepper::isr() {
1193 1192
 
1194 1193
     uint32_t interval =
1195 1194
       #if ENABLED(LIN_ADVANCE)
1196
-        // Select the closest interval in time
1197
-        MIN(nextAdvanceISR, nextMainISR)
1195
+        MIN(nextAdvanceISR, nextMainISR)  // Nearest time interval
1198 1196
       #else
1199
-        // The interval is just the remaining time to the stepper ISR
1200
-        nextMainISR
1197
+        nextMainISR                       // Remaining stepper ISR time
1201 1198
       #endif
1202 1199
     ;
1203 1200
 
@@ -1239,7 +1236,7 @@ void Stepper::isr() {
1239 1236
     next_isr_ticks += interval;
1240 1237
 
1241 1238
     /**
1242
-     *  The following section must be done with global interrupts disabled.
1239
+     * The following section must be done with global interrupts disabled.
1243 1240
      * We want nothing to interrupt it, as that could mess the calculations
1244 1241
      * we do for the next value to program in the period register of the
1245 1242
      * stepper timer and lead to skipped ISRs (if the value we happen to program

+ 5
- 11
Marlin/src/module/stepper.h View File

@@ -63,7 +63,7 @@ class Stepper {
63 63
     static block_t* current_block;  // A pointer to the block currently being traced
64 64
 
65 65
     #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
66
-      static bool performing_homing;
66
+      static bool homing_dual_axis;
67 67
     #endif
68 68
 
69 69
     #if HAS_MOTOR_CURRENT_PWM
@@ -143,7 +143,7 @@ class Stepper {
143 143
     //
144 144
     // Current direction of stepper motors (+1 or -1)
145 145
     //
146
-    static volatile signed char count_direction[NUM_AXIS];
146
+    static int8_t count_direction[NUM_AXIS];
147 147
 
148 148
     //
149 149
     // Mixing extruder mix counters
@@ -220,18 +220,18 @@ class Stepper {
220 220
       static void microstep_readings();
221 221
     #endif
222 222
 
223
+    #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
224
+      FORCE_INLINE static void set_homing_dual_axis(const bool state) { homing_dual_axis = state; }
225
+    #endif
223 226
     #if ENABLED(X_DUAL_ENDSTOPS)
224
-      FORCE_INLINE static void set_homing_flag_x(const bool state) { performing_homing = state; }
225 227
       FORCE_INLINE static void set_x_lock(const bool state) { locked_X_motor = state; }
226 228
       FORCE_INLINE static void set_x2_lock(const bool state) { locked_X2_motor = state; }
227 229
     #endif
228 230
     #if ENABLED(Y_DUAL_ENDSTOPS)
229
-      FORCE_INLINE static void set_homing_flag_y(const bool state) { performing_homing = state; }
230 231
       FORCE_INLINE static void set_y_lock(const bool state) { locked_Y_motor = state; }
231 232
       FORCE_INLINE static void set_y2_lock(const bool state) { locked_Y2_motor = state; }
232 233
     #endif
233 234
     #if ENABLED(Z_DUAL_ENDSTOPS)
234
-      FORCE_INLINE static void set_homing_flag_z(const bool state) { performing_homing = state; }
235 235
       FORCE_INLINE static void set_z_lock(const bool state) { locked_Z_motor = state; }
236 236
       FORCE_INLINE static void set_z2_lock(const bool state) { locked_Z2_motor = state; }
237 237
     #endif
@@ -247,15 +247,9 @@ class Stepper {
247 247
     // Set the current position in steps
248 248
     inline static void set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) {
249 249
       planner.synchronize();
250
-
251
-      // Disable stepper interrupts, to ensure atomic setting of all the position variables
252 250
       const bool was_enabled = STEPPER_ISR_ENABLED();
253 251
       if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
254
-
255
-      // Set position
256 252
       _set_position(a, b, c, e);
257
-
258
-      // Reenable Stepper ISR
259 253
       if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
260 254
     }
261 255
 

Loading…
Cancel
Save