Skip to content

Commit

Permalink
PID_ADD_EXTRUSION_RATE based on MarlinKimbra
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 20, 2016
1 parent 92ac133 commit 0c7c450
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Marlin/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,29 @@ float Temperature::get_pid_output(int e) {

pid_output = pTerm[e] + iTerm[e] - dTerm[e];

#if ENABLED(SINGLENOZZLE)
#define _NOZZLE_TEST true
#define _NOZZLE_EXTRUDER active_extruder
#define _CTERM_INDEX 0
#else
#define _NOZZLE_TEST e == active_extruder
#define _NOZZLE_EXTRUDER e
#define _CTERM_INDEX e
#endif

#if ENABLED(PID_ADD_EXTRUSION_RATE)
cTerm[e] = 0;
if (e == active_extruder) {
cTerm[_CTERM_INDEX] = 0;
if (_NOZZLE_TEST) {
long e_position = stepper.position(E_AXIS);
if (e_position > last_position[e]) {
lpq[lpq_ptr++] = e_position - last_position[e];
last_position[e] = e_position;
if (e_position > last_position[_NOZZLE_EXTRUDER]) {
lpq[lpq_ptr++] = e_position - last_position[_NOZZLE_EXTRUDER];
last_position[_NOZZLE_EXTRUDER] = e_position;
}
else {
lpq[lpq_ptr++] = 0;
}
if (lpq_ptr >= lpq_len) lpq_ptr = 0;
cTerm[e] = (lpq[lpq_ptr] / planner.axis_steps_per_unit[E_AXIS]) * PID_PARAM(Kc, e);
cTerm[_CTERM_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_unit[E_AXIS]) * PID_PARAM(Kc, e);
pid_output += cTerm[e];
}
#endif //PID_ADD_EXTRUSION_RATE
Expand Down

0 comments on commit 0c7c450

Please sign in to comment.