Browse Source

Replace division in planner with multiplication

Scott Lahteine 9 years ago
parent
commit
f8b5749235

+ 5
- 5
Marlin/Marlin_main.cpp View File

911
   // Send "ok" after commands by default
911
   // Send "ok" after commands by default
912
   for (int8_t i = 0; i < BUFSIZE; i++) send_ok[i] = true;
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
   Config_RetrieveSettings();
916
   Config_RetrieveSettings();
916
 
917
 
917
   // Initialize current position based on home_offset
918
   // Initialize current position based on home_offset
918
   memcpy(current_position, home_offset, sizeof(home_offset));
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
   thermalManager.init();    // Initialize temperature loop
924
   thermalManager.init();    // Initialize temperature loop
926
 
925
 
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
   // steps per s2 needs to be updated to agree with units per s2
171
   // steps per s2 needs to be updated to agree with units per s2
172
   planner.reset_acceleration_rates();
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
   #if ENABLED(DELTA)
176
   #if ENABLED(DELTA)
175
     recalc_delta_settings(delta_radius, delta_diagonal_rod);
177
     recalc_delta_settings(delta_radius, delta_diagonal_rod);
176
   #endif
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
   #if ENABLED(PIDTEMP)
184
   #if ENABLED(PIDTEMP)
179
     thermalManager.updatePID();
185
     thermalManager.updatePID();
180
   #endif
186
   #endif

+ 29
- 20
Marlin/planner.cpp View File

82
 
82
 
83
 float Planner::max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
83
 float Planner::max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
84
 float Planner::axis_steps_per_mm[NUM_AXIS];
84
 float Planner::axis_steps_per_mm[NUM_AXIS];
85
+float Planner::steps_to_mm[NUM_AXIS];
85
 unsigned long Planner::max_acceleration_steps_per_s2[NUM_AXIS];
86
 unsigned long Planner::max_acceleration_steps_per_s2[NUM_AXIS];
86
 unsigned long Planner::max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
87
 unsigned long Planner::max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
87
 
88
 
783
   #if ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
784
   #if ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
784
     float delta_mm[6];
785
     float delta_mm[6];
785
     #if ENABLED(COREXY)
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
     #elif ENABLED(COREXZ)
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
     #elif ENABLED(COREYZ)
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
     #endif
804
     #endif
804
   #else
805
   #else
805
     float delta_mm[4];
806
     float delta_mm[4];
808
       // so calculate distance in steps first, then do one division
809
       // so calculate distance in steps first, then do one division
809
       // at the end to get millimeters
810
       // at the end to get millimeters
810
     #else
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
     #endif
815
     #endif
815
   #endif
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
   if (block->steps[X_AXIS] <= dropsegments && block->steps[Y_AXIS] <= dropsegments && block->steps[Z_AXIS] <= dropsegments) {
819
   if (block->steps[X_AXIS] <= dropsegments && block->steps[Y_AXIS] <= dropsegments && block->steps[Z_AXIS] <= dropsegments) {
819
     block->millimeters = fabs(delta_mm[E_AXIS]);
820
     block->millimeters = fabs(delta_mm[E_AXIS]);
833
       #endif
834
       #endif
834
     )
835
     )
835
       #if ENABLED(DELTA)
836
       #if ENABLED(DELTA)
836
-        / axis_steps_per_mm[X_AXIS]
837
+        * steps_to_mm[X_AXIS]
837
       #endif
838
       #endif
838
     ;
839
     ;
839
   }
840
   }
1176
 void Planner::set_e_position_mm(const float& e) {
1177
 void Planner::set_e_position_mm(const float& e) {
1177
   position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1178
   position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1178
   stepper.set_e_position(position[E_AXIS]);
1179
   stepper.set_e_position(position[E_AXIS]);
1180
+  previous_speed[E_AXIS] = 0.0;
1179
 }
1181
 }
1180
 
1182
 
1181
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
1183
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
1184
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
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
 #if ENABLED(AUTOTEMP)
1196
 #if ENABLED(AUTOTEMP)
1188
 
1197
 
1189
   void Planner::autotemp_M109() {
1198
   void Planner::autotemp_M109() {

+ 3
- 1
Marlin/planner.h View File

121
 
121
 
122
     static float max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
122
     static float max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
123
     static float axis_steps_per_mm[NUM_AXIS];
123
     static float axis_steps_per_mm[NUM_AXIS];
124
+    static float steps_to_mm[NUM_AXIS];
124
     static unsigned long max_acceleration_steps_per_s2[NUM_AXIS];
125
     static unsigned long max_acceleration_steps_per_s2[NUM_AXIS];
125
     static unsigned long max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
126
     static unsigned long max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
126
 
127
 
142
 
143
 
143
     /**
144
     /**
144
      * The current position of the tool in absolute steps
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
     static long position[NUM_AXIS];
148
     static long position[NUM_AXIS];
148
 
149
 
187
      */
188
      */
188
 
189
 
189
     static void reset_acceleration_rates();
190
     static void reset_acceleration_rates();
191
+    static void refresh_positioning();
190
 
192
 
191
     // Manage fans, paste pressure, etc.
193
     // Manage fans, paste pressure, etc.
192
     static void check_axes_activity();
194
     static void check_axes_activity();

+ 1
- 1
Marlin/stepper.cpp View File

951
   #else
951
   #else
952
     axis_steps = position(axis);
952
     axis_steps = position(axis);
953
   #endif
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
 void Stepper::finish_and_disable() {
957
 void Stepper::finish_and_disable() {

+ 1
- 1
Marlin/stepper.h View File

262
     // Triggered position of an axis in mm (not core-savvy)
262
     // Triggered position of an axis in mm (not core-savvy)
263
     //
263
     //
264
     static FORCE_INLINE float triggered_position_mm(AxisEnum axis) {
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
     #if ENABLED(LIN_ADVANCE)
268
     #if ENABLED(LIN_ADVANCE)

+ 1
- 1
Marlin/temperature.cpp View File

572
               lpq[lpq_ptr] = 0;
572
               lpq[lpq_ptr] = 0;
573
             }
573
             }
574
             if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
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
             pid_output += cTerm[HOTEND_INDEX];
576
             pid_output += cTerm[HOTEND_INDEX];
577
           }
577
           }
578
         #endif //PID_ADD_EXTRUSION_RATE
578
         #endif //PID_ADD_EXTRUSION_RATE

+ 7
- 6
Marlin/ultralcd.cpp View File

678
       }
678
       }
679
       if (lcdDrawUpdate)
679
       if (lcdDrawUpdate)
680
         lcd_implementation_drawedit(msg, ftostr43sign(
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
   }
1769
   }
1770
 
1770
 
1771
   static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
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
     MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
1806
     MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
1806
     MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
1807
     MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
1807
     MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
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
     #if ENABLED(DELTA)
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
     #else
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
     #endif
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
     #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
1817
     #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
1817
       MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
1818
       MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
1818
     #endif
1819
     #endif

Loading…
Cancel
Save