Browse Source

Replace division in planner with multiplication

Scott Lahteine 8 years ago
parent
commit
f8b5749235

+ 5
- 5
Marlin/Marlin_main.cpp View File

@@ -911,16 +911,15 @@ void setup() {
911 911
   // Send "ok" after commands by default
912 912
   for (int8_t i = 0; i < BUFSIZE; i++) send_ok[i] = true;
913 913
 
914
-  // loads data from EEPROM if available else uses defaults (and resets step acceleration rate)
914
+  // Load data from EEPROM if available (or use defaults)
915
+  // This also updates variables in the planner, elsewhere
915 916
   Config_RetrieveSettings();
916 917
 
917 918
   // Initialize current position based on home_offset
918 919
   memcpy(current_position, home_offset, sizeof(home_offset));
919 920
 
920
-  #if ENABLED(DELTA) || ENABLED(SCARA)
921
-    // Vital to init kinematic equivalent for X0 Y0 Z0
922
-    SYNC_PLAN_POSITION_KINEMATIC();
923
-  #endif
921
+  // Vital to init stepper/planner equivalent for current_position
922
+  SYNC_PLAN_POSITION_KINEMATIC();
924 923
 
925 924
   thermalManager.init();    // Initialize temperature loop
926 925
 
@@ -5148,6 +5147,7 @@ inline void gcode_M92() {
5148 5147
       }
5149 5148
     }
5150 5149
   }
5150
+  planner.refresh_positioning();
5151 5151
 }
5152 5152
 
5153 5153
 /**

+ 6
- 0
Marlin/configuration_store.cpp View File

@@ -171,10 +171,16 @@ void Config_Postprocess() {
171 171
   // steps per s2 needs to be updated to agree with units per s2
172 172
   planner.reset_acceleration_rates();
173 173
 
174
+  // Make sure delta kinematics are updated before refreshing the
175
+  // planner position so the stepper counts will be set correctly.
174 176
   #if ENABLED(DELTA)
175 177
     recalc_delta_settings(delta_radius, delta_diagonal_rod);
176 178
   #endif
177 179
 
180
+  // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
181
+  // and init stepper.count[], planner.position[] with current_position
182
+  planner.refresh_positioning();
183
+
178 184
   #if ENABLED(PIDTEMP)
179 185
     thermalManager.updatePID();
180 186
   #endif

+ 29
- 20
Marlin/planner.cpp View File

@@ -82,6 +82,7 @@ volatile uint8_t Planner::block_buffer_tail = 0;
82 82
 
83 83
 float Planner::max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
84 84
 float Planner::axis_steps_per_mm[NUM_AXIS];
85
+float Planner::steps_to_mm[NUM_AXIS];
85 86
 unsigned long Planner::max_acceleration_steps_per_s2[NUM_AXIS];
86 87
 unsigned long Planner::max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
87 88
 
@@ -783,23 +784,23 @@ void Planner::check_axes_activity() {
783 784
   #if ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
784 785
     float delta_mm[6];
785 786
     #if ENABLED(COREXY)
786
-      delta_mm[X_HEAD] = dx / axis_steps_per_mm[A_AXIS];
787
-      delta_mm[Y_HEAD] = dy / axis_steps_per_mm[B_AXIS];
788
-      delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS];
789
-      delta_mm[A_AXIS] = (dx + dy) / axis_steps_per_mm[A_AXIS];
790
-      delta_mm[B_AXIS] = (dx - dy) / axis_steps_per_mm[B_AXIS];
787
+      delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS];
788
+      delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS];
789
+      delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS];
790
+      delta_mm[A_AXIS] = (dx + dy) * steps_to_mm[A_AXIS];
791
+      delta_mm[B_AXIS] = (dx - dy) * steps_to_mm[B_AXIS];
791 792
     #elif ENABLED(COREXZ)
792
-      delta_mm[X_HEAD] = dx / axis_steps_per_mm[A_AXIS];
793
-      delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS];
794
-      delta_mm[Z_HEAD] = dz / axis_steps_per_mm[C_AXIS];
795
-      delta_mm[A_AXIS] = (dx + dz) / axis_steps_per_mm[A_AXIS];
796
-      delta_mm[C_AXIS] = (dx - dz) / axis_steps_per_mm[C_AXIS];
793
+      delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS];
794
+      delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS];
795
+      delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS];
796
+      delta_mm[A_AXIS] = (dx + dz) * steps_to_mm[A_AXIS];
797
+      delta_mm[C_AXIS] = (dx - dz) * steps_to_mm[C_AXIS];
797 798
     #elif ENABLED(COREYZ)
798
-      delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS];
799
-      delta_mm[Y_HEAD] = dy / axis_steps_per_mm[B_AXIS];
800
-      delta_mm[Z_HEAD] = dz / axis_steps_per_mm[C_AXIS];
801
-      delta_mm[B_AXIS] = (dy + dz) / axis_steps_per_mm[B_AXIS];
802
-      delta_mm[C_AXIS] = (dy - dz) / axis_steps_per_mm[C_AXIS];
799
+      delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS];
800
+      delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS];
801
+      delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS];
802
+      delta_mm[B_AXIS] = (dy + dz) * steps_to_mm[B_AXIS];
803
+      delta_mm[C_AXIS] = (dy - dz) * steps_to_mm[C_AXIS];
803 804
     #endif
804 805
   #else
805 806
     float delta_mm[4];
@@ -808,12 +809,12 @@ void Planner::check_axes_activity() {
808 809
       // so calculate distance in steps first, then do one division
809 810
       // at the end to get millimeters
810 811
     #else
811
-      delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS];
812
-      delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS];
813
-      delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS];
812
+      delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS];
813
+      delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS];
814
+      delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS];
814 815
     #endif
815 816
   #endif
816
-  delta_mm[E_AXIS] = (de / axis_steps_per_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0;
817
+  delta_mm[E_AXIS] = (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0;
817 818
 
818 819
   if (block->steps[X_AXIS] <= dropsegments && block->steps[Y_AXIS] <= dropsegments && block->steps[Z_AXIS] <= dropsegments) {
819 820
     block->millimeters = fabs(delta_mm[E_AXIS]);
@@ -833,7 +834,7 @@ void Planner::check_axes_activity() {
833 834
       #endif
834 835
     )
835 836
       #if ENABLED(DELTA)
836
-        / axis_steps_per_mm[X_AXIS]
837
+        * steps_to_mm[X_AXIS]
837 838
       #endif
838 839
     ;
839 840
   }
@@ -1176,6 +1177,7 @@ void Planner::check_axes_activity() {
1176 1177
 void Planner::set_e_position_mm(const float& e) {
1177 1178
   position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1178 1179
   stepper.set_e_position(position[E_AXIS]);
1180
+  previous_speed[E_AXIS] = 0.0;
1179 1181
 }
1180 1182
 
1181 1183
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
@@ -1184,6 +1186,13 @@ void Planner::reset_acceleration_rates() {
1184 1186
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
1185 1187
 }
1186 1188
 
1189
+// Recalculate position, steps_to_mm if axis_steps_per_mm changes!
1190
+void Planner::refresh_positioning() {
1191
+  LOOP_XYZE(i) planner.steps_to_mm[i] = 1.0 / planner.axis_steps_per_mm[i];
1192
+  set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1193
+  reset_acceleration_rates();
1194
+}
1195
+
1187 1196
 #if ENABLED(AUTOTEMP)
1188 1197
 
1189 1198
   void Planner::autotemp_M109() {

+ 3
- 1
Marlin/planner.h View File

@@ -121,6 +121,7 @@ class Planner {
121 121
 
122 122
     static float max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
123 123
     static float axis_steps_per_mm[NUM_AXIS];
124
+    static float steps_to_mm[NUM_AXIS];
124 125
     static unsigned long max_acceleration_steps_per_s2[NUM_AXIS];
125 126
     static unsigned long max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
126 127
 
@@ -142,7 +143,7 @@ class Planner {
142 143
 
143 144
     /**
144 145
      * The current position of the tool in absolute steps
145
-     * Reclculated if any axis_steps_per_mm are changed by gcode
146
+     * Recalculated if any axis_steps_per_mm are changed by gcode
146 147
      */
147 148
     static long position[NUM_AXIS];
148 149
 
@@ -187,6 +188,7 @@ class Planner {
187 188
      */
188 189
 
189 190
     static void reset_acceleration_rates();
191
+    static void refresh_positioning();
190 192
 
191 193
     // Manage fans, paste pressure, etc.
192 194
     static void check_axes_activity();

+ 1
- 1
Marlin/stepper.cpp View File

@@ -951,7 +951,7 @@ float Stepper::get_axis_position_mm(AxisEnum axis) {
951 951
   #else
952 952
     axis_steps = position(axis);
953 953
   #endif
954
-  return axis_steps / planner.axis_steps_per_mm[axis];
954
+  return axis_steps * planner.steps_to_mm[axis];
955 955
 }
956 956
 
957 957
 void Stepper::finish_and_disable() {

+ 1
- 1
Marlin/stepper.h View File

@@ -262,7 +262,7 @@ class Stepper {
262 262
     // Triggered position of an axis in mm (not core-savvy)
263 263
     //
264 264
     static FORCE_INLINE float triggered_position_mm(AxisEnum axis) {
265
-      return endstops_trigsteps[axis] / planner.axis_steps_per_mm[axis];
265
+      return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
266 266
     }
267 267
 
268 268
     #if ENABLED(LIN_ADVANCE)

+ 1
- 1
Marlin/temperature.cpp View File

@@ -572,7 +572,7 @@ float Temperature::get_pid_output(int e) {
572 572
               lpq[lpq_ptr] = 0;
573 573
             }
574 574
             if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
575
-            cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
575
+            cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
576 576
             pid_output += cTerm[HOTEND_INDEX];
577 577
           }
578 578
         #endif //PID_ADD_EXTRUSION_RATE

+ 7
- 6
Marlin/ultralcd.cpp View File

@@ -678,7 +678,7 @@ void kill_screen(const char* lcd_msg) {
678 678
       }
679 679
       if (lcdDrawUpdate)
680 680
         lcd_implementation_drawedit(msg, ftostr43sign(
681
-          ((1000 * babysteps_done) / planner.axis_steps_per_mm[axis]) * 0.001f
681
+          ((1000 * babysteps_done) * planner.steps_to_mm[axis]) * 0.001f
682 682
         ));
683 683
     }
684 684
 
@@ -1769,6 +1769,7 @@ void kill_screen(const char* lcd_msg) {
1769 1769
   }
1770 1770
 
1771 1771
   static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
1772
+  static void _planner_refresh_positioning() { planner.refresh_positioning(); }
1772 1773
 
1773 1774
   /**
1774 1775
    *
@@ -1805,14 +1806,14 @@ void kill_screen(const char* lcd_msg) {
1805 1806
     MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
1806 1807
     MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
1807 1808
     MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
1808
-    MENU_ITEM_EDIT(float52, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999);
1809
-    MENU_ITEM_EDIT(float52, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999);
1809
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
1810
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
1810 1811
     #if ENABLED(DELTA)
1811
-      MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999);
1812
+      MENU_ITEM_EDIT_CALLBACK(float52, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
1812 1813
     #else
1813
-      MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999);
1814
+      MENU_ITEM_EDIT_CALLBACK(float51, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
1814 1815
     #endif
1815
-    MENU_ITEM_EDIT(float51, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999);
1816
+    MENU_ITEM_EDIT_CALLBACK(float51, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
1816 1817
     #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
1817 1818
       MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
1818 1819
     #endif

Loading…
Cancel
Save