Browse Source

Some cleanup of st_get_pos functions

Scott Lahteine 8 years ago
parent
commit
e087a99a10
3 changed files with 26 additions and 7 deletions
  1. 12
    0
      Marlin/planner.cpp
  2. 13
    6
      Marlin/stepper.cpp
  3. 1
    1
      Marlin/stepper.h

+ 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

+ 13
- 6
Marlin/stepper.cpp View File

@@ -1099,15 +1099,22 @@ void st_set_e_position(const long& e) {
1099 1099
   CRITICAL_SECTION_END;
1100 1100
 }
1101 1101
 
1102
-long st_get_position(uint8_t axis) {
1102
+/**
1103
+ * Get a stepper's position in steps.
1104
+ */
1105
+long st_get_position(AxisEnum axis) {
1103 1106
   CRITICAL_SECTION_START;
1104 1107
   long count_pos = count_position[axis];
1105 1108
   CRITICAL_SECTION_END;
1106 1109
   return count_pos;
1107 1110
 }
1108 1111
 
1112
+/**
1113
+ * Get an axis position according to stepper position(s)
1114
+ * For CORE machines apply translation from ABC to XYZ.
1115
+ */
1109 1116
 float st_get_axis_position_mm(AxisEnum axis) {
1110
-  float axis_pos;
1117
+  float axis_steps;
1111 1118
   #if ENABLED(COREXY) | ENABLED(COREXZ)
1112 1119
     if (axis == X_AXIS || axis == CORE_AXIS_2) {
1113 1120
       CRITICAL_SECTION_START;
@@ -1116,14 +1123,14 @@ float st_get_axis_position_mm(AxisEnum axis) {
1116 1123
       CRITICAL_SECTION_END;
1117 1124
       // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
1118 1125
       // ((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;
1126
+      axis_steps = (pos1 + ((axis == X_AXIS) ? pos2 : -pos2)) / 2.0f;
1120 1127
     }
1121 1128
     else
1122
-      axis_pos = st_get_position(axis);
1129
+      axis_steps = st_get_position(axis);
1123 1130
   #else
1124
-    axis_pos = st_get_position(axis);
1131
+    axis_steps = st_get_position(axis);
1125 1132
   #endif
1126
-  return axis_pos / axis_steps_per_unit[axis];
1133
+  return axis_steps / axis_steps_per_unit[axis];
1127 1134
 }
1128 1135
 
1129 1136
 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