ソースを参照

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
 
278
 
279
 // Workspace offsets
279
 // Workspace offsets
280
 #if DISABLED(NO_WORKSPACE_OFFSETS)
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
 #else
286
 #else
286
   #define LOGICAL_POSITION(POS, AXIS) (POS)
287
   #define LOGICAL_POSITION(POS, AXIS) (POS)
287
   #define RAW_POSITION(POS, AXIS)     (POS)
288
   #define RAW_POSITION(POS, AXIS)     (POS)

+ 5
- 2
Marlin/Marlin_main.cpp ファイルの表示

405
   // Set by M206, M428, or menu item. Saved to EEPROM.
405
   // Set by M206, M428, or menu item. Saved to EEPROM.
406
   float home_offset[XYZ] = { 0 };
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
 #endif
411
 #endif
409
 
412
 
410
 // Software Endstops are based on the configured limits.
413
 // Software Endstops are based on the configured limits.
1349
    * at the same positions relative to the machine.
1352
    * at the same positions relative to the machine.
1350
    */
1353
    */
1351
   void update_software_endstops(const AxisEnum axis) {
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
     #if ENABLED(DUAL_X_CARRIAGE)
1357
     #if ENABLED(DUAL_X_CARRIAGE)
1355
       if (axis == X_AXIS) {
1358
       if (axis == X_AXIS) {
1408
    * Since this changes the current_position, code should
1411
    * Since this changes the current_position, code should
1409
    * call sync_plan_position soon after this.
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
     current_position[axis] += v - home_offset[axis];
1415
     current_position[axis] += v - home_offset[axis];
1413
     home_offset[axis] = v;
1416
     home_offset[axis] = v;
1414
     update_software_endstops(axis);
1417
     update_software_endstops(axis);

読み込み中…
キャンセル
保存