Преглед на файлове

Optimize coordinate transformation

Pre-compute the combined position shift and home offset to save a
single float fetch-and-add per conversion. Great for delta/scara and
bed leveling.
Scott Lahteine преди 8 години
родител
ревизия
e141f3a03f
променени са 2 файла, в които са добавени 10 реда и са изтрити 6 реда
  1. 5
    4
      Marlin/Marlin.h
  2. 5
    2
      Marlin/Marlin_main.cpp

+ 5
- 4
Marlin/Marlin.h Целия файл

@@ -278,10 +278,11 @@ extern float current_position[NUM_AXIS];
278 278
 
279 279
 // Workspace offsets
280 280
 #if DISABLED(NO_WORKSPACE_OFFSETS)
281
-  extern float position_shift[XYZ];
282
-  extern float home_offset[XYZ];
283
-  #define LOGICAL_POSITION(POS, AXIS) ((POS) + home_offset[AXIS] + position_shift[AXIS])
284
-  #define RAW_POSITION(POS, AXIS)     ((POS) - home_offset[AXIS] - position_shift[AXIS])
281
+  extern float position_shift[XYZ],
282
+               home_offset[XYZ],
283
+               workspace_offset[XYZ];
284
+  #define LOGICAL_POSITION(POS, AXIS) ((POS) + workspace_offset[AXIS])
285
+  #define RAW_POSITION(POS, AXIS)     ((POS) - workspace_offset[AXIS])
285 286
 #else
286 287
   #define LOGICAL_POSITION(POS, AXIS) (POS)
287 288
   #define RAW_POSITION(POS, AXIS)     (POS)

+ 5
- 2
Marlin/Marlin_main.cpp Целия файл

@@ -405,6 +405,9 @@ float filament_size[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_NOMINAL_FILAMENT_DI
405 405
   // Set by M206, M428, or menu item. Saved to EEPROM.
406 406
   float home_offset[XYZ] = { 0 };
407 407
 
408
+  // The above two are combined to save on computes
409
+  float workspace_offset[XYZ] = { 0 };
410
+
408 411
 #endif
409 412
 
410 413
 // Software Endstops are based on the configured limits.
@@ -1349,7 +1352,7 @@ bool get_target_extruder_from_command(int code) {
1349 1352
    * at the same positions relative to the machine.
1350 1353
    */
1351 1354
   void update_software_endstops(const AxisEnum axis) {
1352
-    const float offs = LOGICAL_POSITION(0, axis);
1355
+    const float offs = workspace_offset[axis] = LOGICAL_POSITION(0, axis);
1353 1356
 
1354 1357
     #if ENABLED(DUAL_X_CARRIAGE)
1355 1358
       if (axis == X_AXIS) {
@@ -1408,7 +1411,7 @@ bool get_target_extruder_from_command(int code) {
1408 1411
    * Since this changes the current_position, code should
1409 1412
    * call sync_plan_position soon after this.
1410 1413
    */
1411
-  static void set_home_offset(AxisEnum axis, float v) {
1414
+  static void set_home_offset(const AxisEnum axis, const float v) {
1412 1415
     current_position[axis] += v - home_offset[axis];
1413 1416
     home_offset[axis] = v;
1414 1417
     update_software_endstops(axis);

Loading…
Отказ
Запис