Browse Source

Merge pull request #4389 from thinkyhead/rc_optimize_planner

Optimize planner with precalculation, etc.
Scott Lahteine 8 years ago
parent
commit
b7b7c90477

+ 22
- 21
Marlin/Marlin_main.cpp View File

610
     print_xyz(PSTR(STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); } while(0)
610
     print_xyz(PSTR(STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); } while(0)
611
 #endif
611
 #endif
612
 
612
 
613
+/**
614
+ * sync_plan_position
615
+ * Set planner / stepper positions to the cartesian current_position.
616
+ * The stepper code translates these coordinates into step units.
617
+ * Allows translation between steps and millimeters for cartesian & core robots
618
+ */
619
+inline void sync_plan_position() {
620
+  #if ENABLED(DEBUG_LEVELING_FEATURE)
621
+    if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
622
+  #endif
623
+  planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
624
+}
625
+inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
626
+
613
 #if ENABLED(DELTA) || ENABLED(SCARA)
627
 #if ENABLED(DELTA) || ENABLED(SCARA)
614
   inline void sync_plan_position_delta() {
628
   inline void sync_plan_position_delta() {
615
     #if ENABLED(DEBUG_LEVELING_FEATURE)
629
     #if ENABLED(DEBUG_LEVELING_FEATURE)
897
   // Send "ok" after commands by default
911
   // Send "ok" after commands by default
898
   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;
899
 
913
 
900
-  // 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
901
   Config_RetrieveSettings();
916
   Config_RetrieveSettings();
902
 
917
 
903
   // Initialize current position based on home_offset
918
   // Initialize current position based on home_offset
904
   memcpy(current_position, home_offset, sizeof(home_offset));
919
   memcpy(current_position, home_offset, sizeof(home_offset));
905
 
920
 
906
-  #if ENABLED(DELTA) || ENABLED(SCARA)
907
-    // Vital to init kinematic equivalent for X0 Y0 Z0
908
-    SYNC_PLAN_POSITION_KINEMATIC();
909
-  #endif
921
+  // Vital to init stepper/planner equivalent for current_position
922
+  SYNC_PLAN_POSITION_KINEMATIC();
910
 
923
 
911
   thermalManager.init();    // Initialize temperature loop
924
   thermalManager.init();    // Initialize temperature loop
912
 
925
 
1319
       case TEMPUNIT_C:
1332
       case TEMPUNIT_C:
1320
         return code_value_float();
1333
         return code_value_float();
1321
       case TEMPUNIT_F:
1334
       case TEMPUNIT_F:
1322
-        return (code_value_float() - 32) / 1.8;
1335
+        return (code_value_float() - 32) * 0.5555555556;
1323
       case TEMPUNIT_K:
1336
       case TEMPUNIT_K:
1324
         return code_value_float() - 272.15;
1337
         return code_value_float() - 272.15;
1325
       default:
1338
       default:
1333
       case TEMPUNIT_K:
1346
       case TEMPUNIT_K:
1334
         return code_value_float();
1347
         return code_value_float();
1335
       case TEMPUNIT_F:
1348
       case TEMPUNIT_F:
1336
-        return code_value_float() / 1.8;
1349
+        return code_value_float() * 0.5555555556;
1337
       default:
1350
       default:
1338
         return code_value_float();
1351
         return code_value_float();
1339
     }
1352
     }
1627
 }
1640
 }
1628
 inline void line_to_destination() { line_to_destination(feedrate_mm_m); }
1641
 inline void line_to_destination() { line_to_destination(feedrate_mm_m); }
1629
 
1642
 
1630
-/**
1631
- * sync_plan_position
1632
- * Set planner / stepper positions to the cartesian current_position.
1633
- * The stepper code translates these coordinates into step units.
1634
- * Allows translation between steps and millimeters for cartesian & core robots
1635
- */
1636
-inline void sync_plan_position() {
1637
-  #if ENABLED(DEBUG_LEVELING_FEATURE)
1638
-    if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
1639
-  #endif
1640
-  planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1641
-}
1642
-inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
1643
 inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1643
 inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1644
 inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1644
 inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1645
 
1645
 
5147
       }
5147
       }
5148
     }
5148
     }
5149
   }
5149
   }
5150
+  planner.refresh_positioning();
5150
 }
5151
 }
5151
 
5152
 
5152
 /**
5153
 /**
6140
   bool err = false;
6141
   bool err = false;
6141
   LOOP_XYZ(i) {
6142
   LOOP_XYZ(i) {
6142
     if (axis_homed[i]) {
6143
     if (axis_homed[i]) {
6143
-      float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) / 2) ? base_home_pos(i) : 0,
6144
+      float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) * 0.5) ? base_home_pos(i) : 0,
6144
             diff = current_position[i] - LOGICAL_POSITION(base, i);
6145
             diff = current_position[i] - LOGICAL_POSITION(base, i);
6145
       if (diff > -20 && diff < 20) {
6146
       if (diff > -20 && diff < 20) {
6146
         set_home_offset((AxisEnum)i, home_offset[i] - diff);
6147
         set_home_offset((AxisEnum)i, home_offset[i] - diff);

+ 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

+ 67
- 44
Marlin/planner.cpp View File

80
 volatile uint8_t Planner::block_buffer_head = 0;           // Index of the next block to be pushed
80
 volatile uint8_t Planner::block_buffer_head = 0;           // Index of the next block to be pushed
81
 volatile uint8_t Planner::block_buffer_tail = 0;
81
 volatile uint8_t Planner::block_buffer_tail = 0;
82
 
82
 
83
-float Planner::max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
84
-float Planner::axis_steps_per_mm[NUM_AXIS];
85
-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
83
+float Planner::max_feedrate_mm_s[NUM_AXIS], // Max speeds in mm per second
84
+      Planner::axis_steps_per_mm[NUM_AXIS],
85
+      Planner::steps_to_mm[NUM_AXIS];
86
+
87
+unsigned long Planner::max_acceleration_steps_per_s2[NUM_AXIS],
88
+              Planner::max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
87
 
89
 
88
 millis_t Planner::min_segment_time;
90
 millis_t Planner::min_segment_time;
89
-float Planner::min_feedrate_mm_s;
90
-float Planner::acceleration;         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
91
-float Planner::retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
92
-float Planner::travel_acceleration;  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
93
-float Planner::max_xy_jerk;          // The largest speed change requiring no acceleration
94
-float Planner::max_z_jerk;
95
-float Planner::max_e_jerk;
96
-float Planner::min_travel_feedrate_mm_s;
91
+float Planner::min_feedrate_mm_s,
92
+      Planner::acceleration,         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
93
+      Planner::retract_acceleration, // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
94
+      Planner::travel_acceleration,  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
95
+      Planner::max_xy_jerk,          // The largest speed change requiring no acceleration
96
+      Planner::max_z_jerk,
97
+      Planner::max_e_jerk,
98
+      Planner::min_travel_feedrate_mm_s;
97
 
99
 
98
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
100
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
99
   matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
101
   matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
100
 #endif
102
 #endif
101
 
103
 
102
 #if ENABLED(AUTOTEMP)
104
 #if ENABLED(AUTOTEMP)
103
-  float Planner::autotemp_max = 250;
104
-  float Planner::autotemp_min = 210;
105
-  float Planner::autotemp_factor = 0.1;
105
+  float Planner::autotemp_max = 250,
106
+        Planner::autotemp_min = 210,
107
+        Planner::autotemp_factor = 0.1;
106
   bool Planner::autotemp_enabled = false;
108
   bool Planner::autotemp_enabled = false;
107
 #endif
109
 #endif
108
 
110
 
110
 
112
 
111
 long Planner::position[NUM_AXIS] = { 0 };
113
 long Planner::position[NUM_AXIS] = { 0 };
112
 
114
 
113
-float Planner::previous_speed[NUM_AXIS];
114
-
115
-float Planner::previous_nominal_speed;
115
+float Planner::previous_speed[NUM_AXIS],
116
+      Planner::previous_nominal_speed;
116
 
117
 
117
 #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
118
 #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
118
   uint8_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 };
119
   uint8_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 };
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[A_AXIS];
799
-      delta_mm[Y_HEAD] = dy / axis_steps_per_mm[Y_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];
806
-    delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS];
807
-    delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS];
808
-    delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS];
807
+    #if ENABLED(DELTA)
808
+      // On delta all axes (should!) have the same steps-per-mm
809
+      // so calculate distance in steps first, then do one division
810
+      // at the end to get millimeters
811
+    #else
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];
815
+    #endif
809
   #endif
816
   #endif
810
-  delta_mm[E_AXIS] = (de / axis_steps_per_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0;
817
+  delta_mm[E_AXIS] = 0.01 * (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder];
811
 
818
 
812
   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) {
813
     block->millimeters = fabs(delta_mm[E_AXIS]);
820
     block->millimeters = fabs(delta_mm[E_AXIS]);
820
         sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_HEAD])
827
         sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_HEAD])
821
       #elif ENABLED(COREYZ)
828
       #elif ENABLED(COREYZ)
822
         sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_HEAD])
829
         sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_HEAD])
830
+      #elif ENABLED(DELTA)
831
+        sq(dx) + sq(dy) + sq(dz)
823
       #else
832
       #else
824
         sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_AXIS])
833
         sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_AXIS])
825
       #endif
834
       #endif
826
-    );
835
+    )
836
+      #if ENABLED(DELTA)
837
+        * steps_to_mm[X_AXIS]
838
+      #endif
839
+    ;
827
   }
840
   }
828
   float inverse_millimeters = 1.0 / block->millimeters;  // Inverse millimeters to remove multiple divides
841
   float inverse_millimeters = 1.0 / block->millimeters;  // Inverse millimeters to remove multiple divides
829
 
842
 
875
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
888
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
876
 
889
 
877
         // Convert into an index into the measurement array
890
         // Convert into an index into the measurement array
878
-        filwidth_delay_index1 = (int)(filwidth_delay_dist / 10.0 + 0.0001);
891
+        filwidth_delay_index1 = (int)(filwidth_delay_dist * 0.1 + 0.0001);
879
 
892
 
880
         // If the index has changed (must have gone forward)...
893
         // If the index has changed (must have gone forward)...
881
         if (filwidth_delay_index1 != filwidth_delay_index2) {
894
         if (filwidth_delay_index1 != filwidth_delay_index2) {
962
       block->acceleration_steps_per_s2 = (max_acceleration_steps_per_s2[E_AXIS] * block->step_event_count) / block->steps[E_AXIS];
975
       block->acceleration_steps_per_s2 = (max_acceleration_steps_per_s2[E_AXIS] * block->step_event_count) / block->steps[E_AXIS];
963
   }
976
   }
964
   block->acceleration = block->acceleration_steps_per_s2 / steps_per_mm;
977
   block->acceleration = block->acceleration_steps_per_s2 / steps_per_mm;
965
-  block->acceleration_rate = (long)(block->acceleration_steps_per_s2 * 16777216.0 / ((F_CPU) / 8.0));
978
+  block->acceleration_rate = (long)(block->acceleration_steps_per_s2 * 16777216.0 / ((F_CPU) * 0.125));
966
 
979
 
967
   #if 0  // Use old jerk for now
980
   #if 0  // Use old jerk for now
968
 
981
 
1008
   #endif
1021
   #endif
1009
 
1022
 
1010
   // Start with a safe speed
1023
   // Start with a safe speed
1011
-  float vmax_junction = max_xy_jerk / 2;
1012
-  float vmax_junction_factor = 1.0;
1013
-  float mz2 = max_z_jerk / 2, me2 = max_e_jerk / 2;
1014
-  float csz = current_speed[Z_AXIS], cse = current_speed[E_AXIS];
1024
+  float vmax_junction = max_xy_jerk * 0.5,
1025
+        vmax_junction_factor = 1.0,
1026
+        mz2 = max_z_jerk * 0.5,
1027
+        me2 = max_e_jerk * 0.5,
1028
+        csz = current_speed[Z_AXIS],
1029
+        cse = current_speed[E_AXIS];
1015
   if (fabs(csz) > mz2) vmax_junction = min(vmax_junction, mz2);
1030
   if (fabs(csz) > mz2) vmax_junction = min(vmax_junction, mz2);
1016
   if (fabs(cse) > me2) vmax_junction = min(vmax_junction, me2);
1031
   if (fabs(cse) > me2) vmax_junction = min(vmax_junction, me2);
1017
   vmax_junction = min(vmax_junction, block->nominal_speed);
1032
   vmax_junction = min(vmax_junction, block->nominal_speed);
1164
 void Planner::set_e_position_mm(const float& e) {
1179
 void Planner::set_e_position_mm(const float& e) {
1165
   position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1180
   position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1166
   stepper.set_e_position(position[E_AXIS]);
1181
   stepper.set_e_position(position[E_AXIS]);
1182
+  previous_speed[E_AXIS] = 0.0;
1167
 }
1183
 }
1168
 
1184
 
1169
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
1185
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
1172
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
1188
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
1173
 }
1189
 }
1174
 
1190
 
1191
+// Recalculate position, steps_to_mm if axis_steps_per_mm changes!
1192
+void Planner::refresh_positioning() {
1193
+  LOOP_XYZE(i) planner.steps_to_mm[i] = 1.0 / planner.axis_steps_per_mm[i];
1194
+  set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1195
+  reset_acceleration_rates();
1196
+}
1197
+
1175
 #if ENABLED(AUTOTEMP)
1198
 #if ENABLED(AUTOTEMP)
1176
 
1199
 
1177
   void Planner::autotemp_M109() {
1200
   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();

+ 4
- 4
Marlin/stepper.cpp View File

944
       CRITICAL_SECTION_END;
944
       CRITICAL_SECTION_END;
945
       // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
945
       // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
946
       // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
946
       // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
947
-      axis_steps = (pos1 + ((axis == CORE_AXIS_1) ? pos2 : -pos2)) / 2.0f;
947
+      axis_steps = (pos1 + ((axis == CORE_AXIS_1) ? pos2 : -pos2)) * 0.5f;
948
     }
948
     }
949
     else
949
     else
950
       axis_steps = position(axis);
950
       axis_steps = position(axis);
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() {
973
 
973
 
974
     float axis_pos = count_position[axis];
974
     float axis_pos = count_position[axis];
975
     if (axis == CORE_AXIS_1)
975
     if (axis == CORE_AXIS_1)
976
-      axis_pos = (axis_pos + count_position[CORE_AXIS_2]) / 2;
976
+      axis_pos = (axis_pos + count_position[CORE_AXIS_2]) * 0.5;
977
     else if (axis == CORE_AXIS_2)
977
     else if (axis == CORE_AXIS_2)
978
-      axis_pos = (count_position[CORE_AXIS_1] - axis_pos) / 2;
978
+      axis_pos = (count_position[CORE_AXIS_1] - axis_pos) * 0.5;
979
     endstops_trigsteps[axis] = axis_pos;
979
     endstops_trigsteps[axis] = axis_pos;
980
 
980
 
981
   #else // !COREXY && !COREXZ && !COREYZ
981
   #else // !COREXY && !COREXZ && !COREYZ

+ 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)

+ 5
- 5
Marlin/temperature.cpp View File

319
               SERIAL_PROTOCOLPAIR(MSG_T_MIN, min);
319
               SERIAL_PROTOCOLPAIR(MSG_T_MIN, min);
320
               SERIAL_PROTOCOLPAIR(MSG_T_MAX, max);
320
               SERIAL_PROTOCOLPAIR(MSG_T_MAX, max);
321
               if (cycles > 2) {
321
               if (cycles > 2) {
322
-                Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
323
-                Tu = ((float)(t_low + t_high) / 1000.0);
322
+                Ku = (4.0 * d) / (3.14159265 * (max - min) * 0.5);
323
+                Tu = ((float)(t_low + t_high) * 0.001);
324
                 SERIAL_PROTOCOLPAIR(MSG_KU, Ku);
324
                 SERIAL_PROTOCOLPAIR(MSG_KU, Ku);
325
                 SERIAL_PROTOCOLPAIR(MSG_TU, Tu);
325
                 SERIAL_PROTOCOLPAIR(MSG_TU, Tu);
326
                 workKp = 0.6 * Ku;
326
                 workKp = 0.6 * Ku;
327
                 workKi = 2 * workKp / Tu;
327
                 workKi = 2 * workKp / Tu;
328
-                workKd = workKp * Tu / 8;
328
+                workKd = workKp * Tu * 0.125;
329
                 SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
329
                 SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
330
                 SERIAL_PROTOCOLPAIR(MSG_KP, workKp);
330
                 SERIAL_PROTOCOLPAIR(MSG_KP, workKp);
331
                 SERIAL_PROTOCOLPAIR(MSG_KI, workKi);
331
                 SERIAL_PROTOCOLPAIR(MSG_KI, workKi);
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
753
       // Get the delayed info and add 100 to reconstitute to a percent of
753
       // Get the delayed info and add 100 to reconstitute to a percent of
754
       // the nominal filament diameter then square it to get an area
754
       // the nominal filament diameter then square it to get an area
755
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
755
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
756
-      float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2);
756
+      float vm = pow((measurement_delay[meas_shift_index] + 100.0) * 0.01, 2);
757
       NOLESS(vm, 0.01);
757
       NOLESS(vm, 0.01);
758
       volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm;
758
       volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm;
759
     }
759
     }

+ 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

+ 1
- 1
Marlin/ultralcd_impl_DOGM.h View File

385
     // SD Card Progress bar and clock
385
     // SD Card Progress bar and clock
386
     if (IS_SD_PRINTING) {
386
     if (IS_SD_PRINTING) {
387
       // Progress bar solid part
387
       // Progress bar solid part
388
-      u8g.drawBox(55, 50, (unsigned int)(71.f * card.percentDone() / 100.f), 2 - (TALL_FONT_CORRECTION));
388
+      u8g.drawBox(55, 50, (unsigned int)(71 * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION));
389
     }
389
     }
390
 
390
 
391
     u8g.setPrintPos(80,48);
391
     u8g.setPrintPos(80,48);

Loading…
Cancel
Save