Skip to content

Commit ea39b62

Browse files
committed
FEEDRATE_MODE_SUPPORT. Adds G93 inverse time mode and G94 units per minute mode
1 parent a506701 commit ea39b62

File tree

17 files changed

+177
-31
lines changed

17 files changed

+177
-31
lines changed

Marlin/Configuration.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,6 +2482,11 @@
24822482
//
24832483
//#define INCH_MODE_SUPPORT
24842484

2485+
//
2486+
// G93/G94 Feedrate mode support
2487+
//
2488+
//#define FEEDRATE_MODE_SUPPORT
2489+
24852490
//
24862491
// M149 Set temperature units support
24872492
//

Marlin/src/core/language.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
#define STR_ERR_MATERIAL_INDEX "M145 S<index> out of range (0-1)"
149149
#define STR_ERR_M421_PARAMETERS "M421 incorrect parameter usage"
150150
#define STR_ERR_BAD_PLANE_MODE "G5 requires XY plane mode"
151+
#define STR_ERR_BAD_FEEDRATE_MODE "G5 currently requires units/min feedrate mode"
151152
#define STR_ERR_MESH_XY "Mesh point out of range"
152153
#define STR_ERR_ARC_ARGS "G2/G3 bad parameters"
153154
#define STR_ERR_PROTECTED_PIN "Protected Pin"

Marlin/src/gcode/bedlevel/G42.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void GcodeSuite::G42() {
5555
return;
5656
}
5757

58+
TERN_(FEEDRATE_MODE_SUPPORT, parser.print_move = true);
59+
5860
// Move to current_position, as modified by I, J, P parameters
5961
destination = current_position;
6062

@@ -68,15 +70,17 @@ void GcodeSuite::G42() {
6870
}
6971
#endif
7072

71-
const feedRate_t fval = parser.linearval('F'),
72-
fr_mm_s = MMM_TO_MMS(fval > 0 ? fval : 0.0f);
73+
const feedRate_t fval = parser.feedrateval('F'),
74+
fr_mm_s = MMM_TO_MMS(fval);
7375

7476
// SCARA kinematic has "safe" XY raw moves
7577
#if IS_SCARA
7678
prepare_internal_fast_move_to_destination(fr_mm_s);
7779
#else
7880
prepare_internal_move_to_destination(fr_mm_s);
7981
#endif
82+
83+
TERN_(FEEDRATE_MODE_SUPPORT, print_move = false);
8084
}
8185

8286
#endif // HAS_MESH

Marlin/src/gcode/feature/camera/M240.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ void GcodeSuite::M240() {
138138

139139
#ifdef PHOTO_RETRACT_MM
140140
const float rval = parser.linearval('R', _PHOTO_RETRACT_MM);
141-
const feedRate_t sval = parser.feedrateval('S', TERN(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_RETRACT_FEEDRATE, TERN(FWRETRACT, RETRACT_FEEDRATE, 45)));
141+
const feedRate_t sval = MMM_TO_MMS(parser.feedrateval('S', TERN(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_RETRACT_FEEDRATE, TERN(FWRETRACT, RETRACT_FEEDRATE, 45))));
142142
e_move_m240(-rval, sval);
143143
#endif
144144

145-
feedRate_t fr_mm_s = parser.feedrateval('F');
146-
if (fr_mm_s) NOLESS(fr_mm_s, 10.0f);
145+
feedRate_t fr_mm_s = MMM_TO_MMS(parser.feedrateval('F'));
146+
if (fr_mm_s && TERN1(FEEDRATE_MODE_SUPPORT, parser.inverse_time_enabled)) NOLESS(fr_mm_s, 10.0f);
147147

148148
constexpr xyz_pos_t photo_position = PHOTO_POSITION;
149149
xyz_pos_t raw = {

Marlin/src/gcode/gcode.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void GcodeSuite::get_destination_from_command() {
202202
#endif
203203

204204
if (parser.floatval('F') > 0) {
205-
const float fr_mm_min = parser.value_linear_units();
205+
const float fr_mm_min = parser.value_feedrate();
206206
feedrate_mm_s = MMM_TO_MMS(fr_mm_min);
207207
// Update the cutter feed rate for use by M4 I set inline moves.
208208
TERN_(LASER_FEATURE, cutter.feedrate_mm_m = fr_mm_min);
@@ -464,6 +464,11 @@ void GcodeSuite::process_parsed_command(bool no_ok/*=false*/) {
464464

465465
case 92: G92(); break; // G92: Set current axis position(s)
466466

467+
#if ENABLED(FEEDRATE_MODE_SUPPORT)
468+
case 93: G93(); break; // G93: Set feedrate mode to inverse time
469+
case 94: G94(); break; // G94: Set feedrate mode to length units per minute
470+
#endif
471+
467472
#if ENABLED(CALIBRATION_GCODE)
468473
case 425: G425(); break; // G425: Perform calibration with calibration cube
469474
#endif

Marlin/src/gcode/gcode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,12 @@ class GcodeSuite {
637637

638638
static void G92();
639639

640+
641+
#if ENABLED(FEEDRATE_MODE_SUPPORT)
642+
static void G93();
643+
static void G94();
644+
#endif
645+
640646
#if ENABLED(CALIBRATION_GCODE)
641647
static void G425();
642648
#endif

Marlin/src/gcode/motion/G0_G1.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,21 @@ void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) {
5656
#ifdef G0_FEEDRATE
5757
feedRate_t old_feedrate;
5858
#if ENABLED(VARIABLE_G0_FEEDRATE)
59+
TERN_(FEEDRATE_MODE_SUPPORT, parser.print_move = true);
5960
if (fast_move) {
6061
old_feedrate = feedrate_mm_s; // Back up the (old) motion mode feedrate
6162
feedrate_mm_s = fast_move_feedrate; // Get G0 feedrate from last usage
6263
}
64+
#elif defined(FEEDRATE_MODE_SUPPORT)
65+
if (fast_move) {
66+
parser.print_move = false;
67+
}
68+
else {
69+
parser.print_move = true;
70+
}
6371
#endif
72+
#elif ENABLED(FEEDRATE_MODE_SUPPORT)
73+
parser.print_move = true;
6474
#endif
6575

6676
get_destination_from_command(); // Get X Y [Z[I[J[K]]]] [E] F (and set cutter power)
@@ -107,6 +117,8 @@ void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) {
107117
if (fast_move) feedrate_mm_s = old_feedrate;
108118
#endif
109119

120+
TERN_(FEEDRATE_MODE_SUPPORT, parser.print_move = false);
121+
110122
#if ENABLED(NANODLP_Z_SYNC)
111123
#if ENABLED(NANODLP_ALL_AXIS)
112124
#define _MOVE_SYNC parser.seenval('X') || parser.seenval('Y') || parser.seenval('Z') // For any move wait and output sync message

Marlin/src/gcode/motion/G2_G3.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,17 @@ void plan_arc(
212212
}
213213

214214
// Feedrate for the move, scaled by the feedrate multiplier
215-
const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
215+
#if ENABLED(FEEDRATE_MODE_SUPPORT)
216+
const feedRate_t scaled_fr = MMS_SCALED(feedrate_mm_s);
217+
const feedRate_t scaled_fr_mm_s = parser.inverse_time_enabled ? scaled_fr * flat_mm : scaled_fr;
218+
#else
219+
const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
220+
#endif
216221

217222
// Get the ideal segment length for the move based on settings
218223
const float ideal_segment_mm = (
219224
#if ARC_SEGMENTS_PER_SEC // Length based on segments per second and feedrate
220-
constrain(scaled_fr_mm_s * RECIPROCAL(ARC_SEGMENTS_PER_SEC), MIN_ARC_SEGMENT_MM, MAX_ARC_SEGMENT_MM)
225+
constrain(scaled_fr_mm_s * RECIPROCAL(ARC_SEGMENTS_PER_SEC, MIN_ARC_SEGMENT_MM, MAX_ARC_SEGMENT_MM))
221226
#else
222227
MAX_ARC_SEGMENT_MM // Length using the maximum segment size
223228
#endif
@@ -236,7 +241,11 @@ void plan_arc(
236241
// Add hints to help optimize the move
237242
PlannerHints hints;
238243
#if ENABLED(FEEDRATE_SCALING)
239-
hints.inv_duration = (scaled_fr_mm_s / flat_mm) * segments;
244+
#if ENABLED(FEEDRATE_MODE_SUPPORT)
245+
hints.inv_duration = segments * (parser.inverse_time_enabled ? scaled_fr : (scaled_fr_mm_s / flat_mm));
246+
#else
247+
hints.inv_duration = segments * (scaled_fr_mm_s / flat_mm);
248+
#endif
240249
#endif
241250

242251
/**
@@ -427,6 +436,8 @@ void GcodeSuite::G2_G3(const bool clockwise) {
427436

428437
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_RUNNING));
429438

439+
TERN_(FEEDRATE_MODE_SUPPORT, parser.print_move = true);
440+
430441
#if ENABLED(SF_ARC_FIX)
431442
const bool relative_mode_backup = relative_mode;
432443
relative_mode = true;
@@ -486,6 +497,8 @@ void GcodeSuite::G2_G3(const bool clockwise) {
486497
else
487498
SERIAL_ERROR_MSG(STR_ERR_ARC_ARGS);
488499

500+
TERN_(FEEDRATE_MODE_SUPPORT, parser.print_move = false);
501+
489502
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
490503
}
491504

Marlin/src/gcode/motion/G5.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ void GcodeSuite::G5() {
5454
}
5555
#endif
5656

57+
#if ENABLED(FEEDRATE_MODE_SUPPORT)
58+
if (parser.inverse_time_enabled) {
59+
SERIAL_ERROR_MSG(STR_ERR_BAD_FEEDRATE_MODE);
60+
return;
61+
}
62+
#endif
63+
5764
get_destination_from_command();
5865

5966
const xy_pos_t offsets[2] = {

Marlin/src/gcode/parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ bool GCodeParser::volumetric_enabled;
3737
float GCodeParser::linear_unit_factor, GCodeParser::volumetric_unit_factor;
3838
#endif
3939

40+
#if ENABLED(FEEDRATE_MODE_SUPPORT)
41+
bool GCodeParser::inverse_time_enabled;
42+
bool GCodeParser::print_move;
43+
#endif
44+
4045
#if ENABLED(TEMPERATURE_UNITS_SUPPORT)
4146
TempUnit GCodeParser::input_temp_units = TEMPUNIT_C;
4247
#endif

0 commit comments

Comments
 (0)