|
@@ -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.
|