Skip to content

Commit

Permalink
powerloss / pin / runout save
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasToka committed Jul 25, 2023
1 parent 6a92159 commit 94b26fb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 117 deletions.
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,8 @@
//#define POWER_LOSS_STATE HIGH // State of pin indicating power loss
//#define POWER_LOSS_PULLUP // Set pullup / pulldown as appropriate for your sensor
//#define POWER_LOSS_PULLDOWN
//#define POWER_LOSS_PURGE_LEN 20 // (mm) Length of filament to purge on resume
//#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail. Requires backup power.
#define POWER_LOSS_PURGE_LEN 0 // (mm) Length of filament to purge on resume
#define POWER_LOSS_RETRACT_LEN 0 // (mm) Length of filament to retract on fail. Requires backup power.

// Without a POWER_LOSS_PIN the following option helps reduce wear on the SD card,
// especially with "vase mode" printing. Set too high and vases cannot be continued.
Expand Down
64 changes: 9 additions & 55 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ PrintJobRecovery recovery;
gcode.process_subcommands_now(cmd); \
}while(0)

#define FEEDING_DEF_DISTANCE 5 // in material: default distance of feeding material
#define FEEDING_DEF_SPEED 5 // in material: default feedrate
static void pause_resume_feedstock(uint16_t _distance, uint16_t _feedRate) {
char cmd[20], str_1[16];
current_position.e += _distance;
line_to_current_position(feedRate_t(_feedRate));
current_position.e -= _distance;
sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(current_position.e, 1, 3, str_1));
gcode.process_subcommands_now(cmd);
// Resume the feedrate
sprintf_P(cmd, PSTR("G1 F%s"), dtostrf(MMS_TO_MMM(feedrate_mm_s), 1, 3, str_1));
gcode.process_subcommands_now(cmd);
}
/**
* Clear the recovery info
*/
Expand Down Expand Up @@ -404,13 +391,6 @@ void PrintJobRecovery::write() {
if (!file.close()) DEBUG_ECHOLNPGM("Power-loss file close failed.");
}

#define DEBUG_SERIAL_PRINT SERIAL_ECHO_MSG

// bugfix - 解决断电续打点击打印停止后引起的问题(停止仍有后续动作)
#define PROCESS_SUBCOMMANDS_NOW_P_AND_RETURN(cmd) do { gcode.process_subcommands_now_P(cmd); if(card.flag.abort_sd_printing) return; }while(0)
#define PROCESS_SUBCOMMANDS_NOW_AND_RETURN(cmd) do { gcode.process_subcommands_now(cmd); if(card.flag.abort_sd_printing) return; }while(0)


/**
* Resume the saved print job
*/
Expand Down Expand Up @@ -473,7 +453,7 @@ void PrintJobRecovery::resume() {

// If Z homing goes to max then just move back to the "raised" position
PROCESS_SUBCOMMANDS_NOW(TS(
F( "G28L0\n" // Home all axes (no raise)
F( "G28R0\n" // Home all axes (no raise)
"G1F1200Z") // Move Z down to (raised) height
, p_float_t(z_now, 3)
));
Expand All @@ -498,7 +478,7 @@ void PrintJobRecovery::resume() {
}

// Home XY with no Z raise
PROCESS_SUBCOMMANDS_NOW(F("G28R0L0XY")); // No raise during G28
PROCESS_SUBCOMMANDS_NOW(F("G28R0XY")); // No raise during G28

#endif

Expand Down Expand Up @@ -595,19 +575,6 @@ void PrintJobRecovery::resume() {
PROCESS_SUBCOMMANDS_NOW(F("G12"));
#endif

PROCESS_SUBCOMMANDS_NOW(F("M420 S0 Z0")); //20220326 rock_modify

// Restore E position with G92.9 Rock_20220913
// If there is a layer-changing and retracting action in GCODE,
// first extrude the material and then return to the origin
char cmd1[20], str_3[16];
sprintf_P(cmd1, PSTR("G92.9E%s"), dtostrf(info.current_position.e, 1, 3, str_3));
PROCESS_SUBCOMMANDS_NOW(cmd1);

// rock_20220914 - To solve the problem of faults in the printed small model,
// the purpose is to fill the hollow section of the throat.
pause_resume_feedstock(FEEDING_DEF_DISTANCE, FEEDING_DEF_SPEED);

// Move back over to the saved XY
PROCESS_SUBCOMMANDS_NOW(TS(
F("G1F3000X"), p_float_t(info.current_position.x, 3), 'Y', p_float_t(info.current_position.y, 3)
Expand All @@ -616,29 +583,16 @@ void PrintJobRecovery::resume() {
// Move back down to the saved Z for printing
PROCESS_SUBCOMMANDS_NOW(TS(F("G1F600Z"), p_float_t(z_print, 3)));

DEBUG_ECHOLN(cmd);
//DEBUG_ECHOLN(cmd);
DEBUG_ECHO_MSG(">>> z_print:", z_print, "current_position.z:", current_position.z);
PROCESS_SUBCOMMANDS_NOW(F("M114"));
//safe_delay(10000);

// Restore the feedrate
PROCESS_SUBCOMMANDS_NOW(TS(F("G1F"), info.feedrate));

#if HAS_LEVELING
// Restore Z fade and possibly re-enable bed leveling compensation.
// Leveling may already be enabled due to the ENABLE_LEVELING_AFTER_G28 option.
// TODO: Add a G28 parameter to leave leveling disabled.
char cmd2[20], str_4[16];
sprintf_P(cmd2, PSTR("M420S%cZ%s"), '0' + (char)info.flag.leveling, dtostrf(info.fade, 1, 1, str_4));
PROCESS_SUBCOMMANDS_NOW(cmd2);

// Restore Z position with G92.9
sprintf_P(cmd2, PSTR("G92.9Z%s"), dtostrf(z_print, 1, 3, str_4));
PROCESS_SUBCOMMANDS_NOW(cmd2);
#endif

// Restore E position with G92.9
//PROCESS_SUBCOMMANDS_NOW(TS(F("G92.9E"), p_float_t(info.current_position.e, 3)));
PROCESS_SUBCOMMANDS_NOW(TS(F("G92.9E"), p_float_t(info.current_position.e, 3)));

TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat);
TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
Expand Down Expand Up @@ -672,11 +626,11 @@ void PrintJobRecovery::resume() {

DEBUG_ECHOLNPGM("zraise: ", info.zraise, " ", info.flag.raised ? "(before)" : "");

#if ENABLED(GCODE_REPEAT_MARKERS)
DEBUG_ECHOLNPGM("repeat index: ", info.stored_repeat.index);
for (uint8_t i = 0; i < info.stored_repeat.index; ++i)
DEBUG_ECHOLNPGM("..... sdpos: ", info.stored_repeat.marker.sdpos, " count: ", info.stored_repeat.marker.counter);
#endif
//#if ENABLED(GCODE_REPEAT_MARKERS)
// DEBUG_ECHOLNPGM("repeat index: ", info.stored_repeat.index);
// for (uint8_t i = 0; i < info.stored_repeat.index; ++i)
// DEBUG_ECHOLNPGM("..... sdpos: ", info.stored_repeat.marker.sdpos, " count: ", info.stored_repeat.marker.counter);
//#endif

#if HAS_HOME_OFFSET
DEBUG_ECHOPGM("home_offset: ");
Expand Down
84 changes: 35 additions & 49 deletions Marlin/src/gcode/control/M3-M5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void GcodeSuite::M3_M4(const bool is_M4) {
reset_stepper_timeout(); // Reset timeout to allow subsequent G-code to power the laser (imm.)
#endif

if (cutter.cutter_mode == CUTTER_MODE_STANDARD)
//if (cutter.cutter_mode == CUTTER_MODE_STANDARD)
planner.synchronize(); // Wait for previous movement commands (G0/G1/G2/G3) to complete before changing power

#if ENABLED(LASER_FEATURE)
Expand All @@ -96,55 +96,45 @@ void GcodeSuite::M3_M4(const bool is_M4) {
#endif

auto get_s_power = [] {
#if ENABLED(LASER_FEATURE)
float u = cutter.unitPower;
#else
float u = 0.0f;
#endif
if (parser.seenval('S')) {
const float v = parser.value_float();
#if ENABLED(LASER_FEATURE)
u = laser_device.power16_to_8(v);
cutter.unitPower = parser.value_ushort();
// PWM implied and ranges from S0 to S180 for a positional servo. Typical use would be a pen up/down function.
#if ENABLED(SPINDLE_SERVO)
cutter.power = cutter.unitPower;
#else
u = TERN(LASER_POWER_TRAP, v, cutter.power_to_range(v));
if (cutter.cutter_mode == CUTTER_MODE_STANDARD){ // PWM not implied, power converted to OCR from unit definition and min/max or on/off if not PWM.
if(laser_device.is_laser_device())
{
// 107011 激光模式下将S0-1000比例转换为S0-255
cutter.unitPower = laser_device.power16_to_8(cutter.unitPower);
//cutter.power= cutter.unitPower;
}else{
cutter.power = TERN(SPINDLE_LASER_PWM, cutter.power_to_range(cutter_power_t(cutter.unitPower)), cutter.unitPower > 0 ? 255 : 0);
}
}
#endif
//cutter.menuPower = cutter.unitPower;
}
else if (cutter.cutter_mode == CUTTER_MODE_STANDARD)
u = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);

cutter.menuPower = cutter.unitPower = u;
else if (cutter.cutter_mode == CUTTER_MODE_STANDARD){
cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);
}
return cutter.unitPower;// cutter.unitPower;

// PWM not implied, power converted to OCR from unit definition and on/off if not PWM.
cutter.power = TERN(SPINDLE_LASER_USE_PWM, cutter.upower_to_ocr(u), u > 0 ? 255 : 0);
return u;
};

if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS || cutter.cutter_mode == CUTTER_MODE_DYNAMIC) { // Laser power in inline mode
#if ENABLED(LASER_FEATURE)
planner.laser_inline.status.isPowered = true; // M3 or M4 is powered either way
get_s_power(); // Update cutter.power if seen
#if ENABLED(LASER_POWER_SYNC)
// With power sync we only set power so it does not effect queued inline power sets
planner.buffer_sync_block(BLOCK_BIT_LASER_PWR); // Send the flag, queueing inline power
#else
planner.synchronize();
cutter.inline_power(cutter.power);
#endif
#endif
TERN_(LASER_FEATURE, cutter.inline_power(cutter.upower_to_ocr(get_s_power())));
}
else {
cutter.set_enabled(true);
get_s_power();
cutter.apply_power(
#if ENABLED(SPINDLE_SERVO)
cutter.unitPower
#elif ENABLED(SPINDLE_LASER_USE_PWM)
cutter.upower_to_ocr(cutter.unitPower)
#else
cutter.unitPower > 0 ? 255 : 0
#endif
);
TERN_(SPINDLE_CHANGE_DIR, cutter.set_reverse(is_M4));
#if ENABLED(SPINDLE_LASER_PWM)
//cutter.set_power(cutter.upower_to_ocr(get_s_power())); // 107011-20210925 修复M3 S 命令无效的bug
cutter.apply_power(get_s_power());//107011 -20211008 cutter.set_ocr(cutter.upower_to_ocr(get_s_power())); // 107011-20210925 修复M3 S 命令无效的bug
#elif ENABLED(SPINDLE_SERVO)
cutter.set_power(get_s_power());
#else
cutter.set_enabled(true);
#endif
//cutter.set_reverse(is_M4); /107011-20210925 //修复M3 S 命令无效的bug
}
}

Expand All @@ -153,16 +143,12 @@ void GcodeSuite::M3_M4(const bool is_M4) {
*/
void GcodeSuite::M5() {
planner.synchronize();
cutter.power = 0;
cutter.apply_power(0); // M5 just kills power, leaving inline mode unchanged
if (cutter.cutter_mode != CUTTER_MODE_STANDARD) {
if (parser.seen_test('I')) {
TERN_(LASER_FEATURE, cutter.inline_power(cutter.power));
cutter.set_enabled(false); // Needs to happen while we are in inline mode to clear inline power.
cutter.cutter_mode = CUTTER_MODE_STANDARD; // Switch from inline to standard mode.
}
if (parser.seen_test('I')) {
cutter.set_enabled(false); // Clear inline mode flags
cutter.cutter_mode = CUTTER_MODE_STANDARD; // Switch from inline to standard mode, has no effect on current power output!
}
cutter.set_enabled(false); // Disable enable output setting
cutter.apply_power(0); // M5 kills power in either mode but if it's in inline it will be still be the active mode

}

#endif // HAS_CUTTER
21 changes: 11 additions & 10 deletions Marlin/src/lcd/rts/e3s1pro/lcd_rts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,16 +1488,16 @@ void RTSSHOW::RTS_HandleData(void)
}
else if(recdat.data[0] == 8)
{
if(runout.enabled)
{
RTS_SndData(102, FILAMENT_CONTROL_ICON_VP);
runout.enabled = false;
}
else
{
RTS_SndData(101, FILAMENT_CONTROL_ICON_VP);
runout.enabled = true;
}
if(runout.enabled)
{
RTS_SndData(102, FILAMENT_CONTROL_ICON_VP);
runout.enabled = false;
}
else
{
RTS_SndData(101, FILAMENT_CONTROL_ICON_VP);
runout.enabled = true;
}
settings.save();
}
else if(recdat.data[0] == 9)
Expand All @@ -1519,6 +1519,7 @@ void RTSSHOW::RTS_HandleData(void)
recovery.enabled = true;
recovery.save(true);
}
settings.save();
}
break;

Expand Down
1 change: 0 additions & 1 deletion Marlin/src/pins/stm32f1/pins_CREALITY_V24S1_301.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
#define FAN0_PIN PA0
#define SPINDLE_LASER_ENA_PIN PC0 // FET 1
#define SPINDLE_LASER_PWM_PIN PC0 // Bed FET
#define SPINDLE_LASER_ENA_PIN PC0 // FET 1
#define SPINDLE_DIR_PIN PC0 // FET 4
#define LASER_SOFT_PWM_PIN PC0
#endif
Expand Down

0 comments on commit 94b26fb

Please sign in to comment.