浏览代码

Make POSITION macros global

Scott Lahteine 9 年前
父节点
当前提交
f75b0c2ee1
共有 2 个文件被更改,包括 47 次插入39 次删除
  1. 16
    4
      Marlin/Marlin.h
  2. 31
    35
      Marlin/Marlin_main.cpp

+ 16
- 4
Marlin/Marlin.h 查看文件

292
 extern int extruder_multiplier[EXTRUDERS]; // sets extrude multiply factor (in percent) for each extruder individually
292
 extern int extruder_multiplier[EXTRUDERS]; // sets extrude multiply factor (in percent) for each extruder individually
293
 extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
293
 extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
294
 extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
294
 extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
295
-extern float current_position[NUM_AXIS];
296
-extern float home_offset[3]; // axis[n].home_offset
297
-extern float sw_endstop_min[3]; // axis[n].sw_endstop_min
298
-extern float sw_endstop_max[3]; // axis[n].sw_endstop_max
299
 extern bool axis_known_position[3]; // axis[n].is_known
295
 extern bool axis_known_position[3]; // axis[n].is_known
300
 extern bool axis_homed[3]; // axis[n].is_homed
296
 extern bool axis_homed[3]; // axis[n].is_homed
301
 extern volatile bool wait_for_heatup;
297
 extern volatile bool wait_for_heatup;
302
 
298
 
299
+extern float current_position[NUM_AXIS];
300
+extern float position_shift[3];
301
+extern float home_offset[3];
302
+extern float sw_endstop_min[3];
303
+extern float sw_endstop_max[3];
304
+
305
+#define LOGICAL_POSITION(POS, AXIS) (POS + home_offset[AXIS] + position_shift[AXIS])
306
+#define RAW_POSITION(POS, AXIS)     (POS - home_offset[AXIS] - position_shift[AXIS])
307
+#define LOGICAL_X_POSITION(POS)     LOGICAL_POSITION(POS, X_AXIS)
308
+#define LOGICAL_Y_POSITION(POS)     LOGICAL_POSITION(POS, Y_AXIS)
309
+#define LOGICAL_Z_POSITION(POS)     LOGICAL_POSITION(POS, Z_AXIS)
310
+#define RAW_X_POSITION(POS)         RAW_POSITION(POS, X_AXIS)
311
+#define RAW_Y_POSITION(POS)         RAW_POSITION(POS, Y_AXIS)
312
+#define RAW_Z_POSITION(POS)         RAW_POSITION(POS, Z_AXIS)
313
+#define RAW_CURRENT_POSITION(AXIS)  RAW_POSITION(current_position[AXIS], AXIS)
314
+
303
 // GCode support for external objects
315
 // GCode support for external objects
304
 bool code_seen(char);
316
 bool code_seen(char);
305
 int code_value_int();
317
 int code_value_int();

+ 31
- 35
Marlin/Marlin_main.cpp 查看文件

331
 // Set by M206, M428, or menu item. Saved to EEPROM.
331
 // Set by M206, M428, or menu item. Saved to EEPROM.
332
 float home_offset[3] = { 0 };
332
 float home_offset[3] = { 0 };
333
 
333
 
334
-#define LOGICAL_POSITION(POS, AXIS) (POS + home_offset[AXIS] + position_shift[AXIS])
335
-#define RAW_POSITION(POS, AXIS) (POS - home_offset[AXIS] - position_shift[AXIS])
336
-#define RAW_CURRENT_POSITION(AXIS) (RAW_POSITION(current_position[AXIS], AXIS))
337
-
338
 // Software Endstops. Default to configured limits.
334
 // Software Endstops. Default to configured limits.
339
 float sw_endstop_min[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
335
 float sw_endstop_min[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
340
 float sw_endstop_max[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
336
 float sw_endstop_max[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
1408
 
1404
 
1409
   static float x_home_pos(int extruder) {
1405
   static float x_home_pos(int extruder) {
1410
     if (extruder == 0)
1406
     if (extruder == 0)
1411
-      return LOGICAL_POSITION(base_home_pos(X_AXIS), X_AXIS);
1407
+      return LOGICAL_X_POSITION(base_home_pos(X_AXIS));
1412
     else
1408
     else
1413
       /**
1409
       /**
1414
        * In dual carriage mode the extruder offset provides an override of the
1410
        * In dual carriage mode the extruder offset provides an override of the
1513
       if (active_extruder != 0)
1509
       if (active_extruder != 0)
1514
         current_position[X_AXIS] = x_home_pos(active_extruder);
1510
         current_position[X_AXIS] = x_home_pos(active_extruder);
1515
       else
1511
       else
1516
-        current_position[X_AXIS] = LOGICAL_POSITION(base_home_pos(X_AXIS), X_AXIS);
1512
+        current_position[X_AXIS] = LOGICAL_X_POSITION(base_home_pos(X_AXIS));
1517
       update_software_endstops(X_AXIS);
1513
       update_software_endstops(X_AXIS);
1518
       return;
1514
       return;
1519
     }
1515
     }
1803
         SERIAL_ECHOLNPGM(")");
1799
         SERIAL_ECHOLNPGM(")");
1804
       }
1800
       }
1805
     #endif
1801
     #endif
1806
-    float z_dest = LOGICAL_POSITION(z_raise, Z_AXIS);
1802
+    float z_dest = LOGICAL_Z_POSITION(z_raise);
1807
 
1803
 
1808
     if (zprobe_zoffset < 0)
1804
     if (zprobe_zoffset < 0)
1809
       z_dest -= zprobe_zoffset;
1805
       z_dest -= zprobe_zoffset;
2964
 
2960
 
2965
       if (home_all_axis || homeX || homeY) {
2961
       if (home_all_axis || homeX || homeY) {
2966
         // Raise Z before homing any other axes and z is not already high enough (never lower z)
2962
         // Raise Z before homing any other axes and z is not already high enough (never lower z)
2967
-        destination[Z_AXIS] = LOGICAL_POSITION(MIN_Z_HEIGHT_FOR_HOMING, Z_AXIS);
2963
+        destination[Z_AXIS] = LOGICAL_Z_POSITION(MIN_Z_HEIGHT_FOR_HOMING);
2968
         if (destination[Z_AXIS] > current_position[Z_AXIS]) {
2964
         if (destination[Z_AXIS] > current_position[Z_AXIS]) {
2969
 
2965
 
2970
           #if ENABLED(DEBUG_LEVELING_FEATURE)
2966
           #if ENABLED(DEBUG_LEVELING_FEATURE)
3218
     ;
3214
     ;
3219
     line_to_current_position();
3215
     line_to_current_position();
3220
 
3216
 
3221
-    current_position[X_AXIS] = LOGICAL_POSITION(x, X_AXIS);
3222
-    current_position[Y_AXIS] = LOGICAL_POSITION(y, Y_AXIS);
3217
+    current_position[X_AXIS] = LOGICAL_X_POSITION(x);
3218
+    current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
3223
     line_to_current_position();
3219
     line_to_current_position();
3224
 
3220
 
3225
     #if Z_RAISE_BETWEEN_PROBINGS > 0 || MIN_Z_HEIGHT_FOR_HOMING > 0
3221
     #if Z_RAISE_BETWEEN_PROBINGS > 0 || MIN_Z_HEIGHT_FOR_HOMING > 0
3226
-      current_position[Z_AXIS] = LOGICAL_POSITION(MESH_HOME_SEARCH_Z, Z_AXIS);
3222
+      current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z);
3227
       line_to_current_position();
3223
       line_to_current_position();
3228
     #endif
3224
     #endif
3229
 
3225
 
3641
       #endif
3637
       #endif
3642
 
3638
 
3643
       // Probe at 3 arbitrary points
3639
       // Probe at 3 arbitrary points
3644
-      float z_at_pt_1 = probe_pt( LOGICAL_POSITION(ABL_PROBE_PT_1_X, X_AXIS),
3645
-                                  LOGICAL_POSITION(ABL_PROBE_PT_1_Y, Y_AXIS),
3640
+      float z_at_pt_1 = probe_pt( LOGICAL_X_POSITION(ABL_PROBE_PT_1_X, X_AXIS),
3641
+                                  LOGICAL_Y_POSITION(ABL_PROBE_PT_1_Y, Y_AXIS),
3646
                                   stow_probe_after_each, verbose_level),
3642
                                   stow_probe_after_each, verbose_level),
3647
-            z_at_pt_2 = probe_pt( LOGICAL_POSITION(ABL_PROBE_PT_2_X, X_AXIS),
3648
-                                  LOGICAL_POSITION(ABL_PROBE_PT_2_Y, Y_AXIS),
3643
+            z_at_pt_2 = probe_pt( LOGICAL_X_POSITION(ABL_PROBE_PT_2_X, X_AXIS),
3644
+                                  LOGICAL_Y_POSITION(ABL_PROBE_PT_2_Y, Y_AXIS),
3649
                                   stow_probe_after_each, verbose_level),
3645
                                   stow_probe_after_each, verbose_level),
3650
-            z_at_pt_3 = probe_pt( LOGICAL_POSITION(ABL_PROBE_PT_3_X, X_AXIS),
3651
-                                  LOGICAL_POSITION(ABL_PROBE_PT_3_Y, Y_AXIS),
3646
+            z_at_pt_3 = probe_pt( LOGICAL_X_POSITION(ABL_PROBE_PT_3_X, X_AXIS),
3647
+                                  LOGICAL_Y_POSITION(ABL_PROBE_PT_3_Y, Y_AXIS),
3652
                                   stow_probe_after_each, verbose_level);
3648
                                   stow_probe_after_each, verbose_level);
3653
 
3649
 
3654
       if (!dryrun) set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
3650
       if (!dryrun) set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
7748
   void inverse_kinematics(const float in_cartesian[3]) {
7744
   void inverse_kinematics(const float in_cartesian[3]) {
7749
 
7745
 
7750
     const float cartesian[3] = {
7746
     const float cartesian[3] = {
7751
-      RAW_POSITION(in_cartesian[X_AXIS], X_AXIS),
7752
-      RAW_POSITION(in_cartesian[Y_AXIS], Y_AXIS),
7753
-      RAW_POSITION(in_cartesian[Z_AXIS], Z_AXIS)
7747
+      RAW_X_POSITION(in_cartesian[X_AXIS]),
7748
+      RAW_Y_POSITION(in_cartesian[Y_AXIS]),
7749
+      RAW_Z_POSITION(in_cartesian[Z_AXIS])
7754
     };
7750
     };
7755
 
7751
 
7756
     delta[TOWER_1] = sqrt(delta_diagonal_rod_2_tower_1
7752
     delta[TOWER_1] = sqrt(delta_diagonal_rod_2_tower_1
7778
 
7774
 
7779
   float delta_safe_distance_from_top() {
7775
   float delta_safe_distance_from_top() {
7780
     float cartesian[3] = {
7776
     float cartesian[3] = {
7781
-      LOGICAL_POSITION(0, X_AXIS),
7782
-      LOGICAL_POSITION(0, Y_AXIS),
7783
-      LOGICAL_POSITION(0, Z_AXIS)
7777
+      LOGICAL_X_POSITION(0),
7778
+      LOGICAL_Y_POSITION(0),
7779
+      LOGICAL_Z_POSITION(0)
7784
     };
7780
     };
7785
     inverse_kinematics(cartesian);
7781
     inverse_kinematics(cartesian);
7786
     float distance = delta[TOWER_3];
7782
     float distance = delta[TOWER_3];
7787
-    cartesian[Y_AXIS] = LOGICAL_POSITION(DELTA_PRINTABLE_RADIUS, Y_AXIS);
7783
+    cartesian[Y_AXIS] = LOGICAL_Y_POSITION(DELTA_PRINTABLE_RADIUS);
7788
     inverse_kinematics(cartesian);
7784
     inverse_kinematics(cartesian);
7789
     return abs(distance - delta[TOWER_3]);
7785
     return abs(distance - delta[TOWER_3]);
7790
   }
7786
   }
7876
 
7872
 
7877
       int half = (AUTO_BED_LEVELING_GRID_POINTS - 1) / 2;
7873
       int half = (AUTO_BED_LEVELING_GRID_POINTS - 1) / 2;
7878
       float h1 = 0.001 - half, h2 = half - 0.001,
7874
       float h1 = 0.001 - half, h2 = half - 0.001,
7879
-            grid_x = max(h1, min(h2, RAW_POSITION(cartesian[X_AXIS], X_AXIS) / delta_grid_spacing[0])),
7880
-            grid_y = max(h1, min(h2, RAW_POSITION(cartesian[Y_AXIS], Y_AXIS) / delta_grid_spacing[1]));
7875
+            grid_x = max(h1, min(h2, RAW_X_POSITION(cartesian[X_AXIS]) / delta_grid_spacing[0])),
7876
+            grid_y = max(h1, min(h2, RAW_Y_POSITION(cartesian[Y_AXIS]) / delta_grid_spacing[1]));
7881
       int floor_x = floor(grid_x), floor_y = floor(grid_y);
7877
       int floor_x = floor(grid_x), floor_y = floor(grid_y);
7882
       float ratio_x = grid_x - floor_x, ratio_y = grid_y - floor_y,
7878
       float ratio_x = grid_x - floor_x, ratio_y = grid_y - floor_y,
7883
             z1 = bed_level[floor_x + half][floor_y + half],
7879
             z1 = bed_level[floor_x + half][floor_y + half],
7918
     current_position[axis] = LOGICAL_POSITION(cartesian_position[axis], axis);
7914
     current_position[axis] = LOGICAL_POSITION(cartesian_position[axis], axis);
7919
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
7915
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
7920
     vector_3 pos = planner.adjusted_position();
7916
     vector_3 pos = planner.adjusted_position();
7921
-    current_position[axis] = LOGICAL_POSITION(axis == X_AXIS ? pos.x : axis == Y_AXIS ? pos.y : pos.z, axis);
7917
+    current_position[axis] = axis == X_AXIS ? pos.x : axis == Y_AXIS ? pos.y : pos.z;
7922
   #else
7918
   #else
7923
-    current_position[axis] = LOGICAL_POSITION(stepper.get_axis_position_mm(axis), axis); // CORE handled transparently
7919
+    current_position[axis] = stepper.get_axis_position_mm(axis); // CORE handled transparently
7924
   #endif
7920
   #endif
7925
 }
7921
 }
7926
 
7922
 
7930
 void mesh_line_to_destination(float fr_mm_m, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7926
 void mesh_line_to_destination(float fr_mm_m, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7931
   int cx1 = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)),
7927
   int cx1 = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)),
7932
       cy1 = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)),
7928
       cy1 = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)),
7933
-      cx2 = mbl.cell_index_x(RAW_POSITION(destination[X_AXIS], X_AXIS)),
7934
-      cy2 = mbl.cell_index_y(RAW_POSITION(destination[Y_AXIS], Y_AXIS));
7929
+      cx2 = mbl.cell_index_x(RAW_X_POSITION(destination[X_AXIS])),
7930
+      cy2 = mbl.cell_index_y(RAW_Y_POSITION(destination[Y_AXIS]));
7935
   NOMORE(cx1, MESH_NUM_X_POINTS - 2);
7931
   NOMORE(cx1, MESH_NUM_X_POINTS - 2);
7936
   NOMORE(cy1, MESH_NUM_Y_POINTS - 2);
7932
   NOMORE(cy1, MESH_NUM_Y_POINTS - 2);
7937
   NOMORE(cx2, MESH_NUM_X_POINTS - 2);
7933
   NOMORE(cx2, MESH_NUM_X_POINTS - 2);
7952
   int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
7948
   int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
7953
   if (cx2 != cx1 && TEST(x_splits, gcx)) {
7949
   if (cx2 != cx1 && TEST(x_splits, gcx)) {
7954
     memcpy(end, destination, sizeof(end));
7950
     memcpy(end, destination, sizeof(end));
7955
-    destination[X_AXIS] = LOGICAL_POSITION(mbl.get_probe_x(gcx), X_AXIS);
7951
+    destination[X_AXIS] = LOGICAL_X_POSITION(mbl.get_probe_x(gcx));
7956
     normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
7952
     normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
7957
     destination[Y_AXIS] = MBL_SEGMENT_END(Y);
7953
     destination[Y_AXIS] = MBL_SEGMENT_END(Y);
7958
     CBI(x_splits, gcx);
7954
     CBI(x_splits, gcx);
7959
   }
7955
   }
7960
   else if (cy2 != cy1 && TEST(y_splits, gcy)) {
7956
   else if (cy2 != cy1 && TEST(y_splits, gcy)) {
7961
     memcpy(end, destination, sizeof(end));
7957
     memcpy(end, destination, sizeof(end));
7962
-    destination[Y_AXIS] = LOGICAL_POSITION(mbl.get_probe_y(gcy), Y_AXIS);
7958
+    destination[Y_AXIS] = LOGICAL_Y_POSITION(mbl.get_probe_y(gcy));
7963
     normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
7959
     normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
7964
     destination[X_AXIS] = MBL_SEGMENT_END(X);
7960
     destination[X_AXIS] = MBL_SEGMENT_END(X);
7965
     CBI(y_splits, gcy);
7961
     CBI(y_splits, gcy);
8374
     float SCARA_pos[2];
8370
     float SCARA_pos[2];
8375
     static float SCARA_C2, SCARA_S2, SCARA_K1, SCARA_K2, SCARA_theta, SCARA_psi;
8371
     static float SCARA_C2, SCARA_S2, SCARA_K1, SCARA_K2, SCARA_theta, SCARA_psi;
8376
 
8372
 
8377
-    SCARA_pos[X_AXIS] = RAW_POSITION(cartesian[X_AXIS], X_AXIS) * axis_scaling[X_AXIS] - SCARA_offset_x;  //Translate SCARA to standard X Y
8378
-    SCARA_pos[Y_AXIS] = RAW_POSITION(cartesian[Y_AXIS], Y_AXIS) * axis_scaling[Y_AXIS] - SCARA_offset_y;  // With scaling factor.
8373
+    SCARA_pos[X_AXIS] = RAW_X_POSITION(cartesian[X_AXIS]) * axis_scaling[X_AXIS] - SCARA_offset_x;  //Translate SCARA to standard X Y
8374
+    SCARA_pos[Y_AXIS] = RAW_Y_POSITION(cartesian[Y_AXIS]) * axis_scaling[Y_AXIS] - SCARA_offset_y;  // With scaling factor.
8379
 
8375
 
8380
     #if (Linkage_1 == Linkage_2)
8376
     #if (Linkage_1 == Linkage_2)
8381
       SCARA_C2 = ((sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS])) / (2 * (float)L1_2)) - 1;
8377
       SCARA_C2 = ((sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS])) / (2 * (float)L1_2)) - 1;
8393
 
8389
 
8394
     delta[X_AXIS] = SCARA_theta * SCARA_RAD2DEG;  // Multiply by 180/Pi  -  theta is support arm angle
8390
     delta[X_AXIS] = SCARA_theta * SCARA_RAD2DEG;  // Multiply by 180/Pi  -  theta is support arm angle
8395
     delta[Y_AXIS] = (SCARA_theta + SCARA_psi) * SCARA_RAD2DEG;  //       -  equal to sub arm angle (inverted motor)
8391
     delta[Y_AXIS] = (SCARA_theta + SCARA_psi) * SCARA_RAD2DEG;  //       -  equal to sub arm angle (inverted motor)
8396
-    delta[Z_AXIS] = RAW_POSITION(cartesian[Z_AXIS], Z_AXIS);
8392
+    delta[Z_AXIS] = RAW_Z_POSITION(cartesian[Z_AXIS]);
8397
 
8393
 
8398
     /**
8394
     /**
8399
     SERIAL_ECHOPGM("cartesian x="); SERIAL_ECHO(cartesian[X_AXIS]);
8395
     SERIAL_ECHOPGM("cartesian x="); SERIAL_ECHO(cartesian[X_AXIS]);

正在加载...
取消
保存