Fix and improve EEPROM storage (#12054)

* Clean up Temperature PID
* Improve EEPROM read/write/validate
* Group `SINGLENOZZLE` saved settings
* Group planner saved settings
* Group filament change saved settings
* Group skew saved settings
* Group `FWRETRACT` saved settings
This commit is contained in:
Scott Lahteine
2018-10-10 09:45:20 -05:00
committed by GitHub
parent 9b5c1a5e77
commit d556dc1865
35 changed files with 1151 additions and 1246 deletions

File diff suppressed because it is too large Load Diff

View File

@ -817,9 +817,9 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
#define RAISED_Y raised_parked_position[Y_AXIS]
#define RAISED_Z raised_parked_position[Z_AXIS]
if ( planner.buffer_line(RAISED_X, RAISED_Y, RAISED_Z, CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder))
if ( planner.buffer_line(RAISED_X, RAISED_Y, RAISED_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder))
if (planner.buffer_line( CUR_X, CUR_Y, RAISED_Z, CUR_E, PLANNER_XY_FEEDRATE(), active_extruder))
planner.buffer_line( CUR_X, CUR_Y, CUR_Z, CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line( CUR_X, CUR_Y, CUR_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
delayed_move_time = 0;
active_extruder_parked = false;
#if ENABLED(DEBUG_LEVELING_FEATURE)
@ -841,7 +841,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
if (!planner.buffer_line(
dual_x_carriage_mode == DXC_DUPLICATION_MODE ? duplicate_extruder_x_offset + current_position[X_AXIS] : inactive_extruder_x_pos,
current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
planner.max_feedrate_mm_s[X_AXIS], 1
planner.settings.max_feedrate_mm_s[X_AXIS], 1
)
) break;
planner.synchronize();

View File

@ -111,18 +111,11 @@ volatile uint8_t Planner::block_buffer_head, // Index of the next block to be
uint16_t Planner::cleaning_buffer_counter; // A counter to disable queuing of blocks
uint8_t Planner::delay_before_delivering; // This counter delays delivery of blocks when queue becomes empty to allow the opportunity of merging blocks
uint32_t Planner::max_acceleration_mm_per_s2[XYZE_N], // (mm/s^2) M201 XYZE
Planner::max_acceleration_steps_per_s2[XYZE_N], // (steps/s^2) Derived from mm_per_s2
Planner::min_segment_time_us; // (µs) M205 B
planner_settings_t Planner::settings; // Initialized by settings.load()
float Planner::max_feedrate_mm_s[XYZE_N], // (mm/s) M203 XYZE - Max speeds
Planner::axis_steps_per_mm[XYZE_N], // (steps) M92 XYZE - Steps per millimeter
Planner::steps_to_mm[XYZE_N], // (mm) Millimeters per step
Planner::min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate
Planner::acceleration, // (mm/s^2) M204 S - Normal acceleration. DEFAULT ACCELERATION for all printing moves.
Planner::retract_acceleration, // (mm/s^2) M204 R - Retract acceleration. Filament pull-back and push-forward while standing still in the other axes
Planner::travel_acceleration, // (mm/s^2) M204 T - Travel acceleration. DEFAULT ACCELERATION for all NON printing moves.
Planner::min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate
uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N]; // (steps/s^2) Derived from mm_per_s2
float Planner::steps_to_mm[XYZE_N]; // (mm) Millimeters per step
#if ENABLED(JUNCTION_DEVIATION)
float Planner::junction_deviation_mm; // (mm) M205 J
@ -177,18 +170,7 @@ float Planner::e_factor[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0f); // The flow perc
constexpr bool Planner::leveling_active;
#endif
#if ENABLED(SKEW_CORRECTION)
#if ENABLED(SKEW_CORRECTION_GCODE)
float Planner::xy_skew_factor;
#else
constexpr float Planner::xy_skew_factor;
#endif
#if ENABLED(SKEW_CORRECTION_FOR_Z) && ENABLED(SKEW_CORRECTION_GCODE)
float Planner::xz_skew_factor, Planner::yz_skew_factor;
#else
constexpr float Planner::xz_skew_factor, Planner::yz_skew_factor;
#endif
#endif
skew_factor_t Planner::skew_factor; // Initialized by settings.load()
#if ENABLED(AUTOTEMP)
float Planner::autotemp_max = 250,
@ -1094,7 +1076,7 @@ void Planner::recalculate_trapezoids() {
calculate_trapezoid_for_block(current, current_entry_speed * nomr, next_entry_speed * nomr);
#if ENABLED(LIN_ADVANCE)
if (current->use_advance_lead) {
const float comp = current->e_D_ratio * extruder_advance_K[active_extruder] * axis_steps_per_mm[E_AXIS];
const float comp = current->e_D_ratio * extruder_advance_K[active_extruder] * settings.axis_steps_per_mm[E_AXIS];
current->max_adv_steps = current_nominal_speed * comp;
current->final_adv_steps = next_entry_speed * comp;
}
@ -1133,7 +1115,7 @@ void Planner::recalculate_trapezoids() {
calculate_trapezoid_for_block(next, next_entry_speed * nomr, float(MINIMUM_PLANNER_SPEED) * nomr);
#if ENABLED(LIN_ADVANCE)
if (next->use_advance_lead) {
const float comp = next->e_D_ratio * extruder_advance_K[active_extruder] * axis_steps_per_mm[E_AXIS];
const float comp = next->e_D_ratio * extruder_advance_K[active_extruder] * settings.axis_steps_per_mm[E_AXIS];
next->max_adv_steps = next_nominal_speed * comp;
next->final_adv_steps = (MINIMUM_PLANNER_SPEED) * comp;
}
@ -1687,7 +1669,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
}
#endif // PREVENT_COLD_EXTRUSION
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
if (ABS(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N(extruder)] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
if (ABS(de * e_factor[extruder]) > (int32_t)settings.axis_steps_per_mm[E_AXIS_N(extruder)] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
#if HAS_POSITION_FLOAT
position_float[E_AXIS] = target_float[E_AXIS];
@ -1946,9 +1928,9 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
}
if (esteps)
NOLESS(fr_mm_s, min_feedrate_mm_s);
NOLESS(fr_mm_s, settings.min_feedrate_mm_s);
else
NOLESS(fr_mm_s, min_travel_feedrate_mm_s);
NOLESS(fr_mm_s, settings.min_travel_feedrate_mm_s);
/**
* This part of the code calculates the total length of the movement.
@ -2023,9 +2005,9 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
#if ENABLED(SLOWDOWN)
if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
if (segment_time_us < min_segment_time_us) {
if (segment_time_us < settings.min_segment_time_us) {
// buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more.
const uint32_t nst = segment_time_us + LROUND(2 * (min_segment_time_us - segment_time_us) / moves_queued);
const uint32_t nst = segment_time_us + LROUND(2 * (settings.min_segment_time_us - segment_time_us) / moves_queued);
inverse_secs = 1000000.0f / nst;
#if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD)
segment_time_us = nst;
@ -2100,7 +2082,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
#if ENABLED(DISTINCT_E_FACTORS)
if (i == E_AXIS) i += extruder;
#endif
if (cs > max_feedrate_mm_s[i]) NOMORE(speed_factor, max_feedrate_mm_s[i] / cs);
if (cs > settings.max_feedrate_mm_s[i]) NOMORE(speed_factor, settings.max_feedrate_mm_s[i] / cs);
}
// Max segment time in µs.
@ -2153,7 +2135,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
uint32_t accel;
if (!block->steps[A_AXIS] && !block->steps[B_AXIS] && !block->steps[C_AXIS]) {
// convert to: acceleration steps/sec^2
accel = CEIL(retract_acceleration * steps_per_mm);
accel = CEIL(settings.retract_acceleration * steps_per_mm);
#if ENABLED(LIN_ADVANCE)
block->use_advance_lead = false;
#endif
@ -2174,7 +2156,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
}while(0)
// Start with print or travel acceleration
accel = CEIL((esteps ? acceleration : travel_acceleration) * steps_per_mm);
accel = CEIL((esteps ? settings.acceleration : settings.travel_acceleration) * steps_per_mm);
#if ENABLED(LIN_ADVANCE)
@ -2254,7 +2236,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
#endif
#if ENABLED(LIN_ADVANCE)
if (block->use_advance_lead) {
block->advance_speed = (STEPPER_TIMER_RATE) / (extruder_advance_K[active_extruder] * block->e_D_ratio * block->acceleration * axis_steps_per_mm[E_AXIS_N(extruder)]);
block->advance_speed = (STEPPER_TIMER_RATE) / (extruder_advance_K[active_extruder] * block->e_D_ratio * block->acceleration * settings.axis_steps_per_mm[E_AXIS_N(extruder)]);
#if ENABLED(LA_DEBUG)
if (extruder_advance_K[active_extruder] * block->e_D_ratio * block->acceleration * 2 < SQRT(block->nominal_speed_sqr) * block->e_D_ratio)
SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed.");
@ -2566,8 +2548,8 @@ bool Planner::buffer_segment(const float &a, const float &b, const float &c, con
// When changing extruders recalculate steps corresponding to the E position
#if ENABLED(DISTINCT_E_FACTORS)
if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N(extruder)] != axis_steps_per_mm[E_AXIS + last_extruder]) {
position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N(extruder)] * steps_to_mm[E_AXIS + last_extruder]);
if (last_extruder != extruder && settings.axis_steps_per_mm[E_AXIS_N(extruder)] != settings.axis_steps_per_mm[E_AXIS + last_extruder]) {
position[E_AXIS] = LROUND(position[E_AXIS] * settings.axis_steps_per_mm[E_AXIS_N(extruder)] * steps_to_mm[E_AXIS + last_extruder]);
last_extruder = extruder;
}
#endif
@ -2575,10 +2557,10 @@ bool Planner::buffer_segment(const float &a, const float &b, const float &c, con
// The target position of the tool in absolute steps
// Calculate target position in absolute steps
const int32_t target[ABCE] = {
LROUND(a * axis_steps_per_mm[A_AXIS]),
LROUND(b * axis_steps_per_mm[B_AXIS]),
LROUND(c * axis_steps_per_mm[C_AXIS]),
LROUND(e * axis_steps_per_mm[E_AXIS_N(extruder)])
LROUND(a * settings.axis_steps_per_mm[A_AXIS]),
LROUND(b * settings.axis_steps_per_mm[B_AXIS]),
LROUND(c * settings.axis_steps_per_mm[C_AXIS]),
LROUND(e * settings.axis_steps_per_mm[E_AXIS_N(extruder)])
};
#if HAS_POSITION_FLOAT
@ -2714,10 +2696,10 @@ void Planner::set_machine_position_mm(const float &a, const float &b, const floa
#if ENABLED(DISTINCT_E_FACTORS)
last_extruder = active_extruder;
#endif
position[A_AXIS] = LROUND(a * axis_steps_per_mm[A_AXIS]);
position[B_AXIS] = LROUND(b * axis_steps_per_mm[B_AXIS]);
position[C_AXIS] = LROUND(c * axis_steps_per_mm[C_AXIS]);
position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
position[A_AXIS] = LROUND(a * settings.axis_steps_per_mm[A_AXIS]);
position[B_AXIS] = LROUND(b * settings.axis_steps_per_mm[B_AXIS]);
position[C_AXIS] = LROUND(c * settings.axis_steps_per_mm[C_AXIS]);
position[E_AXIS] = LROUND(e * settings.axis_steps_per_mm[_EINDEX]);
#if HAS_POSITION_FLOAT
position_float[A_AXIS] = a;
position_float[B_AXIS] = b;
@ -2770,7 +2752,7 @@ void Planner::set_e_position_mm(const float &e) {
#else
const float e_new = e;
#endif
position[E_AXIS] = LROUND(axis_steps_per_mm[axis_index] * e_new);
position[E_AXIS] = LROUND(settings.axis_steps_per_mm[axis_index] * e_new);
#if HAS_POSITION_FLOAT
position_float[E_AXIS] = e_new;
#endif
@ -2792,7 +2774,7 @@ void Planner::reset_acceleration_rates() {
#endif
uint32_t highest_rate = 1;
LOOP_XYZE_N(i) {
max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
max_acceleration_steps_per_s2[i] = settings.max_acceleration_mm_per_s2[i] * settings.axis_steps_per_mm[i];
if (AXIS_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
}
cutoff_long = 4294967295UL / highest_rate; // 0xFFFFFFFFUL
@ -2801,9 +2783,9 @@ void Planner::reset_acceleration_rates() {
#endif
}
// Recalculate position, steps_to_mm if axis_steps_per_mm changes!
// Recalculate position, steps_to_mm if settings.axis_steps_per_mm changes!
void Planner::refresh_positioning() {
LOOP_XYZE_N(i) steps_to_mm[i] = 1.0f / axis_steps_per_mm[i];
LOOP_XYZE_N(i) steps_to_mm[i] = 1.0f / settings.axis_steps_per_mm[i];
set_position_mm(current_position);
reset_acceleration_rates();
}

View File

@ -19,6 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
/**
* planner.h
@ -29,9 +30,6 @@
* Copyright (c) 2009-2011 Simen Svale Skogsrud
*/
#ifndef PLANNER_H
#define PLANNER_H
#include "../Marlin.h"
#include "motion.h"
@ -159,6 +157,42 @@ typedef struct {
#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
typedef struct {
uint32_t max_acceleration_mm_per_s2[XYZE_N], // (mm/s^2) M201 XYZE
min_segment_time_us; // (µs) M205 B
float axis_steps_per_mm[XYZE_N], // (steps) M92 XYZE - Steps per millimeter
max_feedrate_mm_s[XYZE_N], // (mm/s) M203 XYZE - Max speeds
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.
min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate
min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate
} planner_settings_t;
#ifndef XY_SKEW_FACTOR
#define XY_SKEW_FACTOR 0
#endif
#ifndef XZ_SKEW_FACTOR
#define XZ_SKEW_FACTOR 0
#endif
#ifndef YZ_SKEW_FACTOR
#define YZ_SKEW_FACTOR 0
#endif
typedef struct {
#if ENABLED(SKEW_CORRECTION_GCODE)
float xy;
#if ENABLED(SKEW_CORRECTION_FOR_Z)
float xz, yz;
#else
const float xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
#endif
#else
const float xy = XY_SKEW_FACTOR,
xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
#endif
} skew_factor_t;
class Planner {
public:
@ -199,17 +233,10 @@ class Planner {
// May be auto-adjusted by a filament width sensor
#endif
static uint32_t max_acceleration_mm_per_s2[XYZE_N], // (mm/s^2) M201 XYZE
max_acceleration_steps_per_s2[XYZE_N], // (steps/s^2) Derived from mm_per_s2
min_segment_time_us; // (µs) M205 B
static float max_feedrate_mm_s[XYZE_N], // (mm/s) M203 XYZE - Max speeds
axis_steps_per_mm[XYZE_N], // (steps) M92 XYZE - Steps per millimeter
steps_to_mm[XYZE_N], // (mm) Millimeters per step
min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate
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.
min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate
static planner_settings_t settings;
static uint32_t max_acceleration_steps_per_s2[XYZE_N]; // (steps/s^2) Derived from mm_per_s2
static float steps_to_mm[XYZE_N]; // Millimeters per step
#if ENABLED(JUNCTION_DEVIATION)
static float junction_deviation_mm; // (mm) M205 J
@ -256,22 +283,7 @@ class Planner {
static float position_cart[XYZE];
#endif
#if ENABLED(SKEW_CORRECTION)
#if ENABLED(SKEW_CORRECTION_GCODE)
static float xy_skew_factor;
#else
static constexpr float xy_skew_factor = XY_SKEW_FACTOR;
#endif
#if ENABLED(SKEW_CORRECTION_FOR_Z)
#if ENABLED(SKEW_CORRECTION_GCODE)
static float xz_skew_factor, yz_skew_factor;
#else
static constexpr float xz_skew_factor = XZ_SKEW_FACTOR, yz_skew_factor = YZ_SKEW_FACTOR;
#endif
#else
static constexpr float xz_skew_factor = 0, yz_skew_factor = 0;
#endif
#endif
static skew_factor_t skew_factor;
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
static bool abort_on_endstop_hit;
@ -419,8 +431,8 @@ class Planner {
FORCE_INLINE static void skew(float &cx, float &cy, const float &cz) {
if (WITHIN(cx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(cy, Y_MIN_POS + 1, Y_MAX_POS)) {
const float sx = cx - cy * xy_skew_factor - cz * (xz_skew_factor - (xy_skew_factor * yz_skew_factor)),
sy = cy - cz * yz_skew_factor;
const float sx = cx - cy * skew_factor.xy - cz * (skew_factor.xz - (skew_factor.xy * skew_factor.yz)),
sy = cy - cz * skew_factor.yz;
if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) {
cx = sx; cy = sy;
}
@ -431,8 +443,8 @@ class Planner {
FORCE_INLINE static void unskew(float &cx, float &cy, const float &cz) {
if (WITHIN(cx, X_MIN_POS, X_MAX_POS) && WITHIN(cy, Y_MIN_POS, Y_MAX_POS)) {
const float sx = cx + cy * xy_skew_factor + cz * xz_skew_factor,
sy = cy + cz * yz_skew_factor;
const float sx = cx + cy * skew_factor.xy + cz * skew_factor.xz,
sy = cy + cz * skew_factor.yz;
if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) {
cx = sx; cy = sy;
}
@ -848,9 +860,9 @@ class Planner {
#define GET_MAX_E_JERK(N) SQRT(SQRT(0.5) * junction_deviation_mm * (N) * RECIPROCAL(1.0 - SQRT(0.5)))
#if ENABLED(DISTINCT_E_FACTORS)
for (uint8_t i = 0; i < EXTRUDERS; i++)
max_e_jerk[i] = GET_MAX_E_JERK(max_acceleration_mm_per_s2[E_AXIS + i]);
max_e_jerk[i] = GET_MAX_E_JERK(settings.max_acceleration_mm_per_s2[E_AXIS + i]);
#else
max_e_jerk = GET_MAX_E_JERK(max_acceleration_mm_per_s2[E_AXIS]);
max_e_jerk = GET_MAX_E_JERK(settings.max_acceleration_mm_per_s2[E_AXIS]);
#endif
}
#endif
@ -927,15 +939,13 @@ class Planner {
FORCE_INLINE static float limit_value_by_axis_maximum(const float &max_value, float (&unit_vec)[XYZE]) {
float limit_value = max_value;
LOOP_XYZE(idx) if (unit_vec[idx]) // Avoid divide by zero
NOMORE(limit_value, ABS(max_acceleration_mm_per_s2[idx] / unit_vec[idx]));
NOMORE(limit_value, ABS(settings.max_acceleration_mm_per_s2[idx] / unit_vec[idx]));
return limit_value;
}
#endif // JUNCTION_DEVIATION
};
#define PLANNER_XY_FEEDRATE() (MIN(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]))
#define PLANNER_XY_FEEDRATE() (MIN(planner.settings.max_feedrate_mm_s[X_AXIS], planner.settings.max_feedrate_mm_s[Y_AXIS]))
extern Planner planner;
#endif // PLANNER_H

View File

@ -2413,7 +2413,7 @@ void Stepper::report_positions() {
#if HAS_MOTOR_CURRENT_PWM
void Stepper::refresh_motor_power() {
for (uint8_t i = 0; i < COUNT(motor_current_setting); ++i) {
LOOP_L_N(i, COUNT(motor_current_setting)) {
switch (i) {
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
case 0:
@ -2443,7 +2443,7 @@ void Stepper::report_positions() {
#elif HAS_MOTOR_CURRENT_PWM
if (WITHIN(driver, 0, 2))
if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1))
motor_current_setting[driver] = current; // update motor_current_setting
#define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))

View File

@ -606,43 +606,43 @@ void reset_stepper_drivers() {
#endif
#if AXIS_IS_TMC(X)
_TMC_INIT(X, planner.axis_steps_per_mm[X_AXIS]);
_TMC_INIT(X, planner.settings.axis_steps_per_mm[X_AXIS]);
#endif
#if AXIS_IS_TMC(X2)
_TMC_INIT(X2, planner.axis_steps_per_mm[X_AXIS]);
_TMC_INIT(X2, planner.settings.axis_steps_per_mm[X_AXIS]);
#endif
#if AXIS_IS_TMC(Y)
_TMC_INIT(Y, planner.axis_steps_per_mm[Y_AXIS]);
_TMC_INIT(Y, planner.settings.axis_steps_per_mm[Y_AXIS]);
#endif
#if AXIS_IS_TMC(Y2)
_TMC_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]);
_TMC_INIT(Y2, planner.settings.axis_steps_per_mm[Y_AXIS]);
#endif
#if AXIS_IS_TMC(Z)
_TMC_INIT(Z, planner.axis_steps_per_mm[Z_AXIS]);
_TMC_INIT(Z, planner.settings.axis_steps_per_mm[Z_AXIS]);
#endif
#if AXIS_IS_TMC(Z2)
_TMC_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]);
_TMC_INIT(Z2, planner.settings.axis_steps_per_mm[Z_AXIS]);
#endif
#if AXIS_IS_TMC(Z3)
_TMC_INIT(Z3, planner.axis_steps_per_mm[Z_AXIS]);
_TMC_INIT(Z3, planner.settings.axis_steps_per_mm[Z_AXIS]);
#endif
#if AXIS_IS_TMC(E0)
_TMC_INIT(E0, planner.axis_steps_per_mm[E_AXIS_N(0)]);
_TMC_INIT(E0, planner.settings.axis_steps_per_mm[E_AXIS_N(0)]);
#endif
#if AXIS_IS_TMC(E1)
_TMC_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N(1)]);
_TMC_INIT(E1, planner.settings.axis_steps_per_mm[E_AXIS_N(1)]);
#endif
#if AXIS_IS_TMC(E2)
_TMC_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N(2)]);
_TMC_INIT(E2, planner.settings.axis_steps_per_mm[E_AXIS_N(2)]);
#endif
#if AXIS_IS_TMC(E3)
_TMC_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N(3)]);
_TMC_INIT(E3, planner.settings.axis_steps_per_mm[E_AXIS_N(3)]);
#endif
#if AXIS_IS_TMC(E4)
_TMC_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N(4)]);
_TMC_INIT(E4, planner.settings.axis_steps_per_mm[E_AXIS_N(4)]);
#endif
#if AXIS_IS_TMC(E5)
_TMC_INIT(E5, planner.axis_steps_per_mm[E_AXIS_N(5)]);
_TMC_INIT(E5, planner.settings.axis_steps_per_mm[E_AXIS_N(5)]);
#endif
#if USE_SENSORLESS

View File

@ -116,13 +116,7 @@ int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
millis_t Temperature::watch_bed_next_ms = 0;
#endif
#if ENABLED(PIDTEMPBED)
float Temperature::bedKp, Temperature::bedKi, Temperature::bedKd, // Initialized by settings.load()
Temperature::temp_iState_bed = { 0 },
Temperature::temp_dState_bed = { 0 },
Temperature::pTerm_bed,
Temperature::iTerm_bed,
Temperature::dTerm_bed,
Temperature::pid_error_bed;
PID_t Temperature::bed_pid; // Initialized by settings.load()
#else
millis_t Temperature::next_bed_check_ms;
#endif
@ -141,17 +135,7 @@ int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
// Initialized by settings.load()
#if ENABLED(PIDTEMP)
#if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
float Temperature::Kp[HOTENDS], Temperature::Ki[HOTENDS], Temperature::Kd[HOTENDS];
#if ENABLED(PID_EXTRUSION_SCALING)
float Temperature::Kc[HOTENDS];
#endif
#else
float Temperature::Kp, Temperature::Ki, Temperature::Kd;
#if ENABLED(PID_EXTRUSION_SCALING)
float Temperature::Kc;
#endif
#endif
hotend_pid_t Temperature::pid[HOTENDS];
#endif
#if ENABLED(BABYSTEPPING)
@ -182,21 +166,11 @@ int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
volatile bool Temperature::temp_meas_ready = false;
#if ENABLED(PIDTEMP)
float Temperature::temp_iState[HOTENDS] = { 0 },
Temperature::temp_dState[HOTENDS] = { 0 },
Temperature::pTerm[HOTENDS],
Temperature::iTerm[HOTENDS],
Temperature::dTerm[HOTENDS];
#if ENABLED(PID_EXTRUSION_SCALING)
float Temperature::cTerm[HOTENDS];
long Temperature::last_e_position;
long Temperature::lpq[LPQ_MAX_LEN];
int Temperature::lpq_ptr = 0;
#endif
float Temperature::pid_error[HOTENDS];
bool Temperature::pid_reset[HOTENDS];
#endif
uint16_t Temperature::raw_temp_value[MAX_EXTRUDERS] = { 0 };
@ -254,6 +228,8 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
#if HAS_PID_HEATING
inline void say_default_() { SERIAL_PROTOCOLPGM("#define DEFAULT_"); }
/**
* PID Autotuning (M303)
*
@ -269,9 +245,8 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
long t_high = 0, t_low = 0;
long bias, d;
float Ku, Tu,
workKp = 0, workKi = 0, workKd = 0,
max = 0, min = 10000;
PID_t tune_pid = { 0, 0, 0 };
float max = 0, min = 10000;
#if HAS_PID_FOR_BOTH
#define GHV(B,H) (hotend < 0 ? (B) : (H))
@ -375,32 +350,32 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
SERIAL_PROTOCOLPAIR(MSG_T_MIN, min);
SERIAL_PROTOCOLPAIR(MSG_T_MAX, max);
if (cycles > 2) {
Ku = (4.0f * d) / (float(M_PI) * (max - min) * 0.5f);
Tu = ((float)(t_low + t_high) * 0.001f);
float Ku = (4.0f * d) / (float(M_PI) * (max - min) * 0.5f),
Tu = ((float)(t_low + t_high) * 0.001f);
SERIAL_PROTOCOLPAIR(MSG_KU, Ku);
SERIAL_PROTOCOLPAIR(MSG_TU, Tu);
workKp = 0.6f * Ku;
workKi = 2 * workKp / Tu;
workKd = workKp * Tu * 0.125f;
tune_pid.Kp = 0.6f * Ku;
tune_pid.Ki = 2 * tune_pid.Kp / Tu;
tune_pid.Kd = tune_pid.Kp * Tu * 0.125f;
SERIAL_PROTOCOLLNPGM("\n" MSG_CLASSIC_PID);
SERIAL_PROTOCOLPAIR(MSG_KP, workKp);
SERIAL_PROTOCOLPAIR(MSG_KI, workKi);
SERIAL_PROTOCOLLNPAIR(MSG_KD, workKd);
SERIAL_PROTOCOLPAIR(MSG_KP, tune_pid.Kp);
SERIAL_PROTOCOLPAIR(MSG_KI, tune_pid.Ki);
SERIAL_PROTOCOLLNPAIR(MSG_KD, tune_pid.Kd);
/**
workKp = 0.33*Ku;
workKi = workKp/Tu;
workKd = workKp*Tu/3;
tune_pid.Kp = 0.33*Ku;
tune_pid.Ki = tune_pid.Kp/Tu;
tune_pid.Kd = tune_pid.Kp*Tu/3;
SERIAL_PROTOCOLLNPGM(" Some overshoot");
SERIAL_PROTOCOLPAIR(" Kp: ", workKp);
SERIAL_PROTOCOLPAIR(" Ki: ", workKi);
SERIAL_PROTOCOLPAIR(" Kd: ", workKd);
workKp = 0.2*Ku;
workKi = 2*workKp/Tu;
workKd = workKp*Tu/3;
SERIAL_PROTOCOLPAIR(" Kp: ", tune_pid.Kp);
SERIAL_PROTOCOLPAIR(" Ki: ", tune_pid.Ki);
SERIAL_PROTOCOLPAIR(" Kd: ", tune_pid.Kd);
tune_pid.Kp = 0.2*Ku;
tune_pid.Ki = 2*tune_pid.Kp/Tu;
tune_pid.Kd = tune_pid.Kp*Tu/3;
SERIAL_PROTOCOLLNPGM(" No overshoot");
SERIAL_PROTOCOLPAIR(" Kp: ", workKp);
SERIAL_PROTOCOLPAIR(" Ki: ", workKi);
SERIAL_PROTOCOLPAIR(" Kd: ", workKd);
SERIAL_PROTOCOLPAIR(" Kp: ", tune_pid.Kp);
SERIAL_PROTOCOLPAIR(" Ki: ", tune_pid.Ki);
SERIAL_PROTOCOLPAIR(" Kd: ", tune_pid.Kd);
*/
}
}
@ -467,39 +442,36 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
#if HAS_PID_FOR_BOTH
const char* estring = GHV("bed", "");
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kp ", workKp); SERIAL_EOL();
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Ki ", workKi); SERIAL_EOL();
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kd ", workKd); SERIAL_EOL();
const char * const estring = GHV(PSTR("bed"), PSTR(""));
say_default_(); serialprintPGM(estring); SERIAL_PROTOCOLLNPAIR("Kp ", tune_pid.Kp);
say_default_(); serialprintPGM(estring); SERIAL_PROTOCOLLNPAIR("Ki ", tune_pid.Ki);
say_default_(); serialprintPGM(estring); SERIAL_PROTOCOLLNPAIR("Kd ", tune_pid.Kd);
#elif ENABLED(PIDTEMP)
SERIAL_PROTOCOLPAIR("#define DEFAULT_Kp ", workKp); SERIAL_EOL();
SERIAL_PROTOCOLPAIR("#define DEFAULT_Ki ", workKi); SERIAL_EOL();
SERIAL_PROTOCOLPAIR("#define DEFAULT_Kd ", workKd); SERIAL_EOL();
say_default_(); SERIAL_PROTOCOLLNPAIR("Kp ", tune_pid.Kp);
say_default_(); SERIAL_PROTOCOLLNPAIR("Ki ", tune_pid.Ki);
say_default_(); SERIAL_PROTOCOLLNPAIR("Kd ", tune_pid.Kd);
#else
SERIAL_PROTOCOLPAIR("#define DEFAULT_bedKp ", workKp); SERIAL_EOL();
SERIAL_PROTOCOLPAIR("#define DEFAULT_bedKi ", workKi); SERIAL_EOL();
SERIAL_PROTOCOLPAIR("#define DEFAULT_bedKd ", workKd); SERIAL_EOL();
say_default_(); SERIAL_PROTOCOLLNPAIR("bedKp ", tune_pid.Kp);
say_default_(); SERIAL_PROTOCOLLNPAIR("bedKi ", tune_pid.Ki);
say_default_(); SERIAL_PROTOCOLLNPAIR("bedKd ", tune_pid.Kd);
#endif
#define _SET_BED_PID() do { \
bedKp = workKp; \
bedKi = scalePID_i(workKi); \
bedKd = scalePID_d(workKd); \
bed_pid.Kp = tune_pid.Kp; \
bed_pid.Ki = scalePID_i(tune_pid.Ki); \
bed_pid.Kd = scalePID_d(tune_pid.Kd); \
}while(0)
#define _SET_EXTRUDER_PID() do { \
PID_PARAM(Kp, hotend) = workKp; \
PID_PARAM(Ki, hotend) = scalePID_i(workKi); \
PID_PARAM(Kd, hotend) = scalePID_d(workKd); \
PID_PARAM(Kp, hotend) = tune_pid.Kp; \
PID_PARAM(Ki, hotend) = scalePID_i(tune_pid.Ki); \
PID_PARAM(Kd, hotend) = scalePID_d(tune_pid.Kd); \
updatePID(); }while(0)
// Use the result? (As with "M303 U1")
if (set_result) {
#if HAS_PID_FOR_BOTH
if (hotend < 0)
_SET_BED_PID();
else
_SET_EXTRUDER_PID();
if (hotend < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
#elif ENABLED(PIDTEMP)
_SET_EXTRUDER_PID();
#else
@ -612,15 +584,19 @@ void Temperature::min_temp_error(const int8_t e) {
float Temperature::get_pid_output(const int8_t e) {
#if HOTENDS == 1
UNUSED(e);
#define _HOTEND_TEST true
#define _HOTEND_TEST true
#else
#define _HOTEND_TEST e == active_extruder
#define _HOTEND_TEST (e == active_extruder)
#endif
float pid_output;
#if ENABLED(PIDTEMP)
#if DISABLED(PID_OPENLOOP)
pid_error[HOTEND_INDEX] = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
dTerm[HOTEND_INDEX] = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + float(PID_K1) * dTerm[HOTEND_INDEX];
static hotend_pid_t work_pid[HOTENDS];
static float temp_iState[HOTENDS] = { 0 },
temp_dState[HOTENDS] = { 0 };
static bool pid_reset[HOTENDS] = { false };
float pid_output,
pid_error = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
work_pid[HOTEND_INDEX].Kd = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + float(PID_K1) * work_pid[HOTEND_INDEX].Kd;
temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX];
#if HEATER_IDLE_HANDLER
if (heater_idle_timeout_exceeded[HOTEND_INDEX]) {
@ -629,57 +605,60 @@ float Temperature::get_pid_output(const int8_t e) {
}
else
#endif
if (pid_error[HOTEND_INDEX] > PID_FUNCTIONAL_RANGE) {
pid_output = BANG_MAX;
pid_reset[HOTEND_INDEX] = true;
}
else if (pid_error[HOTEND_INDEX] < -(PID_FUNCTIONAL_RANGE) || target_temperature[HOTEND_INDEX] == 0
#if HEATER_IDLE_HANDLER
|| heater_idle_timeout_exceeded[HOTEND_INDEX]
#endif
) {
pid_output = 0;
pid_reset[HOTEND_INDEX] = true;
}
else {
if (pid_reset[HOTEND_INDEX]) {
temp_iState[HOTEND_INDEX] = 0.0;
pid_reset[HOTEND_INDEX] = false;
}
pTerm[HOTEND_INDEX] = PID_PARAM(Kp, HOTEND_INDEX) * pid_error[HOTEND_INDEX];
temp_iState[HOTEND_INDEX] += pid_error[HOTEND_INDEX];
iTerm[HOTEND_INDEX] = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
pid_output = pTerm[HOTEND_INDEX] + iTerm[HOTEND_INDEX] - dTerm[HOTEND_INDEX];
#if ENABLED(PID_EXTRUSION_SCALING)
cTerm[HOTEND_INDEX] = 0;
if (_HOTEND_TEST) {
const long e_position = stepper.position(E_AXIS);
if (e_position > last_e_position) {
lpq[lpq_ptr] = e_position - last_e_position;
last_e_position = e_position;
}
else
lpq[lpq_ptr] = 0;
if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
pid_output += cTerm[HOTEND_INDEX];
if (pid_error > PID_FUNCTIONAL_RANGE) {
pid_output = BANG_MAX;
pid_reset[HOTEND_INDEX] = true;
}
#endif // PID_EXTRUSION_SCALING
else if (pid_error < -(PID_FUNCTIONAL_RANGE) || target_temperature[HOTEND_INDEX] == 0
#if HEATER_IDLE_HANDLER
|| heater_idle_timeout_exceeded[HOTEND_INDEX]
#endif
) {
pid_output = 0;
pid_reset[HOTEND_INDEX] = true;
}
else {
if (pid_reset[HOTEND_INDEX]) {
temp_iState[HOTEND_INDEX] = 0.0;
pid_reset[HOTEND_INDEX] = false;
}
temp_iState[HOTEND_INDEX] += pid_error;
work_pid[HOTEND_INDEX].Kp = PID_PARAM(Kp, HOTEND_INDEX) * pid_error;
work_pid[HOTEND_INDEX].Ki = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
pid_output = work_pid[HOTEND_INDEX].Kp + work_pid[HOTEND_INDEX].Ki - work_pid[HOTEND_INDEX].Kd;
#if ENABLED(PID_EXTRUSION_SCALING)
work_pid[HOTEND_INDEX].Kc = 0;
if (_HOTEND_TEST) {
const long e_position = stepper.position(E_AXIS);
if (e_position > last_e_position) {
lpq[lpq_ptr] = e_position - last_e_position;
last_e_position = e_position;
}
else
lpq[lpq_ptr] = 0;
if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
work_pid[HOTEND_INDEX].Kc = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
pid_output += work_pid[HOTEND_INDEX].Kc;
}
#endif // PID_EXTRUSION_SCALING
if (pid_output > PID_MAX) {
if (pid_error > 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
pid_output = PID_MAX;
}
else if (pid_output < 0) {
if (pid_error < 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
pid_output = 0;
}
}
#else // PID_OPENLOOP
const float pid_output = constrain(target_temperature[HOTEND_INDEX], 0, PID_MAX);
if (pid_output > PID_MAX) {
if (pid_error[HOTEND_INDEX] > 0) temp_iState[HOTEND_INDEX] -= pid_error[HOTEND_INDEX]; // conditional un-integration
pid_output = PID_MAX;
}
else if (pid_output < 0) {
if (pid_error[HOTEND_INDEX] < 0) temp_iState[HOTEND_INDEX] -= pid_error[HOTEND_INDEX]; // conditional un-integration
pid_output = 0;
}
}
#else
pid_output = constrain(target_temperature[HOTEND_INDEX], 0, PID_MAX);
#endif // PID_OPENLOOP
#if ENABLED(PID_DEBUG)
@ -687,11 +666,13 @@ float Temperature::get_pid_output(const int8_t e) {
SERIAL_ECHOPAIR(MSG_PID_DEBUG, HOTEND_INDEX);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_INPUT, current_temperature[HOTEND_INDEX]);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_OUTPUT, pid_output);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_PTERM, pTerm[HOTEND_INDEX]);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_ITERM, iTerm[HOTEND_INDEX]);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_DTERM, dTerm[HOTEND_INDEX]);
#if ENABLED(PID_EXTRUSION_SCALING)
SERIAL_ECHOPAIR(MSG_PID_DEBUG_CTERM, cTerm[HOTEND_INDEX]);
#if DISABLED(PID_OPENLOOP)
SERIAL_ECHOPAIR(MSG_PID_DEBUG_PTERM, work_pid[HOTEND_INDEX].Kp);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_ITERM, work_pid[HOTEND_INDEX].Ki);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_DTERM, work_pid[HOTEND_INDEX].Kd);
#if ENABLED(PID_EXTRUSION_SCALING)
SERIAL_ECHOPAIR(MSG_PID_DEBUG_CTERM, work_pid[HOTEND_INDEX].Kc);
#endif
#endif
SERIAL_EOL();
#endif // PID_DEBUG
@ -709,47 +690,52 @@ float Temperature::get_pid_output(const int8_t e) {
}
#if ENABLED(PIDTEMPBED)
float Temperature::get_pid_output_bed() {
float pid_output;
#if DISABLED(PID_OPENLOOP)
pid_error_bed = target_temperature_bed - current_temperature_bed;
pTerm_bed = bedKp * pid_error_bed;
temp_iState_bed += pid_error_bed;
iTerm_bed = bedKi * temp_iState_bed;
dTerm_bed = PID_K2 * bedKd * (current_temperature_bed - temp_dState_bed) + PID_K1 * dTerm_bed;
temp_dState_bed = current_temperature_bed;
static PID_t work_pid = { 0 };
static float temp_iState = 0, temp_dState = 0;
pid_output = pTerm_bed + iTerm_bed - dTerm_bed;
float pid_error = target_temperature_bed - current_temperature_bed;
temp_iState += pid_error;
work_pid.Kp = bed_pid.Kp * pid_error;
work_pid.Ki = bed_pid.Ki * temp_iState;
work_pid.Kd = PID_K2 * bed_pid.Kd * (current_temperature_bed - temp_dState) + PID_K1 * work_pid.Kd;
temp_dState = current_temperature_bed;
float pid_output = work_pid.Kp + work_pid.Ki - work_pid.Kd;
if (pid_output > MAX_BED_POWER) {
if (pid_error_bed > 0) temp_iState_bed -= pid_error_bed; // conditional un-integration
if (pid_error > 0) temp_iState -= pid_error; // conditional un-integration
pid_output = MAX_BED_POWER;
}
else if (pid_output < 0) {
if (pid_error_bed < 0) temp_iState_bed -= pid_error_bed; // conditional un-integration
if (pid_error < 0) temp_iState -= pid_error; // conditional un-integration
pid_output = 0;
}
#else
pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
#else // PID_OPENLOOP
const float pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
#endif // PID_OPENLOOP
#if ENABLED(PID_BED_DEBUG)
SERIAL_ECHO_START();
SERIAL_ECHOPGM(" PID_BED_DEBUG ");
SERIAL_ECHOPGM(": Input ");
SERIAL_ECHO(current_temperature_bed);
SERIAL_ECHOPGM(" Output ");
SERIAL_ECHO(pid_output);
SERIAL_ECHOPGM(" pTerm ");
SERIAL_ECHO(pTerm_bed);
SERIAL_ECHOPGM(" iTerm ");
SERIAL_ECHO(iTerm_bed);
SERIAL_ECHOPGM(" dTerm ");
SERIAL_ECHOLN(dTerm_bed);
#endif // PID_BED_DEBUG
SERIAL_ECHOPAIR(" PID_BED_DEBUG : Input ", current_temperature_bed);
SERIAL_ECHOPAIR(" Output ", pid_output);
#if DISABLED(PID_OPENLOOP)
SERIAL_ECHOPAIR(MSG_PID_DEBUG_PTERM, work_pid.Kp);
SERIAL_ECHOPAIR(MSG_PID_DEBUG_ITERM, work_pid.Ki);
SERIAL_ECHOLNPAIR(MSG_PID_DEBUG_DTERM, work_pid.Kd);
#endif
#endif
return pid_output;
}
#endif // PIDTEMPBED
/**

View File

@ -48,6 +48,35 @@
#define HOTEND_INDEX e
#endif
// PID storage
typedef struct { float Kp, Ki, Kd; } PID_t;
typedef struct { float Kp, Ki, Kd, Kc; } PIDC_t;
#if ENABLED(PID_EXTRUSION_SCALING)
typedef PIDC_t hotend_pid_t;
#else
typedef PID_t hotend_pid_t;
#endif
#define DUMMY_PID_VALUE 3000.0f
#if ENABLED(PIDTEMP)
#define _PID_Kp(H) Temperature::pid[H].Kp
#define _PID_Ki(H) Temperature::pid[H].Ki
#define _PID_Kd(H) Temperature::pid[H].Kd
#if ENABLED(PID_EXTRUSION_SCALING)
#define _PID_Kc(H) Temperature::pid[H].Kc
#else
#define _PID_Kc(H) 1
#endif
#else
#define _PID_Kp(H) DUMMY_PID_VALUE
#define _PID_Ki(H) DUMMY_PID_VALUE
#define _PID_Kd(H) DUMMY_PID_VALUE
#define _PID_Kc(H) 1
#endif
#define PID_PARAM(F,H) _PID_##F(H)
/**
* States for ADC reading in the ISR
*/
@ -132,25 +161,7 @@ class Temperature {
#endif
#if ENABLED(PIDTEMP)
#if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
static float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
#if ENABLED(PID_EXTRUSION_SCALING)
static float Kc[HOTENDS];
#endif
#define PID_PARAM(param, h) Temperature::param[h]
#else
static float Kp, Ki, Kd;
#if ENABLED(PID_EXTRUSION_SCALING)
static float Kc;
#endif
#define PID_PARAM(param, h) Temperature::param
#endif // PID_PARAMS_PER_HOTEND
static hotend_pid_t pid[HOTENDS];
#endif
#if HAS_HEATED_BED
@ -158,7 +169,7 @@ class Temperature {
static int16_t current_temperature_bed_raw, target_temperature_bed;
static uint8_t soft_pwm_amount_bed;
#if ENABLED(PIDTEMPBED)
static float bedKp, bedKi, bedKd;
static PID_t bed_pid;
#endif
#endif
@ -210,21 +221,11 @@ class Temperature {
#endif
#if ENABLED(PIDTEMP)
static float temp_iState[HOTENDS],
temp_dState[HOTENDS],
pTerm[HOTENDS],
iTerm[HOTENDS],
dTerm[HOTENDS];
#if ENABLED(PID_EXTRUSION_SCALING)
static float cTerm[HOTENDS];
static long last_e_position;
static long lpq[LPQ_MAX_LEN];
static int lpq_ptr;
#endif
static float pid_error[HOTENDS];
static bool pid_reset[HOTENDS];
#endif
// Init min and max temp with extreme values to prevent false errors during startup
@ -239,14 +240,7 @@ class Temperature {
static uint16_t watch_target_bed_temp;
static millis_t watch_bed_next_ms;
#endif
#if ENABLED(PIDTEMPBED)
static float temp_iState_bed,
temp_dState_bed,
pTerm_bed,
iTerm_bed,
dTerm_bed,
pid_error_bed;
#else
#if DISABLED(PIDTEMPBED)
static millis_t next_bed_check_ms;
#endif
#if HEATER_IDLE_HANDLER

View File

@ -30,9 +30,7 @@
#include "../Marlin.h"
#if ENABLED(SINGLENOZZLE)
float singlenozzle_swap_length = SINGLENOZZLE_SWAP_LENGTH;
int16_t singlenozzle_prime_speed = SINGLENOZZLE_SWAP_PRIME_SPEED,
singlenozzle_retract_speed = SINGLENOZZLE_SWAP_RETRACT_SPEED;
singlenozzle_settings_t sn_settings; // Initialized by settings.load()
uint16_t singlenozzle_temp[EXTRUDERS];
#if FAN_COUNT > 0
uint8_t singlenozzle_fan_speed[EXTRUDERS];
@ -152,7 +150,7 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.synchronize();
// STEP 2
@ -163,7 +161,7 @@
DEBUG_POS("Moving ParkPos", current_position);
}
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.synchronize();
// STEP 3
@ -181,7 +179,7 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.synchronize();
// STEP 5
@ -196,12 +194,12 @@
// STEP 6
current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10);
planner.buffer_line(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
current_position[X_AXIS] = grabpos;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(6) Unpark extruder", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[X_AXIS]/2, active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS]/2, active_extruder);
planner.synchronize();
// Step 7
@ -209,7 +207,7 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(7) Move midway between hotends", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.synchronize();
#if ENABLED(DEBUG_LEVELING_FEATURE)
SERIAL_ECHOLNPGM("Autopark done.");
@ -259,7 +257,7 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.synchronize();
// STEP 2
@ -270,14 +268,14 @@
DEBUG_POS("Move X SwitchPos", current_position);
}
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.synchronize();
current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Y_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
planner.synchronize();
// STEP 3
@ -291,14 +289,14 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
#endif
planner.buffer_line(current_position,(planner.max_feedrate_mm_s[Y_AXIS] * 0.5), active_extruder);
planner.buffer_line(current_position,(planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5), active_extruder);
planner.synchronize();
safe_delay(200);
current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
planner.synchronize();
// STEP 4
@ -309,13 +307,13 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.synchronize();
current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Y_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
planner.synchronize();
// STEP 5
@ -326,7 +324,7 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Y_AXIS] * 0.5, active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5, active_extruder);
planner.synchronize();
safe_delay(200);
@ -337,7 +335,7 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
#endif
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
planner.synchronize();
// STEP 6
@ -413,9 +411,9 @@ inline void invalid_extruder_error(const uint8_t e) {
#define CUR_Z current_position[Z_AXIS]
#define CUR_E current_position[E_AXIS]
planner.buffer_line(CUR_X, CUR_Y, raised_z, CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(xhome, CUR_Y, raised_z, CUR_E, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(xhome, CUR_Y, CUR_Z, CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(CUR_X, CUR_Y, raised_z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(xhome, CUR_Y, raised_z, CUR_E, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
planner.buffer_line(xhome, CUR_Y, CUR_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.synchronize();
}
@ -556,7 +554,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#if ENABLED(SWITCHING_NOZZLE)
// Always raise by at least 1 to avoid workpiece
current_position[Z_AXIS] += MAX(-zdiff, 0.0) + 1;
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
move_nozzle_servo(tmp_extruder);
#endif
#endif
@ -595,7 +593,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#if DISABLED(SWITCHING_NOZZLE)
// Do a small lift to avoid the workpiece in the move back (below)
current_position[Z_AXIS] += 1.0;
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move back", destination);
@ -616,7 +614,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#if ENABLED(SWITCHING_NOZZLE)
else {
// Move back down. (Including when the new tool is higher.)
do_blocking_move_to_z(destination[Z_AXIS], planner.max_feedrate_mm_s[Z_AXIS]);
do_blocking_move_to_z(destination[Z_AXIS], planner.settings.max_feedrate_mm_s[Z_AXIS]);
}
#endif
} // (tmp_extruder != active_extruder)
@ -663,12 +661,12 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
set_destination_from_current();
if (singlenozzle_swap_length) {
if (sn_settings.swap_length) {
#if ENABLED(ADVANCED_PAUSE_FEATURE)
do_pause_e_move(-singlenozzle_swap_length, MMM_TO_MMS(singlenozzle_retract_speed));
do_pause_e_move(-sn_settings.swap_length, MMM_TO_MMS(sn_settings.retract_speed));
#else
current_position[E_AXIS] -= singlenozzle_swap_length / planner.e_factor[active_extruder];
planner.buffer_line(current_position, MMM_TO_MMS(singlenozzle_retract_speed), active_extruder);
current_position[E_AXIS] -= sn_settings.swap_length / planner.e_factor[active_extruder];
planner.buffer_line(current_position, MMM_TO_MMS(sn_settings.retract_speed), active_extruder);
#endif
}
@ -680,7 +678,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#endif
);
planner.buffer_line(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
#if ENABLED(SINGLENOZZLE_SWAP_PARK)
current_position[X_AXIS] = singlenozzle_change_point.x;
@ -699,12 +697,12 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
active_extruder = tmp_extruder;
if (singlenozzle_swap_length) {
if (sn_settings.swap_length) {
#if ENABLED(ADVANCED_PAUSE_FEATURE)
do_pause_e_move(singlenozzle_swap_length, singlenozzle_prime_speed);
do_pause_e_move(sn_settings.swap_length, sn_settings.prime_speed);
#else
current_position[E_AXIS] += singlenozzle_swap_length / planner.e_factor[tmp_extruder];
planner.buffer_line(current_position, singlenozzle_prime_speed, tmp_extruder);
current_position[E_AXIS] += sn_settings.swap_length / planner.e_factor[tmp_extruder];
planner.buffer_line(current_position, sn_settings.prime_speed, tmp_extruder);
#endif
}

View File

@ -19,11 +19,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#ifndef TOOL_CHANGE_H
#define TOOL_CHANGE_H
#include "../inc/MarlinConfig.h"
#include "../inc/MarlinConfigPre.h"
#if DO_SWITCH_EXTRUDER
void move_extruder_servo(const uint8_t e);
@ -51,9 +49,11 @@
#endif // PARKING_EXTRUDER
#if ENABLED(SINGLENOZZLE)
extern float singlenozzle_swap_length;
extern int16_t singlenozzle_prime_speed,
singlenozzle_retract_speed;
typedef struct {
float swap_length;
int16_t prime_speed, retract_speed;
} singlenozzle_settings_t;
extern singlenozzle_settings_t sn_settings;
extern uint16_t singlenozzle_temp[EXTRUDERS];
#if FAN_COUNT > 0
extern uint8_t singlenozzle_fan_speed[EXTRUDERS];
@ -65,5 +65,3 @@
* previous tool out of the way and the new tool into place.
*/
void tool_change(const uint8_t tmp_extruder, const float fr_mm_s=0.0, bool no_move=false);
#endif // TOOL_CHANGE_H