Przeglądaj źródła

Implement CNC_COORDINATE_SYSTEMS

Scott Lahteine 7 lat temu
rodzic
commit
8ab368559a

+ 1
- 1
.travis.yml Wyświetl plik

@@ -86,7 +86,7 @@ script:
86 86
   - opt_set TEMP_SENSOR_0 -2
87 87
   - opt_set TEMP_SENSOR_1 1
88 88
   - opt_set TEMP_SENSOR_BED 1
89
-  - opt_enable PIDTEMPBED FIX_MOUNTED_PROBE Z_SAFE_HOMING ARC_P_CIRCLES CNC_WORKSPACE_PLANES
89
+  - opt_enable PIDTEMPBED FIX_MOUNTED_PROBE Z_SAFE_HOMING ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS
90 90
   - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS
91 91
   - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED
92 92
   - opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE

+ 1
- 1
Marlin/Conditionals_post.h Wyświetl plik

@@ -1036,7 +1036,7 @@
1036 1036
   #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
1037 1037
 
1038 1038
   // Add commands that need sub-codes to this list
1039
-  #define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET)
1039
+  #define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET) || ENABLED(CNC_COORDINATE_SYSTEMS)
1040 1040
 
1041 1041
   // MESH_BED_LEVELING overrides PROBE_MANUALLY
1042 1042
   #if ENABLED(MESH_BED_LEVELING)

+ 8
- 0
Marlin/Marlin.h Wyświetl plik

@@ -290,6 +290,14 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
290 290
   void update_software_endstops(const AxisEnum axis);
291 291
 #endif
292 292
 
293
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
294
+  #define MAX_COORDINATE_SYSTEMS 9
295
+  extern float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
296
+  bool select_coordinate_system(const int8_t _new);
297
+#endif
298
+
299
+void report_current_position();
300
+
293 301
 #if IS_KINEMATIC
294 302
   extern float delta[ABC];
295 303
   void inverse_kinematics(const float raw[XYZ]);

+ 129
- 25
Marlin/Marlin_main.cpp Wyświetl plik

@@ -364,6 +364,11 @@
364 364
   #define LED_WHITE 0, 0, 0, 255
365 365
 #endif
366 366
 
367
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
368
+  int8_t active_coordinate_system = -1; // machine space
369
+  float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
370
+#endif
371
+
367 372
 bool Running = true;
368 373
 
369 374
 uint8_t marlin_debug_flags = DEBUG_NONE;
@@ -745,6 +750,7 @@ void stop();
745 750
 
746 751
 void get_available_commands();
747 752
 void process_next_command();
753
+void process_parsed_command();
748 754
 void prepare_move_to_destination();
749 755
 
750 756
 void get_cartesian_from_steppers();
@@ -3672,6 +3678,73 @@ inline void gcode_G4() {
3672 3678
 
3673 3679
 #endif // CNC_WORKSPACE_PLANES
3674 3680
 
3681
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
3682
+
3683
+  /**
3684
+   * Select a coordinate system and update the current position.
3685
+   * System index -1 is used to specify machine-native.
3686
+   */
3687
+  bool select_coordinate_system(const int8_t _new) {
3688
+    if (active_coordinate_system == _new) return false;
3689
+    float old_offset[XYZ] = { 0 }, new_offset[XYZ] = { 0 };
3690
+    if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
3691
+      COPY(old_offset, coordinate_system[active_coordinate_system]);
3692
+    if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
3693
+      COPY(new_offset, coordinate_system[_new]);
3694
+    active_coordinate_system = _new;
3695
+    bool didXYZ = false;
3696
+    LOOP_XYZ(i) {
3697
+      const float diff = new_offset[i] - old_offset[i];
3698
+      if (diff) {
3699
+        position_shift[i] += diff;
3700
+        update_software_endstops((AxisEnum)i);
3701
+        didXYZ = true;
3702
+      }
3703
+    }
3704
+    if (didXYZ) SYNC_PLAN_POSITION_KINEMATIC();
3705
+    return true;
3706
+  }
3707
+
3708
+  /**
3709
+   * In CNC G-code G53 is like a modifier
3710
+   * It precedes a movement command (or other modifiers) on the same line.
3711
+   * This is the first command to use parser.chain() to make this possible.
3712
+   */
3713
+  inline void gcode_G53() {
3714
+    // If this command has more following...
3715
+    if (parser.chain()) {
3716
+      const int8_t _system = active_coordinate_system;
3717
+      active_coordinate_system = -1;
3718
+      process_parsed_command();
3719
+      active_coordinate_system = _system;
3720
+    }
3721
+  }
3722
+
3723
+  /**
3724
+   * G54-G59.3: Select a new workspace
3725
+   *
3726
+   * A workspace is an XYZ offset to the machine native space.
3727
+   * All workspaces default to 0,0,0 at start, or with EEPROM
3728
+   * support they may be restored from a previous session.
3729
+   *
3730
+   * G92 is used to set the current workspace's offset.
3731
+   */
3732
+  inline void gcode_G54_59(uint8_t subcode=0) {
3733
+    const int8_t _space = parser.codenum - 54 + subcode;
3734
+    if (select_coordinate_system(_space)) {
3735
+      SERIAL_PROTOCOLLNPAIR("Select workspace ", _space);
3736
+      report_current_position();
3737
+    }
3738
+  }
3739
+  FORCE_INLINE void gcode_G54() { gcode_G54_59(); }
3740
+  FORCE_INLINE void gcode_G55() { gcode_G54_59(); }
3741
+  FORCE_INLINE void gcode_G56() { gcode_G54_59(); }
3742
+  FORCE_INLINE void gcode_G57() { gcode_G54_59(); }
3743
+  FORCE_INLINE void gcode_G58() { gcode_G54_59(); }
3744
+  FORCE_INLINE void gcode_G59() { gcode_G54_59(parser.subcode); }
3745
+
3746
+#endif
3747
+
3675 3748
 #if ENABLED(INCH_MODE_SUPPORT)
3676 3749
   /**
3677 3750
    * G20: Set input mode to inches
@@ -4153,13 +4226,12 @@ inline void gcode_G28(const bool always_home_all) {
4153 4226
 
4154 4227
   // Restore the active tool after homing
4155 4228
   #if HOTENDS > 1
4156
-    tool_change(old_tool_index, 0,
4157
-      #if ENABLED(PARKING_EXTRUDER)
4158
-        false // fetch the previous toolhead
4159
-      #else
4160
-        true
4161
-      #endif
4162
-    );
4229
+    #if ENABLED(PARKING_EXTRUDER)
4230
+      #define NO_FETCH false // fetch the previous toolhead
4231
+    #else
4232
+      #define NO_FETCH true
4233
+    #endif
4234
+    tool_change(old_tool_index, 0, NO_FETCH);
4163 4235
   #endif
4164 4236
 
4165 4237
   lcd_refresh();
@@ -6201,7 +6273,30 @@ inline void gcode_G92() {
6201 6273
 
6202 6274
   if (!didE) stepper.synchronize();
6203 6275
 
6204
-  LOOP_XYZE(i) {
6276
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
6277
+    switch (parser.subcode) {
6278
+      case 1:
6279
+        // Zero the G92 values and restore current position
6280
+        #if !IS_SCARA
6281
+          LOOP_XYZ(i) {
6282
+            const float v = position_shift[i];
6283
+            if (v) {
6284
+              position_shift[i] = 0;
6285
+              update_software_endstops((AxisEnum)i);
6286
+            }
6287
+          }
6288
+        #endif // Not SCARA
6289
+        return;
6290
+    }
6291
+  #endif
6292
+
6293
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
6294
+    #define IS_G92_0 (parser.subcode == 0)
6295
+  #else
6296
+    #define IS_G92_0 true
6297
+  #endif
6298
+
6299
+  if (IS_G92_0) LOOP_XYZE(i) {
6205 6300
     if (parser.seenval(axis_codes[i])) {
6206 6301
       #if IS_SCARA
6207 6302
         if (i != E_AXIS) didXYZ = true;
@@ -6221,6 +6316,13 @@ inline void gcode_G92() {
6221 6316
       #endif
6222 6317
     }
6223 6318
   }
6319
+
6320
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
6321
+    // Apply workspace offset to the active coordinate system
6322
+    if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
6323
+      COPY(coordinate_system[active_coordinate_system], position_shift);
6324
+  #endif
6325
+
6224 6326
   if (didXYZ)
6225 6327
     SYNC_PLAN_POSITION_KINEMATIC();
6226 6328
   else if (didE)
@@ -11194,26 +11296,11 @@ inline void gcode_T(const uint8_t tmp_extruder) {
11194 11296
 }
11195 11297
 
11196 11298
 /**
11197
- * Process a single command and dispatch it to its handler
11198
- * This is called from the main loop()
11299
+ * Process the parsed command and dispatch it to its handler
11199 11300
  */
11200
-void process_next_command() {
11201
-  char * const current_command = command_queue[cmd_queue_index_r];
11202
-
11203
-  if (DEBUGGING(ECHO)) {
11204
-    SERIAL_ECHO_START();
11205
-    SERIAL_ECHOLN(current_command);
11206
-    #if ENABLED(M100_FREE_MEMORY_WATCHER)
11207
-      SERIAL_ECHOPAIR("slot:", cmd_queue_index_r);
11208
-      M100_dump_routine("   Command Queue:", (const char*)command_queue, (const char*)(command_queue + sizeof(command_queue)));
11209
-    #endif
11210
-  }
11211
-
11301
+void process_parsed_command() {
11212 11302
   KEEPALIVE_STATE(IN_HANDLER);
11213 11303
 
11214
-  // Parse the next command in the queue
11215
-  parser.parse(current_command);
11216
-
11217 11304
   // Handle a known G, M, or T
11218 11305
   switch (parser.command_letter) {
11219 11306
     case 'G': switch (parser.codenum) {
@@ -12053,6 +12140,23 @@ void process_next_command() {
12053 12140
   ok_to_send();
12054 12141
 }
12055 12142
 
12143
+void process_next_command() {
12144
+  char * const current_command = command_queue[cmd_queue_index_r];
12145
+
12146
+  if (DEBUGGING(ECHO)) {
12147
+    SERIAL_ECHO_START();
12148
+    SERIAL_ECHOLN(current_command);
12149
+    #if ENABLED(M100_FREE_MEMORY_WATCHER)
12150
+      SERIAL_ECHOPAIR("slot:", cmd_queue_index_r);
12151
+      M100_dump_routine("   Command Queue:", (const char*)command_queue, (const char*)(command_queue + sizeof(command_queue)));
12152
+    #endif
12153
+  }
12154
+
12155
+  // Parse the next command in the queue
12156
+  parser.parse(current_command);
12157
+  process_parsed_command();
12158
+}
12159
+
12056 12160
 /**
12057 12161
  * Send a "Resend: nnn" message to the host to
12058 12162
  * indicate that a command needs to be re-sent.

+ 4
- 0
Marlin/SanityCheck.h Wyświetl plik

@@ -1483,3 +1483,7 @@ static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too m
1483 1483
     #endif
1484 1484
   #endif
1485 1485
 #endif // SPINDLE_LASER_ENABLE
1486
+
1487
+#if ENABLED(CNC_COORDINATE_SYSTEMS) && ENABLED(NO_WORKSPACE_OFFSETS)
1488
+  #error "CNC_COORDINATE_SYSTEMS is incompatible with NO_WORKSPACE_OFFSETS."
1489
+#endif

+ 36
- 4
Marlin/configuration_store.cpp Wyświetl plik

@@ -36,13 +36,13 @@
36 36
  *
37 37
  */
38 38
 
39
-#define EEPROM_VERSION "V43"
39
+#define EEPROM_VERSION "V44"
40 40
 
41 41
 // Change EEPROM version if these are changed:
42 42
 #define EEPROM_OFFSET 100
43 43
 
44 44
 /**
45
- * V43 EEPROM Layout:
45
+ * V44 EEPROM Layout:
46 46
  *
47 47
  *  100  Version                                    (char x4)
48 48
  *  104  EEPROM CRC16                               (uint16_t)
@@ -162,8 +162,11 @@
162 162
  *  588  M907 Z    Stepper Z current                (uint32_t)
163 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 172
  * meshes_begin (between max and min end-point, directly above)
@@ -209,6 +212,10 @@ MarlinSettings settings;
209 212
   float new_z_fade_height;
210 213
 #endif
211 214
 
215
+#if ENABLED(CNC_COORDINATE_SYSTEMS)
216
+  bool position_changed;
217
+#endif
218
+
212 219
 /**
213 220
 * Post-process after Retrieve or Reset
214 221
 */
@@ -253,6 +260,13 @@ void MarlinSettings::postprocess() {
253 260
   #if HAS_MOTOR_CURRENT_PWM
254 261
     stepper.refresh_motor_power();
255 262
   #endif
263
+
264
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
265
+    if (position_changed) {
266
+      report_current_position();
267
+      position_changed = false;
268
+    }
269
+  #endif
256 270
 }
257 271
 
258 272
 #if ENABLED(EEPROM_SETTINGS)
@@ -663,6 +677,13 @@ void MarlinSettings::postprocess() {
663 677
       for (uint8_t q = 3; q--;) EEPROM_WRITE(dummyui32);
664 678
     #endif
665 679
 
680
+    #if ENABLED(CNC_COORDINATE_SYSTEMS)
681
+      EEPROM_WRITE(coordinate_system); // 27 floats
682
+    #else
683
+      dummy = 0.0f;
684
+      for (uint8_t q = 27; q--;) EEPROM_WRITE(dummy);
685
+    #endif
686
+
666 687
     if (!eeprom_error) {
667 688
       const int eeprom_size = eeprom_index;
668 689
 
@@ -1093,6 +1114,17 @@ void MarlinSettings::postprocess() {
1093 1114
         for (uint8_t q = 3; q--;) EEPROM_READ(dummyui32);
1094 1115
       #endif
1095 1116
 
1117
+      //
1118
+      // CNC Coordinate System
1119
+      //
1120
+
1121
+      #if ENABLED(CNC_COORDINATE_SYSTEMS)
1122
+        position_changed = select_coordinate_system(-1); // Go back to machine space
1123
+        EEPROM_READ(coordinate_system);                  // 27 floats
1124
+      #else
1125
+        for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
1126
+      #endif
1127
+
1096 1128
       if (working_crc == stored_crc) {
1097 1129
         postprocess();
1098 1130
         #if ENABLED(EEPROM_CHITCHAT)

+ 20
- 0
Marlin/gcode.cpp Wyświetl plik

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

+ 5
- 0
Marlin/gcode.h Wyświetl plik

@@ -169,6 +169,11 @@ public:
169 169
   // This uses 54 bytes of SRAM to speed up seen/value
170 170
   static void parse(char * p);
171 171
 
172
+  #if ENABLED(CNC_COORDINATE_SYSTEMS)
173
+    // Parse the next parameter as a new command
174
+    static bool chain();
175
+  #endif
176
+
172 177
   // The code value pointer was set
173 178
   FORCE_INLINE static bool has_value() { return value_ptr != NULL; }
174 179
 

Ładowanie…
Anuluj
Zapisz