-
-
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 21 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
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,16 @@ relative_t GcodeSuite::axis_relative; // Init in constructor | |
| xyz_pos_t GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS]; | ||
| #endif | ||
|
|
||
| #if ENABLED(SCALE_WORKSPACE) | ||
| scaling_center_t GcodeSuite::scaling_center; | ||
| scaling_factor_t GcodeSuite::scaling_factor; | ||
| #endif | ||
|
|
||
| #if ENABLED(ROTATE_WORKSPACE) | ||
| float GcodeSuite::rotation_angle; // = 0.0f | ||
| xy_pos_t GcodeSuite::rotation_center; // = { 0.0f, 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; | ||
|
|
@@ -171,19 +181,65 @@ void GcodeSuite::get_destination_from_command() { | |
| constexpr bool skip_move = false; | ||
| #endif | ||
|
|
||
| #if ANY(ROTATE_WORKSPACE, SCALE_WORKSPACE) | ||
| static xyz_pos_t raw_destination; // {0} | ||
| #endif | ||
|
|
||
| // Get new XYZ position, whether absolute or relative | ||
| 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 { | ||
| const float v = parser.value_axis_units((AxisEnum)i); | ||
| #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 ANY(SCALE_WORKSPACE, ROTATE_WORKSPACE) | ||
| raw_destination[i] = current_position[i]; | ||
| #else | ||
| 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 a = RADIANS(rotation_angle), | ||
| cos_angle = cosf(a), | ||
| sin_angle = sinf(a); | ||
|
|
||
| // Apply rotation | ||
| const xy_pos_t temp = xy_pos_t(destination) - rotation_center; | ||
| destination.set( | ||
| temp.x * cos_angle - temp.y * sin_angle + rotation_center.x, | ||
| temp.y * cos_angle + temp.x * sin_angle + rotation_center.y | ||
| ); | ||
| } | ||
| #endif | ||
|
|
||
| #if HAS_EXTRUDERS | ||
| // Get new E position, whether absolute or relative | ||
| if ( (seen.e = parser.seenval('E')) ) { | ||
|
|
@@ -435,6 +491,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 +511,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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.