Add a feedRate_t data type (#15349)

This commit is contained in:
Scott Lahteine
2019-09-26 01:28:09 -05:00
committed by GitHub
parent ee7558a622
commit 455dabb183
42 changed files with 384 additions and 377 deletions

View File

@ -216,41 +216,32 @@ mesh_index_pair find_closest_circle_to_print(const float &X, const float &Y) {
return return_val;
}
void G26_line_to_destination(const float &feed_rate) {
const float save_feedrate = feedrate_mm_s;
feedrate_mm_s = feed_rate;
prepare_move_to_destination(); // will ultimately call ubl.line_to_destination_cartesian or ubl.prepare_linear_move_to for UBL_SEGMENTED
feedrate_mm_s = save_feedrate;
}
void move_to(const float &rx, const float &ry, const float &z, const float &e_delta) {
float feed_value;
static float last_z = -999.99;
bool has_xy_component = (rx != current_position[X_AXIS] || ry != current_position[Y_AXIS]); // Check if X or Y is involved in the movement.
if (z != last_z) {
last_z = z;
feed_value = planner.settings.max_feedrate_mm_s[Z_AXIS]/(2.0); // Base the feed rate off of the configured Z_AXIS feed rate
const feedRate_t feed_value = planner.settings.max_feedrate_mm_s[Z_AXIS] * 0.5f; // Use half of the Z_AXIS max feed rate
destination[X_AXIS] = current_position[X_AXIS];
destination[Y_AXIS] = current_position[Y_AXIS];
destination[Z_AXIS] = z; // We know the last_z!=z or we wouldn't be in this block of code.
destination[E_AXIS] = current_position[E_AXIS];
G26_line_to_destination(feed_value);
prepare_internal_move_to_destination(feed_value);
set_destination_from_current();
}
// Check if X or Y is involved in the movement.
// Yes: a 'normal' movement. No: a retract() or recover()
feed_value = has_xy_component ? G26_XY_FEEDRATE : planner.settings.max_feedrate_mm_s[E_AXIS] / 1.5;
// If X or Y is involved do a 'normal' move. Otherwise retract/recover/hop.
const feedRate_t feed_value = has_xy_component ? feedRate_t(G26_XY_FEEDRATE) : planner.settings.max_feedrate_mm_s[E_AXIS] * 0.666f;
destination[X_AXIS] = rx;
destination[Y_AXIS] = ry;
destination[E_AXIS] += e_delta;
G26_line_to_destination(feed_value);
prepare_internal_move_to_destination(feed_value);
set_destination_from_current();
}
@ -433,6 +424,7 @@ inline bool turn_on_heaters() {
*/
inline bool prime_nozzle() {
const feedRate_t fr_slow_e = planner.settings.max_feedrate_mm_s[E_AXIS] / 15.0f;
#if HAS_LCD_MENU
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
float Total_Prime = 0.0;
@ -455,7 +447,7 @@ inline bool prime_nozzle() {
Total_Prime += 0.25;
if (Total_Prime >= EXTRUDE_MAXLENGTH) return G26_ERR;
#endif
G26_line_to_destination(planner.settings.max_feedrate_mm_s[E_AXIS] / 15.0);
prepare_internal_move_to_destination(fr_slow_e);
set_destination_from_current();
planner.synchronize(); // Without this synchronize, the purge is more consistent,
// but because the planner has a buffer, we won't be able
@ -478,7 +470,7 @@ inline bool prime_nozzle() {
#endif
set_destination_from_current();
destination[E_AXIS] += g26_prime_length;
G26_line_to_destination(planner.settings.max_feedrate_mm_s[E_AXIS] / 15.0);
prepare_internal_move_to_destination(fr_slow_e);
set_destination_from_current();
retract_filament(destination);
}
@ -781,12 +773,13 @@ void GcodeSuite::G26() {
move_to(sx, sy, g26_layer_height, 0.0); // Get to the starting point with no extrusion / un-Z bump
recover_filament(destination);
const float save_feedrate = feedrate_mm_s;
feedrate_mm_s = PLANNER_XY_FEEDRATE() / 10.0;
const feedRate_t old_feedrate = feedrate_mm_s;
feedrate_mm_s = PLANNER_XY_FEEDRATE() * 0.1f;
plan_arc(endpoint, arc_offset, false); // Draw a counter-clockwise arc
feedrate_mm_s = save_feedrate;
feedrate_mm_s = old_feedrate;
set_destination_from_current();
#if HAS_LCD_MENU
if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation
#endif

View File

@ -45,8 +45,10 @@ void GcodeSuite::G42() {
}
set_destination_from_current();
if (hasI) destination[X_AXIS] = _GET_MESH_X(ix);
if (hasJ) destination[Y_AXIS] = _GET_MESH_Y(iy);
#if HAS_BED_PROBE
if (parser.boolval('P')) {
if (hasI) destination[X_AXIS] -= probe_offset[X_AXIS];
@ -54,14 +56,14 @@ void GcodeSuite::G42() {
}
#endif
const float fval = parser.linearval('F');
if (fval > 0.0) feedrate_mm_s = MMM_TO_MMS(fval);
const feedRate_t fval = parser.linearval('F'),
fr_mm_s = fval > 0 ? MMM_TO_MMS(fval) : 0.0f;
// SCARA kinematic has "safe" XY raw moves
#if IS_SCARA
prepare_uninterpolated_move_to_destination();
prepare_internal_fast_move_to_destination(fr_mm_s);
#else
prepare_move_to_destination();
prepare_internal_move_to_destination(fr_mm_s);
#endif
}
}

View File

@ -143,8 +143,7 @@ void GcodeSuite::G29() {
#if ENABLED(MESH_G28_REST_ORIGIN)
current_position[Z_AXIS] = 0;
set_destination_from_current();
buffer_line_to_destination(homing_feedrate(Z_AXIS));
line_to_current_position(homing_feedrate(Z_AXIS));
planner.synchronize();
#endif

View File

@ -171,17 +171,16 @@ inline bool read_calibration_pin() {
* fast in - Fast vs. precise measurement
*/
float measuring_movement(const AxisEnum axis, const int dir, const bool stop_state, const bool fast) {
const float step = fast ? 0.25 : CALIBRATION_MEASUREMENT_RESOLUTION;
const float mms = MMM_TO_MMS(fast ? CALIBRATION_FEEDRATE_FAST : CALIBRATION_FEEDRATE_SLOW);
const float limit = fast ? 50 : 5;
const float step = fast ? 0.25 : CALIBRATION_MEASUREMENT_RESOLUTION;
const feedRate_t mms = fast ? MMM_TO_MMS(CALIBRATION_FEEDRATE_FAST) : MMM_TO_MMS(CALIBRATION_FEEDRATE_SLOW);
const float limit = fast ? 50 : 5;
set_destination_from_current();
for (float travel = 0; travel < limit; travel += step) {
destination[axis] += dir * step;
do_blocking_move_to(destination, mms);
planner.synchronize();
if (read_calibration_pin() == stop_state)
break;
if (read_calibration_pin() == stop_state) break;
}
return destination[axis];
}

View File

@ -32,7 +32,7 @@
#define DEBUG_OUT ENABLED(L6470_CHITCHAT)
#include "../../../core/debug_out.h"
static void jiggle_axis(const char axis_char, const float &min, const float &max, const float &rate) {
static void jiggle_axis(const char axis_char, const float &min, const float &max, const feedRate_t &fr_mm_m) {
char gcode_string[30], str1[11], str2[11];
// Turn the motor(s) both directions
@ -84,7 +84,7 @@ void GcodeSuite::M916() {
uint8_t driver_count = 1;
float position_max;
float position_min;
float final_feedrate;
feedRate_t final_fr_mm_m;
uint8_t kval_hold;
uint8_t ocd_th_val = 0;
uint8_t stall_th_val = 0;
@ -93,10 +93,10 @@ void GcodeSuite::M916() {
uint8_t j; // general purpose counter
if (L6470.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_feedrate, kval_hold, over_current_flag, ocd_th_val, stall_th_val, over_current_threshold))
if (L6470.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_fr_mm_m, kval_hold, over_current_flag, ocd_th_val, stall_th_val, over_current_threshold))
return; // quit if invalid user input
DEBUG_ECHOLNPAIR("feedrate = ", final_feedrate);
DEBUG_ECHOLNPAIR("feedrate = ", final_fr_mm_m);
planner.synchronize(); // Wait for moves to finish
@ -115,7 +115,7 @@ void GcodeSuite::M916() {
L6470.set_param(axis_index[j], L6470_KVAL_HOLD, kval_hold);
// Turn the motor(s) both directions
jiggle_axis(axis_mon[0][0], position_min, position_max, final_feedrate);
jiggle_axis(axis_mon[0][0], position_min, position_max, final_fr_mm_m);
status_composite = 0; // clear out the old bits
@ -190,7 +190,7 @@ void GcodeSuite::M917() {
uint8_t driver_count = 1;
float position_max;
float position_min;
float final_feedrate;
feedRate_t final_fr_mm_m;
uint8_t kval_hold;
uint8_t ocd_th_val = 0;
uint8_t stall_th_val = 0;
@ -199,10 +199,10 @@ void GcodeSuite::M917() {
uint8_t j; // general purpose counter
if (L6470.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_feedrate, kval_hold, over_current_flag, ocd_th_val, stall_th_val, over_current_threshold))
if (L6470.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_fr_mm_m, kval_hold, over_current_flag, ocd_th_val, stall_th_val, over_current_threshold))
return; // quit if invalid user input
DEBUG_ECHOLNPAIR("feedrate = ", final_feedrate);
DEBUG_ECHOLNPAIR("feedrate = ", final_fr_mm_m);
planner.synchronize(); // Wait for moves to finish
for (j = 0; j < driver_count; j++)
@ -225,7 +225,7 @@ void GcodeSuite::M917() {
DEBUG_ECHOPAIR("STALL threshold : ", (stall_th_val + 1) * 31.25);
DEBUG_ECHOLNPAIR(" OCD threshold : ", (ocd_th_val + 1) * 375);
jiggle_axis(axis_mon[0][0], position_min, position_max, final_feedrate);
jiggle_axis(axis_mon[0][0], position_min, position_max, final_fr_mm_m);
status_composite = 0; // clear out the old bits
@ -452,7 +452,7 @@ void GcodeSuite::M918() {
uint16_t axis_status[3];
uint8_t driver_count = 1;
float position_max, position_min;
float final_feedrate;
feedRate_t final_fr_mm_m;
uint8_t kval_hold;
uint8_t ocd_th_val = 0;
uint8_t stall_th_val = 0;
@ -461,7 +461,7 @@ void GcodeSuite::M918() {
uint8_t j; // general purpose counter
if (L6470.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_feedrate, kval_hold, over_current_flag, ocd_th_val, stall_th_val, over_current_threshold))
if (L6470.get_user_input(driver_count, axis_index, axis_mon, position_max, position_min, final_fr_mm_m, kval_hold, over_current_flag, ocd_th_val, stall_th_val, over_current_threshold))
return; // quit if invalid user input
uint8_t m_steps = parser.byteval('M');
@ -489,10 +489,7 @@ void GcodeSuite::M918() {
for (j = 0; j < driver_count; j++)
L6470.set_param(axis_index[j], L6470_STEP_MODE, m_bits); // set microsteps
DEBUG_ECHOLNPAIR("target (maximum) feedrate = ",final_feedrate);
float feedrate_inc = final_feedrate / 10, // start at 1/10 of max & go up by 1/10 per step)
current_feedrate = 0;
DEBUG_ECHOLNPAIR("target (maximum) feedrate = ", final_fr_mm_m);
planner.synchronize(); // Wait for moves to finish
@ -502,18 +499,19 @@ void GcodeSuite::M918() {
uint16_t status_composite = 0;
DEBUG_ECHOLNPGM(".\n.\n."); // Make the feedrate prints easier to see
do {
current_feedrate += feedrate_inc;
DEBUG_ECHOLNPAIR("...feedrate = ", current_feedrate);
constexpr uint8_t iterations = 10;
for (uint8_t i = 1; i <= iterations; i++) {
const feedRate_t fr_mm_m = i * final_fr_mm_m / iterations;
DEBUG_ECHOLNPAIR("...feedrate = ", fr_mm_m);
jiggle_axis(axis_mon[0][0], position_min, position_max, current_feedrate);
jiggle_axis(axis_mon[0][0], position_min, position_max, fr_mm_m);
for (j = 0; j < driver_count; j++) {
axis_status[j] = (~L6470.get_status(axis_index[j])) & 0x0800; // bits of interest are all active low
status_composite |= axis_status[j];
}
if (status_composite) break; // quit if any errors flags are raised
} while (current_feedrate < final_feedrate * 0.99);
}
DEBUG_ECHOPGM("Completed with errors");
if (status_composite) {

View File

@ -43,7 +43,7 @@
#endif
#ifdef PHOTO_RETRACT_MM
inline void e_move_m240(const float length, const float fr_mm_s) {
inline void e_move_m240(const float length, const feedRate_t &fr_mm_s) {
if (length && thermalManager.hotEnoughToExtrude(active_extruder)) {
#if ENABLED(ADVANCED_PAUSE_FEATURE)
do_pause_e_move(length, fr_mm_s);
@ -104,7 +104,8 @@ void GcodeSuite::M240() {
};
#ifdef PHOTO_RETRACT_MM
constexpr float rfr = (MMS_TO_MMM(
const float rval = parser.seenval('R') ? parser.value_linear_units() : _PHOTO_RETRACT_MM;
feedRate_t sval = (
#if ENABLED(ADVANCED_PAUSE_FEATURE)
PAUSE_PARK_RETRACT_FEEDRATE
#elif ENABLED(FWRETRACT)
@ -112,13 +113,12 @@ void GcodeSuite::M240() {
#else
45
#endif
));
const float rval = parser.seenval('R') ? parser.value_linear_units() : _PHOTO_RETRACT_MM,
sval = parser.seenval('S') ? MMM_TO_MMS(parser.value_feedrate()) : rfr;
);
if (parser.seenval('S')) sval = parser.value_feedrate();
e_move_m240(-rval, sval);
#endif
float fr_mm_s = MMM_TO_MMS(parser.linearval('F'));
feedRate_t fr_mm_s = MMM_TO_MMS(parser.linearval('F'));
if (fr_mm_s) NOLESS(fr_mm_s, 10.0f);
constexpr float photo_position[XYZ] = PHOTO_POSITION;

View File

@ -97,7 +97,7 @@ void GcodeSuite::M701() {
// Lift Z axis
if (park_point.z > 0)
do_blocking_move_to_z(_MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
do_blocking_move_to_z(_MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
// Load filament
#if ENABLED(PRUSA_MMU2)
@ -116,7 +116,7 @@ void GcodeSuite::M701() {
// Restore Z axis
if (park_point.z > 0)
do_blocking_move_to_z(_MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
do_blocking_move_to_z(_MAX(current_position[Z_AXIS] - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
#if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
// Restore toolhead if it was changed
@ -196,7 +196,7 @@ void GcodeSuite::M702() {
// Lift Z axis
if (park_point.z > 0)
do_blocking_move_to_z(_MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
do_blocking_move_to_z(_MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
// Unload filament
#if ENABLED(PRUSA_MMU2)
@ -226,7 +226,7 @@ void GcodeSuite::M702() {
// Restore Z axis
if (park_point.z > 0)
do_blocking_move_to_z(_MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
do_blocking_move_to_z(_MAX(current_position[Z_AXIS] - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
#if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
// Restore toolhead if it was changed

View File

@ -129,7 +129,7 @@ void GcodeSuite::get_destination_from_command() {
#endif
if (parser.linearval('F') > 0)
feedrate_mm_s = MMM_TO_MMS(parser.value_feedrate());
feedrate_mm_s = parser.value_feedrate();
#if ENABLED(PRINTCOUNTER)
if (!DEBUGGING(DRYRUN))

View File

@ -370,7 +370,7 @@ private:
static void G0_G1(
#if IS_SCARA || defined(G0_FEEDRATE)
bool fast_move=false
const bool fast_move=false
#endif
);

View File

@ -38,7 +38,7 @@
extern float destination[XYZE];
#if ENABLED(VARIABLE_G0_FEEDRATE)
float saved_g0_feedrate_mm_s = MMM_TO_MMS(G0_FEEDRATE);
feedRate_t fast_move_feedrate = MMM_TO_MMS(G0_FEEDRATE);
#endif
/**
@ -46,7 +46,7 @@ extern float destination[XYZE];
*/
void GcodeSuite::G0_G1(
#if IS_SCARA || defined(G0_FEEDRATE)
bool fast_move/*=false*/
const bool fast_move/*=false*/
#endif
) {
@ -60,23 +60,23 @@ void GcodeSuite::G0_G1(
) {
#ifdef G0_FEEDRATE
float saved_feedrate_mm_s;
feedRate_t old_feedrate;
#if ENABLED(VARIABLE_G0_FEEDRATE)
if (fast_move) {
saved_feedrate_mm_s = feedrate_mm_s; // Back up the (old) motion mode feedrate
feedrate_mm_s = saved_g0_feedrate_mm_s; // Get G0 feedrate from last usage
old_feedrate = feedrate_mm_s; // Back up the (old) motion mode feedrate
feedrate_mm_s = fast_move_feedrate; // Get G0 feedrate from last usage
}
#endif
#endif
get_destination_from_command(); // For X Y Z E F
get_destination_from_command(); // Process X Y Z E F parameters
#ifdef G0_FEEDRATE
if (fast_move) {
#if ENABLED(VARIABLE_G0_FEEDRATE)
saved_g0_feedrate_mm_s = feedrate_mm_s; // Save feedrate for the next G0
fast_move_feedrate = feedrate_mm_s; // Save feedrate for the next G0
#else
saved_feedrate_mm_s = feedrate_mm_s; // Back up the (new) motion mode feedrate
old_feedrate = feedrate_mm_s; // Back up the (new) motion mode feedrate
feedrate_mm_s = MMM_TO_MMS(G0_FEEDRATE); // Get the fixed G0 feedrate
#endif
}
@ -100,14 +100,14 @@ void GcodeSuite::G0_G1(
#endif // FWRETRACT
#if IS_SCARA
fast_move ? prepare_uninterpolated_move_to_destination() : prepare_move_to_destination();
fast_move ? prepare_fast_move_to_destination() : prepare_move_to_destination();
#else
prepare_move_to_destination();
#endif
#ifdef G0_FEEDRATE
// Restore the motion mode feedrate
if (fast_move) feedrate_mm_s = saved_feedrate_mm_s;
if (fast_move) feedrate_mm_s = old_feedrate;
#endif
#if ENABLED(NANODLP_Z_SYNC)

View File

@ -146,10 +146,10 @@ void plan_arc(
// Initialize the extruder axis
raw[E_AXIS] = current_position[E_AXIS];
const float fr_mm_s = MMS_SCALED(feedrate_mm_s);
const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
#if ENABLED(SCARA_FEEDRATE_SCALING)
const float inv_duration = fr_mm_s / MM_PER_ARC_SEGMENT;
const float inv_duration = scaled_fr_mm_s / MM_PER_ARC_SEGMENT;
#endif
millis_t next_idle_ms = millis() + 200UL;
@ -206,7 +206,7 @@ void plan_arc(
planner.apply_leveling(raw);
#endif
if (!planner.buffer_line(raw, fr_mm_s, active_extruder, MM_PER_ARC_SEGMENT
if (!planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, MM_PER_ARC_SEGMENT
#if ENABLED(SCARA_FEEDRATE_SCALING)
, inv_duration
#endif
@ -226,7 +226,7 @@ void plan_arc(
planner.apply_leveling(raw);
#endif
planner.buffer_line(raw, fr_mm_s, active_extruder, MM_PER_ARC_SEGMENT
planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, MM_PER_ARC_SEGMENT
#if ENABLED(SCARA_FEEDRATE_SCALING)
, inv_duration
#endif

View File

@ -364,7 +364,7 @@ public:
#endif // !TEMPERATURE_UNITS_SUPPORT
static inline float value_feedrate() { return value_linear_units(); }
static inline feedRate_t value_feedrate() { return MMM_TO_MMS(value_linear_units()); }
void unknown_command_error();