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,8 +1351,14 @@ static void setup_for_endstop_move() {
1351 1351
     #if DISABLED(DELTA)
1352 1352
 
1353 1353
       static void set_bed_level_equation_lsq(double* plane_equation_coefficients) {
1354
+
1354 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 1362
         #endif
1357 1363
 
1358 1364
         vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
@@ -1371,7 +1377,7 @@ static void setup_for_endstop_move() {
1371 1377
         current_position[Z_AXIS] = corrected_position.z;
1372 1378
 
1373 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 1381
         #endif
1376 1382
 
1377 1383
         sync_plan_position();
@@ -3059,7 +3065,11 @@ inline void gcode_G28() {
3059 3065
       #else //!DELTA
3060 3066
 
3061 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 3073
         #endif
3064 3074
 
3065 3075
         //vector_3 corrected_position = plan_get_position();
@@ -3069,12 +3079,13 @@ inline void gcode_G28() {
3069 3079
         current_position[X_AXIS] = uncorrected_position.x;
3070 3080
         current_position[Y_AXIS] = uncorrected_position.y;
3071 3081
         current_position[Z_AXIS] = uncorrected_position.z;
3072
-        sync_plan_position();
3073 3082
 
3074 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 3085
         #endif
3077 3086
 
3087
+        sync_plan_position();
3088
+
3078 3089
       #endif // !DELTA
3079 3090
     }
3080 3091
 

+ 12
- 0
Marlin/planner.cpp View File

@@ -1090,6 +1090,12 @@ float junction_deviation = 0.1;
1090 1090
 } // plan_buffer_line()
1091 1091
 
1092 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 1099
   vector_3 plan_get_position() {
1094 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,8 +1108,14 @@ float junction_deviation = 0.1;
1102 1108
 
1103 1109
     return position;
1104 1110
   }
1111
+
1105 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 1119
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1108 1120
   void plan_set_position(float x, float y, float z, const float& e)
1109 1121
 #else

+ 41
- 9
Marlin/stepper.cpp View File

@@ -1084,11 +1084,36 @@ void st_init() {
1084 1084
  */
1085 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 1096
 void st_set_position(const long& x, const long& y, const long& z, const long& e) {
1088 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 1117
   count_position[E_AXIS] = e;
1093 1118
   CRITICAL_SECTION_END;
1094 1119
 }
@@ -1099,15 +1124,22 @@ void st_set_e_position(const long& e) {
1099 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 1131
   CRITICAL_SECTION_START;
1104 1132
   long count_pos = count_position[axis];
1105 1133
   CRITICAL_SECTION_END;
1106 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 1141
 float st_get_axis_position_mm(AxisEnum axis) {
1110
-  float axis_pos;
1142
+  float axis_steps;
1111 1143
   #if ENABLED(COREXY) | ENABLED(COREXZ)
1112 1144
     if (axis == X_AXIS || axis == CORE_AXIS_2) {
1113 1145
       CRITICAL_SECTION_START;
@@ -1116,14 +1148,14 @@ float st_get_axis_position_mm(AxisEnum axis) {
1116 1148
       CRITICAL_SECTION_END;
1117 1149
       // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
1118 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 1153
     else
1122
-      axis_pos = st_get_position(axis);
1154
+      axis_steps = st_get_position(axis);
1123 1155
   #else
1124
-    axis_pos = st_get_position(axis);
1156
+    axis_steps = st_get_position(axis);
1125 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 1161
 void finishAndDisableSteppers() {

+ 1
- 1
Marlin/stepper.h View File

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

Loading…
Cancel
Save