Skip to content

Commit

Permalink
Enforce sensor range for temperature target (MarlinFirmware#18465)
Browse files Browse the repository at this point in the history
* Mitigate stepper timeout

* Add CHAMBER PWM code

* Structured thermistor tables

* Fix reversed sensor ranges

* Prevent temps outside sensor range
  • Loading branch information
thinkyhead authored and Alexander Yasnogor committed Aug 7, 2020
1 parent 11d50a7 commit 49b7f61
Show file tree
Hide file tree
Showing 56 changed files with 296 additions and 168 deletions.
23 changes: 11 additions & 12 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ bool wait_for_heatup = true;

#endif

// Inactivity shutdown
millis_t max_inactive_time, // = 0
stepper_inactive_time = SEC_TO_MS(DEFAULT_STEPPER_DEACTIVE_TIME);

#if PIN_EXISTS(CHDK)
extern millis_t chdk_timeout;
#endif
Expand Down Expand Up @@ -469,20 +465,23 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {

const millis_t ms = millis();

if (max_inactive_time && ELAPSED(ms, gcode.previous_move_ms + max_inactive_time)) {
// Prevent steppers timing-out in the middle of M600
#define STAY_TEST (BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT) && did_pause_print)

if (STAY_TEST || ignore_stepper_queue)
gcode.reset_stepper_timeout(ms);

if (gcode.stepper_max_timed_out(ms)) {
SERIAL_ERROR_START();
SERIAL_ECHOLNPAIR(STR_KILL_INACTIVE_TIME, parser.command_ptr);
kill();
}

// Prevent steppers timing-out in the middle of M600
#define STAY_TEST (BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT) && did_pause_print)

if (stepper_inactive_time) {
if (gcode.stepper_inactive_time) {
static bool already_shutdown_steppers; // = false
if (planner.has_blocks_queued())
gcode.reset_stepper_timeout();
else if (!STAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) {
gcode.reset_stepper_timeout(ms);
else if (!STAY_TEST && !ignore_stepper_queue && gcode.stepper_inactive_timeout()) {
if (!already_shutdown_steppers) {
already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this
if (ENABLED(DISABLE_INACTIVE_X)) DISABLE_AXIS_X();
Expand Down Expand Up @@ -601,7 +600,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}
#endif // !SWITCHING_EXTRUDER

gcode.reset_stepper_timeout();
gcode.reset_stepper_timeout(ms);
}
#endif // EXTRUDER_RUNOUT_PREVENT

Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ extern bool wait_for_heatup;
void wait_for_user_response(millis_t ms=0, const bool no_sleep=false);
#endif

// Inactivity shutdown timer
extern millis_t max_inactive_time, stepper_inactive_time;

#if ENABLED(PSU_CONTROL)
extern bool powersupply_on;
#define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_HIGH); powersupply_on = true; }while(0)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/ubl/ubl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
if (human) SERIAL_CHAR(is_current ? ']' : ' ');

SERIAL_FLUSHTX();
idle();
idle_no_sleep();
}
if (!lcd) SERIAL_EOL();

Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
*/
G29_TYPE GcodeSuite::G29() {

reset_stepper_timeout();

const bool seenQ = EITHER(DEBUG_LEVELING_FEATURE, PROBE_MANUALLY) && parser.seen('Q');

// G29 Q is also available if debugging
Expand Down Expand Up @@ -675,7 +677,7 @@ G29_TYPE GcodeSuite::G29() {
#endif

abl_should_enable = false;
idle();
idle_no_sleep();

} // inner
} // outer
Expand Down
11 changes: 7 additions & 4 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@
*/
void GcodeSuite::G28() {

#if ENABLED(LASER_MOVE_G28_OFF)
cutter.set_inline_enabled(false); // turn off laser
#endif

if (DEBUGGING(LEVELING)) {
DEBUG_ECHOLNPGM(">>> G28");
log_machine_info();
}

#if ENABLED(LASER_MOVE_G28_OFF)
cutter.set_inline_enabled(false); // turn off laser
#endif

TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);

#if ENABLED(DUAL_X_CARRIAGE)
Expand Down Expand Up @@ -251,6 +251,9 @@ void GcodeSuite::G28() {

TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY);

// Count this command as movement / activity
reset_stepper_timeout();

#define HAS_CURRENT_HOME(N) (defined(N##_CURRENT_HOME) && N##_CURRENT_HOME != N##_CURRENT)
#if HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(X2) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Y2)
#define HAS_HOMING_CURRENT 1
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/gcode/control/M17_M18_M84.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void GcodeSuite::M17() {
*/
void GcodeSuite::M18_M84() {
if (parser.seenval('S')) {
reset_stepper_timeout();
stepper_inactive_time = parser.value_millis_from_seconds();
}
else {
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/gcode/control/M85.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

#include "../gcode.h"
#include "../../MarlinCore.h" // for max_inactive_time

/**
* M85: Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/gcode/control/T.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ void GcodeSuite::T(const uint8_t tool_index) {
DEBUG_POS("BEFORE", current_position);
}

// Count this command as movement / activity
reset_stepper_timeout();

#if ENABLED(PRUSA_MMU2)
if (parser.string_arg) {
mmu2.tool_change(parser.string_arg); // Special commands T?/Tx/Tc
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ GcodeSuite gcode;

#include "../MarlinCore.h" // for idle()

millis_t GcodeSuite::previous_move_ms;
// Inactivity shutdown
millis_t GcodeSuite::previous_move_ms = 0,
GcodeSuite::max_inactive_time = 0,
GcodeSuite::stepper_inactive_time = SEC_TO_MS(DEFAULT_STEPPER_DEACTIVE_TIME);

// Relative motion mode for each logical axis
static constexpr xyze_bool_t ar_init = AXIS_RELATIVE_MODES;
Expand Down
10 changes: 8 additions & 2 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,14 @@ class GcodeSuite {
static bool select_coordinate_system(const int8_t _new);
#endif

static millis_t previous_move_ms;
FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); }
static millis_t previous_move_ms, max_inactive_time, stepper_inactive_time;
FORCE_INLINE static void reset_stepper_timeout(const millis_t ms=millis()) { previous_move_ms = ms; }
FORCE_INLINE static bool stepper_max_timed_out(const millis_t ms=millis()) {
return max_inactive_time && ELAPSED(ms, previous_move_ms + max_inactive_time);
}
FORCE_INLINE static bool stepper_inactive_timeout(const millis_t ms=millis()) {
return ELAPSED(ms, previous_move_ms + stepper_inactive_time);
}

static int8_t get_target_extruder_from_command();
static int8_t get_target_e_stepper_from_command();
Expand Down
Loading

0 comments on commit 49b7f61

Please sign in to comment.