Skip to content

Commit

Permalink
Use struct
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndere1 committed Jul 3, 2022
1 parent 33d1a99 commit b0163e1
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 475 deletions.
8 changes: 8 additions & 0 deletions Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ typedef IF<(NUM_AXIS_ENUMS > 8), uint16_t, uint8_t>::type axis_bits_t;
//
typedef float feedRate_t;

//
// FeedRate is a struct of two variables of type feedRate_t. One for angular feedrate in °/s, one for linear feedrate in mm/s
//
struct FeedRate {
feedRate_t mm_s;
TERN_(HAS_ROTATIONAL_AXES, feedRate_t deg_s);
};

//
// celsius_t is the native unit of temperature. Signed to handle a disconnected thermistor value (-14).
// For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
const int x_axis_home_dir = TOOL_X_HOME_DIR(active_extruder);

// Use a higher diagonal feedrate so axes move at homing speed
const float minfr = _MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)),
fr_mm_s = HYPOT(minfr, minfr);
const float minfr = _MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS));
const FeedRate fr_quickhome = { HYPOT(minfr, minfr) OPTARG(HAS_ROTATIONAL_AXES, 0.0f) };

#if ENABLED(SENSORLESS_HOMING)
sensorless_t stealth_states {
Expand All @@ -92,7 +92,7 @@
};
#endif

do_blocking_move_to_xy(1.5 * max_length(X_AXIS) * x_axis_home_dir, 1.5 * max_length(Y_AXIS) * Y_HOME_DIR, fr_mm_s);
do_blocking_move_to_xy(1.5 * max_length(X_AXIS) * x_axis_home_dir, 1.5 * max_length(Y_AXIS) * Y_HOME_DIR, fr_quickhome);

endstops.validate_homing_move();

Expand Down
63 changes: 19 additions & 44 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ int8_t GcodeSuite::get_target_e_stepper_from_command(const int8_t dval/*=-1*/) {
*/
void GcodeSuite::get_destination_from_command() {
xyze_bool_t seen{false};

#if HAS_ROTATIONAL_AXES
bool seen_rotational_axes = false;
bool seen_linear_axes = false;
#endif

#if ENABLED(CANCEL_OBJECTS)
const bool &skip_move = cancelable.skipping;
Expand All @@ -183,6 +188,15 @@ void GcodeSuite::get_destination_from_command() {

// Get new XYZ position, whether absolute or relative
LOOP_NUM_AXES(i) {
#if HAS_ROTATIONAL_AXES
if (parser.seen(AXIS_CHAR(i))) {
if (parser.axis_is_rotational((AxisEnum)i))
seen_rotational_axes = true;
else
seen_linear_axes = true;
}
#endif

if ( (seen[i] = parser.seenval(AXIS_CHAR(i))) ) {
const float v = parser.value_axis_units((AxisEnum)i);
if (skip_move)
Expand Down Expand Up @@ -212,52 +226,13 @@ void GcodeSuite::get_destination_from_command() {

if (parser.floatval('F') > 0) {
#if HAS_ROTATIONAL_AXES
if ((!seen.x
#if HAS_Y_AXIS
&& !seen.y
#endif
#if HAS_Z_AXIS
&& !seen.z
#endif
#if HAS_J_AXIS && !defined(AXIS5_ROTATES)
&& !seen.j
#endif
#if HAS_K_AXIS && !defined(AXIS6_ROTATES)
&& !seen.k
#endif
#if HAS_U_AXIS && !defined(AXIS7_ROTATES)
&& !seen.u
#endif
#if HAS_V_AXIS && !defined(AXIS8_ROTATES)
&& !seen.v
#endif
#if HAS_W_AXIS && !defined(AXIS9_ROTATES)
&& !seen.w
#endif
) && (seen.i
#if AXIS5_ROTATES
|| seen.j
#endif
#if AXIS6_ROTATES
|| seen.k
#endif
#if AXIS7_ROTATES
|| seen.u
#endif
#if AXIS8_ROTATES
|| seen.v
#endif
#if AXIS9_ROTATES
|| seen.w
#endif
)
) {
feedrate_deg_s = parser.value_angular_feedrate();
if (!seen_rotational_axes)
feedrate.mm_s = parser.value_feedrate();
else if (!seen_linear_axes) {
feedrate.deg_s = parser.value_angular_feedrate();
}
else
feedrate_mm_s = parser.value_feedrate();
#else
feedrate_mm_s = parser.value_feedrate();
feedrate.mm_s = parser.value_feedrate();
#endif
}

Expand Down
32 changes: 9 additions & 23 deletions Marlin/src/gcode/motion/G0_G1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
extern xyze_pos_t destination;

#if ENABLED(VARIABLE_G0_FEEDRATE)
feedRate_t fast_move_feedrate = MMM_TO_MMS(G0_FEEDRATE);
TERN_(HAS_ROTATIONAL_AXES, feedRate_t fast_move_angular_feedrate = MMM_TO_MMS(G0_ANGULAR_FEEDRATE));
FeedRate fast_move_feedrate = { MMM_TO_MMS(G0_FEEDRATE) OPTARG(HAS_ROTATIONAL_AXES, MMM_TO_MMS(G0_ANGULAR_FEEDRATE)) };
#endif

/**
Expand All @@ -66,34 +65,24 @@ void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) {
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_RUNNING));

#ifdef G0_FEEDRATE
feedRate_t old_feedrate;
TERN_(HAS_ROTATIONAL_AXES, feedRate_t old_angular_feedrate);
FeedRate old_feedrate;
#if ENABLED(VARIABLE_G0_FEEDRATE)
if (fast_move) {
old_feedrate = feedrate_mm_s; // Back up the (old) motion mode feedrate
feedrate_mm_s = fast_move_feedrate; // Get G0 feedrate from last usage
#if HAS_ROTATIONAL_AXES
old_angular_feedrate = feedrate_deg_s; // Back up the (old) motion mode angular feedrate
feedrate_deg_s = fast_move_angular_feedrate; // Get G0 angular feedrate from last usage with rotational axes
#endif
old_feedrate = feedrate; // Back up the (old) motion mode feedrate
feedrate = fast_move_feedrate; // Get G0 feedrate from last usage
}
#endif
#endif

get_destination_from_command(); // Get X Y [Z[I[J[K]]]] [E] F (and set cutter power)
get_destination_from_command(); // Get X Y [Z[I[J[K]]]] [E] F (and set cutter power)

#ifdef G0_FEEDRATE
if (fast_move) {
#if ENABLED(VARIABLE_G0_FEEDRATE)
fast_move_feedrate = feedrate_mm_s; // Save feedrate for the next G0
TERN_(ROTATIONAL_AXES, fast_move_angular_feedrate = feedrate_deg_s); // Save angular feedrate for the next G0
fast_move_feedrate = feedrate; // Save feedrate for the next G0
#else
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
#if HAS_ROTATIONAL_AXES
old_angular_feedrate = feedrate_deg_s; // Back up the (new) motion mode angular feedrate
feedrate_deg_s = MMM_TO_MMS(G0_ANGULAR_FEEDRATE); // Get the fixed G0 angular feedrate
#endif
old_feedrate = feedrate; // Back up the (new) motion mode feedrate
feedrate = { MMM_TO_MMS(G0_FEEDRATE) OPTARG(HAS_ROTATIONAL_AXES, MMM_TO_MMS(G0_ANGULAR_FEEDRATE)) }; // Get the fixed G0 feedrate
#endif
}
#endif
Expand Down Expand Up @@ -125,10 +114,7 @@ void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) {

#ifdef G0_FEEDRATE
// Restore the motion mode feedrate
if (fast_move) feedrate_mm_s = old_feedrate;
#if HAS_ROTATIONAL_AXES
if (fast_move) feedrate_deg_s = old_angular_feedrate;
#endif
if (fast_move) feedrate = old_feedrate;
#endif

#if ENABLED(NANODLP_Z_SYNC)
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/gcode/motion/G2_G3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ void plan_arc(
) return;

// Feedrate for the move, scaled by the feedrate multiplier
const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
const FeedRate scaled_fr = { MMS_SCALED(feedrate.mm_s) OPTARG(HAS_ROTATIONAL_AXES, MMS_SCALED(feedrate.deg_s)) };

// Get the ideal segment length for the move based on settings
const float ideal_segment_mm = (
#if ARC_SEGMENTS_PER_SEC // Length based on segments per second and feedrate
constrain(scaled_fr_mm_s * RECIPROCAL(ARC_SEGMENTS_PER_SEC), MIN_ARC_SEGMENT_MM, MAX_ARC_SEGMENT_MM)
constrain(scaled_fr.mm_s * RECIPROCAL(ARC_SEGMENTS_PER_SEC), MIN_ARC_SEGMENT_MM, MAX_ARC_SEGMENT_MM) // FIXME: Needs proper logic for moves involving only rotational axes
#else
MAX_ARC_SEGMENT_MM // Length using the maximum segment size
#endif
Expand All @@ -216,7 +216,7 @@ void plan_arc(
nominal_segments;

#if ENABLED(SCARA_FEEDRATE_SCALING)
const float inv_duration = (scaled_fr_mm_s / flat_mm) * segments;
const float inv_duration = (scaled_fr.mm_s / flat_mm) * segments;
#endif

/**
Expand Down Expand Up @@ -342,7 +342,7 @@ void plan_arc(
planner.apply_leveling(raw);
#endif

if (!planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, 0 OPTARG(SCARA_FEEDRATE_SCALING, inv_duration)))
if (!planner.buffer_line(raw, scaled_fr, active_extruder, 0 OPTARG(SCARA_FEEDRATE_SCALING, inv_duration)))
break;
}
}
Expand All @@ -363,7 +363,7 @@ void plan_arc(
planner.apply_leveling(raw);
#endif

planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, 0 OPTARG(SCARA_FEEDRATE_SCALING, inv_duration));
planner.buffer_line(raw, scaled_fr, active_extruder, 0 OPTARG(SCARA_FEEDRATE_SCALING, inv_duration));

#if ENABLED(AUTO_BED_LEVELING_UBL)
ARC_LIJKUVW_CODE(
Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/gcode/probe/G38.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ inline bool G38_run_probe() {
prepare_line_to_destination();
planner.synchronize();

REMEMBER(fr, feedrate_mm_s, feedrate_mm_s * 0.25);
REMEMBER(fr, feedrate, feedrate * 0.25);

// Bump the target more slowly
destination -= retract_mm * 2;
Expand Down Expand Up @@ -122,8 +122,7 @@ void GcodeSuite::G38(const int8_t subcode) {
LOOP_NUM_AXES(i)
if (ABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) {
if (!parser.seenval('F')) {
feedrate_mm_s = homing_feedrate((AxisEnum)i);
TERN_(HAS_ROTATIONAL_AXES, feedrate_deg_s = homing_feedrate((AxisEnum)i));
feedrate = { homing_feedrate((AxisEnum)i) OPTARG(HAS_ROATIONAL_AXES, homing_feedrate((AxisEnum)i)) };
// If G38.2 fails throw an error
if (!G38_run_probe() && error_on_fail) SERIAL_ERROR_MSG("Failed to reach target");
break;
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,11 @@ void MarlinUI::init() {
// Add a manual move to the queue?
if (axis != NO_AXIS_ENUM && ELAPSED(millis(), start_time) && !planner.is_full()) {

const feedRate_t fr = (axis < LOGICAL_AXES) ? manual_feedrate_mm_s[axis] : XY_PROBE_FEEDRATE_MM_S;
FeedRate fr;
if (axis < LOGICAL_AXES)
fr = { manual_feedrate_mm_s[axis] OPTARG(HAS_ROTATIONAL_AXES, manual_feedrate_mm_s[axis]) };
else
fr = { XY_PROBE_FEEDRATE_MM_S OPTARG(HAS_ROTATIONAL_AXES, 0.0f) };

#if IS_KINEMATIC

Expand All @@ -813,7 +817,7 @@ void MarlinUI::init() {
// Apply a linear offset to a single axis
if (axis == ALL_AXES_ENUM)
destination = all_axes_destination;
else if (axis <= XYZE) {
else if (axis <= LOGICAL_AXES) {
destination = current_position;
destination[axis] += offset;
}
Expand All @@ -827,18 +831,14 @@ void MarlinUI::init() {
// previous invocation is being blocked. Modifications to offset shouldn't be made while
// processing is true or the planner will get out of sync.
processing = true;
prepare_internal_move_to_destination(fr
OPTARG(HAS_ROTATIONAL_AXES, fr)
); // will set current_position from destination
prepare_internal_move_to_destination(fr); // will set current_position from destination
processing = false;

#else

// For Cartesian / Core motion simply move to the current_position
planner.buffer_line(current_position
OPTARG(HAS_ROTATIONAL_AXES, fr)
, fr
, TERN_(MULTI_E_MANUAL, axis == E_AXIS ? e_index :) active_extruder
planner.buffer_line(current_position, fr,
TERN_(MULTI_E_MANUAL, axis == E_AXIS ? e_index :) active_extruder
);

//SERIAL_ECHOLNPGM("Add planner.move with Axis ", AS_CHAR(AXIS_CHAR(axis)), " at FR ", fr);
Expand Down
Loading

0 comments on commit b0163e1

Please sign in to comment.