浏览代码

Implement CNC_COORDINATE_SYSTEMS

Scott Lahteine 7 年前
父节点
当前提交
1b40e9c464

+ 5
- 10
.travis.yml 查看文件

59
   - opt_set TEMP_SENSOR_0 -2
59
   - opt_set TEMP_SENSOR_0 -2
60
   - opt_set TEMP_SENSOR_1 1
60
   - opt_set TEMP_SENSOR_1 1
61
   - opt_set TEMP_SENSOR_BED 1
61
   - opt_set TEMP_SENSOR_BED 1
62
-  - opt_enable PIDTEMPBED Z_SAFE_HOMING ARC_P_CIRCLES CNC_WORKSPACE_PLANES
62
+  - opt_enable PIDTEMPBED FIX_MOUNTED_PROBE Z_SAFE_HOMING ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS
63
   - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS
63
   - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS
64
   - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED
64
   - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED
65
-  - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
66
-
67
-  #
68
-  # ...with AUTO_BED_LEVELING_LINEAR, Z_MIN_PROBE_REPEATABILITY_TEST, and DEBUG_LEVELING_FEATURE
69
-  #
70
-  - opt_enable AUTO_BED_LEVELING_LINEAR BLTOUCH Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE
65
+  - opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE
71
   - opt_enable_adv FWRETRACT MAX7219_DEBUG
66
   - opt_enable_adv FWRETRACT MAX7219_DEBUG
72
   - opt_set ABL_GRID_POINTS_X 16
67
   - opt_set ABL_GRID_POINTS_X 16
73
   - opt_set ABL_GRID_POINTS_Y 16
68
   - opt_set ABL_GRID_POINTS_Y 16
69
+  - opt_set_adv FANMUX0_PIN 53
74
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
70
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
75
   #
71
   #
76
   # Test a probeless build of AUTO_BED_LEVELING_UBL
72
   # Test a probeless build of AUTO_BED_LEVELING_UBL
80
   - opt_enable_adv CUSTOM_USER_MENUS I2C_POSITION_ENCODERS BABYSTEPPING
76
   - opt_enable_adv CUSTOM_USER_MENUS I2C_POSITION_ENCODERS BABYSTEPPING
81
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
77
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
82
   #
78
   #
83
-  # ...and with a probe
79
+  # And with a probe...
84
   #
80
   #
85
-  - opt_enable BLTOUCH
86
-  - opt_enable_adv BABYSTEP_ZPROBE_OFFSET
81
+  - opt_enable FIX_MOUNTED_PROBE
87
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
82
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
88
   #
83
   #
89
   # Test a Sled Z Probe
84
   # Test a Sled Z Probe

+ 28
- 17
Marlin/src/gcode/gcode.cpp 查看文件

56
   GcodeSuite::WorkspacePlane GcodeSuite::workspace_plane = PLANE_XY;
56
   GcodeSuite::WorkspacePlane GcodeSuite::workspace_plane = PLANE_XY;
57
 #endif
57
 #endif
58
 
58
 
59
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
60
+  int8_t GcodeSuite::active_coordinate_system = -1; // machine space
61
+  float GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
62
+#endif
63
+
59
 /**
64
 /**
60
  * Set target_extruder from the T parameter or the active_extruder
65
  * Set target_extruder from the T parameter or the active_extruder
61
  *
66
  *
125
 #endif
130
 #endif
126
 
131
 
127
 /**
132
 /**
128
- * Process a single command and dispatch it to its handler
129
- * This is called from the main loop()
133
+ * Process the parsed command and dispatch it to its handler
130
  */
134
  */
131
-void GcodeSuite::process_next_command() {
132
-  char * const current_command = command_queue[cmd_queue_index_r];
133
-
134
-  if (DEBUGGING(ECHO)) {
135
-    SERIAL_ECHO_START();
136
-    SERIAL_ECHOLN(current_command);
137
-    #if ENABLED(M100_FREE_MEMORY_WATCHER)
138
-      SERIAL_ECHOPAIR("slot:", cmd_queue_index_r);
139
-      M100_dump_routine("   Command Queue:", (const char*)command_queue, (const char*)(command_queue + sizeof(command_queue)));
140
-    #endif
141
-  }
142
-
135
+void GcodeSuite::process_parsed_command() {
143
   KEEPALIVE_STATE(IN_HANDLER);
136
   KEEPALIVE_STATE(IN_HANDLER);
144
 
137
 
145
-  // Parse the next command in the queue
146
-  parser.parse(current_command);
147
-
148
   // Handle a known G, M, or T
138
   // Handle a known G, M, or T
149
   switch (parser.command_letter) {
139
   switch (parser.command_letter) {
150
     case 'G': switch (parser.codenum) {
140
     case 'G': switch (parser.codenum) {
711
   ok_to_send();
701
   ok_to_send();
712
 }
702
 }
713
 
703
 
704
+/**
705
+ * Process a single command and dispatch it to its handler
706
+ * This is called from the main loop()
707
+ */
708
+void GcodeSuite::process_next_command() {
709
+  char * const current_command = command_queue[cmd_queue_index_r];
710
+
711
+  if (DEBUGGING(ECHO)) {
712
+    SERIAL_ECHO_START();
713
+    SERIAL_ECHOLN(current_command);
714
+    #if ENABLED(M100_FREE_MEMORY_WATCHER)
715
+      SERIAL_ECHOPAIR("slot:", cmd_queue_index_r);
716
+      M100_dump_routine("   Command Queue:", (const char*)command_queue, (const char*)(command_queue + sizeof(command_queue)));
717
+    #endif
718
+  }
719
+
720
+  // Parse the next command in the queue
721
+  parser.parse(current_command);
722
+  process_parsed_command();
723
+}
724
+
714
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
725
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
715
 
726
 
716
   /**
727
   /**

+ 19
- 0
Marlin/src/gcode/gcode.h 查看文件

266
     static WorkspacePlane workspace_plane;
266
     static WorkspacePlane workspace_plane;
267
   #endif
267
   #endif
268
 
268
 
269
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
270
+    #define MAX_COORDINATE_SYSTEMS 9
271
+    static int8_t active_coordinate_system;
272
+    static float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
273
+    static bool select_coordinate_system(const int8_t _new);
274
+  #endif
275
+
269
   static millis_t previous_cmd_ms;
276
   static millis_t previous_cmd_ms;
270
   FORCE_INLINE static void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
277
   FORCE_INLINE static void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
271
 
278
 
272
   static bool get_target_extruder_from_command();
279
   static bool get_target_extruder_from_command();
273
   static void get_destination_from_command();
280
   static void get_destination_from_command();
281
+  static void process_parsed_command();
274
   static void process_next_command();
282
   static void process_next_command();
275
 
283
 
276
   static FORCE_INLINE void home_all_axes() { G28(true); }
284
   static FORCE_INLINE void home_all_axes() { G28(true); }
383
     static void G42();
391
     static void G42();
384
   #endif
392
   #endif
385
 
393
 
394
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
395
+    bool select_coordinate_system(const int8_t _new);
396
+    static void G53();
397
+    static void G54();
398
+    static void G55();
399
+    static void G56();
400
+    static void G57();
401
+    static void G58();
402
+    static void G59();
403
+  #endif
404
+
386
   static void G92();
405
   static void G92();
387
 
406
 
388
   #if HAS_RESUME_CONTINUE
407
   #if HAS_RESUME_CONTINUE

+ 93
- 0
Marlin/src/gcode/geometry/G53-G59.cpp 查看文件

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../gcode.h"
24
+#include "../../module/motion.h"
25
+//#include "../../module/stepper.h"
26
+
27
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
28
+
29
+  /**
30
+   * Select a coordinate system and update the current position.
31
+   * System index -1 is used to specify machine-native.
32
+   */
33
+  bool GCodeSuite::select_coordinate_system(const int8_t _new) {
34
+    if (active_coordinate_system == _new) return false;
35
+    stepper.synchronize();
36
+    float old_offset[XYZ] = { 0 }, new_offset[XYZ] = { 0 };
37
+    if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
38
+      COPY(old_offset, coordinate_system[active_coordinate_system]);
39
+    if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
40
+      COPY(new_offset, coordinate_system[_new]);
41
+    active_coordinate_system = _new;
42
+    bool didXYZ = false;
43
+    LOOP_XYZ(i) {
44
+      const float diff = new_offset[i] - old_offset[i];
45
+      if (diff) {
46
+        position_shift[i] += diff;
47
+        update_software_endstops((AxisEnum)i);
48
+        didXYZ = true;
49
+      }
50
+    }
51
+    if (didXYZ) SYNC_PLAN_POSITION_KINEMATIC();
52
+    return true;
53
+  }
54
+
55
+  /**
56
+   * In CNC G-code G53 is like a modifier
57
+   * It precedes a movement command (or other modifiers) on the same line.
58
+   * This is the first command to use parser.chain() to make this possible.
59
+   */
60
+  void GCodeSuite::G53() {
61
+    // If this command has more following...
62
+    if (parser.chain()) {
63
+      const int8_t _system = active_coordinate_system;
64
+      active_coordinate_system = -1;
65
+      process_parsed_command();
66
+      active_coordinate_system = _system;
67
+    }
68
+  }
69
+
70
+  /**
71
+   * G54-G59.3: Select a new workspace
72
+   *
73
+   * A workspace is an XYZ offset to the machine native space.
74
+   * All workspaces default to 0,0,0 at start, or with EEPROM
75
+   * support they may be restored from a previous session.
76
+   *
77
+   * G92 is used to set the current workspace's offset.
78
+   */
79
+  void G54_59(uint8_t subcode=0) {
80
+    const int8_t _space = parser.codenum - 54 + subcode;
81
+    if (gcode.select_coordinate_system(_space)) {
82
+      SERIAL_PROTOCOLLNPAIR("Select workspace ", _space);
83
+      report_current_position();
84
+    }
85
+  }
86
+  void GCodeSuite::G54() { G54_59(); }
87
+  void GCodeSuite::G55() { G54_59(); }
88
+  void GCodeSuite::G56() { G54_59(); }
89
+  void GCodeSuite::G57() { G54_59(); }
90
+  void GCodeSuite::G58() { G54_59(); }
91
+  void GCodeSuite::G59() { G54_59(parser.subcode); }
92
+
93
+#endif // CNC_COORDINATE_SYSTEMS

+ 31
- 1
Marlin/src/gcode/geometry/G92.cpp 查看文件

37
 
37
 
38
   if (!didE) stepper.synchronize();
38
   if (!didE) stepper.synchronize();
39
 
39
 
40
-  LOOP_XYZE(i) {
40
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
41
+    switch (parser.subcode) {
42
+      case 1:
43
+        // Zero the G92 values and restore current position
44
+        #if !IS_SCARA
45
+          LOOP_XYZ(i) {
46
+            const float v = position_shift[i];
47
+            if (v) {
48
+              position_shift[i] = 0;
49
+              update_software_endstops((AxisEnum)i);
50
+            }
51
+          }
52
+        #endif // Not SCARA
53
+        return;
54
+    }
55
+  #endif
56
+
57
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
58
+    #define IS_G92_0 (parser.subcode == 0)
59
+  #else
60
+    #define IS_G92_0 true
61
+  #endif
62
+
63
+  if (IS_G92_0) LOOP_XYZE(i) {
41
     if (parser.seenval(axis_codes[i])) {
64
     if (parser.seenval(axis_codes[i])) {
42
       #if IS_SCARA
65
       #if IS_SCARA
43
         current_position[i] = parser.value_axis_units((AxisEnum)i);
66
         current_position[i] = parser.value_axis_units((AxisEnum)i);
60
       #endif
83
       #endif
61
     }
84
     }
62
   }
85
   }
86
+
87
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
88
+    // Apply workspace offset to the active coordinate system
89
+    if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
90
+      COPY(coordinate_system[active_coordinate_system], position_shift);
91
+  #endif
92
+
63
   if (didXYZ)
93
   if (didXYZ)
64
     SYNC_PLAN_POSITION_KINEMATIC();
94
     SYNC_PLAN_POSITION_KINEMATIC();
65
   else if (didE)
95
   else if (didE)

+ 20
- 0
Marlin/src/gcode/parser.cpp 查看文件

233
   }
233
   }
234
 }
234
 }
235
 
235
 
236
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
237
+
238
+  // Parse the next parameter as a new command
239
+  bool GCodeParser::chain() {
240
+    #if ENABLED(FASTER_GCODE_PARSER)
241
+      char *next_command = command_ptr;
242
+      if (next_command) {
243
+        while (*next_command && *next_command != ' ') ++next_command;
244
+        while (*next_command == ' ') ++next_command;
245
+        if (!*next_command) next_command = NULL;
246
+      }
247
+    #else
248
+      const char *next_command = command_args;
249
+    #endif
250
+    if (next_command) parse(next_command);
251
+    return !!next_command;
252
+  }
253
+
254
+#endif // CNC_COORDINATE_SYSTEMS
255
+
236
 void GCodeParser::unknown_command_error() {
256
 void GCodeParser::unknown_command_error() {
237
   SERIAL_ECHO_START();
257
   SERIAL_ECHO_START();
238
   SERIAL_ECHOPAIR(MSG_UNKNOWN_COMMAND, command_ptr);
258
   SERIAL_ECHOPAIR(MSG_UNKNOWN_COMMAND, command_ptr);

+ 5
- 0
Marlin/src/gcode/parser.h 查看文件

156
   // This uses 54 bytes of SRAM to speed up seen/value
156
   // This uses 54 bytes of SRAM to speed up seen/value
157
   static void parse(char * p);
157
   static void parse(char * p);
158
 
158
 
159
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
160
+    // Parse the next parameter as a new command
161
+    static bool chain();
162
+  #endif
163
+
159
   // The code value pointer was set
164
   // The code value pointer was set
160
   FORCE_INLINE static bool has_value() { return value_ptr != NULL; }
165
   FORCE_INLINE static bool has_value() { return value_ptr != NULL; }
161
 
166
 

+ 1
- 1
Marlin/src/inc/Conditionals_post.h 查看文件

1112
 #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
1112
 #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
1113
 
1113
 
1114
 // Add commands that need sub-codes to this list
1114
 // Add commands that need sub-codes to this list
1115
-#define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET)
1115
+#define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET) || ENABLED(CNC_COORDINATE_SYSTEMS)
1116
 
1116
 
1117
 // MESH_BED_LEVELING overrides PROBE_MANUALLY
1117
 // MESH_BED_LEVELING overrides PROBE_MANUALLY
1118
 #if ENABLED(MESH_BED_LEVELING)
1118
 #if ENABLED(MESH_BED_LEVELING)

+ 4
- 0
Marlin/src/inc/SanityCheck.h 查看文件

1450
 static_assert(COUNT(sanity_arr_2) <= XYZE_N, "DEFAULT_MAX_FEEDRATE has too many elements.");
1450
 static_assert(COUNT(sanity_arr_2) <= XYZE_N, "DEFAULT_MAX_FEEDRATE has too many elements.");
1451
 static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too many elements.");
1451
 static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too many elements.");
1452
 
1452
 
1453
+#if ENABLED(CNC_COORDINATE_SYSTEMS) && ENABLED(NO_WORKSPACE_OFFSETS)
1454
+  #error "CNC_COORDINATE_SYSTEMS is incompatible with NO_WORKSPACE_OFFSETS."
1455
+#endif
1456
+
1453
 #include "../HAL/HAL_SanityCheck.h"  // get CPU specific checks
1457
 #include "../HAL/HAL_SanityCheck.h"  // get CPU specific checks
1454
 
1458
 
1455
 #endif // _SANITYCHECK_H_
1459
 #endif // _SANITYCHECK_H_

+ 36
- 4
Marlin/src/module/configuration_store.cpp 查看文件

36
  *
36
  *
37
  */
37
  */
38
 
38
 
39
-#define EEPROM_VERSION "V43"
39
+#define EEPROM_VERSION "V44"
40
 
40
 
41
 // Change EEPROM version if these are changed:
41
 // Change EEPROM version if these are changed:
42
 #define EEPROM_OFFSET 100
42
 #define EEPROM_OFFSET 100
43
 
43
 
44
 /**
44
 /**
45
- * V43 EEPROM Layout:
45
+ * V44 EEPROM Layout:
46
  *
46
  *
47
  *  100  Version                                    (char x4)
47
  *  100  Version                                    (char x4)
48
  *  104  EEPROM CRC16                               (uint16_t)
48
  *  104  EEPROM CRC16                               (uint16_t)
162
  *  588  M907 Z    Stepper Z current                (uint32_t)
162
  *  588  M907 Z    Stepper Z current                (uint32_t)
163
  *  592  M907 E    Stepper E current                (uint32_t)
163
  *  592  M907 E    Stepper E current                (uint32_t)
164
  *
164
  *
165
- *  596                                Minimum end-point
166
- * 1917 (596 + 36 + 9 + 288 + 988)     Maximum end-point
165
+ * CNC_COORDINATE_SYSTEMS                           108 bytes
166
+ *  596  G54-G59.3 coordinate_system                (float x 27)
167
+ *
168
+ *  704                                Minimum end-point
169
+ * 2025 (704 + 36 + 9 + 288 + 988)     Maximum end-point
167
  *
170
  *
168
  * ========================================================================
171
  * ========================================================================
169
  * meshes_begin (between max and min end-point, directly above)
172
  * meshes_begin (between max and min end-point, directly above)
207
   float new_z_fade_height;
210
   float new_z_fade_height;
208
 #endif
211
 #endif
209
 
212
 
213
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
214
+  bool position_changed;
215
+#endif
216
+
210
 /**
217
 /**
211
  * Post-process after Retrieve or Reset
218
  * Post-process after Retrieve or Reset
212
  */
219
  */
255
   #if ENABLED(FWRETRACT)
262
   #if ENABLED(FWRETRACT)
256
     fwretract.refresh_autoretract();
263
     fwretract.refresh_autoretract();
257
   #endif
264
   #endif
265
+
266
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
267
+    if (position_changed) {
268
+      report_current_position();
269
+      position_changed = false;
270
+    }
271
+  #endif
258
 }
272
 }
259
 
273
 
260
 #if ENABLED(EEPROM_SETTINGS)
274
 #if ENABLED(EEPROM_SETTINGS)
630
       for (uint8_t q = 3; q--;) EEPROM_WRITE(dummyui32);
644
       for (uint8_t q = 3; q--;) EEPROM_WRITE(dummyui32);
631
     #endif
645
     #endif
632
 
646
 
647
+    #if ENABLED(CNC_COORDINATE_SYSTEMS)
648
+      EEPROM_WRITE(coordinate_system); // 27 floats
649
+    #else
650
+      dummy = 0.0f;
651
+      for (uint8_t q = 27; q--;) EEPROM_WRITE(dummy);
652
+    #endif
653
+
633
     if (!eeprom_error) {
654
     if (!eeprom_error) {
634
       #if ENABLED(EEPROM_CHITCHAT)
655
       #if ENABLED(EEPROM_CHITCHAT)
635
         const int eeprom_size = eeprom_index;
656
         const int eeprom_size = eeprom_index;
1064
         for (uint8_t q = 3; q--;) EEPROM_READ(dummyui32);
1085
         for (uint8_t q = 3; q--;) EEPROM_READ(dummyui32);
1065
       #endif
1086
       #endif
1066
 
1087
 
1088
+      //
1089
+      // CNC Coordinate System
1090
+      //
1091
+
1092
+      #if ENABLED(CNC_COORDINATE_SYSTEMS)
1093
+        position_changed = gcode.select_coordinate_system(-1); // Go back to machine space
1094
+        EEPROM_READ(gcode.coordinate_system);                  // 27 floats
1095
+      #else
1096
+        for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
1097
+      #endif
1098
+
1067
       if (working_crc == stored_crc) {
1099
       if (working_crc == stored_crc) {
1068
         postprocess();
1100
         postprocess();
1069
         #if ENABLED(EEPROM_CHITCHAT)
1101
         #if ENABLED(EEPROM_CHITCHAT)

正在加载...
取消
保存