Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions lib/Marlin/Marlin/src/feature/phase_stepping/axes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ struct AxisMotorParams {
float rev_to_mm = 0;
int phase_per_ustep = 0;

static AxisMotorParams make_for_motor(int steps_per_rev, int steps_per_unit, int microsteps) {
static AxisMotorParams make_for_motor(int steps_per_rev, float steps_per_unit, int microsteps) {
return {
.steps_per_rev = steps_per_rev,
.pos_to_phase = 256.f * steps_per_unit / microsteps,
.pos_to_steps = float(steps_per_unit),
.pos_to_msteps = float(steps_per_unit) / PLANNER_STEPS_MULTIPLIER,
.pos_to_steps = steps_per_unit,
.pos_to_msteps = steps_per_unit / PLANNER_STEPS_MULTIPLIER,
.mm_to_rev = 1.f / (steps_per_rev * float(microsteps) / steps_per_unit),
.rev_to_mm = steps_per_rev * float(microsteps) / steps_per_unit,
.phase_per_ustep = 256 / microsteps
Expand All @@ -40,6 +40,28 @@ void phase_stepping::initialize_axis_motor_params() {
}
}

void phase_stepping::update_axis_motor_params() {
auto &s = planner.settings;
std::array<AxisMotorParams, phase_stepping::opts::SUPPORTED_AXIS_COUNT> new_axis_motor_params;

int xy_steps_per_rev = get_has_400step_xy_motors() ? 400 : 200;

new_axis_motor_params[0] = AxisMotorParams::make_for_motor(xy_steps_per_rev, s.axis_steps_per_mm[X_AXIS], get_microsteps_x());
new_axis_motor_params[1] = AxisMotorParams::make_for_motor(xy_steps_per_rev, s.axis_steps_per_mm[Y_AXIS], get_microsteps_y());
if (opts::SUPPORTED_AXIS_COUNT > 2) {
new_axis_motor_params[2] = AxisMotorParams::make_for_motor(200, s.axis_steps_per_mm[Z_AXIS], get_microsteps_z());
}
if (opts::SUPPORTED_AXIS_COUNT > 3) {
new_axis_motor_params[3] = AxisMotorParams::make_for_motor(200, s.axis_steps_per_mm[E_AXIS], get_microsteps_e());
}

{
// If the ISR triggers while we're updating this, we get Undefined Behavior, so we need to disable interrupts.
buddy::InterruptDisabler _;
axis_motor_params = new_axis_motor_params;
}
}

int phase_stepping::get_motor_steps(AxisEnum axis) {
return axis_motor_params[static_cast<int>(axis)].steps_per_rev;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Marlin/Marlin/src/feature/phase_stepping/axes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace phase_stepping {

void initialize_axis_motor_params();

/**
* Update the axis motor parameters (must be called after a change to the axis steps per unit)
**/
void update_axis_motor_params();

/**
* Return a motor step count for given axis
**/
Expand Down
1 change: 1 addition & 0 deletions lib/Marlin/Marlin/src/module/configuration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ void MarlinSettings::reset_motion(const bool no_limits) {
#endif

planner.apply_settings(s, no_limits);
planner.refresh_positioning();
#endif /* HAS_PLANNER() */
}

Expand Down
48 changes: 7 additions & 41 deletions lib/Marlin/Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,10 @@ void Planner::refresh_positioning() {
}
set_position_mm(current_position);
refresh_acceleration_rates();

#if HAS_PHASE_STEPPING()
phase_stepping::update_axis_motor_params();
#endif
}

#if ENABLED(DISTINCT_E_FACTORS)
Expand Down Expand Up @@ -2814,50 +2818,12 @@ void Motion_Parameters::save_reset(const bool no_limits) {

void Motion_Parameters::save() {
const auto &src = planner.user_settings;

for (int i = 0; i < XYZE_N; ++i) {
mp.max_acceleration_mm_per_s2[i] = src.max_acceleration_mm_per_s2[i];
mp.max_feedrate_mm_s[i] = src.max_feedrate_mm_s[i];
}

mp.min_segment_time_us = src.min_segment_time_us;
mp.acceleration = src.acceleration;
mp.retract_acceleration = src.retract_acceleration;
mp.travel_acceleration = src.travel_acceleration;
mp.min_feedrate_mm_s = src.min_feedrate_mm_s;
mp.min_travel_feedrate_mm_s = src.min_travel_feedrate_mm_s;

#if DISABLED(CLASSIC_JERK)
mp.junction_deviation_mm = planner.junction_deviation_mm;
#endif
#if HAS_CLASSIC_JERK
mp.max_jerk = src.max_jerk;
#endif
mp = src;
}

void Motion_Parameters::load() const {
auto s = planner.user_settings;

for (int i = 0; i < XYZE_N; ++i) {
s.max_acceleration_mm_per_s2[i] = mp.max_acceleration_mm_per_s2[i];
s.max_feedrate_mm_s[i] = mp.max_feedrate_mm_s[i];
}

s.min_segment_time_us = mp.min_segment_time_us;
s.acceleration = mp.acceleration;
s.retract_acceleration = mp.retract_acceleration;
s.travel_acceleration = mp.travel_acceleration;
s.min_feedrate_mm_s = mp.min_feedrate_mm_s;
s.min_travel_feedrate_mm_s = mp.min_travel_feedrate_mm_s;

#if DISABLED(CLASSIC_JERK)
planner.junction_deviation_mm = mp.junction_deviation_mm;
#endif
#if HAS_CLASSIC_JERK
s.max_jerk = mp.max_jerk;
#endif

planner.apply_settings(s);
planner.apply_settings(mp);
planner.refresh_positioning();
}

void Motion_Parameters::reset(const bool no_limits) {
Expand Down
30 changes: 5 additions & 25 deletions lib/Marlin/Marlin/src/module/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,6 @@ typedef struct {
feedRate_t min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate
min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate

#if HAS_CLASSIC_JERK
#if HAS_LINEAR_E_JERK
xyz_pos_t max_jerk; // (mm/s^2) M205 XYZ - The largest speed change requiring no acceleration.
#else
xyze_pos_t max_jerk; // (mm/s^2) M205 XYZE - The largest speed change requiring no acceleration.
#endif
#endif
} planner_settings_t;

/// Subclass to enforce that people are using user settings when applying settings
struct user_planner_settings_t : public planner_settings_t {};

// Structure for saving/loading movement parameters
typedef struct {
uint32_t max_acceleration_mm_per_s2[XYZE_N], // (mm/s^2) M201 XYZE
min_segment_time_us; // (µs) M205 B
feedRate_t max_feedrate_mm_s[XYZE_N]; // (mm/s) M203 XYZE - Max speeds
float acceleration, // (mm/s^2) M204 S - Normal acceleration. DEFAULT ACCELERATION for all printing moves.
retract_acceleration, // (mm/s^2) M204 R - Retract acceleration. Filament pull-back and push-forward while standing still in the other axes
travel_acceleration; // (mm/s^2) M204 T - Travel acceleration. DEFAULT ACCELERATION for all NON printing moves.
feedRate_t min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate
min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate

#if DISABLED(CLASSIC_JERK)
float junction_deviation_mm; // (mm) M205 J
#endif
Expand All @@ -208,7 +185,10 @@ typedef struct {
xyze_pos_t max_jerk; // (mm/s^2) M205 XYZE - The largest speed change requiring no acceleration.
#endif
#endif
} motion_parameters_t;
} planner_settings_t;

/// Subclass to enforce that people are using user settings when applying settings
struct user_planner_settings_t : public planner_settings_t {};

#if DISABLED(SKEW_CORRECTION)
#define XY_SKEW_FACTOR 0
Expand Down Expand Up @@ -1045,7 +1025,7 @@ class Motion_Parameters {
void load() const;

private:
motion_parameters_t mp;
user_planner_settings_t mp;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/common/selftest/selftest_firstlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ LoopResult CSelftestPart_FirstLayer::stateShowCalibrateMsg() {
return LoopResult::RunNext;
}

static constexpr int axis_steps_per_unit[] = DEFAULT_AXIS_STEPS_PER_UNIT;
static constexpr float z_offset_step = 1.0F / float(axis_steps_per_unit[AxisEnum::Z_AXIS]);
static constexpr float axis_steps_per_unit[] = DEFAULT_AXIS_STEPS_PER_UNIT;
static constexpr float z_offset_step = 1.0F / axis_steps_per_unit[AxisEnum::Z_AXIS];
static constexpr float nozzle_to_probe[] = NOZZLE_TO_PROBE_OFFSET;
static constexpr float z_offset_def = nozzle_to_probe[AxisEnum::Z_AXIS];

Expand Down
4 changes: 2 additions & 2 deletions src/gui/menu_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#define STR(x) QUOTE_ME(x)

// axis length [mm]
static constexpr int axis_steps_per_unit[] = DEFAULT_AXIS_STEPS_PER_UNIT;
static constexpr float axis_steps_per_unit[] = DEFAULT_AXIS_STEPS_PER_UNIT;

static constexpr float nozzle_to_probe[3] = NOZZLE_TO_PROBE_OFFSET;

static constexpr float z_offset_step = 1.0F / float(axis_steps_per_unit[2]);
static constexpr float z_offset_step = 1.0F / axis_steps_per_unit[2];
static constexpr float z_offset_min = Z_OFFSET_MIN;
static constexpr float z_offset_max = Z_OFFSET_MAX;

Expand Down
5 changes: 1 addition & 4 deletions src/marlin_stubs/G123.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ void PrusaGcodeSuite::G123() {
// but also short enough so that we have snappy reaction time
static constexpr float max_segment_duration_s = 0.02f;

const auto prev_settings = planner.user_settings;
ScopeGuard _sg = [&] { planner.apply_settings(prev_settings); };

// Reset to default parameters for the duration of this gcode
Motion_Parameters::reset();
Temporary_Reset_Motion_Parameters mp_guard;

#if HAS_AUTO_RETRACT()
// When the user takes manual control over the extruder, do not do any retracting/deretracting moves
Expand Down