Browse Source

Move get_axis_position_mm to Planner (#10718)

Scott Lahteine 6 years ago
parent
commit
8f8c6a9bc4
No account linked to committer's email address

+ 3
- 3
Marlin/src/core/utility.cpp View File

338
         #endif
338
         #endif
339
         #if ABL_PLANAR
339
         #if ABL_PLANAR
340
           const float diff[XYZ] = {
340
           const float diff[XYZ] = {
341
-            stepper.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
342
-            stepper.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
343
-            stepper.get_axis_position_mm(Z_AXIS) - current_position[Z_AXIS]
341
+            planner.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
342
+            planner.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
343
+            planner.get_axis_position_mm(Z_AXIS) - current_position[Z_AXIS]
344
           };
344
           };
345
           SERIAL_ECHOPGM("ABL Adjustment X");
345
           SERIAL_ECHOPGM("ABL Adjustment X");
346
           if (diff[X_AXIS] > 0) SERIAL_CHAR('+');
346
           if (diff[X_AXIS] > 0) SERIAL_CHAR('+');

+ 12
- 12
Marlin/src/feature/I2CPositionEncoder.cpp View File

99
 
99
 
100
         //the encoder likely lost its place when the error occured, so we'll reset and use the printer's
100
         //the encoder likely lost its place when the error occured, so we'll reset and use the printer's
101
         //idea of where it the axis is to re-initialise
101
         //idea of where it the axis is to re-initialise
102
-        float position = stepper.get_axis_position_mm(encoderAxis);
103
-        int32_t positionInTicks = position * get_ticks_unit();
102
+        const float pos = planner.get_axis_position_mm(encoderAxis);
103
+        int32_t positionInTicks = pos * get_ticks_unit();
104
 
104
 
105
         //shift position from previous to current position
105
         //shift position from previous to current position
106
         zeroOffset -= (positionInTicks - get_position());
106
         zeroOffset -= (positionInTicks - get_position());
107
 
107
 
108
         #ifdef I2CPE_DEBUG
108
         #ifdef I2CPE_DEBUG
109
           SERIAL_ECHOPGM("Current position is ");
109
           SERIAL_ECHOPGM("Current position is ");
110
-          SERIAL_ECHOLN(position);
110
+          SERIAL_ECHOLN(pos);
111
 
111
 
112
           SERIAL_ECHOPGM("Position in encoder ticks is ");
112
           SERIAL_ECHOPGM("Position in encoder ticks is ");
113
           SERIAL_ECHOLN(positionInTicks);
113
           SERIAL_ECHOLN(positionInTicks);
254
 float I2CPositionEncoder::get_axis_error_mm(const bool report) {
254
 float I2CPositionEncoder::get_axis_error_mm(const bool report) {
255
   float target, actual, error;
255
   float target, actual, error;
256
 
256
 
257
-  target = stepper.get_axis_position_mm(encoderAxis);
257
+  target = planner.get_axis_position_mm(encoderAxis);
258
   actual = mm_from_count(position);
258
   actual = mm_from_count(position);
259
   error = actual - target;
259
   error = actual - target;
260
 
260
 
349
   ec = false;
349
   ec = false;
350
 
350
 
351
   LOOP_NA(i) {
351
   LOOP_NA(i) {
352
-    startCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
353
-    endCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
352
+    startCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
353
+    endCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
354
   }
354
   }
355
 
355
 
356
   startCoord[encoderAxis] = startPosition;
356
   startCoord[encoderAxis] = startPosition;
359
   planner.synchronize();
359
   planner.synchronize();
360
 
360
 
361
   planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
361
   planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
362
-                      stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
362
+                      planner.get_axis_position_mm(E_AXIS), feedrate, 0);
363
   planner.synchronize();
363
   planner.synchronize();
364
 
364
 
365
   // if the module isn't currently trusted, wait until it is (or until it should be if things are working)
365
   // if the module isn't currently trusted, wait until it is (or until it should be if things are working)
371
 
371
 
372
   if (trusted) { // if trusted, commence test
372
   if (trusted) { // if trusted, commence test
373
     planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
373
     planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
374
-                        stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
374
+                        planner.get_axis_position_mm(E_AXIS), feedrate, 0);
375
     planner.synchronize();
375
     planner.synchronize();
376
   }
376
   }
377
 
377
 
408
   travelDistance = endDistance - startDistance;
408
   travelDistance = endDistance - startDistance;
409
 
409
 
410
   LOOP_NA(i) {
410
   LOOP_NA(i) {
411
-    startCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
412
-    endCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
411
+    startCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
412
+    endCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
413
   }
413
   }
414
 
414
 
415
   startCoord[encoderAxis] = startDistance;
415
   startCoord[encoderAxis] = startDistance;
419
 
419
 
420
   LOOP_L_N(i, iter) {
420
   LOOP_L_N(i, iter) {
421
     planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
421
     planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
422
-                        stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
422
+                        planner.get_axis_position_mm(E_AXIS), feedrate, 0);
423
     planner.synchronize();
423
     planner.synchronize();
424
 
424
 
425
     delay(250);
425
     delay(250);
428
     //do_blocking_move_to(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS]);
428
     //do_blocking_move_to(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS]);
429
 
429
 
430
     planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
430
     planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
431
-                        stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
431
+                        planner.get_axis_position_mm(E_AXIS), feedrate, 0);
432
     planner.synchronize();
432
     planner.synchronize();
433
 
433
 
434
     //Read encoder distance
434
     //Read encoder distance

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp View File

448
 
448
 
449
     #if IS_SCARA // scale the feed rate from mm/s to degrees/s
449
     #if IS_SCARA // scale the feed rate from mm/s to degrees/s
450
       scara_feed_factor = cartesian_xy_mm * inv_segments * feedrate;
450
       scara_feed_factor = cartesian_xy_mm * inv_segments * feedrate;
451
-      scara_oldA = stepper.get_axis_position_degrees(A_AXIS);
452
-      scara_oldB = stepper.get_axis_position_degrees(B_AXIS);
451
+      scara_oldA = planner.get_axis_position_degrees(A_AXIS);
452
+      scara_oldB = planner.get_axis_position_degrees(B_AXIS);
453
     #endif
453
     #endif
454
 
454
 
455
     const float diff[XYZE] = {
455
     const float diff[XYZE] = {

+ 3
- 3
Marlin/src/gcode/host/M114.cpp View File

90
 
90
 
91
     #if IS_SCARA
91
     #if IS_SCARA
92
       const float deg[XYZ] = {
92
       const float deg[XYZ] = {
93
-        stepper.get_axis_position_degrees(A_AXIS),
94
-        stepper.get_axis_position_degrees(B_AXIS)
93
+        planner.get_axis_position_degrees(A_AXIS),
94
+        planner.get_axis_position_degrees(B_AXIS)
95
       };
95
       };
96
       SERIAL_PROTOCOLPGM("Degrees:");
96
       SERIAL_PROTOCOLPGM("Degrees:");
97
       report_xyze(deg, 2);
97
       report_xyze(deg, 2);
99
 
99
 
100
     SERIAL_PROTOCOLPGM("FromStp:");
100
     SERIAL_PROTOCOLPGM("FromStp:");
101
     get_cartesian_from_steppers();  // writes cartes[XYZ] (with forward kinematics)
101
     get_cartesian_from_steppers();  // writes cartes[XYZ] (with forward kinematics)
102
-    const float from_steppers[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], stepper.get_axis_position_mm(E_AXIS) };
102
+    const float from_steppers[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], planner.get_axis_position_mm(E_AXIS) };
103
     report_xyze(from_steppers);
103
     report_xyze(from_steppers);
104
 
104
 
105
     const float diff[XYZE] = {
105
     const float diff[XYZE] = {

+ 9
- 14
Marlin/src/module/motion.cpp View File

193
 void get_cartesian_from_steppers() {
193
 void get_cartesian_from_steppers() {
194
   #if ENABLED(DELTA)
194
   #if ENABLED(DELTA)
195
     forward_kinematics_DELTA(
195
     forward_kinematics_DELTA(
196
-      stepper.get_axis_position_mm(A_AXIS),
197
-      stepper.get_axis_position_mm(B_AXIS),
198
-      stepper.get_axis_position_mm(C_AXIS)
196
+      planner.get_axis_position_mm(A_AXIS),
197
+      planner.get_axis_position_mm(B_AXIS),
198
+      planner.get_axis_position_mm(C_AXIS)
199
     );
199
     );
200
   #else
200
   #else
201
     #if IS_SCARA
201
     #if IS_SCARA
202
       forward_kinematics_SCARA(
202
       forward_kinematics_SCARA(
203
-        stepper.get_axis_position_degrees(A_AXIS),
204
-        stepper.get_axis_position_degrees(B_AXIS)
203
+        planner.get_axis_position_degrees(A_AXIS),
204
+        planner.get_axis_position_degrees(B_AXIS)
205
       );
205
       );
206
     #else
206
     #else
207
-      cartes[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
208
-      cartes[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
207
+      cartes[X_AXIS] = planner.get_axis_position_mm(X_AXIS);
208
+      cartes[Y_AXIS] = planner.get_axis_position_mm(Y_AXIS);
209
     #endif
209
     #endif
210
-    cartes[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
210
+    cartes[Z_AXIS] = planner.get_axis_position_mm(Z_AXIS);
211
   #endif
211
   #endif
212
 }
212
 }
213
 
213
 
870
               }
870
               }
871
             #endif
871
             #endif
872
             // move duplicate extruder into correct duplication position.
872
             // move duplicate extruder into correct duplication position.
873
-            planner.set_position_mm(
874
-              inactive_extruder_x_pos,
875
-              current_position[Y_AXIS],
876
-              current_position[Z_AXIS],
877
-              current_position[E_AXIS]
878
-            );
873
+            planner.set_position_mm(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
879
             planner.buffer_line(
874
             planner.buffer_line(
880
               current_position[X_AXIS] + duplicate_extruder_x_offset,
875
               current_position[X_AXIS] + duplicate_extruder_x_offset,
881
               current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
876
               current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],

+ 31
- 0
Marlin/src/module/planner.cpp View File

1300
 #endif // PLANNER_LEVELING
1300
 #endif // PLANNER_LEVELING
1301
 
1301
 
1302
 /**
1302
 /**
1303
+ * Get an axis position according to stepper position(s)
1304
+ * For CORE machines apply translation from ABC to XYZ.
1305
+ */
1306
+float Planner::get_axis_position_mm(const AxisEnum axis) {
1307
+  float axis_steps;
1308
+  #if IS_CORE
1309
+    // Requesting one of the "core" axes?
1310
+    if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
1311
+
1312
+      // Protect the access to the position.
1313
+      const bool was_enabled = STEPPER_ISR_ENABLED();
1314
+      DISABLE_STEPPER_DRIVER_INTERRUPT();
1315
+
1316
+      // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
1317
+      // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
1318
+      axis_steps = 0.5f * (
1319
+        axis == CORE_AXIS_2 ? CORESIGN(stepper.position(CORE_AXIS_1) - stepper.position(CORE_AXIS_2))
1320
+                            : stepper.position(CORE_AXIS_1) + stepper.position(CORE_AXIS_2)
1321
+      );
1322
+
1323
+      if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
1324
+    }
1325
+    else
1326
+      axis_steps = stepper.position(axis);
1327
+  #else
1328
+    axis_steps = stepper.position(axis);
1329
+  #endif
1330
+  return axis_steps * steps_to_mm[axis];
1331
+}
1332
+
1333
+/**
1303
  * Block until all buffered steps are executed / cleaned
1334
  * Block until all buffered steps are executed / cleaned
1304
  */
1335
  */
1305
 void Planner::synchronize() { while (has_blocks_queued() || stepper.cleaning_buffer_counter) idle(); }
1336
 void Planner::synchronize() { while (has_blocks_queued() || stepper.cleaning_buffer_counter) idle(); }

+ 11
- 0
Marlin/src/module/planner.h View File

547
     static void sync_from_steppers();
547
     static void sync_from_steppers();
548
 
548
 
549
     /**
549
     /**
550
+     * Get an axis position according to stepper position(s)
551
+     * For CORE machines apply translation from ABC to XYZ.
552
+     */
553
+    static float get_axis_position_mm(const AxisEnum axis);
554
+
555
+    // SCARA AB axes are in degrees, not mm
556
+    #if IS_SCARA
557
+      FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
558
+    #endif
559
+
560
+    /**
550
      * Does the buffer have any blocks queued?
561
      * Does the buffer have any blocks queued?
551
      */
562
      */
552
     FORCE_INLINE static bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }
563
     FORCE_INLINE static bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }

+ 3
- 3
Marlin/src/module/scara.cpp View File

30
 
30
 
31
 #include "scara.h"
31
 #include "scara.h"
32
 #include "motion.h"
32
 #include "motion.h"
33
-#include "stepper.h"
33
+#include "planner.h"
34
 
34
 
35
 float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
35
 float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
36
 
36
 
147
 }
147
 }
148
 
148
 
149
 void scara_report_positions() {
149
 void scara_report_positions() {
150
-  SERIAL_PROTOCOLPAIR("SCARA Theta:", stepper.get_axis_position_degrees(A_AXIS));
151
-  SERIAL_PROTOCOLLNPAIR("   Psi+Theta:", stepper.get_axis_position_degrees(B_AXIS));
150
+  SERIAL_PROTOCOLPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS));
151
+  SERIAL_PROTOCOLLNPAIR("   Psi+Theta:", planner.get_axis_position_degrees(B_AXIS));
152
   SERIAL_EOL();
152
   SERIAL_EOL();
153
 }
153
 }
154
 
154
 

+ 0
- 26
Marlin/src/module/stepper.cpp View File

2037
   return count_pos;
2037
   return count_pos;
2038
 }
2038
 }
2039
 
2039
 
2040
-/**
2041
- * Get an axis position according to stepper position(s)
2042
- * For CORE machines apply translation from ABC to XYZ.
2043
- */
2044
-float Stepper::get_axis_position_mm(const AxisEnum axis) {
2045
-  float axis_steps;
2046
-  #if IS_CORE
2047
-    // Requesting one of the "core" axes?
2048
-    if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
2049
-      CRITICAL_SECTION_START;
2050
-      // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
2051
-      // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
2052
-      axis_steps = 0.5f * (
2053
-        axis == CORE_AXIS_2 ? CORESIGN(count_position[CORE_AXIS_1] - count_position[CORE_AXIS_2])
2054
-                            : count_position[CORE_AXIS_1] + count_position[CORE_AXIS_2]
2055
-      );
2056
-      CRITICAL_SECTION_END;
2057
-    }
2058
-    else
2059
-      axis_steps = position(axis);
2060
-  #else
2061
-    axis_steps = position(axis);
2062
-  #endif
2063
-  return axis_steps * planner.steps_to_mm[axis];
2064
-}
2065
-
2066
 void Stepper::finish_and_disable() {
2040
 void Stepper::finish_and_disable() {
2067
   planner.synchronize();
2041
   planner.synchronize();
2068
   disable_all_steppers();
2042
   disable_all_steppers();

+ 0
- 12
Marlin/src/module/stepper.h View File

229
     static void report_positions();
229
     static void report_positions();
230
 
230
 
231
     //
231
     //
232
-    // Get the position (mm) of an axis based on stepper position(s)
233
-    //
234
-    static float get_axis_position_mm(const AxisEnum axis);
235
-
236
-    //
237
-    // SCARA AB axes are in degrees, not mm
238
-    //
239
-    #if IS_SCARA
240
-      FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
241
-    #endif
242
-
243
-    //
244
     // The stepper subsystem goes to sleep when it runs out of things to execute. Call this
232
     // The stepper subsystem goes to sleep when it runs out of things to execute. Call this
245
     // to notify the subsystem that it is time to go to work.
233
     // to notify the subsystem that it is time to go to work.
246
     //
234
     //

+ 1
- 1
Marlin/src/module/temperature.cpp View File

36
   #include "../libs/private_spi.h"
36
   #include "../libs/private_spi.h"
37
 #endif
37
 #endif
38
 
38
 
39
-#if ENABLED(BABYSTEPPING)
39
+#if ENABLED(BABYSTEPPING) || ENABLED(PID_EXTRUSION_SCALING)
40
   #include "stepper.h"
40
   #include "stepper.h"
41
 #endif
41
 #endif
42
 
42
 

+ 0
- 4
Marlin/src/module/temperature.h View File

38
   #include "../feature/power.h"
38
   #include "../feature/power.h"
39
 #endif
39
 #endif
40
 
40
 
41
-#if ENABLED(PID_EXTRUSION_SCALING)
42
-  #include "stepper.h"
43
-#endif
44
-
45
 #ifndef SOFT_PWM_SCALE
41
 #ifndef SOFT_PWM_SCALE
46
   #define SOFT_PWM_SCALE 0
42
   #define SOFT_PWM_SCALE 0
47
 #endif
43
 #endif

Loading…
Cancel
Save