Skip to content

Commit

Permalink
Fix G53 as prefix, G28 with CNC_COORDINATE_SYSTEMS (MarlinFirmware#15069
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shitcreek authored and thinkyhead committed Aug 28, 2019
1 parent ca084dc commit 081e450
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
1 change: 1 addition & 0 deletions Marlin/src/gcode/calibrate/G28.cpp
Expand Up @@ -453,6 +453,7 @@ void GcodeSuite::G28(const bool always_home_all) {
ui.refresh();

report_current_position();

#if ENABLED(NANODLP_Z_SYNC)
#if ENABLED(NANODLP_ALL_AXIS)
#define _HOME_SYNC true // For any axis, output sync text.
Expand Down
33 changes: 20 additions & 13 deletions Marlin/src/gcode/geometry/G53-G59.cpp
Expand Up @@ -27,23 +27,21 @@

#include "../../module/stepper.h"

//#define DEBUG_M53

/**
* Select a coordinate system and update the workspace offset.
* System index -1 is used to specify machine-native.
*/
bool GcodeSuite::select_coordinate_system(const int8_t _new) {
if (active_coordinate_system == _new) return false;
planner.synchronize();
float old_offset[XYZ] = { 0 }, new_offset[XYZ] = { 0 };
if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
COPY(old_offset, coordinate_system[active_coordinate_system]);
active_coordinate_system = _new;
float new_offset[XYZ] = { 0 };
if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
COPY(new_offset, coordinate_system[_new]);
active_coordinate_system = _new;
LOOP_XYZ(i) {
const float diff = new_offset[i] - old_offset[i];
if (diff) {
position_shift[i] += diff;
if (position_shift[i] != new_offset[i]) {
position_shift[i] = new_offset[i];
update_workspace_offset((AxisEnum)i);
}
}
Expand All @@ -60,11 +58,20 @@ bool GcodeSuite::select_coordinate_system(const int8_t _new) {
* Marlin also uses G53 on a line by itself to go back to native space.
*/
void GcodeSuite::G53() {
const int8_t _system = active_coordinate_system;
active_coordinate_system = -1;
if (parser.chain()) { // If this command has more following...
process_parsed_command();
active_coordinate_system = _system;
const int8_t old_system = active_coordinate_system;
select_coordinate_system(-1); // Always remove workspace offsets
#ifdef DEBUG_M53
SERIAL_ECHOLNPGM("Go to native space");
report_current_position();
#endif

if (parser.chain()) { // Command to chain?
process_parsed_command(); // ...process the chained command
select_coordinate_system(old_system);
#ifdef DEBUG_M53
SERIAL_ECHOLNPAIR("Go back to workspace ", old_system);
report_current_position();
#endif
}
}

Expand Down
9 changes: 3 additions & 6 deletions Marlin/src/gcode/geometry/G92.cpp
Expand Up @@ -52,12 +52,9 @@ void GcodeSuite::G92() {
case 1: {
// Zero the G92 values and restore current position
#if !IS_SCARA
LOOP_XYZ(i) {
const float v = position_shift[i];
if (v) {
position_shift[i] = 0;
update_workspace_offset((AxisEnum)i);
}
LOOP_XYZ(i) if (position_shift[i]) {
position_shift[i] = 0;
update_workspace_offset((AxisEnum)i);
}
#endif // Not SCARA
} return;
Expand Down
5 changes: 0 additions & 5 deletions Marlin/src/module/motion.cpp
Expand Up @@ -1325,11 +1325,6 @@ void set_axis_is_at_home(const AxisEnum axis) {
SBI(axis_known_position, axis);
SBI(axis_homed, axis);

#if HAS_POSITION_SHIFT
position_shift[axis] = 0;
update_workspace_offset(axis);
#endif

#if ENABLED(DUAL_X_CARRIAGE)
if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) {
current_position[X_AXIS] = x_home_pos(active_extruder);
Expand Down

0 comments on commit 081e450

Please sign in to comment.