Merge pull request #44 from XPila/MK3

MAKER FAIRE
This commit is contained in:
XPila 2017-09-21 02:56:26 +02:00 committed by GitHub
commit 47f955e306
5 changed files with 109 additions and 62 deletions

View file

@ -565,27 +565,45 @@ void servo_init()
static void lcd_language_menu();
void stop_and_save_print_to_ram(float z_move, float e_move);
void restore_print_from_ram_and_continue(float e_move);
#ifdef PAT9125
void fsensor_stop_and_save_print()
{
// stop_and_save_print_to_ram(10, -0.8); //XY - no change, Z 10mm up, E 0.8mm in
stop_and_save_print_to_ram(0, 0); //XY - no change, Z 10mm up, E 0.8mm in
}
void fsensor_restore_print_and_continue()
{
restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change
}
bool fsensor_enabled = true;
bool fsensor_ignore_error = true;
bool fsensor_M600 = false;
long prev_pos_e = 0;
long err_cnt = 0;
long fsensor_prev_pos_e = 0;
uint8_t fsensor_err_cnt = 0;
#define FSENS_ESTEPS 280 //extruder resolution [steps/mm]
#define FSENS_MINDEL 560 //filament sensor min delta [steps] (3mm)
//#define FSENS_MINDEL 560 //filament sensor min delta [steps] (3mm)
#define FSENS_MINDEL 280 //filament sensor min delta [steps] (3mm)
#define FSENS_MINFAC 3 //filament sensor minimum factor [count/mm]
#define FSENS_MAXFAC 50 //filament sensor maximum factor [count/mm]
#define FSENS_MAXERR 2 //filament sensor max error count
//#define FSENS_MAXFAC 50 //filament sensor maximum factor [count/mm]
#define FSENS_MAXFAC 40 //filament sensor maximum factor [count/mm]
//#define FSENS_MAXERR 2 //filament sensor max error count
#define FSENS_MAXERR 5 //filament sensor max error count
void fsensor_enable()
{
MYSERIAL.println("fsensor_enable");
pat9125_y = 0;
prev_pos_e = st_get_position(E_AXIS);
err_cnt = 0;
fsensor_prev_pos_e = st_get_position(E_AXIS);
fsensor_err_cnt = 0;
fsensor_enabled = true;
fsensor_ignore_error = true;
fsensor_M600 = false;
@ -602,24 +620,26 @@ void fsensor_update()
if (!fsensor_enabled) return;
long pos_e = st_get_position(E_AXIS); //current position
pat9125_update();
long del_e = pos_e - prev_pos_e; //delta
long del_e = pos_e - fsensor_prev_pos_e; //delta
if (abs(del_e) < FSENS_MINDEL) return;
float de = ((float)del_e / FSENS_ESTEPS);
int cmin = de * FSENS_MINFAC;
int cmax = de * FSENS_MAXFAC;
int cnt = pat9125_y;
prev_pos_e = pos_e;
int cnt = -pat9125_y;
fsensor_prev_pos_e = pos_e;
pat9125_y = 0;
bool err = false;
if ((del_e > 0) && ((cnt < cmin) || (cnt > cmax))) err = true;
if ((del_e < 0) && ((cnt > cmin) || (cnt < cmax))) err = true;
if (err)
err_cnt++;
fsensor_err_cnt++;
else
err_cnt = 0;
fsensor_err_cnt = 0;
/**/
MYSERIAL.print("de=");
MYSERIAL.print("pos_e=");
MYSERIAL.print(pos_e);
MYSERIAL.print(" de=");
MYSERIAL.print(de);
MYSERIAL.print(" cmin=");
MYSERIAL.print((int)cmin);
@ -628,13 +648,13 @@ void fsensor_update()
MYSERIAL.print(" cnt=");
MYSERIAL.print((int)cnt);
MYSERIAL.print(" err=");
MYSERIAL.println((int)err_cnt);/**/
MYSERIAL.println((int)fsensor_err_cnt);/**/
return;
// return;
if (err_cnt > FSENS_MAXERR)
if (fsensor_err_cnt > FSENS_MAXERR)
{
MYSERIAL.println("fsensor_update (err_cnt > FSENS_MAXERR)");
MYSERIAL.println("fsensor_update (fsensor_err_cnt > FSENS_MAXERR)");
if (fsensor_ignore_error)
{
MYSERIAL.println("fsensor_update - error ignored)");
@ -643,10 +663,10 @@ void fsensor_update()
else
{
MYSERIAL.println("fsensor_update - ERROR!!!");
planner_abort_hard();
// enquecommand_front_P((PSTR("M600")));
// fsensor_M600 = true;
// fsensor_enabled = false;
fsensor_stop_and_save_print();
enquecommand_front_P((PSTR("M600")));
fsensor_M600 = true;
fsensor_enabled = false;
}
}
}
@ -5233,7 +5253,14 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
if (fsensor_M600)
{
cmdqueue_pop_front(); //hack because M600 repeated 2x when enqueued to front
st_synchronize();
while (!is_buffer_empty())
{
process_commands();
cmdqueue_pop_front();
}
fsensor_enable();
fsensor_restore_print_and_continue();
}
#endif //PAT9125
@ -6898,50 +6925,49 @@ float saved_feedrate2 = 0;
uint8_t saved_active_extruder = 0;
bool saved_extruder_under_pressure = false;
void stop_and_save_print_to_ram()
void stop_and_save_print_to_ram(float z_move, float e_move)
{
if (saved_printing) return;
cli();
saved_sdpos = sdpos_atomic;
uint16_t sdlen_planner = planner_calc_sd_length();
saved_sdpos = sdpos_atomic; //atomic sd position of last command added in queue
uint16_t sdlen_planner = planner_calc_sd_length(); //length of sd commands in planner
saved_sdpos -= sdlen_planner;
uint16_t sdlen_cmdqueue = cmdqueue_calc_sd_length();
uint16_t sdlen_cmdqueue = cmdqueue_calc_sd_length(); //length of sd commands in cmdqueue
saved_sdpos -= sdlen_cmdqueue;
planner_abort_hard();
// babystep_reset();
for (int axis = X_AXIS; axis <= E_AXIS; axis++)
planner_abort_hard(); //abort printing
for (int axis = X_AXIS; axis <= E_AXIS; axis++) //save positions
saved_pos[axis] = current_position[axis];
saved_feedrate2 = feedrate;
saved_active_extruder = active_extruder;
saved_extruder_under_pressure = extruder_under_pressure;
cmdqueue_reset();
// saved_pos[axis] = st_get_position_mm(axis);
saved_feedrate2 = feedrate; //save feedrate
saved_active_extruder = active_extruder; //save active_extruder
saved_extruder_under_pressure = extruder_under_pressure; //extruder under pressure flag - currently unused
cmdqueue_reset(); //empty cmdqueue
card.sdprinting = false;
// card.closefile();
saved_printing = true;
sei();
float extruder_move = 0;
if (extruder_under_pressure) extruder_move -= 0.8;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + 10, current_position[E_AXIS] + extruder_move, homing_feedrate[Z_AXIS], active_extruder);
st_synchronize();
if ((z_move != 0) || (e_move != 0)) // extruder and z move
plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS] + z_move, saved_pos[E_AXIS] + e_move, homing_feedrate[Z_AXIS], active_extruder);
st_synchronize(); //wait moving
MYSERIAL.print("SDPOS="); MYSERIAL.println(sdpos_atomic, DEC);
MYSERIAL.print("SDLEN_PLAN="); MYSERIAL.println(sdlen_planner, DEC);
MYSERIAL.print("SDLEN_CMDQ="); MYSERIAL.println(sdlen_cmdqueue, DEC);
}
void restore_print_from_ram_and_continue()
void restore_print_from_ram_and_continue(float e_move)
{
if (!saved_printing) return;
// babystep_apply();
for (int axis = X_AXIS; axis <= E_AXIS; axis++)
current_position[axis] = st_get_position_mm(axis);
active_extruder = saved_active_extruder;
float extruder_move = 0;
if (saved_extruder_under_pressure) extruder_move += 0.8;
plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], current_position[E_AXIS] + extruder_move, homing_feedrate[Z_AXIS], active_extruder);
// for (int axis = X_AXIS; axis <= E_AXIS; axis++)
// current_position[axis] = st_get_position_mm(axis);
active_extruder = saved_active_extruder; //restore active_extruder
feedrate = saved_feedrate2; //restore feedrate
float e = saved_pos[E_AXIS] - e_move;
plan_set_e_position(e);
plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], saved_pos[E_AXIS], homing_feedrate[Z_AXIS], active_extruder);
st_synchronize();
feedrate = saved_feedrate2;
card.setIndex(saved_sdpos);
card.sdprinting = true;
saved_printing = false;

View file

@ -2863,12 +2863,12 @@ const char * const MSG_SHOW_END_STOPS_LANG_TABLE[LANG_NUM] PROGMEM = {
MSG_SHOW_END_STOPS_DE
};
const char MSG_FSENSOR_OFF_EN[] PROGMEM = "Filam. probe [off]";
const char MSG_FSENSOR_OFF_CZ[] PROGMEM = "Filam. probe [off]";
const char MSG_FSENSOR_OFF_IT[] PROGMEM = "Filam. probe [off]";
const char MSG_FSENSOR_OFF_ES[] PROGMEM = "Filam. probe [off]";
const char MSG_FSENSOR_OFF_PL[] PROGMEM = "Filam. probe [off]";
const char MSG_FSENSOR_OFF_DE[] PROGMEM = "Filam. probe [off]";
const char MSG_FSENSOR_OFF_EN[] PROGMEM = "Fil. sensor [off]";
const char MSG_FSENSOR_OFF_CZ[] PROGMEM = "Fil. sensor [off]";
const char MSG_FSENSOR_OFF_IT[] PROGMEM = "Fil. sensor [off]";
const char MSG_FSENSOR_OFF_ES[] PROGMEM = "Fil. sensor [off]";
const char MSG_FSENSOR_OFF_PL[] PROGMEM = "Fil. sensor [off]";
const char MSG_FSENSOR_OFF_DE[] PROGMEM = "Fil. sensor [off]";
const char * const MSG_FSENSOR_OFF_LANG_TABLE[LANG_NUM] PROGMEM = {
MSG_FSENSOR_OFF_EN,
MSG_FSENSOR_OFF_CZ,
@ -2878,12 +2878,12 @@ const char * const MSG_FSENSOR_OFF_LANG_TABLE[LANG_NUM] PROGMEM = {
MSG_FSENSOR_OFF_DE
};
const char MSG_FSENSOR_ON_EN[] PROGMEM = "Filam. probe [on]";
const char MSG_FSENSOR_ON_CZ[] PROGMEM = "Filam. probe [on]";
const char MSG_FSENSOR_ON_IT[] PROGMEM = "Filam. probe [on]";
const char MSG_FSENSOR_ON_ES[] PROGMEM = "Filam. probe [on]";
const char MSG_FSENSOR_ON_PL[] PROGMEM = "Filam. probe [on]";
const char MSG_FSENSOR_ON_DE[] PROGMEM = "Filam. probe [on]";
const char MSG_FSENSOR_ON_EN[] PROGMEM = "Fil. sensor [on]";
const char MSG_FSENSOR_ON_CZ[] PROGMEM = "Fil. sensor [on]";
const char MSG_FSENSOR_ON_IT[] PROGMEM = "Fil. sensor [on]";
const char MSG_FSENSOR_ON_ES[] PROGMEM = "Fil. sensor [on]";
const char MSG_FSENSOR_ON_PL[] PROGMEM = "Fil. sensor [on]";
const char MSG_FSENSOR_ON_DE[] PROGMEM = "Fil. sensor [on]";
const char * const MSG_FSENSOR_ON_LANG_TABLE[LANG_NUM] PROGMEM = {
MSG_FSENSOR_ON_EN,
MSG_FSENSOR_ON_CZ,

View file

@ -36,6 +36,9 @@
#include "tmc2130.h"
#endif //TMC2130
#ifdef PAT9125
extern uint8_t fsensor_err_cnt;
#endif //PAT9125
//===========================================================================
//=============================public variables ============================
@ -759,6 +762,12 @@ void isr() {
// If current block is finished, reset pointer
if (step_events_completed >= current_block->step_event_count) {
#ifdef PAT9125
if (current_block->steps_e < 0) //black magic - decrement filament sensor errors for negative extruder move
if (fsensor_err_cnt) fsensor_err_cnt--;
#endif //PAT9125
current_block = NULL;
plan_discard_current_block();
}

View file

@ -277,14 +277,20 @@ void tmc2130_home_exit()
if (sg_homing_axes_mask & mask & (X_AXIS_MASK | Y_AXIS_MASK))
{
if (tmc2130_mode == TMC2130_MODE_SILENT)
{
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SILENT); // Configuration back to stealthChop
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_TCOOLTHRS, 0);
// tmc2130_wr_PWMCONF(tmc2130_cs[i], tmc2130_pwm_ampl[i], tmc2130_pwm_grad[i], tmc2130_pwm_freq[i], tmc2130_pwm_auto[i], 0, 0);
}
else
{
#ifdef TMC2130_SG_HOMING_SW_XY
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
#else //TMC2130_SG_HOMING_SW_XY
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
#endif //TMC2130_SG_HOMING_SW_XY
}
}
tmc2130_axis_stalled[axis] = false;
}
sg_homing_axes_mask = 0x00;

View file

@ -971,17 +971,17 @@ static void lcd_menu_temperatures()
}
}
extern void stop_and_save_print_to_ram();
extern void restore_print_from_ram_and_continue();
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);
static void lcd_menu_test_save()
{
stop_and_save_print_to_ram();
stop_and_save_print_to_ram(10, -0.8);
}
static void lcd_menu_test_restore()
{
restore_print_from_ram_and_continue();
restore_print_from_ram_and_continue(0.8);
}
static void lcd_preheat_menu()
@ -2523,8 +2523,11 @@ static void lcd_silent_mode_set() {
SilentModeMenu = !SilentModeMenu;
eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
#ifdef TMC2130
st_synchronize();
cli();
tmc2130_mode = SilentModeMenu?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
tmc2130_init();
sei();
#endif //TMC2130
digipot_init();
lcd_goto_menu(lcd_settings_menu, 7);
@ -3987,8 +3990,11 @@ static void lcd_silent_mode_set_tune() {
SilentModeMenu = !SilentModeMenu;
eeprom_update_byte((unsigned char*)EEPROM_SILENT, SilentModeMenu);
#ifdef TMC2130
st_synchronize();
cli();
tmc2130_mode = SilentModeMenu?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
tmc2130_init();
sei();
#endif //TMC2130
digipot_init();
lcd_goto_menu(lcd_tune_menu, 9);