Merge pull request #940 from XPila/MK3-new_lang

Filament sensor tunning
This commit is contained in:
PavelSindler 2018-07-19 15:22:47 +02:00 committed by GitHub
commit 3cb3ec9975
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 68 deletions

View file

@ -6227,7 +6227,7 @@ Sigma_Exit:
{
#ifdef PAT9125
bool old_fsensor_enabled = fsensor_enabled;
fsensor_enabled = false; //temporary solution for unexpected restarting
// fsensor_enabled = false; //temporary solution for unexpected restarting
#endif //PAT9125
st_synchronize();
@ -6692,7 +6692,7 @@ Sigma_Exit:
custom_message_type = 0;
#ifdef PAT9125
fsensor_enabled = old_fsensor_enabled; //temporary solution for unexpected restarting
// fsensor_enabled = old_fsensor_enabled; //temporary solution for unexpected restarting
if (fsensor_M600)
{
@ -6704,10 +6704,10 @@ Sigma_Exit:
cmdqueue_pop_front();
}
KEEPALIVE_STATE(IN_HANDLER);
fsensor_enable();
// fsensor_enable();
fsensor_restore_print_and_continue();
}
fsensor_M600 = false;
#endif //PAT9125
}
@ -7034,7 +7034,7 @@ Sigma_Exit:
#else
#ifdef PAT9125
bool old_fsensor_enabled = fsensor_enabled;
fsensor_enabled = false;
// fsensor_enabled = false;
#endif //PAT9125
custom_message = true;
custom_message_type = 2;
@ -7078,7 +7078,7 @@ Sigma_Exit:
custom_message = false;
custom_message_type = 0;
#ifdef PAT9125
fsensor_enabled = old_fsensor_enabled;
// fsensor_enabled = old_fsensor_enabled;
#endif //PAT9125
#endif
}

View file

@ -10,11 +10,14 @@
#include "cmdqueue.h"
const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n";
#define FSENSOR_ERR_MAX 5 //filament sensor max error count
//#define FSENSOR_ERR_MAX 5 //filament sensor max error count
#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
//#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);
@ -35,7 +38,6 @@ uint8_t fsensor_int_pin_old = 0;
int16_t fsensor_chunk_len = FSENSOR_CHUNK_LEN;
bool fsensor_enabled = true;
bool fsensor_not_responding = false;
//bool fsensor_ignore_error = true;
bool fsensor_M600 = false;
uint8_t fsensor_err_cnt = 0;
int16_t fsensor_st_cnt = 0;
@ -48,6 +50,10 @@ uint8_t fsensor_autoload_c = 0;
uint32_t fsensor_autoload_last_millis = 0;
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;
@ -67,12 +73,16 @@ bool fsensor_enable()
else
fsensor_not_responding = true;
fsensor_enabled = pat9125?true:false;
// fsensor_ignore_error = true;
fsensor_M600 = false;
fsensor_err_cnt = 0;
eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled?0x01:0x00);
FSensorStateMenu = fsensor_enabled?1:0;
// printf_P(PSTR("fsensor_enable - end %d\n"), fsensor_enabled?1:0);
fsensor_st_sum = 0;
fsensor_yd_sum = 0;
fsensor_er_sum = 0;
return fsensor_enabled;
}
@ -115,7 +125,7 @@ void fsensor_autoload_check_start(void)
// puts_P(PSTR("fsensor_autoload_check_start\n"));
if (!pat9125_update_y()) //update sensor
{
puts_P(PSTR("pat9125 not responding (3).\n"));
printf_P(ERRMSG_PAT9125_NOT_RESP, 3);
fsensor_disable();
fsensor_not_responding = true;
fsensor_autoload_enabled = false;
@ -144,7 +154,7 @@ bool fsensor_check_autoload(void)
fsensor_autoload_last_millis = millis();
if (!pat9125_update_y())
{
puts_P(PSTR("pat9125 not responding (2).\n"));
printf_P(ERRMSG_PAT9125_NOT_RESP, 2);
fsensor_disable();
fsensor_not_responding = true;
return false; //update sensor
@ -173,74 +183,54 @@ bool fsensor_check_autoload(void)
ISR(PCINT2_vect)
{
// puts("PCINT2\n");
if (!((fsensor_int_pin_old ^ PINK) & FSENSOR_INT_PIN_MSK)) return;
fsensor_int_pin_old = PINK;
static bool _lock = false;
if (_lock) return;
_lock = true;
// return;
int st_cnt = fsensor_st_cnt;
fsensor_st_cnt = 0;
sei();
/* *digitalPinToPCMSK(fsensor_int_pin) &= ~bit(digitalPinToPCMSKbit(fsensor_int_pin));
digitalWrite(fsensor_int_pin, HIGH);
*digitalPinToPCMSK(fsensor_int_pin) |= bit(digitalPinToPCMSKbit(fsensor_int_pin));*/
uint8_t old_err_cnt = fsensor_err_cnt;
if (!pat9125_update_y())
{
//#ifdef DEBUG_FSENSOR_LOG
puts_P(PSTR("pat9125 not responding (1).\n"));
//#endif //DEBUG_FSENSOR_LOG
printf_P(ERRMSG_PAT9125_NOT_RESP, 1);
fsensor_disable();
fsensor_not_responding = true;
}
if (st_cnt != 0)
{ //movement
if (st_cnt > 0) //positive movement
{
#ifdef DEBUG_FSENSOR_LOG
if (fsensor_log)
if (pat9125_y <= 0)
{
MYSERIAL.print("cnt=");
MYSERIAL.print(st_cnt, DEC);
MYSERIAL.print(" dy=");
MYSERIAL.print(pat9125_y, DEC);
}
#endif //DEBUG_FSENSOR_LOG
if (st_cnt != 0)
{
if( (pat9125_y == 0) || ((pat9125_y > 0) && (st_cnt < 0)) || ((pat9125_y < 0) && (st_cnt > 0)))
{ //invalid movement
if (st_cnt > 0) //only positive movements
fsensor_err_cnt++;
#ifdef DEBUG_FSENSOR_LOG
if (fsensor_log)
{
MYSERIAL.print("\tNG ! err=");
MYSERIAL.println(fsensor_err_cnt, DEC);
}
#endif //DEBUG_FSENSOR_LOG
fsensor_er_sum++;
}
else
{ //propper movement
if (fsensor_err_cnt > 0)
fsensor_err_cnt--;
// fsensor_err_cnt = 0;
#ifdef DEBUG_FSENSOR_LOG
if (fsensor_log)
{
MYSERIAL.print("\tOK err=");
MYSERIAL.println(fsensor_err_cnt, DEC);
if (fsensor_err_cnt)
fsensor_err_cnt--;
fsensor_st_sum += st_cnt;
fsensor_yd_sum += pat9125_y;
}
#endif //DEBUG_FSENSOR_LOG
}
else //negative movement
{
}
}
else
{ //no movement
}
#ifdef DEBUG_FSENSOR_LOG
if (fsensor_log)
MYSERIAL.println("\tOK 0");
{
printf_P(_N("FSENSOR cnt=%d dy=%d err=%d %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK"));
printf_P(_N("FSENSOR st_sum=%lu yd_sum=%lu er_sum=%lu\n"), fsensor_st_sum, fsensor_yd_sum, fsensor_er_sum);
}
#endif //DEBUG_FSENSOR_LOG
}
}
pat9125_y = 0;
_lock = false;
return;
@ -274,7 +264,7 @@ void fsensor_st_block_chunk(block_t* bl, int cnt)
void fsensor_update()
{
if (!fsensor_enabled) return;
if (!fsensor_enabled || fsensor_M600) return;
if (fsensor_err_cnt > FSENSOR_ERR_MAX)
{
fsensor_stop_and_save_print();
@ -301,7 +291,7 @@ void fsensor_update()
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;
// fsensor_enabled = false;
}
}
}

View file

@ -224,7 +224,18 @@ uint8_t menu_item_gcode_P(const char* str, const char* str_gcode)
return 0;
}
const char menu_fmt_int3[] PROGMEM = "%c%S:\x1b[%hhu;16H%3d";
const char menu_20x_space[] PROGMEM = " ";
const char menu_fmt_int3[] PROGMEM = "%c%.15S:%s%3d";
void menu_draw_int3(char chr, const char* str, int16_t val)
{
int text_len = strlen_P(str);
if (text_len > 15) text_len = 15;
char spaces[21];
strcpy_P(spaces, menu_20x_space);
spaces[15 - text_len] = 0;
lcd_printf_P(menu_fmt_int3, chr, str, spaces, val);
}
#define _menu_data (*((menu_data_edit_t*)menu_data))
void _menu_edit_int3(void)
@ -234,7 +245,7 @@ void _menu_edit_int3(void)
if (lcd_encoder < _menu_data.minEditValue) lcd_encoder = _menu_data.minEditValue;
if (lcd_encoder > _menu_data.maxEditValue) lcd_encoder = _menu_data.maxEditValue;
lcd_set_cursor(0, 1);
lcd_printf_P(menu_fmt_int3, ' ', _menu_data.editLabel, (uint8_t)1, (int)lcd_encoder);
menu_draw_int3(' ', _menu_data.editLabel, (int)lcd_encoder);
}
if (LCD_CLICKED)
{
@ -250,7 +261,7 @@ uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int
if (lcd_draw_update)
{
lcd_set_cursor(0, menu_row);
lcd_printf_P(menu_fmt_int3, (lcd_encoder == menu_item)?'>':' ', str, menu_row, *pval);
menu_draw_int3((lcd_encoder == menu_item)?'>':' ', str, *pval);
}
if (menu_clicked && (lcd_encoder == menu_item))
{

View file

@ -6163,13 +6163,15 @@ static void lcd_sd_updir()
menu_top = 0;
}
void lcd_print_stop() {
void lcd_print_stop()
{
cancel_heatup = true;
#ifdef MESH_BED_LEVELING
mbl.active = false;
#endif
// Stop the stoppers, update the position from the stoppers.
if (mesh_bed_leveling_flag == false && homing_flag == false) {
if (mesh_bed_leveling_flag == false && homing_flag == false)
{
planner_abort_hard();
// Because the planner_abort_hard() initialized current_position[Z] from the stepper,
// Z baystep is no more applied. Reset it.
@ -6178,20 +6180,16 @@ void lcd_print_stop() {
// Clean the input command queue.
cmdqueue_reset();
lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
lcd_update(2);
card.sdprinting = false;
card.closefile();
stoptime = millis();
unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
pause_time = 0;
save_statistics(total_filament_used, t);
lcd_return_to_status();
lcd_ignore_click(true);
lcd_commands_step = 0;
lcd_commands_type = LCD_COMMAND_STOP_PRINT;
// Turn off the print fan
SET_OUTPUT(FAN_PIN);
WRITE(FAN_PIN, 0);
@ -7502,6 +7500,7 @@ uint8_t get_message_level()
void menu_lcd_longpress_func(void)
{
move_menu_scale = 1.0;
menu_submenu(lcd_move_z);
}