|
@@ -24,70 +24,71 @@
|
24
|
24
|
#include "../../module/motion.h"
|
25
|
25
|
|
26
|
26
|
#if ENABLED(CNC_COORDINATE_SYSTEMS)
|
27
|
|
- #include "../../module/stepper.h"
|
28
|
27
|
|
29
|
|
- /**
|
30
|
|
- * Select a coordinate system and update the workspace offset.
|
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
|
|
- LOOP_XYZ(i) {
|
43
|
|
- const float diff = new_offset[i] - old_offset[i];
|
44
|
|
- if (diff) {
|
45
|
|
- position_shift[i] += diff;
|
46
|
|
- update_software_endstops((AxisEnum)i);
|
47
|
|
- }
|
|
28
|
+#include "../../module/stepper.h"
|
|
29
|
+
|
|
30
|
+/**
|
|
31
|
+ * Select a coordinate system and update the workspace offset.
|
|
32
|
+ * System index -1 is used to specify machine-native.
|
|
33
|
+ */
|
|
34
|
+bool GcodeSuite::select_coordinate_system(const int8_t _new) {
|
|
35
|
+ if (active_coordinate_system == _new) return false;
|
|
36
|
+ stepper.synchronize();
|
|
37
|
+ float old_offset[XYZ] = { 0 }, new_offset[XYZ] = { 0 };
|
|
38
|
+ if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
|
|
39
|
+ COPY(old_offset, coordinate_system[active_coordinate_system]);
|
|
40
|
+ if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
|
|
41
|
+ COPY(new_offset, coordinate_system[_new]);
|
|
42
|
+ active_coordinate_system = _new;
|
|
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
|
48
|
}
|
49
|
|
- return true;
|
50
|
49
|
}
|
|
50
|
+ return true;
|
|
51
|
+}
|
51
|
52
|
|
52
|
|
- /**
|
53
|
|
- * G53: Apply native workspace to the current move
|
54
|
|
- *
|
55
|
|
- * In CNC G-code G53 is a modifier.
|
56
|
|
- * It precedes a movement command (or other modifiers) on the same line.
|
57
|
|
- * This is the first command to use parser.chain() to make this possible.
|
58
|
|
- *
|
59
|
|
- * Marlin also uses G53 on a line by itself to go back to native space.
|
60
|
|
- */
|
61
|
|
- inline void gcode_G53() {
|
62
|
|
- const int8_t _system = active_coordinate_system;
|
63
|
|
- active_coordinate_system = -1;
|
64
|
|
- if (parser.chain()) { // If this command has more following...
|
65
|
|
- process_parsed_command();
|
66
|
|
- active_coordinate_system = _system;
|
67
|
|
- }
|
|
53
|
+/**
|
|
54
|
+ * G53: Apply native workspace to the current move
|
|
55
|
+ *
|
|
56
|
+ * In CNC G-code G53 is 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
|
+ * Marlin also uses G53 on a line by itself to go back to native space.
|
|
61
|
+ */
|
|
62
|
+inline void GcodeSuite::G53() {
|
|
63
|
+ const int8_t _system = active_coordinate_system;
|
|
64
|
+ active_coordinate_system = -1;
|
|
65
|
+ if (parser.chain()) { // If this command has more following...
|
|
66
|
+ process_parsed_command();
|
|
67
|
+ active_coordinate_system = _system;
|
68
|
68
|
}
|
|
69
|
+}
|
69
|
70
|
|
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
|
|
- }
|
|
71
|
+/**
|
|
72
|
+ * G54-G59.3: Select a new workspace
|
|
73
|
+ *
|
|
74
|
+ * A workspace is an XYZ offset to the machine native space.
|
|
75
|
+ * All workspaces default to 0,0,0 at start, or with EEPROM
|
|
76
|
+ * support they may be restored from a previous session.
|
|
77
|
+ *
|
|
78
|
+ * G92 is used to set the current workspace's offset.
|
|
79
|
+ */
|
|
80
|
+void G54_59(uint8_t subcode=0) {
|
|
81
|
+ const int8_t _space = parser.codenum - 54 + subcode;
|
|
82
|
+ if (gcode.select_coordinate_system(_space)) {
|
|
83
|
+ SERIAL_PROTOCOLLNPAIR("Select workspace ", _space);
|
|
84
|
+ report_current_position();
|
85
|
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); }
|
|
86
|
+}
|
|
87
|
+void GcodeSuite::G54() { G54_59(); }
|
|
88
|
+void GcodeSuite::G55() { G54_59(); }
|
|
89
|
+void GcodeSuite::G56() { G54_59(); }
|
|
90
|
+void GcodeSuite::G57() { G54_59(); }
|
|
91
|
+void GcodeSuite::G58() { G54_59(); }
|
|
92
|
+void GcodeSuite::G59() { G54_59(parser.subcode); }
|
92
|
93
|
|
93
|
94
|
#endif // CNC_COORDINATE_SYSTEMS
|