FSensor - meassuring filament optical quality
This commit is contained in:
parent
2a66251170
commit
5483bee885
@ -856,7 +856,7 @@ void factory_reset(char level, bool quiet)
|
||||
eeprom_update_word((uint16_t *)EEPROM_POWER_COUNT_TOT, 0);
|
||||
|
||||
fsensor_enable();
|
||||
fautoload_set(true);
|
||||
fsensor_autoload_set(true);
|
||||
|
||||
WRITE(BEEPER, HIGH);
|
||||
_delay_ms(100);
|
||||
@ -3107,6 +3107,8 @@ void gcode_M114()
|
||||
|
||||
void gcode_M701()
|
||||
{
|
||||
printf_P(PSTR("gcode_M701 begin\n"));
|
||||
|
||||
#if defined (SNMM) || defined (SNMM_V2)
|
||||
extr_adj(snmm_extruder);//loads current extruder
|
||||
#else
|
||||
@ -3114,7 +3116,13 @@ void gcode_M701()
|
||||
custom_message = true;
|
||||
custom_message_type = 2;
|
||||
|
||||
|
||||
bool old_watch_runout = fsensor_watch_runout;
|
||||
fsensor_watch_runout = false;
|
||||
fsensor_st_sum = 0;
|
||||
fsensor_yd_sum = 0;
|
||||
fsensor_er_sum = 0;
|
||||
fsensor_yd_min = 255;
|
||||
fsensor_yd_max = 0;
|
||||
|
||||
lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
|
||||
current_position[E_AXIS] += 40;
|
||||
@ -3156,6 +3164,11 @@ void gcode_M701()
|
||||
custom_message_type = 0;
|
||||
#endif
|
||||
|
||||
fsensor_err_cnt = 0;
|
||||
fsensor_watch_runout = old_watch_runout;
|
||||
printf_P(_N("\nFSENSOR st_sum=%lu yd_sum=%lu er_sum=%lu\n"), fsensor_st_sum, fsensor_yd_sum, fsensor_er_sum);
|
||||
printf_P(_N("\nFSENSOR yd_min=%hhu yd_max=%hhu yd_avg=%hhu\n"), fsensor_yd_min, fsensor_yd_max, fsensor_yd_sum * FSENSOR_CHUNK_LEN / fsensor_st_sum);
|
||||
printf_P(PSTR("gcode_M701 end\n"));
|
||||
}
|
||||
/**
|
||||
* @brief Get serial number from 32U2 processor
|
||||
@ -6543,15 +6556,14 @@ Sigma_Exit:
|
||||
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
||||
|
||||
#ifdef PAT9125
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || fsensor_M600)) fsensor_autoload_check_start();
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_start();
|
||||
#endif //PAT9125
|
||||
// printf_P(PSTR("M600 PAT9125 filament_autoload_enabled=%d, old_fsensor_enabled=%d, fsensor_M600=%d"), filament_autoload_enabled, old_fsensor_enabled, fsensor_M600);
|
||||
while(!lcd_clicked())
|
||||
{
|
||||
manage_heater();
|
||||
manage_inactivity(true);
|
||||
#ifdef PAT9125
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || fsensor_M600) && fsensor_check_autoload())
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout) && fsensor_check_autoload())
|
||||
{
|
||||
tone(BEEPER, 1000);
|
||||
delay_keep_alive(50);
|
||||
@ -6567,7 +6579,7 @@ Sigma_Exit:
|
||||
|
||||
}
|
||||
#ifdef PAT9125
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || fsensor_M600)) fsensor_autoload_check_stop();
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_stop();
|
||||
#endif //PAT9125
|
||||
//WRITE(BEEPER, LOW);
|
||||
KEEPALIVE_STATE(IN_HANDLER);
|
||||
@ -6717,6 +6729,7 @@ Sigma_Exit:
|
||||
custom_message_type = 0;
|
||||
|
||||
#ifdef PAT9125
|
||||
/*
|
||||
// fsensor_enabled = old_fsensor_enabled; //temporary solution for unexpected restarting
|
||||
|
||||
if (fsensor_M600)
|
||||
@ -6733,6 +6746,7 @@ Sigma_Exit:
|
||||
fsensor_restore_print_and_continue();
|
||||
}
|
||||
fsensor_M600 = false;
|
||||
*/
|
||||
#endif //PAT9125
|
||||
|
||||
}
|
||||
@ -7659,7 +7673,7 @@ static void handleSafetyTimer()
|
||||
void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h
|
||||
{
|
||||
#ifdef PAT9125
|
||||
if (fsensor_enabled && filament_autoload_enabled && !fsensor_M600 && !moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
|
||||
if (fsensor_enabled && filament_autoload_enabled && fsensor_watch_runout && !moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
|
||||
{
|
||||
if (fsensor_autoload_enabled)
|
||||
{
|
||||
|
@ -16,8 +16,6 @@ const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n";
|
||||
#define FSENSOR_ERR_MAX 10 //filament sensor max error count
|
||||
#define FSENSOR_INT_PIN 63 //filament sensor interrupt pin PK1
|
||||
#define FSENSOR_INT_PIN_MSK 0x02 //filament sensor interrupt pin mask (bit1)
|
||||
//#define FSENSOR_CHUNK_LEN 280 //filament sensor chunk length in steps - 1mm
|
||||
#define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm
|
||||
|
||||
extern void stop_and_save_print_to_ram(float z_move, float e_move);
|
||||
extern void restore_print_from_ram_and_continue(float e_move);
|
||||
@ -36,11 +34,15 @@ void fsensor_restore_print_and_continue()
|
||||
//uint8_t fsensor_int_pin = FSENSOR_INT_PIN;
|
||||
uint8_t fsensor_int_pin_old = 0;
|
||||
int16_t fsensor_chunk_len = FSENSOR_CHUNK_LEN;
|
||||
|
||||
bool fsensor_enabled = true;
|
||||
bool fsensor_watch_runout = true;
|
||||
bool fsensor_not_responding = false;
|
||||
bool fsensor_M600 = false;
|
||||
|
||||
uint8_t fsensor_err_cnt = 0;
|
||||
int16_t fsensor_st_cnt = 0;
|
||||
|
||||
|
||||
uint8_t fsensor_log = 1;
|
||||
|
||||
//autoload enable/disable flag
|
||||
@ -53,15 +55,8 @@ uint8_t fsensor_autoload_sum = 0;
|
||||
uint32_t fsensor_st_sum = 0;
|
||||
uint32_t fsensor_yd_sum = 0;
|
||||
uint32_t fsensor_er_sum = 0;
|
||||
|
||||
void fsensor_block()
|
||||
{
|
||||
fsensor_enabled = false;
|
||||
}
|
||||
|
||||
void fsensor_unblock() {
|
||||
fsensor_enabled = (eeprom_read_byte((uint8_t*)EEPROM_FSENSOR) == 0x01);
|
||||
}
|
||||
uint8_t fsensor_yd_min = 255;
|
||||
uint8_t fsensor_yd_max = 0;
|
||||
|
||||
bool fsensor_enable()
|
||||
{
|
||||
@ -73,7 +68,7 @@ bool fsensor_enable()
|
||||
else
|
||||
fsensor_not_responding = true;
|
||||
fsensor_enabled = pat9125?true:false;
|
||||
fsensor_M600 = false;
|
||||
fsensor_watch_runout = true;
|
||||
fsensor_err_cnt = 0;
|
||||
eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled?0x01:0x00);
|
||||
FSensorStateMenu = fsensor_enabled?1:0;
|
||||
@ -94,7 +89,7 @@ void fsensor_disable()
|
||||
FSensorStateMenu = 0;
|
||||
}
|
||||
|
||||
void fautoload_set(bool State)
|
||||
void fsensor_autoload_set(bool State)
|
||||
{
|
||||
filament_autoload_enabled = State;
|
||||
eeprom_update_byte((unsigned char *)EEPROM_FSENS_AUTOLOAD_ENABLED, filament_autoload_enabled);
|
||||
@ -211,9 +206,14 @@ ISR(PCINT2_vect)
|
||||
{
|
||||
if (fsensor_err_cnt)
|
||||
fsensor_err_cnt--;
|
||||
fsensor_st_sum += st_cnt;
|
||||
fsensor_yd_sum += pat9125_y;
|
||||
if (st_cnt == FSENSOR_CHUNK_LEN)
|
||||
{
|
||||
if (fsensor_yd_min > pat9125_y) fsensor_yd_min = pat9125_y;
|
||||
if (fsensor_yd_max < pat9125_y) fsensor_yd_max = pat9125_y;
|
||||
}
|
||||
}
|
||||
fsensor_st_sum += st_cnt;
|
||||
fsensor_yd_sum += pat9125_y;
|
||||
}
|
||||
else //negative movement
|
||||
{
|
||||
@ -264,36 +264,35 @@ void fsensor_st_block_chunk(block_t* bl, int cnt)
|
||||
|
||||
void fsensor_update()
|
||||
{
|
||||
if (!fsensor_enabled || fsensor_M600) return;
|
||||
if (fsensor_err_cnt > FSENSOR_ERR_MAX)
|
||||
{
|
||||
fsensor_stop_and_save_print();
|
||||
|
||||
fsensor_err_cnt = 0;
|
||||
|
||||
enquecommand_front_P((PSTR("G1 E-3 F200")));
|
||||
process_commands();
|
||||
cmdqueue_pop_front();
|
||||
st_synchronize();
|
||||
|
||||
enquecommand_front_P((PSTR("G1 E3 F200")));
|
||||
process_commands();
|
||||
cmdqueue_pop_front();
|
||||
st_synchronize();
|
||||
|
||||
if (fsensor_err_cnt == 0)
|
||||
if (fsensor_enabled && fsensor_watch_runout)
|
||||
if (fsensor_err_cnt > FSENSOR_ERR_MAX)
|
||||
{
|
||||
fsensor_restore_print_and_continue();
|
||||
fsensor_stop_and_save_print();
|
||||
|
||||
fsensor_err_cnt = 0;
|
||||
|
||||
enquecommand_front_P((PSTR("G1 E-3 F200")));
|
||||
process_commands();
|
||||
cmdqueue_pop_front();
|
||||
st_synchronize();
|
||||
|
||||
enquecommand_front_P((PSTR("G1 E3 F200")));
|
||||
process_commands();
|
||||
cmdqueue_pop_front();
|
||||
st_synchronize();
|
||||
|
||||
if (fsensor_err_cnt == 0)
|
||||
{
|
||||
fsensor_restore_print_and_continue();
|
||||
}
|
||||
else
|
||||
{
|
||||
eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1);
|
||||
eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1);
|
||||
enquecommand_front_P((PSTR("M600")));
|
||||
fsensor_watch_runout = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1);
|
||||
eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1);
|
||||
enquecommand_front_P((PSTR("M600")));
|
||||
fsensor_M600 = true;
|
||||
// fsensor_enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //PAT9125
|
||||
|
@ -3,20 +3,19 @@
|
||||
|
||||
#include "planner.h"
|
||||
|
||||
//#define FSENSOR_CHUNK_LEN 280 //filament sensor chunk length in steps - 1mm
|
||||
#define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm
|
||||
|
||||
//save restore printing
|
||||
extern void fsensor_stop_and_save_print();
|
||||
extern void fsensor_restore_print_and_continue();
|
||||
|
||||
//temporarily enable/disable without writing to eeprom
|
||||
extern void fsensor_block();
|
||||
extern void fsensor_unblock();
|
||||
|
||||
//enable/disable
|
||||
extern bool fsensor_enable();
|
||||
extern void fsensor_disable();
|
||||
|
||||
extern bool filament_autoload_enabled;
|
||||
extern void fautoload_set(bool State);
|
||||
extern void fsensor_autoload_set(bool State);
|
||||
|
||||
//update (perform M600 on filament runout)
|
||||
extern void fsensor_update();
|
||||
@ -39,15 +38,23 @@ extern void fsensor_st_block_chunk(block_t* bl, int cnt);
|
||||
|
||||
//minimum meassured chunk length in steps
|
||||
extern int16_t fsensor_chunk_len;
|
||||
//M600 in progress
|
||||
extern bool fsensor_M600;
|
||||
//enable/disable flag
|
||||
extern bool fsensor_enabled;
|
||||
//watch runout flag
|
||||
extern bool fsensor_watch_runout;
|
||||
//not responding flag
|
||||
extern bool fsensor_not_responding;
|
||||
|
||||
extern uint8_t fsensor_err_cnt;
|
||||
|
||||
//autoload enable/disable flag
|
||||
extern bool fsensor_autoload_enabled;
|
||||
|
||||
|
||||
extern uint32_t fsensor_st_sum;
|
||||
extern uint32_t fsensor_yd_sum;
|
||||
extern uint32_t fsensor_er_sum;
|
||||
extern uint8_t fsensor_yd_min;
|
||||
extern uint8_t fsensor_yd_max;
|
||||
|
||||
#endif //FSENSOR_H
|
||||
|
@ -146,8 +146,6 @@ int8_t FSensorStateMenu = 1;
|
||||
|
||||
int8_t CrashDetectMenu = 1;
|
||||
|
||||
extern void fsensor_block();
|
||||
extern void fsensor_unblock();
|
||||
|
||||
extern bool fsensor_enable();
|
||||
extern void fsensor_disable();
|
||||
@ -2282,7 +2280,7 @@ void lcd_set_fan_check() {
|
||||
}
|
||||
|
||||
void lcd_set_filament_autoload() {
|
||||
fautoload_set(!filament_autoload_enabled);
|
||||
fsensor_autoload_set(!filament_autoload_enabled);
|
||||
}
|
||||
|
||||
void lcd_unLoadFilament()
|
||||
@ -4465,9 +4463,6 @@ void lcd_wizard(int state) {
|
||||
state = 7;
|
||||
break;
|
||||
case 7: //load filament
|
||||
#ifdef PAT9125
|
||||
fsensor_block();
|
||||
#endif //PAT9125
|
||||
lcd_show_fullscreen_message_and_wait_P(_i("Please insert PLA filament to the extruder, then press knob to load it."));////MSG_WIZARD_LOAD_FILAMENT c=20 r=8
|
||||
lcd_update_enable(false);
|
||||
lcd_clear();
|
||||
@ -4476,9 +4471,6 @@ void lcd_wizard(int state) {
|
||||
change_extr(0);
|
||||
#endif
|
||||
gcode_M701();
|
||||
#ifdef PAT9125
|
||||
fsensor_unblock();
|
||||
#endif //PAT9125
|
||||
state = 9;
|
||||
break;
|
||||
case 8:
|
||||
|
Loading…
Reference in New Issue
Block a user