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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include "../../module/stepper.h"
  26. //#define DEBUG_M53
  27. /**
  28. * Select a coordinate system and update the workspace offset.
  29. * System index -1 is used to specify machine-native.
  30. */
  31. bool GcodeSuite::select_coordinate_system(const int8_t _new) {
  32. if (active_coordinate_system == _new) return false;
  33. active_coordinate_system = _new;
  34. xyz_float_t new_offset{0};
  35. if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
  36. new_offset = coordinate_system[_new];
  37. LOOP_NUM_AXES(i) {
  38. if (position_shift[i] != new_offset[i]) {
  39. position_shift[i] = new_offset[i];
  40. update_workspace_offset((AxisEnum)i);
  41. }
  42. }
  43. return true;
  44. }
  45. /**
  46. * G53: Apply native workspace to the current move
  47. *
  48. * In CNC G-code G53 is a modifier.
  49. * It precedes a movement command (or other modifiers) on the same line.
  50. * This is the first command to use parser.chain() to make this possible.
  51. *
  52. * Marlin also uses G53 on a line by itself to go back to native space.
  53. */
  54. void GcodeSuite::G53() {
  55. const int8_t old_system = active_coordinate_system;
  56. select_coordinate_system(-1); // Always remove workspace offsets
  57. #ifdef DEBUG_M53
  58. SERIAL_ECHOLNPGM("Go to native space");
  59. report_current_position();
  60. #endif
  61. if (parser.chain()) { // Command to chain?
  62. process_parsed_command(); // ...process the chained command
  63. select_coordinate_system(old_system);
  64. #ifdef DEBUG_M53
  65. SERIAL_ECHOLNPGM("Go back to workspace ", old_system);
  66. report_current_position();
  67. #endif
  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_ECHOLNPGM("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. #endif // CNC_COORDINATE_SYSTEMS