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

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