Sfoglia il codice sorgente

Cleanup for dual endstops homing

Scott Lahteine 6 anni fa
parent
commit
ad8d3150aa

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

396
 // Check endstops - Could be called from ISR!
396
 // Check endstops - Could be called from ISR!
397
 void Endstops::update() {
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
   // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
399
   // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
401
   #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
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
   // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
401
   // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
590
     if (dual_hit) { \
589
     if (dual_hit) { \
591
       _ENDSTOP_HIT(AXIS1, MINMAX); \
590
       _ENDSTOP_HIT(AXIS1, MINMAX); \
592
       /* if not performing home or if both endstops were trigged during homing... */ \
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
         planner.endstop_triggered(_AXIS(AXIS1)); \
593
         planner.endstop_triggered(_AXIS(AXIS1)); \
595
     } \
594
     } \
596
   }while(0)
595
   }while(0)

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

1052
     if (DEBUGGING(LEVELING)) {
1052
     if (DEBUGGING(LEVELING)) {
1053
       SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]);
1053
       SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]);
1054
       SERIAL_ECHOPAIR(", ", distance);
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
   #endif
1064
   #endif
1060
 
1065
 
1262
     }
1267
     }
1263
   #endif
1268
   #endif
1264
 
1269
 
1265
-  const int axis_home_dir =
1270
+  const int axis_home_dir = (
1266
     #if ENABLED(DUAL_X_CARRIAGE)
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
     #endif
1273
     #endif
1269
-    home_dir(axis);
1274
+    home_dir(axis)
1275
+  );
1270
 
1276
 
1271
   // Homing Z towards the bed? Deploy the Z probe or endstop.
1277
   // Homing Z towards the bed? Deploy the Z probe or endstop.
1272
   #if HOMING_Z_WITH_PROBE
1278
   #if HOMING_Z_WITH_PROBE
1274
   #endif
1280
   #endif
1275
 
1281
 
1276
   // Set flags for X, Y, Z motor locking
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
   #endif
1297
   #endif
1286
 
1298
 
1287
   // Fast move towards endstop until triggered
1299
   // Fast move towards endstop until triggered
1321
     const bool pos_dir = axis_home_dir > 0;
1333
     const bool pos_dir = axis_home_dir > 0;
1322
     #if ENABLED(X_DUAL_ENDSTOPS)
1334
     #if ENABLED(X_DUAL_ENDSTOPS)
1323
       if (axis == X_AXIS) {
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
     #endif
1342
     #endif
1333
     #if ENABLED(Y_DUAL_ENDSTOPS)
1343
     #if ENABLED(Y_DUAL_ENDSTOPS)
1334
       if (axis == Y_AXIS) {
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
     #endif
1351
     #endif
1344
     #if ENABLED(Z_DUAL_ENDSTOPS)
1352
     #if ENABLED(Z_DUAL_ENDSTOPS)
1345
       if (axis == Z_AXIS) {
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
     #endif
1360
     #endif
1361
+    stepper.set_homing_dual_axis(false);
1355
   #endif
1362
   #endif
1356
 
1363
 
1357
   #if IS_SCARA
1364
   #if IS_SCARA
1393
     if (axis == Z_AXIS && STOW_PROBE()) return;
1400
     if (axis == Z_AXIS && STOW_PROBE()) return;
1394
   #endif
1401
   #endif
1395
 
1402
 
1396
-  // Clear z_lift if homing the Z axis
1403
+  // Clear retracted status if homing the Z axis
1397
   #if ENABLED(FWRETRACT)
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
   #endif
1406
   #endif
1401
 
1407
 
1402
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1408
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1470
     #endif
1476
     #endif
1471
 
1477
 
1472
     #if ENABLED(DELTA)
1478
     #if ENABLED(DELTA)
1473
-      switch(axis) {
1479
+      switch (axis) {
1474
         #if HAS_SOFTWARE_ENDSTOPS
1480
         #if HAS_SOFTWARE_ENDSTOPS
1475
           case X_AXIS:
1481
           case X_AXIS:
1476
           case Y_AXIS:
1482
           case Y_AXIS:

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

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

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

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

Loading…
Annulla
Salva