-
-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Add G68/G51 rotate/scale workspace (LinuxCNC) #27945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bugfix-2.1.x
Are you sure you want to change the base?
Changes from 15 commits
0cd2d5d
a7dab7c
491620a
09c6a73
0e74e67
b8a6033
10126fc
558a4b5
c6536e4
74c788d
003b136
f10483e
e64387e
aa5f0c8
4fff50a
5f2aebc
4f677de
fdd899c
a378a20
f155c69
166c167
2deec18
b5c4dec
f99408f
13dc9d2
e6f42ec
a222334
2549b85
51b7e56
2e34887
539c808
0be7a6b
fa4ffd7
b73504c
70558fd
0cb6c91
91637f9
deb5694
0d0ee8b
e4e0101
6b5415c
1b094d0
ef8753a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,21 @@ relative_t GcodeSuite::axis_relative; // Init in constructor | |
| xyz_pos_t GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS]; | ||
| #endif | ||
|
|
||
| #if ENABLED(SCALE_WORKSPACE) | ||
| float GcodeSuite::scaling_center_x = 0.0f; | ||
| float GcodeSuite::scaling_center_y = 0.0f; | ||
| float GcodeSuite::scaling_center_z = 0.0f; | ||
| float GcodeSuite::scaling_factor_x = 1.0f; | ||
| float GcodeSuite::scaling_factor_y = 1.0f; | ||
| float GcodeSuite::scaling_factor_z = 1.0f; | ||
| #endif | ||
|
|
||
| #if ENABLED(ROTATE_WORKSPACE) | ||
| float GcodeSuite::rotation_center_x = 0.0f; | ||
| float GcodeSuite::rotation_center_y = 0.0f; | ||
| float GcodeSuite::rotation_angle = 0.0f; | ||
| #endif | ||
|
|
||
| void GcodeSuite::report_echo_start(const bool forReplay) { if (!forReplay) SERIAL_ECHO_START(); } | ||
| void GcodeSuite::report_heading(const bool forReplay, FSTR_P const fstr, const bool eol/*=true*/) { | ||
| if (forReplay) return; | ||
|
|
@@ -175,15 +190,54 @@ void GcodeSuite::get_destination_from_command() { | |
| LOOP_NUM_AXES(i) { | ||
| if ( (seen[i] = parser.seenval(AXIS_CHAR(i))) ) { | ||
| const float v = parser.value_axis_units((AxisEnum)i); | ||
| if (skip_move) | ||
| if (skip_move) { | ||
| #if ANY(SCALE_WORKSPACE, ROTATE_WORKSPACE) | ||
| raw_destination[i] = current_position[i]; | ||
|
||
| #else | ||
| destination[i] = current_position[i]; | ||
| #endif | ||
| } | ||
| else { | ||
| #if ANY(SCALE_WORKSPACE, ROTATE_WORKSPACE) | ||
| raw_destination[i] = axis_is_relative(AxisEnum(i)) ? raw_destination[i] + v : LOGICAL_TO_NATIVE(v, i); | ||
| #else | ||
| destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : LOGICAL_TO_NATIVE(v, i); | ||
| #endif | ||
| } | ||
| } | ||
| else { | ||
| #if NONE(SCALE_WORKSPACE, ROTATE_WORKSPACE) | ||
| destination[i] = current_position[i]; | ||
| else | ||
| destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : LOGICAL_TO_NATIVE(v, i); | ||
| #endif | ||
| } | ||
| else | ||
| destination[i] = current_position[i]; | ||
| } | ||
|
|
||
| #if ANY(SCALE_WORKSPACE, ROTATE_WORKSPACE) | ||
| destination = raw_destination; | ||
| #endif | ||
|
|
||
| #if ENABLED(SCALE_WORKSPACE) | ||
| if (!(NEAR(scaling_factor_x, 1.0f) || NEAR(scaling_factor_y, 1.0f) || NEAR(scaling_factor_z, 1.0f))) { | ||
| destination.x = (raw_destination.x - scaling_center_x) * scaling_factor_x + scaling_center_x; | ||
| TERN_(HAS_Y_AXIS, destination.y = (raw_destination.y - scaling_center_y) * scaling_factor_y + scaling_center_y); | ||
| TERN_(HAS_Z_AXIS, destination.z = (raw_destination.z - scaling_center_z) * scaling_factor_z + scaling_center_z); | ||
| } | ||
| #endif | ||
|
|
||
| #if ENABLED(ROTATE_WORKSPACE) | ||
| if (!NEAR_ZERO(rotation_angle)) { | ||
| const float angle_rad = RADIANS(rotation_angle); | ||
| const float cos_angle = cos(angle_rad); | ||
| const float sin_angle = sin(angle_rad); | ||
|
|
||
| // Apply rotation | ||
| const float temp_x = destination.x - rotation_center_x; | ||
| const float temp_y = destination.y - rotation_center_y; | ||
| destination.x = temp_x * cos_angle - temp_y * sin_angle + rotation_center_x; | ||
| destination.y = temp_x * sin_angle + temp_y * cos_angle + rotation_center_y; | ||
| } | ||
| #endif | ||
|
|
||
| #if HAS_EXTRUDERS | ||
| // Get new E position, whether absolute or relative | ||
| if ( (seen.e = parser.seenval('E')) ) { | ||
|
|
@@ -435,6 +489,11 @@ void GcodeSuite::process_parsed_command(bool no_ok/*=false*/) { | |
| case 42: G42(); break; // G42: Coordinated move to a mesh point | ||
| #endif | ||
|
|
||
| #if ENABLED(SCALE_WORKSPACE) | ||
| case 50: G50(); break; // G50: Cancel Workspace Scaling | ||
| case 51: G51(); break; // G51: Set Workspace Scaling | ||
| #endif | ||
|
|
||
| #if ENABLED(CNC_COORDINATE_SYSTEMS) | ||
| case 53: G53(); break; // G53: (prefix) Apply native workspace | ||
| case 54: G54(); break; // G54: Switch to Workspace 1 | ||
|
|
@@ -450,6 +509,11 @@ void GcodeSuite::process_parsed_command(bool no_ok/*=false*/) { | |
| case 61: G61(); break; // G61: Apply/restore saved coordinates. | ||
| #endif | ||
|
|
||
| #if ENABLED(ROTATE_WORKSPACE) | ||
| case 68: G68(); break; // G68: Set Workspace Rotation | ||
| case 69: G69(); break; // G69: Cancel Workspace Rotation | ||
| #endif | ||
|
|
||
| #if ALL(PTC_PROBE, PTC_BED) | ||
| case 76: G76(); break; // G76: Calibrate first layer compensation values | ||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /** | ||
| * Marlin 3D Printer Firmware | ||
| * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] | ||
| * | ||
| * Based on Sprinter and grbl. | ||
| * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| #include "../../inc/MarlinConfigPre.h" | ||
|
|
||
| #if ENABLED(SCALE_WORKSPACE) | ||
|
|
||
| #include "../gcode.h" | ||
| #include "../../module/motion.h" | ||
|
|
||
| /** | ||
| * G50: Set Workspace Scaling | ||
| * | ||
| * Scale the current workspace coordinate system. | ||
| * | ||
| * Parameters: | ||
| * X<linear> X coordinate of the scaling center | ||
| * Y<linear> Y coordinate of the scaling center | ||
| * Z<linear> Z coordinate of the scaling center | ||
| * I<float> scaling factor for X axis | ||
| * J<float> scaling factor for Y axis | ||
| * K<float> scaling factor for Z axis | ||
| * P<float> scaling factor | ||
| */ | ||
| void GcodeSuite::G50() { | ||
|
||
| if (parser.seenval('P')) { | ||
| const float scaling_factor = parser.value_float(); | ||
| scaling_factor_x = scaling_factor; | ||
| TERN_(HAS_Y_AXIS, scaling_factor_y = scaling_factor); | ||
| TERN_(HAS_Z_AXIS, scaling_factor_z = scaling_factor); | ||
| } | ||
| else { | ||
| if (parser.seenval('I')) | ||
| scaling_factor_x = parser.value_float(); | ||
| #if HAS_Y_AXIS | ||
| if (parser.seenval('J')) | ||
| scaling_factor_y = parser.value_float(); | ||
| #endif | ||
| #if HAS_Z_AXIS | ||
| if (parser.seenval('K')) | ||
| scaling_factor_z = parser.value_float(); | ||
| #endif | ||
| } | ||
|
|
||
| scaling_center_x = parser.seenval('X') ? LOGICAL_TO_NATIVE(parser.value_axis_units(X_AXIS), X_AXIS) : current_position.x; | ||
| TERN_(HAS_Y_AXIS, scaling_center_y = parser.seenval('Y') ? LOGICAL_TO_NATIVE(parser.value_axis_units(Y_AXIS), Y_AXIS) : current_position.y); | ||
| TERN_(HAS_Z_AXIS, scaling_center_z = parser.seenval('Z') ? LOGICAL_TO_NATIVE(parser.value_axis_units(Z_AXIS), Z_AXIS) : current_position.z); | ||
|
|
||
| SERIAL_ECHOLNPGM("Workspace scaling set"); | ||
| } | ||
|
|
||
| /** | ||
| * G51: Cancel Workspace Scaling | ||
| */ | ||
| void GcodeSuite::G51() { | ||
| scaling_factor_x = 1.0f; | ||
| scaling_center_x = 0.0f; | ||
| scaling_factor_y = 1.0f; | ||
| scaling_center_y = 0.0f; | ||
| #if HAS_Z_AXIS | ||
| scaling_factor_z = 1.0f; | ||
| scaling_center_z = 0.0f; | ||
| #endif | ||
| SERIAL_ECHOLNPGM("Workspace scaling canceled"); | ||
| } | ||
|
|
||
| #endif // SCALE_WORKSPACE | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ | |
| */ | ||
| bool GcodeSuite::select_coordinate_system(const int8_t _new) { | ||
| if (active_coordinate_system == _new) return false; | ||
| if (TERN0(ROTATE_WORKSPACE, !NEAR_ZERO(gcode.rotation_angle))) { | ||
|
||
| SERIAL_ECHOLNPGM("Cannot change workspace while workspace rotation is active"); | ||
classicrocker883 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return false; | ||
| } | ||
| active_coordinate_system = _new; | ||
| xyz_float_t new_offset{0}; | ||
| if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.