initial version which works on old and new hw, initial version of idler sensor detection

This commit is contained in:
PavelSindler 2018-12-21 17:12:16 +01:00
parent 880163dbcb
commit 3c64bad1cb
7 changed files with 91 additions and 74 deletions

View File

@ -38,9 +38,10 @@ static int8_t mmu_state = 0;
uint8_t mmu_cmd = 0; uint8_t mmu_cmd = 0;
#ifdef MMU_IDLER_SENSOR_PIN //idler ir sensor
uint8_t mmu_idl_sens = 0; uint8_t mmu_idl_sens = 0;
#endif //MMU_IDLER_SENSOR_PIN bool mmu_idler_sensor_detected = false;
uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN; uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN;
@ -111,10 +112,25 @@ void mmu_init(void)
_delay_ms(10); //wait 10ms for sure _delay_ms(10); //wait 10ms for sure
mmu_reset(); //reset mmu (HW or SW), do not wait for response mmu_reset(); //reset mmu (HW or SW), do not wait for response
mmu_state = -1; mmu_state = -1;
#ifdef MMU_IDLER_SENSOR_PIN
PIN_INP(MMU_IDLER_SENSOR_PIN); //input mode PIN_INP(MMU_IDLER_SENSOR_PIN); //input mode
PIN_SET(MMU_IDLER_SENSOR_PIN); //pullup PIN_SET(MMU_IDLER_SENSOR_PIN); //pullup
#endif //MMU_IDLER_SENSOR_PIN }
//returns true if idler IR sensor was detected, otherwise returns false
bool check_for_idler_sensor()
{
bool detected = false;
//if MMU_IDLER_SENSOR_PIN input is low and pat9125sensor is not present we detected idler sensor
if ((PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) && fsensor_not_responding)
{
detected = true;
//printf_P(PSTR("Idler IR sensor detected\n"));
}
else
{
//printf_P(PSTR("Idler IR sensor not detected\n"));
}
return detected;
} }
//mmu main loop - state machine processing //mmu main loop - state machine processing
@ -167,9 +183,9 @@ void mmu_loop(void)
if ((PRINTER_TYPE == PRINTER_MK3) || (PRINTER_TYPE == PRINTER_MK3_SNMM)) if ((PRINTER_TYPE == PRINTER_MK3) || (PRINTER_TYPE == PRINTER_MK3_SNMM))
{ {
#ifdef MMU_DEBUG #if defined MMU_DEBUG && defined MMU_FINDA_DEBUG
puts_P(PSTR("MMU <= 'P0'")); puts_P(PSTR("MMU <= 'P0'"));
#endif //MMU_DEBUG #endif //MMU_DEBUG && MMU_FINDA_DEBUG
mmu_puts_P(PSTR("P0\n")); //send 'read finda' request mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
mmu_state = -4; mmu_state = -4;
} }
@ -187,9 +203,9 @@ void mmu_loop(void)
case -5: case -5:
if (mmu_rx_ok() > 0) if (mmu_rx_ok() > 0)
{ {
#ifdef MMU_DEBUG #if defined MMU_DEBUG && defined MMU_FINDA_DEBUG
puts_P(PSTR("MMU <= 'P0'")); puts_P(PSTR("MMU <= 'P0'"));
#endif //MMU_DEBUG #endif //MMU_DEBUG && MMU_FINDA_DEBUG
mmu_puts_P(PSTR("P0\n")); //send 'read finda' request mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
mmu_state = -4; mmu_state = -4;
} }
@ -198,11 +214,13 @@ void mmu_loop(void)
if (mmu_rx_ok() > 0) if (mmu_rx_ok() > 0)
{ {
fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
#ifdef MMU_DEBUG #if defined MMU_DEBUG && defined MMU_FINDA_DEBUG
printf_P(PSTR("MMU => '%dok'\n"), mmu_finda); printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
#endif //MMU_DEBUG #endif //MMU_DEBUG && MMU_FINDA_DEBUG
puts_P(PSTR("MMU - ENABLED")); puts_P(PSTR("MMU - ENABLED"));
mmu_enabled = true; mmu_enabled = true;
//if we have filament loaded into the nozzle, we can decide if printer has idler sensor right now; otherwise we will will wait till start of T-code so it will be detected on beginning of second T-code
if(check_for_idler_sensor()) mmu_idler_sensor_detected = true;
mmu_state = 1; mmu_state = 1;
} }
return; return;
@ -218,9 +236,7 @@ void mmu_loop(void)
mmu_printf_P(PSTR("T%d\n"), filament); mmu_printf_P(PSTR("T%d\n"), filament);
mmu_state = 3; // wait for response mmu_state = 3; // wait for response
mmu_fil_loaded = true; mmu_fil_loaded = true;
#ifdef MMU_IDLER_SENSOR_PIN if(mmu_idler_sensor_detected) mmu_idl_sens = 1; //if idler sensor detected, use it for T-code
mmu_idl_sens = 1; //enable idler sensor
#endif //MMU_IDLER_SENSOR_PIN
} }
else if ((mmu_cmd >= MMU_CMD_L0) && (mmu_cmd <= MMU_CMD_L4)) else if ((mmu_cmd >= MMU_CMD_L0) && (mmu_cmd <= MMU_CMD_L4))
{ {
@ -238,9 +254,7 @@ void mmu_loop(void)
#endif //MMU_DEBUG #endif //MMU_DEBUG
mmu_puts_P(PSTR("C0\n")); //send 'continue loading' mmu_puts_P(PSTR("C0\n")); //send 'continue loading'
mmu_state = 3; mmu_state = 3;
#ifdef MMU_IDLER_SENSOR_PIN if(mmu_idler_sensor_detected) mmu_idl_sens = 1; //if idler sensor detected use it for C0 code
mmu_idl_sens = 1; //enable idler sensor
#endif //MMU_IDLER_SENSOR_PIN
} }
else if (mmu_cmd == MMU_CMD_U0) else if (mmu_cmd == MMU_CMD_U0)
{ {
@ -273,9 +287,10 @@ void mmu_loop(void)
} }
else if ((mmu_last_response + 300) < millis()) //request every 300ms else if ((mmu_last_response + 300) < millis()) //request every 300ms
{ {
#ifdef MMU_DEBUG if(check_for_idler_sensor()) mmu_idler_sensor_detected = true;
#if defined MMU_DEBUG && defined MMU_FINDA_DEBUG
puts_P(PSTR("MMU <= 'P0'")); puts_P(PSTR("MMU <= 'P0'"));
#endif //MMU_DEBUG #endif //MMU_DEBUG && MMU_FINDA_DEBUG
mmu_puts_P(PSTR("P0\n")); //send 'read finda' request mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
mmu_state = 2; mmu_state = 2;
} }
@ -284,9 +299,9 @@ void mmu_loop(void)
if (mmu_rx_ok() > 0) if (mmu_rx_ok() > 0)
{ {
fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
#ifdef MMU_DEBUG #if defined MMU_DEBUG && MMU_FINDA_DEBUG
printf_P(PSTR("MMU => '%dok'\n"), mmu_finda); printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
#endif //MMU_DEBUG #endif //MMU_DEBUG && MMU_FINDA_DEBUG
//printf_P(PSTR("Eact: %d\n"), int(e_active())); //printf_P(PSTR("Eact: %d\n"), int(e_active()));
if (!mmu_finda && CHECK_FINDA && fsensor_enabled) { if (!mmu_finda && CHECK_FINDA && fsensor_enabled) {
fsensor_stop_and_save_print(); fsensor_stop_and_save_print();
@ -304,7 +319,7 @@ void mmu_loop(void)
} }
return; return;
case 3: //response to mmu commands case 3: //response to mmu commands
#ifdef MMU_IDLER_SENSOR_PIN if (mmu_idler_sensor_detected) {
if (mmu_idl_sens) if (mmu_idl_sens)
{ {
if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0)
@ -319,7 +334,7 @@ void mmu_loop(void)
//else //else
//printf_P(PSTR("MMU IDLER_SENSOR = 1 - WAIT\n")); //printf_P(PSTR("MMU IDLER_SENSOR = 1 - WAIT\n"));
} }
#endif //MMU_IDLER_SENSOR_PIN }
if (mmu_rx_ok() > 0) if (mmu_rx_ok() > 0)
{ {
#ifdef MMU_DEBUG #ifdef MMU_DEBUG
@ -379,6 +394,8 @@ void mmu_load_step() {
} }
bool mmu_get_response(uint8_t move) bool mmu_get_response(uint8_t move)
{ {
if (!mmu_idler_sensor_detected) move = MMU_NO_MOVE;
printf_P(PSTR("mmu_get_response - begin move:%d\n"), move); printf_P(PSTR("mmu_get_response - begin move:%d\n"), move);
KEEPALIVE_STATE(IN_PROCESS); KEEPALIVE_STATE(IN_PROCESS);
while (mmu_cmd != 0) while (mmu_cmd != 0)
@ -399,7 +416,6 @@ bool mmu_get_response(uint8_t move)
mmu_load_step(); mmu_load_step();
break; break;
case MMU_UNLOAD_MOVE: case MMU_UNLOAD_MOVE:
#ifdef MMU_IDLER_SENSOR_PIN
if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) //filament is still detected by idler sensor, printer helps with unlading if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) //filament is still detected by idler sensor, printer helps with unlading
{ {
printf_P(PSTR("Unload 1\n")); printf_P(PSTR("Unload 1\n"));
@ -408,7 +424,6 @@ bool mmu_get_response(uint8_t move)
st_synchronize(); st_synchronize();
} }
else //filament was unloaded from idler, no additional movements needed else //filament was unloaded from idler, no additional movements needed
#endif //MMU_IDLER_SENSOR_PIN
{ {
printf_P(PSTR("Unloading finished 1\n")); printf_P(PSTR("Unloading finished 1\n"));
disable_e0(); //turn off E-stepper to prevent overheating and alow filament pull-out if necessary disable_e0(); //turn off E-stepper to prevent overheating and alow filament pull-out if necessary
@ -417,7 +432,6 @@ bool mmu_get_response(uint8_t move)
break; break;
case MMU_TCODE_MOVE: //first do unload and then continue with infinite loading movements case MMU_TCODE_MOVE: //first do unload and then continue with infinite loading movements
#ifdef MMU_IDLER_SENSOR_PIN
if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) //filament detected by idler sensor, we must unload first if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) //filament detected by idler sensor, we must unload first
{ {
printf_P(PSTR("Unload 2\n")); printf_P(PSTR("Unload 2\n"));
@ -426,7 +440,6 @@ bool mmu_get_response(uint8_t move)
st_synchronize(); st_synchronize();
} }
else //delay to allow mmu unit to pull out filament from bondtech gears and then start with infinite loading else //delay to allow mmu unit to pull out filament from bondtech gears and then start with infinite loading
#endif //MMU_IDLER_SENSOR_PIN
{ {
printf_P(PSTR("Unloading finished 2\n")); printf_P(PSTR("Unloading finished 2\n"));
disable_e0(); //turn off E-stepper to prevent overheating and alow filament pull-out if necessary disable_e0(); //turn off E-stepper to prevent overheating and alow filament pull-out if necessary
@ -1243,9 +1256,9 @@ void mmu_eject_filament(uint8_t filament, bool recover)
void mmu_continue_loading() void mmu_continue_loading()
{ {
#ifdef MMU_IDLER_SENSOR_PIN
for (uint8_t i = 0; i < MMU_IDLER_SENSOR_ATTEMPTS_NR; i++) {
if (mmu_idler_sensor_detected) {
for (uint8_t i = 0; i < MMU_IDLER_SENSOR_ATTEMPTS_NR; i++) {
if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) return; if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) return;
#ifdef MMU_DEBUG #ifdef MMU_DEBUG
printf_P(PSTR("Additional load attempt nr. %d\n"), i); printf_P(PSTR("Additional load attempt nr. %d\n"), i);
@ -1277,7 +1290,8 @@ void mmu_continue_loading()
mmu_fil_loaded = false; //so we can retry same T-code again mmu_fil_loaded = false; //so we can retry same T-code again
restore_print_from_ram_and_continue(0); restore_print_from_ram_and_continue(0);
} }
#else }
else { //mmu_idler_sensor_detected == false
mmu_command(MMU_CMD_C0); mmu_command(MMU_CMD_C0);
#endif //MMU_IDLER_SENSOR_PIN }
} }

View File

@ -11,6 +11,7 @@ extern uint8_t mmu_extruder;
extern uint8_t tmp_extruder; extern uint8_t tmp_extruder;
extern int8_t mmu_finda; extern int8_t mmu_finda;
extern bool mmu_idler_sensor_detected;
extern int16_t mmu_version; extern int16_t mmu_version;
extern int16_t mmu_buildnr; extern int16_t mmu_buildnr;
@ -52,6 +53,7 @@ extern int mmu_printf_P(const char* format, ...);
extern int8_t mmu_rx_ok(void); extern int8_t mmu_rx_ok(void);
extern bool check_for_idler_sensor();
extern void mmu_init(void); extern void mmu_init(void);

View File

@ -121,6 +121,7 @@
#define TACH_0 79 // !!! changed from 81 (EINY03) #define TACH_0 79 // !!! changed from 81 (EINY03)
#define TACH_1 80 #define TACH_1 80
#define MMU_IDLER_SENSOR_PIN 62 //idler sensor @PK0 (digital pin 62/A8)
// Support for an 8 bit logic analyzer, for example the Saleae. // Support for an 8 bit logic analyzer, for example the Saleae.
// Channels 0-2 are fast, they could generate 2.667Mhz waveform with a software loop. // Channels 0-2 are fast, they could generate 2.667Mhz waveform with a software loop.

View File

@ -102,7 +102,7 @@
#define SDCARDDETECT 72 #define SDCARDDETECT 72
#define MMU_IDLER_SENSOR_PIN 62 //idler sensor @PK0 (digital pin 62/A8)
// Support for an 8 bit logic analyzer, for example the Saleae. // Support for an 8 bit logic analyzer, for example the Saleae.
// Channels 0-2 are fast, they could generate 2.667Mhz waveform with a software loop. // Channels 0-2 are fast, they could generate 2.667Mhz waveform with a software loop.

View File

@ -102,7 +102,7 @@
#define SDCARDDETECT 15 #define SDCARDDETECT 15
#define MMU_IDLER_SENSOR_PIN 62 //idler sensor @PK0 (digital pin 62/A8)
// Support for an 8 bit logic analyzer, for example the Saleae. // Support for an 8 bit logic analyzer, for example the Saleae.
// Channels 0-2 are fast, they could generate 2.667Mhz waveform with a software loop. // Channels 0-2 are fast, they could generate 2.667Mhz waveform with a software loop.

View File

@ -3653,9 +3653,9 @@ static void lcd_show_sensors_state()
if (mmu_enabled) { if (mmu_enabled) {
finda_state = mmu_finda; finda_state = mmu_finda;
} }
#ifdef MMU_IDLER_SENSOR_PIN if (mmu_idler_sensor_detected) {
idler_state = !PIN_GET(MMU_IDLER_SENSOR_PIN); idler_state = !PIN_GET(MMU_IDLER_SENSOR_PIN);
#endif }
lcd_puts_at_P(0, 0, _i("Sensors state")); lcd_puts_at_P(0, 0, _i("Sensors state"));
lcd_puts_at_P(1, 1, _i("PINDA:")); lcd_puts_at_P(1, 1, _i("PINDA:"));
lcd_set_cursor(LCD_WIDTH - 4, 1); lcd_set_cursor(LCD_WIDTH - 4, 1);

View File

@ -614,7 +614,7 @@
#define MMU_REQUIRED_FW_BUILDNR 83 #define MMU_REQUIRED_FW_BUILDNR 83
#define MMU_HWRESET #define MMU_HWRESET
//#define MMU_DEBUG //print communication between MMU2 and printer on serial //#define MMU_DEBUG //print communication between MMU2 and printer on serial
#define MMU_IDLER_SENSOR_PIN 62 //idler sensor @PK0 (digital pin 62/A8)
#define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning
#endif //__CONFIGURATION_PRUSA_H #endif //__CONFIGURATION_PRUSA_H