My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

G53-G59.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../gcode.h"
  23. #include "../../module/motion.h"
  24. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  25. //#define DEBUG_M53
  26. /**
  27. * Select a coordinate system and update the workspace offset.
  28. * System index -1 is used to specify machine-native.
  29. */
  30. bool GcodeSuite::select_coordinate_system(const int8_t _new) {
  31. if (active_coordinate_system == _new) return false;
  32. active_coordinate_system = _new;
  33. xyz_float_t new_offset{0};
  34. if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
  35. new_offset = coordinate_system[_new];
  36. LOOP_NUM_AXES(i) {
  37. if (position_shift[i] != new_offset[i]) {
  38. position_shift[i] = new_offset[i];
  39. update_workspace_offset((AxisEnum)i);
  40. }
  41. }
  42. return true;
  43. }
  44. /**
  45. * G53: Apply native workspace to the current move
  46. *
  47. * In CNC G-code G53 is a modifier.
  48. * It precedes a movement command (or other modifiers) on the same line.
  49. * This is the first command to use parser.chain() to make this possible.
  50. *
  51. * Marlin also uses G53 on a line by itself to go back to native space.
  52. */
  53. void GcodeSuite::G53() {
  54. const int8_t old_system = active_coordinate_system;
  55. select_coordinate_system(-1); // Always remove workspace offsets
  56. #ifdef DEBUG_M53
  57. SERIAL_ECHOLNPGM("Go to native space");
  58. report_current_position();
  59. #endif
  60. if (parser.chain()) { // Command to chain?
  61. process_parsed_command(); // ...process the chained command
  62. select_coordinate_system(old_system);
  63. #ifdef DEBUG_M53
  64. SERIAL_ECHOLNPGM("Go back to workspace ", old_system);
  65. report_current_position();
  66. #endif
  67. }
  68. }
  69. /**
  70. * G54-G59.3: Select a new workspace
  71. *
  72. * A workspace is an XYZ offset to the machine native space.
  73. * All workspaces default to 0,0,0 at start, or with EEPROM
  74. * support they may be restored from a previous session.
  75. *
  76. * G92 is used to set the current workspace's offset.
  77. */
  78. void G54_59(uint8_t subcode=0) {
  79. const int8_t _space = parser.codenum - 54 + subcode;
  80. if (gcode.select_coordinate_system(_space)) {
  81. SERIAL_ECHOLNPGM("Select workspace ", _space);
  82. report_current_position();
  83. }
  84. }
  85. void GcodeSuite::G54() { G54_59(); }
  86. void GcodeSuite::G55() { G54_59(); }
  87. void GcodeSuite::G56() { G54_59(); }
  88. void GcodeSuite::G57() { G54_59(); }
  89. void GcodeSuite::G58() { G54_59(); }
  90. void GcodeSuite::G59() { G54_59(parser.subcode); }
  91. #endif // CNC_COORDINATE_SYSTEMS