Browse Source

Merge pull request #3956 from thinkyhead/rc_mbl_single_axis_fix

MBL: Keep active when homing single axes (#3750)
Scott Lahteine 9 years ago
parent
commit
4bdcf3afe4

+ 62
- 24
Marlin/Marlin_main.cpp View File

2644
    * on again when homing all axis
2644
    * on again when homing all axis
2645
    */
2645
    */
2646
   #if ENABLED(MESH_BED_LEVELING)
2646
   #if ENABLED(MESH_BED_LEVELING)
2647
-    uint8_t mbl_was_active = mbl.active;
2648
-    mbl.active = false;
2647
+    float pre_home_z = MESH_HOME_SEARCH_Z;
2648
+    if (mbl.active()) {
2649
+      // Save known Z position if already homed
2650
+      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2651
+        pre_home_z = current_position[Z_AXIS];
2652
+        pre_home_z += mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
2653
+                                current_position[Y_AXIS] - home_offset[Y_AXIS]);
2654
+      }
2655
+      mbl.set_active(false);
2656
+    }
2649
   #endif
2657
   #endif
2650
 
2658
 
2651
   setup_for_endstop_move();
2659
   setup_for_endstop_move();
2945
 
2953
 
2946
   // Enable mesh leveling again
2954
   // Enable mesh leveling again
2947
   #if ENABLED(MESH_BED_LEVELING)
2955
   #if ENABLED(MESH_BED_LEVELING)
2948
-    if (mbl_was_active && home_all_axis) {
2949
-      current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2950
-      sync_plan_position();
2951
-      mbl.active = 1;
2952
-      #if ENABLED(MESH_G28_REST_ORIGIN)
2953
-        current_position[Z_AXIS] = 0.0;
2954
-        set_destination_to_current();
2955
-        feedrate = homing_feedrate[Z_AXIS];
2956
-        line_to_destination();
2957
-        stepper.synchronize();
2958
-      #endif
2959
-      #if ENABLED(DEBUG_LEVELING_FEATURE)
2960
-        if (DEBUGGING(LEVELING)) DEBUG_POS("mbl_was_active", current_position);
2961
-      #endif
2956
+    if (mbl.has_mesh()) {
2957
+      if (home_all_axis || (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && homeZ)) {
2958
+        current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2959
+        sync_plan_position();
2960
+        mbl.set_active(true);
2961
+        #if ENABLED(MESH_G28_REST_ORIGIN)
2962
+          current_position[Z_AXIS] = 0.0;
2963
+          set_destination_to_current();
2964
+          feedrate = homing_feedrate[Z_AXIS];
2965
+          line_to_destination();
2966
+          stepper.synchronize();
2967
+        #else
2968
+          current_position[Z_AXIS] = MESH_HOME_SEARCH_Z -
2969
+            mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
2970
+                      current_position[Y_AXIS] - home_offset[Y_AXIS]);
2971
+        #endif
2972
+      }
2973
+      else if ((axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) && (homeX || homeY)) {
2974
+        current_position[Z_AXIS] = pre_home_z;
2975
+        sync_plan_position();
2976
+        mbl.set_active(true);
2977
+        current_position[Z_AXIS] = pre_home_z -
2978
+          mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
2979
+                    current_position[Y_AXIS] - home_offset[Y_AXIS]);
2980
+      }
2962
     }
2981
     }
2963
   #endif
2982
   #endif
2964
 
2983
 
2978
 
2997
 
2979
 #if ENABLED(MESH_BED_LEVELING)
2998
 #if ENABLED(MESH_BED_LEVELING)
2980
 
2999
 
2981
-  enum MeshLevelingState { MeshReport, MeshStart, MeshNext, MeshSet, MeshSetZOffset };
3000
+  enum MeshLevelingState { MeshReport, MeshStart, MeshNext, MeshSet, MeshSetZOffset, MeshReset };
2982
 
3001
 
2983
   inline void _mbl_goto_xy(float x, float y) {
3002
   inline void _mbl_goto_xy(float x, float y) {
2984
     saved_feedrate = feedrate;
3003
     saved_feedrate = feedrate;
3015
    *  S2              Probe the next mesh point
3034
    *  S2              Probe the next mesh point
3016
    *  S3 Xn Yn Zn.nn  Manually modify a single point
3035
    *  S3 Xn Yn Zn.nn  Manually modify a single point
3017
    *  S4 Zn.nn        Set z offset. Positive away from bed, negative closer to bed.
3036
    *  S4 Zn.nn        Set z offset. Positive away from bed, negative closer to bed.
3037
+   *  S5              Reset and disable mesh
3018
    *
3038
    *
3019
    * The S0 report the points as below
3039
    * The S0 report the points as below
3020
    *
3040
    *
3028
 
3048
 
3029
     static int probe_point = -1;
3049
     static int probe_point = -1;
3030
     MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_short() : MeshReport;
3050
     MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_short() : MeshReport;
3031
-    if (state < 0 || state > 4) {
3032
-      SERIAL_PROTOCOLLNPGM("S out of range (0-4).");
3051
+    if (state < 0 || state > 5) {
3052
+      SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
3033
       return;
3053
       return;
3034
     }
3054
     }
3035
 
3055
 
3038
 
3058
 
3039
     switch (state) {
3059
     switch (state) {
3040
       case MeshReport:
3060
       case MeshReport:
3041
-        if (mbl.active) {
3042
-          SERIAL_PROTOCOLPGM("Num X,Y: ");
3061
+        if (mbl.has_mesh()) {
3062
+          SERIAL_PROTOCOLPGM("State: ");
3063
+          if (mbl.active())
3064
+            SERIAL_PROTOCOLPGM("On");
3065
+          else
3066
+            SERIAL_PROTOCOLPGM("Off");
3067
+          SERIAL_PROTOCOLPGM("\nNum X,Y: ");
3043
           SERIAL_PROTOCOL(MESH_NUM_X_POINTS);
3068
           SERIAL_PROTOCOL(MESH_NUM_X_POINTS);
3044
           SERIAL_PROTOCOLCHAR(',');
3069
           SERIAL_PROTOCOLCHAR(',');
3045
           SERIAL_PROTOCOL(MESH_NUM_Y_POINTS);
3070
           SERIAL_PROTOCOL(MESH_NUM_Y_POINTS);
3100
           // After recording the last point, activate the mbl and home
3125
           // After recording the last point, activate the mbl and home
3101
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
3126
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
3102
           probe_point = -1;
3127
           probe_point = -1;
3103
-          mbl.active = true;
3128
+          mbl.set_has_mesh(true);
3104
           enqueue_and_echo_commands_P(PSTR("G28"));
3129
           enqueue_and_echo_commands_P(PSTR("G28"));
3105
         }
3130
         }
3106
         break;
3131
         break;
3147
           return;
3172
           return;
3148
         }
3173
         }
3149
         mbl.z_offset = z;
3174
         mbl.z_offset = z;
3175
+        break;
3176
+
3177
+      case MeshReset:
3178
+        if (mbl.active()) {
3179
+          current_position[Z_AXIS] +=
3180
+            mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
3181
+                      current_position[Y_AXIS] - home_offset[Y_AXIS]) - MESH_HOME_SEARCH_Z;
3182
+          mbl.reset();
3183
+          sync_plan_position();
3184
+        }
3185
+        else
3186
+          mbl.reset();
3187
+
3150
     } // switch(state)
3188
     } // switch(state)
3151
 
3189
 
3152
     report_current_position();
3190
     report_current_position();
5944
   /**
5982
   /**
5945
    * M420: Enable/Disable Mesh Bed Leveling
5983
    * M420: Enable/Disable Mesh Bed Leveling
5946
    */
5984
    */
5947
-  inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.active = !!code_value_short(); }
5985
+  inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.set_has_mesh(!!code_value_short()); }
5948
 
5986
 
5949
   /**
5987
   /**
5950
    * M421: Set a single Mesh Bed Leveling Z coordinate
5988
    * M421: Set a single Mesh Bed Leveling Z coordinate
7335
 
7373
 
7336
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
7374
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
7337
 void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7375
 void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7338
-  if (!mbl.active) {
7376
+  if (!mbl.active()) {
7339
     planner.buffer_line(x, y, z, e, feed_rate, extruder);
7377
     planner.buffer_line(x, y, z, e, feed_rate, extruder);
7340
     set_current_to_destination();
7378
     set_current_to_destination();
7341
     return;
7379
     return;

+ 12
- 11
Marlin/configuration_store.cpp View File

58
  *  188  M206 XYZ  home_offset (float x3)
58
  *  188  M206 XYZ  home_offset (float x3)
59
  *
59
  *
60
  * Mesh bed leveling:
60
  * Mesh bed leveling:
61
- *  200  M420 S    active (bool)
62
- *  201            z_offset (float) (added in V23)
61
+ *  200  M420 S    status (uint8)
62
+ *  201            z_offset (float)
63
  *  205            mesh_num_x (uint8 as set in firmware)
63
  *  205            mesh_num_x (uint8 as set in firmware)
64
  *  206            mesh_num_y (uint8 as set in firmware)
64
  *  206            mesh_num_y (uint8 as set in firmware)
65
  *  207 G29 S3 XYZ z_values[][] (float x9, by default)
65
  *  207 G29 S3 XYZ z_values[][] (float x9, by default)
187
   EEPROM_WRITE_VAR(i, planner.max_e_jerk);
187
   EEPROM_WRITE_VAR(i, planner.max_e_jerk);
188
   EEPROM_WRITE_VAR(i, home_offset);
188
   EEPROM_WRITE_VAR(i, home_offset);
189
 
189
 
190
-  uint8_t mesh_num_x = 3;
191
-  uint8_t mesh_num_y = 3;
192
   #if ENABLED(MESH_BED_LEVELING)
190
   #if ENABLED(MESH_BED_LEVELING)
193
     // Compile time test that sizeof(mbl.z_values) is as expected
191
     // Compile time test that sizeof(mbl.z_values) is as expected
194
     typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
192
     typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
195
-    mesh_num_x = MESH_NUM_X_POINTS;
196
-    mesh_num_y = MESH_NUM_Y_POINTS;
197
-    EEPROM_WRITE_VAR(i, mbl.active);
193
+    uint8_t mesh_num_x = MESH_NUM_X_POINTS,
194
+            mesh_num_y = MESH_NUM_Y_POINTS,
195
+            dummy_uint8 = mbl.status & _BV(MBL_STATUS_HAS_MESH_BIT);
196
+    EEPROM_WRITE_VAR(i, dummy_uint8);
198
     EEPROM_WRITE_VAR(i, mbl.z_offset);
197
     EEPROM_WRITE_VAR(i, mbl.z_offset);
199
     EEPROM_WRITE_VAR(i, mesh_num_x);
198
     EEPROM_WRITE_VAR(i, mesh_num_x);
200
     EEPROM_WRITE_VAR(i, mesh_num_y);
199
     EEPROM_WRITE_VAR(i, mesh_num_y);
201
     EEPROM_WRITE_VAR(i, mbl.z_values);
200
     EEPROM_WRITE_VAR(i, mbl.z_values);
202
   #else
201
   #else
203
-    uint8_t dummy_uint8 = 0;
202
+    uint8_t mesh_num_x = 3,
203
+            mesh_num_y = 3,
204
+            dummy_uint8 = 0;
204
     dummy = 0.0f;
205
     dummy = 0.0f;
205
     EEPROM_WRITE_VAR(i, dummy_uint8);
206
     EEPROM_WRITE_VAR(i, dummy_uint8);
206
     EEPROM_WRITE_VAR(i, dummy);
207
     EEPROM_WRITE_VAR(i, dummy);
376
     EEPROM_READ_VAR(i, mesh_num_x);
377
     EEPROM_READ_VAR(i, mesh_num_x);
377
     EEPROM_READ_VAR(i, mesh_num_y);
378
     EEPROM_READ_VAR(i, mesh_num_y);
378
     #if ENABLED(MESH_BED_LEVELING)
379
     #if ENABLED(MESH_BED_LEVELING)
379
-      mbl.active = dummy_uint8;
380
+      mbl.status = dummy_uint8;
380
       mbl.z_offset = dummy;
381
       mbl.z_offset = dummy;
381
       if (mesh_num_x == MESH_NUM_X_POINTS && mesh_num_y == MESH_NUM_Y_POINTS) {
382
       if (mesh_num_x == MESH_NUM_X_POINTS && mesh_num_y == MESH_NUM_Y_POINTS) {
382
         EEPROM_READ_VAR(i, mbl.z_values);
383
         EEPROM_READ_VAR(i, mbl.z_values);
550
   home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
551
   home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
551
 
552
 
552
   #if ENABLED(MESH_BED_LEVELING)
553
   #if ENABLED(MESH_BED_LEVELING)
553
-    mbl.active = false;
554
+    mbl.reset();
554
   #endif
555
   #endif
555
 
556
 
556
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
557
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
729
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
730
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
730
       CONFIG_ECHO_START;
731
       CONFIG_ECHO_START;
731
     }
732
     }
732
-    SERIAL_ECHOPAIR("  M420 S", mbl.active);
733
+    SERIAL_ECHOPAIR("  M420 S", mbl.has_mesh() ? 1 : 0);
733
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
734
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
734
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
735
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
735
     SERIAL_EOL;
736
     SERIAL_EOL;

+ 1
- 1
Marlin/mesh_bed_leveling.cpp View File

29
   mesh_bed_leveling::mesh_bed_leveling() { reset(); }
29
   mesh_bed_leveling::mesh_bed_leveling() { reset(); }
30
 
30
 
31
   void mesh_bed_leveling::reset() {
31
   void mesh_bed_leveling::reset() {
32
-    active = 0;
32
+    status = MBL_STATUS_NONE;
33
     z_offset = 0;
33
     z_offset = 0;
34
     for (int8_t y = MESH_NUM_Y_POINTS; y--;)
34
     for (int8_t y = MESH_NUM_Y_POINTS; y--;)
35
       for (int8_t x = MESH_NUM_X_POINTS; x--;)
35
       for (int8_t x = MESH_NUM_X_POINTS; x--;)

+ 8
- 1
Marlin/mesh_bed_leveling.h View File

24
 
24
 
25
 #if ENABLED(MESH_BED_LEVELING)
25
 #if ENABLED(MESH_BED_LEVELING)
26
 
26
 
27
+  enum MBLStatus { MBL_STATUS_NONE = 0, MBL_STATUS_HAS_MESH_BIT = 0, MBL_STATUS_ACTIVE_BIT = 1 };
28
+
27
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X))/(MESH_NUM_X_POINTS - 1))
29
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X))/(MESH_NUM_X_POINTS - 1))
28
   #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y))/(MESH_NUM_Y_POINTS - 1))
30
   #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y))/(MESH_NUM_Y_POINTS - 1))
29
 
31
 
30
   class mesh_bed_leveling {
32
   class mesh_bed_leveling {
31
   public:
33
   public:
32
-    bool active;
34
+    uint8_t status; // Has Mesh and Is Active bits
33
     float z_offset;
35
     float z_offset;
34
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
36
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
35
 
37
 
41
     static FORCE_INLINE float get_probe_y(int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
43
     static FORCE_INLINE float get_probe_y(int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
42
     void set_z(const int8_t px, const int8_t py, const float z) { z_values[py][px] = z; }
44
     void set_z(const int8_t px, const int8_t py, const float z) { z_values[py][px] = z; }
43
 
45
 
46
+    bool active()                 { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
47
+    void set_active(bool onOff)   { if (onOff) SBI(status, MBL_STATUS_ACTIVE_BIT); else CBI(status, MBL_STATUS_ACTIVE_BIT); }
48
+    bool has_mesh()               { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
49
+    void set_has_mesh(bool onOff) { if (onOff) SBI(status, MBL_STATUS_HAS_MESH_BIT); else CBI(status, MBL_STATUS_HAS_MESH_BIT); }
50
+
44
     inline void zigzag(int8_t index, int8_t &px, int8_t &py) {
51
     inline void zigzag(int8_t index, int8_t &px, int8_t &py) {
45
       px = index % (MESH_NUM_X_POINTS);
52
       px = index % (MESH_NUM_X_POINTS);
46
       py = index / (MESH_NUM_X_POINTS);
53
       py = index / (MESH_NUM_X_POINTS);

+ 4
- 2
Marlin/planner.cpp View File

539
   while (block_buffer_tail == next_buffer_head) idle();
539
   while (block_buffer_tail == next_buffer_head) idle();
540
 
540
 
541
   #if ENABLED(MESH_BED_LEVELING)
541
   #if ENABLED(MESH_BED_LEVELING)
542
-    if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
542
+    if (mbl.active()) 
543
+      z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
543
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
544
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
544
     apply_rotation_xyz(bed_level_matrix, x, y, z);
545
     apply_rotation_xyz(bed_level_matrix, x, y, z);
545
   #endif
546
   #endif
1120
 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1121
 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1121
   {
1122
   {
1122
     #if ENABLED(MESH_BED_LEVELING)
1123
     #if ENABLED(MESH_BED_LEVELING)
1123
-      if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
1124
+      if (mbl.active())
1125
+        z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
1124
     #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
1126
     #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
1125
       apply_rotation_xyz(bed_level_matrix, x, y, z);
1127
       apply_rotation_xyz(bed_level_matrix, x, y, z);
1126
     #endif
1128
     #endif

+ 1
- 1
Marlin/ultralcd.cpp View File

970
           line_to_current(Z_AXIS);
970
           line_to_current(Z_AXIS);
971
           stepper.synchronize();
971
           stepper.synchronize();
972
 
972
 
973
-          mbl.active = true;
973
+          mbl.set_has_mesh(true);
974
           enqueue_and_echo_commands_P(PSTR("G28"));
974
           enqueue_and_echo_commands_P(PSTR("G28"));
975
           lcd_return_to_status();
975
           lcd_return_to_status();
976
           //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
976
           //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);

Loading…
Cancel
Save