Browse Source

Merge pull request #3466 from thinkyhead/rc_look_for_leveling_bug

Add CORE support to st_set_position and plan_set_position
Scott Lahteine 8 years ago
parent
commit
b1bb1c7989
4 changed files with 70 additions and 15 deletions
  1. 16
    5
      Marlin/Marlin_main.cpp
  2. 12
    0
      Marlin/planner.cpp
  3. 41
    9
      Marlin/stepper.cpp
  4. 1
    1
      Marlin/stepper.h

+ 16
- 5
Marlin/Marlin_main.cpp View File

1351
     #if DISABLED(DELTA)
1351
     #if DISABLED(DELTA)
1352
 
1352
 
1353
       static void set_bed_level_equation_lsq(double* plane_equation_coefficients) {
1353
       static void set_bed_level_equation_lsq(double* plane_equation_coefficients) {
1354
+
1354
         #if ENABLED(DEBUG_LEVELING_FEATURE)
1355
         #if ENABLED(DEBUG_LEVELING_FEATURE)
1355
-          if (DEBUGGING(LEVELING)) DEBUG_POS("BEFORE set_bed_level_equation_lsq", current_position);
1356
+          plan_bed_level_matrix.set_to_identity();
1357
+          if (DEBUGGING(LEVELING)) {
1358
+            vector_3 uncorrected_position = plan_get_position();
1359
+            DEBUG_POS(">>> set_bed_level_equation_lsq", uncorrected_position);
1360
+            DEBUG_POS(">>> set_bed_level_equation_lsq", current_position);
1361
+          }
1356
         #endif
1362
         #endif
1357
 
1363
 
1358
         vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
1364
         vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
1371
         current_position[Z_AXIS] = corrected_position.z;
1377
         current_position[Z_AXIS] = corrected_position.z;
1372
 
1378
 
1373
         #if ENABLED(DEBUG_LEVELING_FEATURE)
1379
         #if ENABLED(DEBUG_LEVELING_FEATURE)
1374
-          if (DEBUGGING(LEVELING)) DEBUG_POS("AFTER set_bed_level_equation_lsq", current_position);
1380
+          if (DEBUGGING(LEVELING)) DEBUG_POS("<<< set_bed_level_equation_lsq", current_position);
1375
         #endif
1381
         #endif
1376
 
1382
 
1377
         sync_plan_position();
1383
         sync_plan_position();
3059
       #else //!DELTA
3065
       #else //!DELTA
3060
 
3066
 
3061
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3067
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3062
-          if (DEBUGGING(LEVELING)) DEBUG_POS("BEFORE matrix.set_to_identity", current_position);
3068
+          if (DEBUGGING(LEVELING)) {
3069
+            vector_3 corrected_position = plan_get_position();
3070
+            DEBUG_POS("BEFORE matrix.set_to_identity", corrected_position);
3071
+            DEBUG_POS("BEFORE matrix.set_to_identity", current_position);
3072
+          }
3063
         #endif
3073
         #endif
3064
 
3074
 
3065
         //vector_3 corrected_position = plan_get_position();
3075
         //vector_3 corrected_position = plan_get_position();
3069
         current_position[X_AXIS] = uncorrected_position.x;
3079
         current_position[X_AXIS] = uncorrected_position.x;
3070
         current_position[Y_AXIS] = uncorrected_position.y;
3080
         current_position[Y_AXIS] = uncorrected_position.y;
3071
         current_position[Z_AXIS] = uncorrected_position.z;
3081
         current_position[Z_AXIS] = uncorrected_position.z;
3072
-        sync_plan_position();
3073
 
3082
 
3074
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3083
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3075
-          if (DEBUGGING(LEVELING)) DEBUG_POS("AFTER matrix.set_to_identity", current_position);
3084
+          if (DEBUGGING(LEVELING)) DEBUG_POS("AFTER matrix.set_to_identity", uncorrected_position);
3076
         #endif
3085
         #endif
3077
 
3086
 
3087
+        sync_plan_position();
3088
+
3078
       #endif // !DELTA
3089
       #endif // !DELTA
3079
     }
3090
     }
3080
 
3091
 

+ 12
- 0
Marlin/planner.cpp View File

1090
 } // plan_buffer_line()
1090
 } // plan_buffer_line()
1091
 
1091
 
1092
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1092
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1093
+
1094
+  /**
1095
+   * Get the XYZ position of the steppers as a vector_3.
1096
+   *
1097
+   * On CORE machines XYZ is derived from ABC.
1098
+   */
1093
   vector_3 plan_get_position() {
1099
   vector_3 plan_get_position() {
1094
     vector_3 position = vector_3(st_get_axis_position_mm(X_AXIS), st_get_axis_position_mm(Y_AXIS), st_get_axis_position_mm(Z_AXIS));
1100
     vector_3 position = vector_3(st_get_axis_position_mm(X_AXIS), st_get_axis_position_mm(Y_AXIS), st_get_axis_position_mm(Z_AXIS));
1095
 
1101
 
1102
 
1108
 
1103
     return position;
1109
     return position;
1104
   }
1110
   }
1111
+
1105
 #endif // AUTO_BED_LEVELING_FEATURE && !DELTA
1112
 #endif // AUTO_BED_LEVELING_FEATURE && !DELTA
1106
 
1113
 
1114
+/**
1115
+ * Directly set the planner XYZ position (hence the stepper positions).
1116
+ *
1117
+ * On CORE machines stepper ABC will be translated from the given XYZ.
1118
+ */
1107
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1119
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1108
   void plan_set_position(float x, float y, float z, const float& e)
1120
   void plan_set_position(float x, float y, float z, const float& e)
1109
 #else
1121
 #else

+ 41
- 9
Marlin/stepper.cpp View File

1084
  */
1084
  */
1085
 void st_synchronize() { while (blocks_queued()) idle(); }
1085
 void st_synchronize() { while (blocks_queued()) idle(); }
1086
 
1086
 
1087
+/**
1088
+ * Set the stepper positions directly in steps
1089
+ *
1090
+ * The input is based on the typical per-axis XYZ steps.
1091
+ * For CORE machines XYZ needs to be translated to ABC.
1092
+ *
1093
+ * This allows st_get_axis_position_mm to correctly
1094
+ * derive the current XYZ position later on.
1095
+ */
1087
 void st_set_position(const long& x, const long& y, const long& z, const long& e) {
1096
 void st_set_position(const long& x, const long& y, const long& z, const long& e) {
1088
   CRITICAL_SECTION_START;
1097
   CRITICAL_SECTION_START;
1089
-  count_position[X_AXIS] = x;
1090
-  count_position[Y_AXIS] = y;
1091
-  count_position[Z_AXIS] = z;
1098
+
1099
+  #if ENABLED(COREXY)
1100
+    // corexy positioning
1101
+    // these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
1102
+    count_position[A_AXIS] = x + y;
1103
+    count_position[B_AXIS] = x - y;
1104
+    count_position[Z_AXIS] = z;
1105
+  #elif ENABLED(COREXZ)
1106
+    // corexz planning
1107
+    count_position[A_AXIS] = x + z;
1108
+    count_position[Y_AXIS] = y;
1109
+    count_position[C_AXIS] = x - z;
1110
+  #else
1111
+    // default non-h-bot planning
1112
+    count_position[X_AXIS] = x;
1113
+    count_position[Y_AXIS] = y;
1114
+    count_position[Z_AXIS] = z;
1115
+  #endif
1116
+
1092
   count_position[E_AXIS] = e;
1117
   count_position[E_AXIS] = e;
1093
   CRITICAL_SECTION_END;
1118
   CRITICAL_SECTION_END;
1094
 }
1119
 }
1099
   CRITICAL_SECTION_END;
1124
   CRITICAL_SECTION_END;
1100
 }
1125
 }
1101
 
1126
 
1102
-long st_get_position(uint8_t axis) {
1127
+/**
1128
+ * Get a stepper's position in steps.
1129
+ */
1130
+long st_get_position(AxisEnum axis) {
1103
   CRITICAL_SECTION_START;
1131
   CRITICAL_SECTION_START;
1104
   long count_pos = count_position[axis];
1132
   long count_pos = count_position[axis];
1105
   CRITICAL_SECTION_END;
1133
   CRITICAL_SECTION_END;
1106
   return count_pos;
1134
   return count_pos;
1107
 }
1135
 }
1108
 
1136
 
1137
+/**
1138
+ * Get an axis position according to stepper position(s)
1139
+ * For CORE machines apply translation from ABC to XYZ.
1140
+ */
1109
 float st_get_axis_position_mm(AxisEnum axis) {
1141
 float st_get_axis_position_mm(AxisEnum axis) {
1110
-  float axis_pos;
1142
+  float axis_steps;
1111
   #if ENABLED(COREXY) | ENABLED(COREXZ)
1143
   #if ENABLED(COREXY) | ENABLED(COREXZ)
1112
     if (axis == X_AXIS || axis == CORE_AXIS_2) {
1144
     if (axis == X_AXIS || axis == CORE_AXIS_2) {
1113
       CRITICAL_SECTION_START;
1145
       CRITICAL_SECTION_START;
1116
       CRITICAL_SECTION_END;
1148
       CRITICAL_SECTION_END;
1117
       // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
1149
       // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
1118
       // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
1150
       // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
1119
-      axis_pos = (pos1 + ((axis == X_AXIS) ? pos2 : -pos2)) / 2.0f;
1151
+      axis_steps = (pos1 + ((axis == X_AXIS) ? pos2 : -pos2)) / 2.0f;
1120
     }
1152
     }
1121
     else
1153
     else
1122
-      axis_pos = st_get_position(axis);
1154
+      axis_steps = st_get_position(axis);
1123
   #else
1155
   #else
1124
-    axis_pos = st_get_position(axis);
1156
+    axis_steps = st_get_position(axis);
1125
   #endif
1157
   #endif
1126
-  return axis_pos / axis_steps_per_unit[axis];
1158
+  return axis_steps / axis_steps_per_unit[axis];
1127
 }
1159
 }
1128
 
1160
 
1129
 void finishAndDisableSteppers() {
1161
 void finishAndDisableSteppers() {

+ 1
- 1
Marlin/stepper.h View File

61
 void st_set_e_position(const long& e);
61
 void st_set_e_position(const long& e);
62
 
62
 
63
 // Get current position in steps
63
 // Get current position in steps
64
-long st_get_position(uint8_t axis);
64
+long st_get_position(AxisEnum axis);
65
 
65
 
66
 // Get current axis position in mm
66
 // Get current axis position in mm
67
 float st_get_axis_position_mm(AxisEnum axis);
67
 float st_get_axis_position_mm(AxisEnum axis);

Loading…
Cancel
Save