From 4e3ea41ba4b4704e7d14756233dbd2cb0c43f532 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 20 Feb 2018 15:30:18 +0100 Subject: [PATCH 01/19] Fix of a loss in precission when the extruder multiplier is set with M221. For 50um layers, the precision loss leads to holes in the print. --- Firmware/Marlin_main.cpp | 6 +++++- Firmware/planner.cpp | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7d3b0d5ae..a96abe2e6 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6527,7 +6527,11 @@ void get_coordinates() for(int8_t i=0; i < NUM_AXIS; i++) { if(code_seen(axis_codes[i])) { - destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i]; + destination[i] = (float)code_value(); + if (i == E_AXIS && extrudemultiply != 100) + destination[i] *= (extrudemultiply * 0.01f); + if (axis_relative_modes[i] || relative_mode) + destination[i] += current_position[i]; seen[i]=true; } else destination[i] = current_position[i]; //Are these else lines really needed? diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index d7f30d23f..2f5f358ef 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -784,10 +784,6 @@ block->steps_y = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-positi block->steps_e = labs(target[E_AXIS]-position[E_AXIS]); if (volumetric_multiplier[active_extruder] != 1.f) block->steps_e *= volumetric_multiplier[active_extruder]; - if (extrudemultiply != 100) { - block->steps_e *= extrudemultiply; - block->steps_e /= 100; - } block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e))); // Bail if this is a zero-length block @@ -919,7 +915,7 @@ Having the real displacement of the head, we can calculate the total movement le delta_mm[Y_AXIS] = ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]))/axis_steps_per_unit[Y_AXIS]; #endif delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS]; - delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*volumetric_multiplier[active_extruder]*extrudemultiply/100.0; + delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*volumetric_multiplier[active_extruder]; if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) { block->millimeters = fabs(delta_mm[E_AXIS]); From cff7b9b39647593fe90de7b73c6199b756c4d97c Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 21 Feb 2018 11:25:21 +0100 Subject: [PATCH 02/19] Unified the volumetric_multiplier with extrusion_multiply to improve numeric accuracy and to reduce compuatitonal load. With this commit, the numeric rounding is fixed not only for the M221 G-code (as implemented by the preceding commit), but also for the volumetric extrusion in general. Removed the old FILAMENT_SENSOR code, which served the purpose to modulate the volumetric multiplayer in real time depending on the measured filament diameter. This feature will certainly not be used by Prusa Research in the near future as we know of no sensor, which would offer sufficient accuracy for a reasonable price. --- Firmware/Configuration.h | 29 +------ Firmware/ConfigurationStore.cpp | 2 +- Firmware/Marlin.h | 13 +-- Firmware/Marlin_main.cpp | 135 +++++++------------------------- Firmware/planner.cpp | 51 +----------- Firmware/temperature.cpp | 60 +------------- Firmware/temperature.h | 8 -- 7 files changed, 32 insertions(+), 266 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index b8669c220..322ea8b22 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -789,34 +789,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // //#define NUM_SERVOS 3 // Servo index starts with 0 for M280 command -/**********************************************************************\ - * Support for a filament diameter sensor - * Also allows adjustment of diameter at print time (vs at slicing) - * Single extruder only at this point (extruder 0) - * - * Motherboards - * 34 - RAMPS1.4 - uses Analog input 5 on the AUX2 connector - * 81 - Printrboard - Uses Analog input 2 on the Exp1 connector (version B,C,D,E) - * 301 - Rambo - uses Analog input 3 - * Note may require analog pins to be defined for different motherboards - **********************************************************************/ -// Uncomment below to enable -//#define FILAMENT_SENSOR - -#define FILAMENT_SENSOR_EXTRUDER_NUM 0 //The number of the extruder that has the filament sensor (0,1,2) -#define MEASUREMENT_DELAY_CM 14 //measurement delay in cm. This is the distance from filament sensor to middle of barrel - -#define DEFAULT_NOMINAL_FILAMENT_DIA 3.0 //Enter the diameter (in mm) of the filament generally used (3.0 mm or 1.75 mm) - this is then used in the slicer software. Used for sensor reading validation -#define MEASURED_UPPER_LIMIT 3.30 //upper limit factor used for sensor reading validation in mm -#define MEASURED_LOWER_LIMIT 1.90 //lower limit factor for sensor reading validation in mm -#define MAX_MEASUREMENT_DELAY 20 //delay buffer size in bytes (1 byte = 1cm)- limits maximum measurement delay allowable (must be larger than MEASUREMENT_DELAY_CM and lower number saves RAM) - -//defines used in the code -#define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA //set measured to nominal initially - -//When using an LCD, uncomment the line below to display the Filament sensor data on the last line instead of status. Status will appear for 5 sec. -//#define FILAMENT_LCD_DISPLAY - +#define DEFAULT_NOMINAL_FILAMENT_DIA 1.75 //Enter the diameter (in mm) of the filament generally used (3.0 mm or 1.75 mm). Used by the volumetric extrusion. // Calibration status of the machine, to be stored into the EEPROM, // (unsigned char*)EEPROM_CALIBRATION_STATUS diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 9b0d0e878..253452fed 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -472,7 +472,7 @@ void Config_ResetDefault() filament_size[2] = DEFAULT_NOMINAL_FILAMENT_DIA; #endif #endif - calculate_volumetric_multipliers(); + calculate_extruder_multipliers(); SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded"); diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index f3f134630..a576a1f26 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -283,17 +283,6 @@ extern void homeaxis(int axis); extern unsigned char fanSpeedSoftPwm; #endif - -#ifdef FILAMENT_SENSOR - extern float filament_width_nominal; //holds the theoretical filament diameter ie., 3.00 or 1.75 - extern bool filament_sensor; //indicates that filament sensor readings should control extrusion - extern float filament_width_meas; //holds the filament diameter as accurately measured - extern signed char measurement_delay[]; //ring buffer to delay measurement - extern int delay_index1, delay_index2; //index into ring buffer - extern float delay_dist; //delay distance counter - extern int meas_delay_cm; //delay distance -#endif - #ifdef FWRETRACT extern bool autoretract_enabled; extern bool retracted[EXTRUDERS]; @@ -358,7 +347,7 @@ extern bool sortAlpha; extern char dir_names[3][9]; -extern void calculate_volumetric_multipliers(); +extern void calculate_extruder_multipliers(); // Similar to the default Arduino delay function, // but it keeps the background tasks running. diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a96abe2e6..3b51a67c4 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -334,7 +334,7 @@ float filament_size[EXTRUDERS] = { DEFAULT_NOMINAL_FILAMENT_DIA #endif #endif }; -float volumetric_multiplier[EXTRUDERS] = {1.0 +float extruder_multiplier[EXTRUDERS] = {1.0 #if EXTRUDERS > 1 , 1.0 #if EXTRUDERS > 2 @@ -411,18 +411,6 @@ bool cancel_heatup = false ; #define KEEPALIVE_STATE(n); #endif -#ifdef FILAMENT_SENSOR - //Variables for Filament Sensor input - float filament_width_nominal=DEFAULT_NOMINAL_FILAMENT_DIA; //Set nominal filament width, can be changed with M404 - bool filament_sensor=false; //M405 turns on filament_sensor control, M406 turns it off - float filament_width_meas=DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter - signed char measurement_delay[MAX_MEASUREMENT_DELAY+1]; //ring buffer to delay measurement store extruder factor after subtracting 100 - int delay_index1=0; //index into ring buffer - int delay_index2=-1; //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized - float delay_dist=0; //delay distance counter - int meas_delay_cm = MEASUREMENT_DELAY_CM; //distance delay setting -#endif - const char errormagic[] PROGMEM = "Error:"; const char echomagic[] PROGMEM = "echo:"; @@ -1971,11 +1959,7 @@ void refresh_cmd_timeout(void) destination[Y_AXIS]=current_position[Y_AXIS]; destination[Z_AXIS]=current_position[Z_AXIS]; destination[E_AXIS]=current_position[E_AXIS]; - if (swapretract) { - current_position[E_AXIS]+=retract_length_swap/volumetric_multiplier[active_extruder]; - } else { - current_position[E_AXIS]+=retract_length/volumetric_multiplier[active_extruder]; - } + current_position[E_AXIS]+=(swapretract?retract_length_swap:retract_length)*float(extrudemultiply)*0.01f; plan_set_e_position(current_position[E_AXIS]); float oldFeedrate = feedrate; feedrate=retract_feedrate*60; @@ -1992,12 +1976,7 @@ void refresh_cmd_timeout(void) destination[E_AXIS]=current_position[E_AXIS]; current_position[Z_AXIS]+=retract_zlift; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - //prepare_move(); - if (swapretract) { - current_position[E_AXIS]-=(retract_length_swap+retract_recover_length_swap)/volumetric_multiplier[active_extruder]; - } else { - current_position[E_AXIS]-=(retract_length+retract_recover_length)/volumetric_multiplier[active_extruder]; - } + current_position[E_AXIS]-=(swapretract?(retract_length_swap+retract_recover_length_swap):(retract_length+retract_recover_length))*float(extrudemultiply)*0.01f; plan_set_e_position(current_position[E_AXIS]); float oldFeedrate = feedrate; feedrate=retract_recover_feedrate*60; @@ -5066,7 +5045,7 @@ Sigma_Exit: //reserved for setting filament diameter via UFID or filament measuring device break; } - calculate_volumetric_multipliers(); + calculate_extruder_multipliers(); } break; case 201: // M201 @@ -5234,6 +5213,7 @@ Sigma_Exit: extrudemultiply = tmp_code ; } } + calculate_extruder_multipliers(); } break; @@ -5472,69 +5452,6 @@ Sigma_Exit: } break; -#ifdef FILAMENT_SENSOR -case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width - { - #if (FILWIDTH_PIN > -1) - if(code_seen('N')) filament_width_nominal=code_value(); - else{ - SERIAL_PROTOCOLPGM("Filament dia (nominal mm):"); - SERIAL_PROTOCOLLN(filament_width_nominal); - } - #endif - } - break; - - case 405: //M405 Turn on filament sensor for control - { - - - if(code_seen('D')) meas_delay_cm=code_value(); - - if(meas_delay_cm> MAX_MEASUREMENT_DELAY) - meas_delay_cm = MAX_MEASUREMENT_DELAY; - - if(delay_index2 == -1) //initialize the ring buffer if it has not been done since startup - { - int temp_ratio = widthFil_to_size_ratio(); - - for (delay_index1=0; delay_index1<(MAX_MEASUREMENT_DELAY+1); ++delay_index1 ){ - measurement_delay[delay_index1]=temp_ratio-100; //subtract 100 to scale within a signed byte - } - delay_index1=0; - delay_index2=0; - } - - filament_sensor = true ; - - //SERIAL_PROTOCOLPGM("Filament dia (measured mm):"); - //SERIAL_PROTOCOL(filament_width_meas); - //SERIAL_PROTOCOLPGM("Extrusion ratio(%):"); - //SERIAL_PROTOCOL(extrudemultiply); - } - break; - - case 406: //M406 Turn off filament sensor for control - { - filament_sensor = false ; - } - break; - - case 407: //M407 Display measured filament diameter - { - - - - SERIAL_PROTOCOLPGM("Filament dia (measured mm):"); - SERIAL_PROTOCOLLN(filament_width_meas); - } - break; - #endif - - - - - case 500: // M500 Store settings in EEPROM { Config_StoreSettings(EEPROM_OFFSET); @@ -6527,10 +6444,19 @@ void get_coordinates() for(int8_t i=0; i < NUM_AXIS; i++) { if(code_seen(axis_codes[i])) { + bool relative = axis_relative_modes[i] || relative_mode; destination[i] = (float)code_value(); - if (i == E_AXIS && extrudemultiply != 100) - destination[i] *= (extrudemultiply * 0.01f); - if (axis_relative_modes[i] || relative_mode) + if (i == E_AXIS) { + float emult = extruder_multiplier[active_extruder]; + if (emult != 1.) { + if (! relative) { + destination[i] -= current_position[i]; + relative = true; + } + destination[i] *= emult; + } + } + if (relative) destination[i] += current_position[i]; seen[i]=true; } @@ -7047,27 +6973,20 @@ void save_statistics(unsigned long _total_filament_used, unsigned long _total_pr } -float calculate_volumetric_multiplier(float diameter) { - float area = .0; - float radius = .0; - - radius = diameter * .5; - if (! volumetric_enabled || radius == 0) { - area = 1; - } - else { - area = M_PI * pow(radius, 2); - } - - return 1.0 / area; +float calculate_extruder_multiplier(float diameter) { + bool enabled = volumetric_enabled && diameter > 0; + float area = enabled ? (M_PI * pow(diameter * .5, 2)) : 0; + return (extrudemultiply == 100) ? + (enabled ? (1.f / area) : 1.f) : + (enabled ? ((float(extrudemultiply) * 0.01f) / area) : 1.f); } -void calculate_volumetric_multipliers() { - volumetric_multiplier[0] = calculate_volumetric_multiplier(filament_size[0]); +void calculate_extruder_multipliers() { + extruder_multiplier[0] = calculate_extruder_multiplier(filament_size[0]); #if EXTRUDERS > 1 - volumetric_multiplier[1] = calculate_volumetric_multiplier(filament_size[1]); + extruder_multiplier[1] = calculate_extruder_multiplier(filament_size[1]); #if EXTRUDERS > 2 - volumetric_multiplier[2] = calculate_volumetric_multiplier(filament_size[2]); + extruder_multiplier[2] = calculate_extruder_multiplier(filament_size[2]); #endif #endif } diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 2f5f358ef..b7c22d44f 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -126,10 +126,6 @@ static uint8_t g_cntr_planner_queue_min = 0; float extrude_min_temp=EXTRUDE_MINTEMP; #endif -#ifdef FILAMENT_SENSOR - static char meas_sample; //temporary variable to hold filament measurement sample -#endif - #ifdef LIN_ADVANCE float extruder_advance_k = LIN_ADVANCE_K, advance_ed_ratio = LIN_ADVANCE_E_D_RATIO, @@ -782,8 +778,6 @@ block->steps_y = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-positi #endif block->steps_z = labs(target[Z_AXIS]-position[Z_AXIS]); block->steps_e = labs(target[E_AXIS]-position[E_AXIS]); - if (volumetric_multiplier[active_extruder] != 1.f) - block->steps_e *= volumetric_multiplier[active_extruder]; block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e))); // Bail if this is a zero-length block @@ -915,7 +909,7 @@ Having the real displacement of the head, we can calculate the total movement le delta_mm[Y_AXIS] = ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]))/axis_steps_per_unit[Y_AXIS]; #endif delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS]; - delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*volumetric_multiplier[active_extruder]; + delta_mm[E_AXIS] = (target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS]; if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) { block->millimeters = fabs(delta_mm[E_AXIS]); @@ -951,49 +945,6 @@ Having the real displacement of the head, we can calculate the total movement le block->nominal_speed = block->millimeters * inverse_second; // (mm/sec) Always > 0 block->nominal_rate = ceil(block->step_event_count * inverse_second); // (step/sec) Always > 0 -#ifdef FILAMENT_SENSOR - //FMM update ring buffer used for delay with filament measurements - - - if((extruder==FILAMENT_SENSOR_EXTRUDER_NUM) && (delay_index2 > -1)) //only for extruder with filament sensor and if ring buffer is initialized - { - delay_dist = delay_dist + delta_mm[E_AXIS]; //increment counter with next move in e axis - - while (delay_dist >= (10*(MAX_MEASUREMENT_DELAY+1))) //check if counter is over max buffer size in mm - delay_dist = delay_dist - 10*(MAX_MEASUREMENT_DELAY+1); //loop around the buffer - while (delay_dist<0) - delay_dist = delay_dist + 10*(MAX_MEASUREMENT_DELAY+1); //loop around the buffer - - delay_index1=delay_dist/10.0; //calculate index - - //ensure the number is within range of the array after converting from floating point - if(delay_index1<0) - delay_index1=0; - else if (delay_index1>MAX_MEASUREMENT_DELAY) - delay_index1=MAX_MEASUREMENT_DELAY; - - if(delay_index1 != delay_index2) //moved index - { - meas_sample=widthFil_to_size_ratio()-100; //subtract off 100 to reduce magnitude - to store in a signed char - } - while( delay_index1 != delay_index2) - { - delay_index2 = delay_index2 + 1; - if(delay_index2>MAX_MEASUREMENT_DELAY) - delay_index2=delay_index2-(MAX_MEASUREMENT_DELAY+1); //loop around buffer when incrementing - if(delay_index2<0) - delay_index2=0; - else if (delay_index2>MAX_MEASUREMENT_DELAY) - delay_index2=MAX_MEASUREMENT_DELAY; - - measurement_delay[delay_index2]=meas_sample; - } - - - } -#endif - - // Calculate and limit speed in mm/sec for each axis float current_speed[4]; float speed_factor = 1.0; //factor <=1 do decrease speed diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 5e7704b8d..870e60e9c 100644 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -104,9 +104,6 @@ unsigned char soft_pwm_bed; volatile int babystepsTodo[3]={0,0,0}; #endif -#ifdef FILAMENT_SENSOR - int current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only -#endif //=========================================================================== //=============================private variables============================ //=========================================================================== @@ -204,9 +201,6 @@ unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0); #define SOFT_PWM_SCALE 0 #endif -#ifdef FILAMENT_SENSOR - static int meas_shift_index; //used to point to a delayed sample in buffer for filament width sensor -#endif //=========================================================================== //============================= functions ============================ //=========================================================================== @@ -810,27 +804,6 @@ void manage_heater() #endif #endif -//code for controlling the extruder rate based on the width sensor -#ifdef FILAMENT_SENSOR - if(filament_sensor) - { - meas_shift_index=delay_index1-meas_delay_cm; - if(meas_shift_index<0) - meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed - - //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter - //then square it to get an area - - if(meas_shift_index<0) - meas_shift_index=0; - else if (meas_shift_index>MAX_MEASUREMENT_DELAY) - meas_shift_index=MAX_MEASUREMENT_DELAY; - - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2); - if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; - } -#endif #ifdef HOST_KEEPALIVE_FEATURE host_keepalive(); #endif @@ -985,9 +958,7 @@ static void updateTemperaturesFromRawValues() #ifdef TEMP_SENSOR_1_AS_REDUNDANT redundant_temperature = analog2temp(redundant_temperature_raw, 1); #endif - #if defined (FILAMENT_SENSOR) && (FILWIDTH_PIN > -1) //check if a sensor is supported - filament_width_meas = analog2widthFil(); - #endif + //Reset the watchdog after we know we have a temperature measurement. watchdog_reset(); @@ -997,35 +968,6 @@ static void updateTemperaturesFromRawValues() } -// For converting raw Filament Width to milimeters -#ifdef FILAMENT_SENSOR -float analog2widthFil() { -return current_raw_filwidth/16383.0*5.0; -//return current_raw_filwidth; -} - -// For converting raw Filament Width to a ratio -int widthFil_to_size_ratio() { - -float temp; - -temp=filament_width_meas; -if(filament_width_measMEASURED_UPPER_LIMIT) - temp= MEASURED_UPPER_LIMIT; - - -return(filament_width_nominal/temp*100); - - -} -#endif - - - - - void tp_init() { #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1)) diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 73c503bcf..91791c4cf 100644 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -31,14 +31,6 @@ void tp_init(); //initialize the heating void manage_heater(); //it is critical that this is called periodically. -#ifdef FILAMENT_SENSOR -// For converting raw Filament Width to milimeters - float analog2widthFil(); - -// For converting raw Filament Width to an extrusion ratio - int widthFil_to_size_ratio(); -#endif - // low level conversion routines // do not use these routines and variables outside of temperature.cpp extern int target_temperature[EXTRUDERS]; From e249e854dad078b1abce7b892a1e95a4f9ef3108 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 26 Feb 2018 18:25:47 +0100 Subject: [PATCH 03/19] dev version: print m114 coordinates when z endstop was triggered --- Firmware/Configuration_prusa.h | 2 +- Firmware/Marlin.h | 1 + Firmware/Marlin_main.cpp | 49 +++++++++++++++++-------------- Firmware/mesh_bed_calibration.cpp | 31 ++++++++++++++----- Firmware/mesh_bed_calibration.h | 1 + Firmware/stepper.cpp | 1 + 6 files changed, 55 insertions(+), 30 deletions(-) diff --git a/Firmware/Configuration_prusa.h b/Firmware/Configuration_prusa.h index 5654506e7..41df5902a 100644 --- a/Firmware/Configuration_prusa.h +++ b/Firmware/Configuration_prusa.h @@ -60,7 +60,7 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define X_MIN_POS 0 #define Y_MAX_POS 210 #define Y_MIN_POS -4 -#define Z_MAX_POS 200 +#define Z_MAX_POS 210 #define Z_MIN_POS 0.15 // Canceled home position diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index a576a1f26..4b2271eec 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -435,6 +435,7 @@ void force_high_power_mode(bool start_high_power_section); // G-codes bool gcode_M45(bool onlyZ, int8_t verbosity_level); +void gcode_M114(); void gcode_M701(); #define UVLO !(PINE & (1<<4)) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3b51a67c4..d1ca24552 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1429,8 +1429,8 @@ void host_keepalive() { switch (busy_state) { case IN_HANDLER: case IN_PROCESS: - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("busy: processing"); + //SERIAL_ECHO_START; + //SERIAL_ECHOLNPGM("busy: processing"); break; case PAUSED_FOR_USER: SERIAL_ECHO_START; @@ -2276,6 +2276,29 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) return final_result; } +void gcode_M114() +{ + SERIAL_PROTOCOLPGM("X:"); + SERIAL_PROTOCOL(current_position[X_AXIS]); + SERIAL_PROTOCOLPGM(" Y:"); + SERIAL_PROTOCOL(current_position[Y_AXIS]); + SERIAL_PROTOCOLPGM(" Z:"); + SERIAL_PROTOCOL(current_position[Z_AXIS]); + SERIAL_PROTOCOLPGM(" E:"); + SERIAL_PROTOCOL(current_position[E_AXIS]); + + SERIAL_PROTOCOLRPGM(MSG_COUNT_X); + SERIAL_PROTOCOL(float(st_get_position(X_AXIS)) / axis_steps_per_unit[X_AXIS]); + SERIAL_PROTOCOLPGM(" Y:"); + SERIAL_PROTOCOL(float(st_get_position(Y_AXIS)) / axis_steps_per_unit[Y_AXIS]); + SERIAL_PROTOCOLPGM(" Z:"); + SERIAL_PROTOCOL(float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS]); + SERIAL_PROTOCOLPGM(" E:"); + SERIAL_PROTOCOL(float(st_get_position(E_AXIS)) / axis_steps_per_unit[E_AXIS]); + + SERIAL_PROTOCOLLN(""); +} + void gcode_M701() { #ifdef SNMM @@ -4246,7 +4269,7 @@ void process_commands() KEEPALIVE_STATE(IN_HANDLER); break; -#if 0 +#if 1 case 48: // M48: scan the bed induction sensor points, print the sensor trigger coordinates to the serial line for visualization on the PC. { // Disable the default update procedure of the display. We will do a modal dialog. @@ -4908,25 +4931,7 @@ Sigma_Exit: lcd_setstatus(strchr_pointer + 5); break;*/ case 114: // M114 - SERIAL_PROTOCOLPGM("X:"); - SERIAL_PROTOCOL(current_position[X_AXIS]); - SERIAL_PROTOCOLPGM(" Y:"); - SERIAL_PROTOCOL(current_position[Y_AXIS]); - SERIAL_PROTOCOLPGM(" Z:"); - SERIAL_PROTOCOL(current_position[Z_AXIS]); - SERIAL_PROTOCOLPGM(" E:"); - SERIAL_PROTOCOL(current_position[E_AXIS]); - - SERIAL_PROTOCOLRPGM(MSG_COUNT_X); - SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]); - SERIAL_PROTOCOLPGM(" Y:"); - SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]); - SERIAL_PROTOCOLPGM(" Z:"); - SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]); - SERIAL_PROTOCOLPGM(" E:"); - SERIAL_PROTOCOL(float(st_get_position(E_AXIS))/axis_steps_per_unit[E_AXIS]); - - SERIAL_PROTOCOLLN(""); + gcode_M114(); break; case 120: // M120 enable_endstops(false) ; diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 15e4743bf..3442b5527 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -975,13 +975,26 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } } endloop: -// SERIAL_ECHOLN("First hit"); + SERIAL_ECHO("First hit"); + SERIAL_ECHO("- X: "); + MYSERIAL.print(current_position[X_AXIS]); + SERIAL_ECHO("; Y: "); + MYSERIAL.print(current_position[Y_AXIS]); + SERIAL_ECHO("; Z: "); + MYSERIAL.println(current_position[Z_AXIS]); + + //scan + //if (current_position[X_AXIS] > 100 && current_position[Y_AXIS] > 100) { + // scan(); + //} // we have to let the planner know where we are right now as it is not where we said to go. update_current_position_xyz(); // Search in this plane for the first hit. Zig-zag first in X, then in Y axis. for (int8_t iter = 0; iter < 3; ++ iter) { + SERIAL_ECHOPGM("iter: "); + MYSERIAL.println(iter); if (iter > 0) { // Slightly lower the Z axis to get a reliable trigger. current_position[Z_AXIS] -= 0.02f; @@ -998,7 +1011,7 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) found = false; for (i = 0, dir_positive = true; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++ i, dir_positive = ! dir_positive) { go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); - if (endstop_z_hit_on_purpose()) { + if (endstop_z_hit_on_purpose()) { found = true; break; } @@ -1368,7 +1381,7 @@ canceled: // Searching in a zig-zag movement in a plane for the maximum width of the response. // This function may set the current_position[Y_AXIS] below Y_MIN_POS, if the function succeeded. // If this function failed, the Y coordinate will never be outside the working space. -#define IMPROVE_BED_INDUCTION_SENSOR_POINT3_SEARCH_RADIUS (4.f) +#define IMPROVE_BED_INDUCTION_SENSOR_POINT3_SEARCH_RADIUS (8.f) #define IMPROVE_BED_INDUCTION_SENSOR_POINT3_SEARCH_STEP_FINE_Y (0.1f) inline bool improve_bed_induction_sensor_point3(int verbosity_level) { @@ -2462,6 +2475,10 @@ bool sample_mesh_and_store_reference() return true; } +void scan() { + scan_bed_induction_sensor_point(); +} + bool scan_bed_induction_points(int8_t verbosity_level) { // Don't let the manage_inactivity() function remove power from the motors. @@ -2490,7 +2507,7 @@ bool scan_bed_induction_points(int8_t verbosity_level) bool endstop_z_enabled = enable_z_endstop(false); // Collect a matrix of 9x9 points. - for (int8_t mesh_point = 0; mesh_point < 9; ++ mesh_point) { + for (int8_t mesh_point = 2; mesh_point < 3; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); @@ -2501,14 +2518,14 @@ bool scan_bed_induction_points(int8_t verbosity_level) go_to_current(homing_feedrate[Z_AXIS]/60); // Go to the measurement point. // Use the coorrected coordinate, which is a result of find_bed_offset_and_skew(). - current_position[X_AXIS] = vec_x[0] * pgm_read_float(bed_ref_points+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points+mesh_point*2+1) + cntr[0]; - current_position[Y_AXIS] = vec_x[1] * pgm_read_float(bed_ref_points+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points+mesh_point*2+1) + cntr[1]; + current_position[X_AXIS] = vec_x[0] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[0]; + current_position[Y_AXIS] = vec_x[1] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[1]; // The calibration points are very close to the min Y. if (current_position[Y_AXIS] < Y_MIN_POS_FOR_BED_CALIBRATION) current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION; go_to_current(homing_feedrate[X_AXIS]/60); find_bed_induction_sensor_point_z(); - scan_bed_induction_sensor_point(); + scan_bed_induction_sensor_point(); } // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); diff --git a/Firmware/mesh_bed_calibration.h b/Firmware/mesh_bed_calibration.h index 4f6ebd724..0fa7d8757 100644 --- a/Firmware/mesh_bed_calibration.h +++ b/Firmware/mesh_bed_calibration.h @@ -172,6 +172,7 @@ extern bool is_bed_z_jitter_data_valid(); // write the trigger coordinates to the serial line. // Useful for visualizing the behavior of the bed induction detector. extern bool scan_bed_induction_points(int8_t verbosity_level); +extern void scan(); // Load Z babystep value from the EEPROM into babystepLoadZ, // but don't apply it through the planner. This is useful on wake up diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 8510daf9b..957d5ae8a 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -270,6 +270,7 @@ bool endstop_z_hit_on_purpose() { bool hit = endstop_z_hit; endstop_z_hit=false; + if (hit == true) gcode_M114(); return hit; } From 0d1cafded5596c2f8fa153d02fe75bf6d703be3c Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 26 Feb 2018 19:26:49 +0100 Subject: [PATCH 04/19] dont improve position of point in first row --- Firmware/mesh_bed_calibration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 3442b5527..91dbffbc9 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -1868,7 +1868,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level #endif // SUPPORT_VERBOSITY if (!find_bed_induction_sensor_point_xy(verbosity_level)) return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; -#if 1 +#if 0 if (k == 0 || k == 1) { // Improve the position of the 1st row sensor points by a zig-zag movement. From 98f0efbc66a3bef9a3b364d30c232904540393f9 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Wed, 28 Feb 2018 11:09:34 +0100 Subject: [PATCH 05/19] debug --- Firmware/Configuration_prusa.h | 2 +- Firmware/mesh_bed_calibration.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Firmware/Configuration_prusa.h b/Firmware/Configuration_prusa.h index 41df5902a..46c751046 100644 --- a/Firmware/Configuration_prusa.h +++ b/Firmware/Configuration_prusa.h @@ -468,6 +468,6 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define M600_TIMEOUT 600 //seconds -//#define SUPPORT_VERBOSITY +#define SUPPORT_VERBOSITY #endif //__CONFIGURATION_PRUSA_H diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 91dbffbc9..cd0c0c8db 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -983,6 +983,10 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) SERIAL_ECHO("; Z: "); MYSERIAL.println(current_position[Z_AXIS]); + lcd_show_fullscreen_message_and_wait_P(PSTR("First hit")); + lcd_update_enable(true); + + //scan //if (current_position[X_AXIS] > 100 && current_position[Y_AXIS] > 100) { // scan(); @@ -1011,6 +1015,8 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) found = false; for (i = 0, dir_positive = true; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++ i, dir_positive = ! dir_positive) { go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); + SERIAL_ECHOPGM("current position Z: "); + MYSERIAL.println(current_position[Z_AXIS]); if (endstop_z_hit_on_purpose()) { found = true; break; @@ -1018,7 +1024,7 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } update_current_position_xyz(); if (! found) { -// SERIAL_ECHOLN("Search in Y - not found"); + SERIAL_ECHOLN("Search in Y - not found"); continue; } // SERIAL_ECHOLN("Search in Y - found"); @@ -1031,14 +1037,16 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) found = false; for (i = 0, dir_positive = true; i < (nsteps_y - 1); current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++ i, dir_positive = ! dir_positive) { go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); - if (endstop_z_hit_on_purpose()) { + SERIAL_ECHOPGM("current position Z: "); + MYSERIAL.println(current_position[Z_AXIS]); + if (endstop_z_hit_on_purpose()) { found = true; break; } } update_current_position_xyz(); if (! found) { -// SERIAL_ECHOLN("Search in Y2 - not found"); + SERIAL_ECHOLN("Search in Y2 - not found"); continue; } // SERIAL_ECHOLN("Search in Y2 - found"); From 15a7699fe0263d21e7c79e92030516fe38196481 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Sat, 3 Mar 2018 20:05:43 +0100 Subject: [PATCH 06/19] max error for searching in xy --- Firmware/mesh_bed_calibration.cpp | 89 +++++++++++++++++++++++++------ Firmware/stepper.cpp | 2 +- 2 files changed, 73 insertions(+), 18 deletions(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index cd0c0c8db..baad04abd 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -904,7 +904,9 @@ error: #define FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS (8.f) #define FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS (4.f) #define FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP (1.f) -#define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (0.2f) +#define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (2.f) +#define FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR (0.01f) + inline bool find_bed_induction_sensor_point_xy(int verbosity_level) { #ifdef SUPPORT_VERBOSITY @@ -948,33 +950,70 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) enable_endstops(false); bool dir_positive = true; + float z_error = 2 * FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP; + float find_bed_induction_sensor_point_z_step = FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP; + float initial_z_position = current_position[Z_AXIS]; // go_xyz(current_position[X_AXIS], current_position[Y_AXIS], MESH_HOME_Z_SEARCH, homing_feedrate[Z_AXIS]/60); go_xyz(x0, y0, current_position[Z_AXIS], feedrate); // Continously lower the Z axis. endstops_hit_on_purpose(); enable_z_endstop(true); - while (current_position[Z_AXIS] > -10.f) { + while (current_position[Z_AXIS] > -10.f && z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { // Do nsteps_y zig-zag movements. + /*SERIAL_ECHOLNPGM("---------------"); + SERIAL_ECHOPGM("Y coordinate:"); + MYSERIAL.println(current_position[Y_AXIS]); + SERIAL_ECHOPGM("Z coordinate:"); + MYSERIAL.println(current_position[Z_AXIS]);*/ + SERIAL_ECHOPGM("z_error: "); + MYSERIAL.println(z_error); current_position[Y_AXIS] = y0; - for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++ i) { + initial_z_position = current_position[Z_AXIS]; + for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++ i) { // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. - current_position[Z_AXIS] -= FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP / float(nsteps_y); + current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); dir_positive = ! dir_positive; - if (endstop_z_hit_on_purpose()) - goto endloop; + if (endstop_z_hit_on_purpose()) { + update_current_position_xyz(); + z_error = 2 * (initial_z_position - current_position[Z_AXIS]); + if (z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { + find_bed_induction_sensor_point_z_step = z_error / 2; + current_position[Z_AXIS] += z_error; + enable_z_endstop(false); + go_xyz(x0, y0, current_position[Z_AXIS], feedrate); + enable_z_endstop(true); + } + goto endloop; + } } - for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++ i) { + initial_z_position = current_position[Z_AXIS]; + for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++ i) { // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. - current_position[Z_AXIS] -= FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP / float(nsteps_y); + current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); dir_positive = ! dir_positive; - if (endstop_z_hit_on_purpose()) - goto endloop; + if (endstop_z_hit_on_purpose()) { + update_current_position_xyz(); + z_error = 2 * (initial_z_position - current_position[Z_AXIS]); + if (z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { + find_bed_induction_sensor_point_z_step = z_error / 2; + current_position[Z_AXIS] += z_error; + enable_z_endstop(false); + go_xyz(x0, y0, current_position[Z_AXIS], feedrate); + enable_z_endstop(true); + } + goto endloop; + } } + endloop: ; + /*SERIAL_ECHOPGM("Y coordinate:"); + MYSERIAL.println(current_position[Y_AXIS]); + SERIAL_ECHOPGM("Z coordinate:"); + MYSERIAL.println(current_position[Z_AXIS]);*/ } - endloop: + // endloop: SERIAL_ECHO("First hit"); SERIAL_ECHO("- X: "); MYSERIAL.print(current_position[X_AXIS]); @@ -995,16 +1034,19 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) // we have to let the planner know where we are right now as it is not where we said to go. update_current_position_xyz(); + // Search in this plane for the first hit. Zig-zag first in X, then in Y axis. - for (int8_t iter = 0; iter < 3; ++ iter) { + for (int8_t iter = 0; iter < 9; ++ iter) { SERIAL_ECHOPGM("iter: "); MYSERIAL.println(iter); if (iter > 0) { // Slightly lower the Z axis to get a reliable trigger. - current_position[Z_AXIS] -= 0.02f; + current_position[Z_AXIS] -= 0.005f; go_xyz(current_position[X_AXIS], current_position[Y_AXIS], MESH_HOME_Z_SEARCH, homing_feedrate[Z_AXIS]/60); } + SERIAL_ECHOPGM("current_position[Z_AXIS]: "); + MYSERIAL.println(current_position[Z_AXIS]); // Do nsteps_y zig-zag movements. float a, b; enable_endstops(false); @@ -1015,8 +1057,8 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) found = false; for (i = 0, dir_positive = true; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++ i, dir_positive = ! dir_positive) { go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); - SERIAL_ECHOPGM("current position Z: "); - MYSERIAL.println(current_position[Z_AXIS]); + //SERIAL_ECHOPGM("current position Z: "); + //MYSERIAL.println(current_position[Z_AXIS]); if (endstop_z_hit_on_purpose()) { found = true; break; @@ -1028,6 +1070,8 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) continue; } // SERIAL_ECHOLN("Search in Y - found"); + lcd_show_fullscreen_message_and_wait_P(PSTR("first Y1 found")); + lcd_update_enable(true); a = current_position[Y_AXIS]; enable_z_endstop(false); @@ -1049,6 +1093,8 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) SERIAL_ECHOLN("Search in Y2 - not found"); continue; } + lcd_show_fullscreen_message_and_wait_P(PSTR("first Y2 found")); + lcd_update_enable(true); // SERIAL_ECHOLN("Search in Y2 - found"); b = current_position[Y_AXIS]; current_position[Y_AXIS] = 0.5f * (a + b); @@ -1058,23 +1104,27 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) enable_z_endstop(false); go_xy(x0, current_position[Y_AXIS], feedrate); enable_z_endstop(true); - go_xy(x1, current_position[Y_AXIS], feedrate); + go_xy(x1, current_position[Y_AXIS], feedrate/10); update_current_position_xyz(); if (! endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search X span 0 - not found"); continue; } + lcd_show_fullscreen_message_and_wait_P(PSTR("X1 found")); + lcd_update_enable(true); // SERIAL_ECHOLN("Search X span 0 - found"); a = current_position[X_AXIS]; enable_z_endstop(false); go_xy(x1, current_position[Y_AXIS], feedrate); enable_z_endstop(true); - go_xy(x0, current_position[Y_AXIS], feedrate); + go_xy(x0, current_position[Y_AXIS], feedrate/10); update_current_position_xyz(); if (! endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search X span 1 - not found"); continue; } + lcd_show_fullscreen_message_and_wait_P(PSTR("X2 found")); + lcd_update_enable(true); // SERIAL_ECHOLN("Search X span 1 - found"); b = current_position[X_AXIS]; // Go to the center. @@ -1095,6 +1145,8 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) // SERIAL_ECHOLN("Search Y2 span 0 - not found"); continue; } + lcd_show_fullscreen_message_and_wait_P(PSTR("Y1 found")); + lcd_update_enable(true); // SERIAL_ECHOLN("Search Y2 span 0 - found"); a = current_position[Y_AXIS]; enable_z_endstop(false); @@ -1108,6 +1160,9 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } // SERIAL_ECHOLN("Search Y2 span 1 - found"); b = current_position[Y_AXIS]; + lcd_show_fullscreen_message_and_wait_P(PSTR("Y2 found")); + lcd_update_enable(true); + // Go to the center. enable_z_endstop(false); current_position[Y_AXIS] = 0.5f * (a + b); diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 957d5ae8a..19283ff0c 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -270,7 +270,7 @@ bool endstop_z_hit_on_purpose() { bool hit = endstop_z_hit; endstop_z_hit=false; - if (hit == true) gcode_M114(); + //if (hit == true) gcode_M114(); return hit; } From ad702c6d1f145de96503b9ec820531e59df5b629 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Sun, 4 Mar 2018 20:21:31 +0100 Subject: [PATCH 07/19] improved algorithm for first hit, improving sensor point changed, just one calibration round for 4point heatbed (no second run for improving measured coordinates) --- Firmware/Marlin_main.cpp | 2 + Firmware/mesh_bed_calibration.cpp | 572 ++++++++++++++++++++---------- Firmware/stepper.cpp | 12 +- Firmware/stepper.h | 1 + 4 files changed, 391 insertions(+), 196 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d1ca24552..c553badad 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2228,6 +2228,7 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder); st_synchronize(); + #ifndef HEATBED_V2 if (result >= 0) { point_too_far_mask = 0; @@ -2246,6 +2247,7 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) st_synchronize(); // if (result >= 0) babystep_apply(); } + #endif //HEATBED_V2 lcd_bed_calibration_show_result(result, point_too_far_mask); if (result >= 0) { diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index baad04abd..996839c7b 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -907,21 +907,22 @@ error: #define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (2.f) #define FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR (0.01f) +#ifdef HEATBED_V2 inline bool find_bed_induction_sensor_point_xy(int verbosity_level) { #ifdef SUPPORT_VERBOSITY - if(verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy"); + if (verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy"); #endif // SUPPORT_VERBOSITY float feedrate = homing_feedrate[X_AXIS] / 60.f; - bool found = false; + bool found = false; - { - float x0 = current_position[X_AXIS] - FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS; - float x1 = current_position[X_AXIS] + FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS; - float y0 = current_position[Y_AXIS] - FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS; - float y1 = current_position[Y_AXIS] + FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS; - uint8_t nsteps_y; - uint8_t i; + { + float x0 = current_position[X_AXIS] - FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS; + float x1 = current_position[X_AXIS] + FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS; + float y0 = current_position[Y_AXIS] - FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS; + float y1 = current_position[Y_AXIS] + FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS; + uint8_t nsteps_y; + uint8_t i; if (x0 < X_MIN_POS) { x0 = X_MIN_POS; #ifdef SUPPORT_VERBOSITY @@ -946,35 +947,31 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius higher than X_MAX. Clamping was done."); #endif // SUPPORT_VERBOSITY } - nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP)); + nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP)); - enable_endstops(false); - bool dir_positive = true; + enable_endstops(false); + bool dir_positive = true; float z_error = 2 * FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP; float find_bed_induction_sensor_point_z_step = FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP; float initial_z_position = current_position[Z_AXIS]; -// go_xyz(current_position[X_AXIS], current_position[Y_AXIS], MESH_HOME_Z_SEARCH, homing_feedrate[Z_AXIS]/60); - go_xyz(x0, y0, current_position[Z_AXIS], feedrate); - // Continously lower the Z axis. - endstops_hit_on_purpose(); - enable_z_endstop(true); - while (current_position[Z_AXIS] > -10.f && z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { - // Do nsteps_y zig-zag movements. - /*SERIAL_ECHOLNPGM("---------------"); - SERIAL_ECHOPGM("Y coordinate:"); - MYSERIAL.println(current_position[Y_AXIS]); - SERIAL_ECHOPGM("Z coordinate:"); - MYSERIAL.println(current_position[Z_AXIS]);*/ - SERIAL_ECHOPGM("z_error: "); - MYSERIAL.println(z_error); - current_position[Y_AXIS] = y0; + // go_xyz(current_position[X_AXIS], current_position[Y_AXIS], MESH_HOME_Z_SEARCH, homing_feedrate[Z_AXIS]/60); + go_xyz(x0, y0, current_position[Z_AXIS], feedrate); + // Continously lower the Z axis. + endstops_hit_on_purpose(); + enable_z_endstop(true); + while (current_position[Z_AXIS] > -10.f && z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { + // Do nsteps_y zig-zag movements. + + //SERIAL_ECHOPGM("z_error: "); + //MYSERIAL.println(z_error); + current_position[Y_AXIS] = y0; initial_z_position = current_position[Z_AXIS]; - for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++ i) { - // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. - current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); - go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); - dir_positive = ! dir_positive; + for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++i) { + // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. + current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); + go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); + dir_positive = !dir_positive; if (endstop_z_hit_on_purpose()) { update_current_position_xyz(); z_error = 2 * (initial_z_position - current_position[Z_AXIS]); @@ -987,13 +984,13 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } goto endloop; } - } + } initial_z_position = current_position[Z_AXIS]; - for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++ i) { - // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. - current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); - go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); - dir_positive = ! dir_positive; + for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++i) { + // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. + current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); + go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); + dir_positive = !dir_positive; if (endstop_z_hit_on_purpose()) { update_current_position_xyz(); z_error = 2 * (initial_z_position - current_position[Z_AXIS]); @@ -1006,177 +1003,356 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } goto endloop; } - } - endloop: ; - /*SERIAL_ECHOPGM("Y coordinate:"); - MYSERIAL.println(current_position[Y_AXIS]); - SERIAL_ECHOPGM("Z coordinate:"); - MYSERIAL.println(current_position[Z_AXIS]);*/ - } - // endloop: - SERIAL_ECHO("First hit"); - SERIAL_ECHO("- X: "); - MYSERIAL.print(current_position[X_AXIS]); - SERIAL_ECHO("; Y: "); - MYSERIAL.print(current_position[Y_AXIS]); - SERIAL_ECHO("; Z: "); - MYSERIAL.println(current_position[Z_AXIS]); + } + endloop:; + } + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) { + SERIAL_ECHO("First hit"); + SERIAL_ECHO("- X: "); + MYSERIAL.print(current_position[X_AXIS]); + SERIAL_ECHO("; Y: "); + MYSERIAL.print(current_position[Y_AXIS]); + SERIAL_ECHO("; Z: "); + MYSERIAL.println(current_position[Z_AXIS]); + } + #endif //SUPPORT_VERBOSITY + //lcd_show_fullscreen_message_and_wait_P(PSTR("First hit")); + //lcd_update_enable(true); - lcd_show_fullscreen_message_and_wait_P(PSTR("First hit")); - lcd_update_enable(true); + float init_x_position = current_position[X_AXIS]; + float init_y_position = current_position[Y_AXIS]; - - //scan - //if (current_position[X_AXIS] > 100 && current_position[Y_AXIS] > 100) { - // scan(); - //} - - // we have to let the planner know where we are right now as it is not where we said to go. - update_current_position_xyz(); - - - // Search in this plane for the first hit. Zig-zag first in X, then in Y axis. - for (int8_t iter = 0; iter < 9; ++ iter) { - SERIAL_ECHOPGM("iter: "); + // we have to let the planner know where we are right now as it is not where we said to go. + update_current_position_xyz(); + enable_z_endstop(false); + + for (int8_t iter = 0; iter < 2; ++iter) { + /*SERIAL_ECHOPGM("iter: "); MYSERIAL.println(iter); - if (iter > 0) { - // Slightly lower the Z axis to get a reliable trigger. - current_position[Z_AXIS] -= 0.005f; - go_xyz(current_position[X_AXIS], current_position[Y_AXIS], MESH_HOME_Z_SEARCH, homing_feedrate[Z_AXIS]/60); - } + SERIAL_ECHOPGM("1 - current_position[Z_AXIS]: "); + MYSERIAL.println(current_position[Z_AXIS]);*/ - SERIAL_ECHOPGM("current_position[Z_AXIS]: "); - MYSERIAL.println(current_position[Z_AXIS]); - // Do nsteps_y zig-zag movements. - float a, b; - enable_endstops(false); - enable_z_endstop(false); - current_position[Y_AXIS] = y0; - go_xy(x0, current_position[Y_AXIS], feedrate); - enable_z_endstop(true); - found = false; - for (i = 0, dir_positive = true; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++ i, dir_positive = ! dir_positive) { - go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); - //SERIAL_ECHOPGM("current position Z: "); - //MYSERIAL.println(current_position[Z_AXIS]); - if (endstop_z_hit_on_purpose()) { - found = true; - break; - } - } - update_current_position_xyz(); - if (! found) { - SERIAL_ECHOLN("Search in Y - not found"); - continue; - } -// SERIAL_ECHOLN("Search in Y - found"); - lcd_show_fullscreen_message_and_wait_P(PSTR("first Y1 found")); + // Slightly lower the Z axis to get a reliable trigger. + current_position[Z_AXIS] -= 0.05f; + go_xyz(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], homing_feedrate[Z_AXIS] / (60 * 10)); + + SERIAL_ECHOPGM("2 - current_position[Z_AXIS]: "); + MYSERIAL.println(current_position[Z_AXIS]); + // Do nsteps_y zig-zag movements. + float a, b; + float avg[2] = { 0,0 }; + + for (int iteration = 0; iteration < 8; iteration++) { + + found = false; + enable_z_endstop(true, true); + go_xy(x0, current_position[Y_AXIS], feedrate / 3); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search X span 0 - not found"); + continue; + } + + //lcd_show_fullscreen_message_and_wait_P(PSTR("X1 found")); + //lcd_update_enable(true); + // SERIAL_ECHOLN("Search X span 0 - found"); + a = current_position[X_AXIS]; + enable_z_endstop(false); + go_xy(init_x_position, current_position[Y_AXIS], feedrate / 3); + enable_z_endstop(true); + go_xy(x1, current_position[Y_AXIS], feedrate / 3); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search X span 1 - not found"); + continue; + } + //lcd_show_fullscreen_message_and_wait_P(PSTR("X2 found")); + //lcd_update_enable(true); + // SERIAL_ECHOLN("Search X span 1 - found"); + b = current_position[X_AXIS]; + // Go to the center. + enable_z_endstop(false); + current_position[X_AXIS] = 0.5f * (a + b); + go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 3); + found = true; + + // Search in the Y direction along a cross. + found = false; + enable_z_endstop(true); + go_xy(current_position[X_AXIS], y0, feedrate / 3); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search Y2 span 0 - not found"); + continue; + } + //lcd_show_fullscreen_message_and_wait_P(PSTR("Y1 found")); + //lcd_update_enable(true); + // SERIAL_ECHOLN("Search Y2 span 0 - found"); + a = current_position[Y_AXIS]; + enable_z_endstop(false); + go_xy(current_position[X_AXIS], init_y_position, feedrate / 3); + enable_z_endstop(true); + go_xy(current_position[X_AXIS], y1, feedrate / 3); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search Y2 span 1 - not found"); + continue; + } + // SERIAL_ECHOLN("Search Y2 span 1 - found"); + b = current_position[Y_AXIS]; + //lcd_show_fullscreen_message_and_wait_P(PSTR("Y2 found")); + //lcd_update_enable(true); + + // Go to the center. + enable_z_endstop(false, false); + current_position[Y_AXIS] = 0.5f * (a + b); + go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 3); + + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) { + SERIAL_ECHOPGM("ITERATION: "); + MYSERIAL.println(iteration); + SERIAL_ECHOPGM("CURRENT POSITION X: "); + MYSERIAL.println(current_position[X_AXIS]); + SERIAL_ECHOPGM("CURRENT POSITION Y: "); + MYSERIAL.println(current_position[Y_AXIS]); + } + #endif //SUPPORT_VERBOSITY + + if (iteration > 3) { + // Average the last 4 measurements. + avg[X_AXIS] += current_position[X_AXIS]; + avg[Y_AXIS] += current_position[Y_AXIS]; + } + + found = true; + + } + avg[X_AXIS] *= (1.f / 4.f); + avg[Y_AXIS] *= (1.f / 4.f); + + current_position[X_AXIS] = avg[X_AXIS]; + current_position[Y_AXIS] = avg[Y_AXIS]; + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) { + SERIAL_ECHOPGM("AVG CURRENT POSITION X: "); + MYSERIAL.println(current_position[X_AXIS]); + SERIAL_ECHOPGM("AVG CURRENT POSITION Y: "); + MYSERIAL.println(current_position[Y_AXIS]); + } + #endif // SUPPORT_VERBOSITY + go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate); + lcd_show_fullscreen_message_and_wait_P(PSTR("Final position")); lcd_update_enable(true); - a = current_position[Y_AXIS]; - enable_z_endstop(false); - current_position[Y_AXIS] = y1; - go_xy(x0, current_position[Y_AXIS], feedrate); - enable_z_endstop(true); - found = false; - for (i = 0, dir_positive = true; i < (nsteps_y - 1); current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++ i, dir_positive = ! dir_positive) { - go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); - SERIAL_ECHOPGM("current position Z: "); - MYSERIAL.println(current_position[Z_AXIS]); + break; + } + } + + enable_z_endstop(false); + return found; + +} +#else //HEATBED_V2 +inline bool find_bed_induction_sensor_point_xy(int verbosity_level) +{ + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy"); + #endif // SUPPORT_VERBOSITY + float feedrate = homing_feedrate[X_AXIS] / 60.f; + bool found = false; + + { + float x0 = current_position[X_AXIS] - FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS; + float x1 = current_position[X_AXIS] + FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS; + float y0 = current_position[Y_AXIS] - FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS; + float y1 = current_position[Y_AXIS] + FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS; + uint8_t nsteps_y; + uint8_t i; + if (x0 < X_MIN_POS) { + x0 = X_MIN_POS; + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius lower than X_MIN. Clamping was done."); + #endif // SUPPORT_VERBOSITY + } + if (x1 > X_MAX_POS) { + x1 = X_MAX_POS; + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius higher than X_MAX. Clamping was done."); + #endif // SUPPORT_VERBOSITY + } + if (y0 < Y_MIN_POS_FOR_BED_CALIBRATION) { + y0 = Y_MIN_POS_FOR_BED_CALIBRATION; + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius lower than Y_MIN. Clamping was done."); + #endif // SUPPORT_VERBOSITY + } + if (y1 > Y_MAX_POS) { + y1 = Y_MAX_POS; + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius higher than X_MAX. Clamping was done."); + #endif // SUPPORT_VERBOSITY + } + nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP)); + + enable_endstops(false); + bool dir_positive = true; + + // go_xyz(current_position[X_AXIS], current_position[Y_AXIS], MESH_HOME_Z_SEARCH, homing_feedrate[Z_AXIS]/60); + go_xyz(x0, y0, current_position[Z_AXIS], feedrate); + // Continously lower the Z axis. + endstops_hit_on_purpose(); + enable_z_endstop(true); + while (current_position[Z_AXIS] > -10.f) { + // Do nsteps_y zig-zag movements. + current_position[Y_AXIS] = y0; + for (i = 0; i < nsteps_y; current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++i) { + // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. + current_position[Z_AXIS] -= FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP / float(nsteps_y); + go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); + dir_positive = !dir_positive; + if (endstop_z_hit_on_purpose()) + goto endloop; + } + for (i = 0; i < nsteps_y; current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++i) { + // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. + current_position[Z_AXIS] -= FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP / float(nsteps_y); + go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); + dir_positive = !dir_positive; + if (endstop_z_hit_on_purpose()) + goto endloop; + } + } + endloop: + // SERIAL_ECHOLN("First hit"); + + // we have to let the planner know where we are right now as it is not where we said to go. + update_current_position_xyz(); + + // Search in this plane for the first hit. Zig-zag first in X, then in Y axis. + for (int8_t iter = 0; iter < 3; ++iter) { + if (iter > 0) { + // Slightly lower the Z axis to get a reliable trigger. + current_position[Z_AXIS] -= 0.02f; + go_xyz(current_position[X_AXIS], current_position[Y_AXIS], MESH_HOME_Z_SEARCH, homing_feedrate[Z_AXIS] / 60); + } + + // Do nsteps_y zig-zag movements. + float a, b; + enable_endstops(false); + enable_z_endstop(false); + current_position[Y_AXIS] = y0; + go_xy(x0, current_position[Y_AXIS], feedrate); + enable_z_endstop(true); + found = false; + for (i = 0, dir_positive = true; i < nsteps_y; current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++i, dir_positive = !dir_positive) { + go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); if (endstop_z_hit_on_purpose()) { - found = true; - break; - } - } - update_current_position_xyz(); - if (! found) { - SERIAL_ECHOLN("Search in Y2 - not found"); - continue; - } - lcd_show_fullscreen_message_and_wait_P(PSTR("first Y2 found")); - lcd_update_enable(true); -// SERIAL_ECHOLN("Search in Y2 - found"); - b = current_position[Y_AXIS]; - current_position[Y_AXIS] = 0.5f * (a + b); + found = true; + break; + } + } + update_current_position_xyz(); + if (!found) { + // SERIAL_ECHOLN("Search in Y - not found"); + continue; + } + // SERIAL_ECHOLN("Search in Y - found"); + a = current_position[Y_AXIS]; - // Search in the X direction along a cross. - found = false; - enable_z_endstop(false); - go_xy(x0, current_position[Y_AXIS], feedrate); - enable_z_endstop(true); - go_xy(x1, current_position[Y_AXIS], feedrate/10); - update_current_position_xyz(); - if (! endstop_z_hit_on_purpose()) { -// SERIAL_ECHOLN("Search X span 0 - not found"); - continue; - } - lcd_show_fullscreen_message_and_wait_P(PSTR("X1 found")); - lcd_update_enable(true); -// SERIAL_ECHOLN("Search X span 0 - found"); - a = current_position[X_AXIS]; - enable_z_endstop(false); - go_xy(x1, current_position[Y_AXIS], feedrate); - enable_z_endstop(true); - go_xy(x0, current_position[Y_AXIS], feedrate/10); - update_current_position_xyz(); - if (! endstop_z_hit_on_purpose()) { -// SERIAL_ECHOLN("Search X span 1 - not found"); - continue; - } - lcd_show_fullscreen_message_and_wait_P(PSTR("X2 found")); - lcd_update_enable(true); -// SERIAL_ECHOLN("Search X span 1 - found"); - b = current_position[X_AXIS]; - // Go to the center. - enable_z_endstop(false); - current_position[X_AXIS] = 0.5f * (a + b); - go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate); - found = true; + enable_z_endstop(false); + current_position[Y_AXIS] = y1; + go_xy(x0, current_position[Y_AXIS], feedrate); + enable_z_endstop(true); + found = false; + for (i = 0, dir_positive = true; i < nsteps_y; current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++i, dir_positive = !dir_positive) { + go_xy(dir_positive ? x1 : x0, current_position[Y_AXIS], feedrate); + if (endstop_z_hit_on_purpose()) { + found = true; + break; + } + } + update_current_position_xyz(); + if (!found) { + // SERIAL_ECHOLN("Search in Y2 - not found"); + continue; + } + // SERIAL_ECHOLN("Search in Y2 - found"); + b = current_position[Y_AXIS]; + current_position[Y_AXIS] = 0.5f * (a + b); + + // Search in the X direction along a cross. + found = false; + enable_z_endstop(false); + go_xy(x0, current_position[Y_AXIS], feedrate); + enable_z_endstop(true); + go_xy(x1, current_position[Y_AXIS], feedrate); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search X span 0 - not found"); + continue; + } + // SERIAL_ECHOLN("Search X span 0 - found"); + a = current_position[X_AXIS]; + enable_z_endstop(false); + go_xy(x1, current_position[Y_AXIS], feedrate); + enable_z_endstop(true); + go_xy(x0, current_position[Y_AXIS], feedrate); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search X span 1 - not found"); + continue; + } + // SERIAL_ECHOLN("Search X span 1 - found"); + b = current_position[X_AXIS]; + // Go to the center. + enable_z_endstop(false); + current_position[X_AXIS] = 0.5f * (a + b); + go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate); + found = true; #if 1 - // Search in the Y direction along a cross. - found = false; - enable_z_endstop(false); - go_xy(current_position[X_AXIS], y0, feedrate); - enable_z_endstop(true); - go_xy(current_position[X_AXIS], y1, feedrate); - update_current_position_xyz(); - if (! endstop_z_hit_on_purpose()) { -// SERIAL_ECHOLN("Search Y2 span 0 - not found"); - continue; - } - lcd_show_fullscreen_message_and_wait_P(PSTR("Y1 found")); - lcd_update_enable(true); -// SERIAL_ECHOLN("Search Y2 span 0 - found"); - a = current_position[Y_AXIS]; - enable_z_endstop(false); - go_xy(current_position[X_AXIS], y1, feedrate); - enable_z_endstop(true); - go_xy(current_position[X_AXIS], y0, feedrate); - update_current_position_xyz(); - if (! endstop_z_hit_on_purpose()) { -// SERIAL_ECHOLN("Search Y2 span 1 - not found"); - continue; - } -// SERIAL_ECHOLN("Search Y2 span 1 - found"); - b = current_position[Y_AXIS]; - lcd_show_fullscreen_message_and_wait_P(PSTR("Y2 found")); - lcd_update_enable(true); - - // Go to the center. - enable_z_endstop(false); - current_position[Y_AXIS] = 0.5f * (a + b); - go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate); - found = true; + // Search in the Y direction along a cross. + found = false; + enable_z_endstop(false); + go_xy(current_position[X_AXIS], y0, feedrate); + enable_z_endstop(true); + go_xy(current_position[X_AXIS], y1, feedrate); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search Y2 span 0 - not found"); + continue; + } + // SERIAL_ECHOLN("Search Y2 span 0 - found"); + a = current_position[Y_AXIS]; + enable_z_endstop(false); + go_xy(current_position[X_AXIS], y1, feedrate); + enable_z_endstop(true); + go_xy(current_position[X_AXIS], y0, feedrate); + update_current_position_xyz(); + if (!endstop_z_hit_on_purpose()) { + // SERIAL_ECHOLN("Search Y2 span 1 - not found"); + continue; + } + // SERIAL_ECHOLN("Search Y2 span 1 - found"); + b = current_position[Y_AXIS]; + // Go to the center. + enable_z_endstop(false); + current_position[Y_AXIS] = 0.5f * (a + b); + go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate); + found = true; #endif - break; - } - } + break; + } + } - enable_z_endstop(false); - return found; + enable_z_endstop(false); + return found; } +#endif //HEATBED_V2 + // Search around the current_position[X,Y,Z]. // It is expected, that the induction sensor is switched on at the current position. // Look around this center point by painting a star around the point. @@ -2211,6 +2387,9 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 // by a cross center method. // Use a zig-zag search for the first row of the points. found = improve_bed_induction_sensor_point3(verbosity_level); + //found = improve_bed_induction_sensor_point2(mesh_point < 2, verbosity_level); + SERIAL_ECHOPGM("ITER: "); + SERIAL_ECHO(iter); } else { switch (method) { case 0: found = improve_bed_induction_sensor_point(); break; @@ -2219,6 +2398,9 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 } } if (found) { + lcd_show_fullscreen_message_and_wait_P(PSTR("found")); + lcd_update_enable(true); + if (iter > 3) { // Average the last 4 measurements. pts[mesh_point*2 ] += current_position[X_AXIS]; diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 19283ff0c..29d4c84ce 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -98,6 +98,7 @@ static bool old_z_max_endstop=false; static bool check_endstops = true; static bool check_z_endstop = false; +static bool z_endstop_invert = false; int8_t SilentMode = 0; @@ -283,6 +284,15 @@ bool enable_endstops(bool check) bool enable_z_endstop(bool check) { + bool old = check_z_endstop; + check_z_endstop = check; + endstop_z_hit = false; + return old; +} + +bool enable_z_endstop(bool check, bool endstop_invert) +{ + z_endstop_invert = endstop_invert; bool old = check_z_endstop; check_z_endstop = check; endstop_z_hit=false; @@ -606,7 +616,7 @@ void isr() { // Stall guard homing turned on z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0); #else - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + z_min_endstop = (READ(Z_MIN_PIN) != z_endstop_invert); #endif //TMC2130_SG_HOMING if(z_min_endstop && old_z_min_endstop) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 2fdec2d6c..915483feb 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -93,6 +93,7 @@ bool endstop_z_hit_on_purpose(); bool enable_endstops(bool check); // Enable/disable endstop checking. Return the old value. bool enable_z_endstop(bool check); +bool enable_z_endstop(bool check, bool endstop_invert); void checkStepperErrors(); //Print errors detected by the stepper From 8800793dd16b6ae51593275f3f5907517a0b3e05 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Sun, 4 Mar 2018 20:49:34 +0100 Subject: [PATCH 08/19] removing debug code --- Firmware/Marlin_main.cpp | 6 +++--- Firmware/mesh_bed_calibration.cpp | 22 ++++++++-------------- Firmware/mesh_bed_calibration.h | 1 - Firmware/stepper.cpp | 9 ++------- Firmware/stepper.h | 2 +- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index c553badad..c1e627f4f 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1429,8 +1429,8 @@ void host_keepalive() { switch (busy_state) { case IN_HANDLER: case IN_PROCESS: - //SERIAL_ECHO_START; - //SERIAL_ECHOLNPGM("busy: processing"); + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("busy: processing"); break; case PAUSED_FOR_USER: SERIAL_ECHO_START; @@ -4271,7 +4271,7 @@ void process_commands() KEEPALIVE_STATE(IN_HANDLER); break; -#if 1 +#if 0 case 48: // M48: scan the bed induction sensor points, print the sensor trigger coordinates to the serial line for visualization on the PC. { // Disable the default update procedure of the display. We will do a modal dialog. diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 996839c7b..9f6999bf6 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -904,8 +904,12 @@ error: #define FIND_BED_INDUCTION_SENSOR_POINT_X_RADIUS (8.f) #define FIND_BED_INDUCTION_SENSOR_POINT_Y_RADIUS (4.f) #define FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP (1.f) +#ifdef HEATBED_V2 #define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (2.f) #define FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR (0.01f) +#else //HEATBED_V2 +#define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (0.2f) +#endif //HEATBED_V2 #ifdef HEATBED_V2 inline bool find_bed_induction_sensor_point_xy(int verbosity_level) @@ -2107,7 +2111,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level #endif // SUPPORT_VERBOSITY if (!find_bed_induction_sensor_point_xy(verbosity_level)) return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; -#if 0 +#if 1 if (k == 0 || k == 1) { // Improve the position of the 1st row sensor points by a zig-zag movement. @@ -2387,9 +2391,6 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 // by a cross center method. // Use a zig-zag search for the first row of the points. found = improve_bed_induction_sensor_point3(verbosity_level); - //found = improve_bed_induction_sensor_point2(mesh_point < 2, verbosity_level); - SERIAL_ECHOPGM("ITER: "); - SERIAL_ECHO(iter); } else { switch (method) { case 0: found = improve_bed_induction_sensor_point(); break; @@ -2398,9 +2399,6 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 } } if (found) { - lcd_show_fullscreen_message_and_wait_P(PSTR("found")); - lcd_update_enable(true); - if (iter > 3) { // Average the last 4 measurements. pts[mesh_point*2 ] += current_position[X_AXIS]; @@ -2720,10 +2718,6 @@ bool sample_mesh_and_store_reference() return true; } -void scan() { - scan_bed_induction_sensor_point(); -} - bool scan_bed_induction_points(int8_t verbosity_level) { // Don't let the manage_inactivity() function remove power from the motors. @@ -2752,7 +2746,7 @@ bool scan_bed_induction_points(int8_t verbosity_level) bool endstop_z_enabled = enable_z_endstop(false); // Collect a matrix of 9x9 points. - for (int8_t mesh_point = 2; mesh_point < 3; ++ mesh_point) { + for (int8_t mesh_point = 0; mesh_point < 9; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); @@ -2763,8 +2757,8 @@ bool scan_bed_induction_points(int8_t verbosity_level) go_to_current(homing_feedrate[Z_AXIS]/60); // Go to the measurement point. // Use the coorrected coordinate, which is a result of find_bed_offset_and_skew(). - current_position[X_AXIS] = vec_x[0] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[0]; - current_position[Y_AXIS] = vec_x[1] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[1]; + current_position[X_AXIS] = vec_x[0] * pgm_read_float(bed_ref_points+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points+mesh_point*2+1) + cntr[0]; + current_position[Y_AXIS] = vec_x[1] * pgm_read_float(bed_ref_points+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points+mesh_point*2+1) + cntr[1]; // The calibration points are very close to the min Y. if (current_position[Y_AXIS] < Y_MIN_POS_FOR_BED_CALIBRATION) current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION; diff --git a/Firmware/mesh_bed_calibration.h b/Firmware/mesh_bed_calibration.h index 0fa7d8757..4f6ebd724 100644 --- a/Firmware/mesh_bed_calibration.h +++ b/Firmware/mesh_bed_calibration.h @@ -172,7 +172,6 @@ extern bool is_bed_z_jitter_data_valid(); // write the trigger coordinates to the serial line. // Useful for visualizing the behavior of the bed induction detector. extern bool scan_bed_induction_points(int8_t verbosity_level); -extern void scan(); // Load Z babystep value from the EEPROM into babystepLoadZ, // but don't apply it through the planner. This is useful on wake up diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 29d4c84ce..27c200817 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -271,7 +271,6 @@ bool endstop_z_hit_on_purpose() { bool hit = endstop_z_hit; endstop_z_hit=false; - //if (hit == true) gcode_M114(); return hit; } @@ -290,13 +289,9 @@ bool enable_z_endstop(bool check) return old; } -bool enable_z_endstop(bool check, bool endstop_invert) +void invert_z_endstop(bool endstop_invert) { z_endstop_invert = endstop_invert; - bool old = check_z_endstop; - check_z_endstop = check; - endstop_z_hit=false; - return old; } // __________________________ @@ -614,7 +609,7 @@ void isr() { // Good for searching for the center of an induction target. #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0); + z_min_endstop = (READ(Z_MIN_PIN) != z_endstop_invert) || (READ(Z_TMC2130_DIAG) != 0); #else z_min_endstop = (READ(Z_MIN_PIN) != z_endstop_invert); #endif //TMC2130_SG_HOMING diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 915483feb..3c1e6ffed 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -93,7 +93,7 @@ bool endstop_z_hit_on_purpose(); bool enable_endstops(bool check); // Enable/disable endstop checking. Return the old value. bool enable_z_endstop(bool check); -bool enable_z_endstop(bool check, bool endstop_invert); +void invert_z_endstop(bool endstop_invert); void checkStepperErrors(); //Print errors detected by the stepper From f1410a37f2b3faa3a770919ef166c9d9785f4d8c Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Sun, 4 Mar 2018 23:49:54 +0100 Subject: [PATCH 09/19] samle z after xyz cal. added, find_point_xy: initial z coordinate after first hit lowered --- Firmware/Marlin_main.cpp | 10 +++-- Firmware/mesh_bed_calibration.cpp | 66 ++++++++++++++++++------------- Firmware/mesh_bed_calibration.h | 1 + Firmware/stepper.cpp | 2 +- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index c1e627f4f..d33ff0200 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2228,9 +2228,12 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder); st_synchronize(); - #ifndef HEATBED_V2 + if (result >= 0) { + #ifdef HEATBED_V2 + sample_z(); + #else //HEATBED_V2 point_too_far_mask = 0; // Second half: The fine adjustment. // Let the planner use the uncorrected coordinates. @@ -2245,9 +2248,10 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder); st_synchronize(); - // if (result >= 0) babystep_apply(); + // if (result >= 0) babystep_apply(); + #endif //HEATBED_V2 } - #endif //HEATBED_V2 + lcd_bed_calibration_show_result(result, point_too_far_mask); if (result >= 0) { diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 9f6999bf6..044df2349 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -1038,7 +1038,7 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) MYSERIAL.println(current_position[Z_AXIS]);*/ // Slightly lower the Z axis to get a reliable trigger. - current_position[Z_AXIS] -= 0.05f; + current_position[Z_AXIS] -= 0.1f; go_xyz(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], homing_feedrate[Z_AXIS] / (60 * 10)); SERIAL_ECHOPGM("2 - current_position[Z_AXIS]: "); @@ -1050,8 +1050,9 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) for (int iteration = 0; iteration < 8; iteration++) { found = false; - enable_z_endstop(true, true); - go_xy(x0, current_position[Y_AXIS], feedrate / 3); + invert_z_endstop(true); + enable_z_endstop(true); + go_xy(x0, current_position[Y_AXIS], feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search X span 0 - not found"); @@ -1063,9 +1064,9 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) // SERIAL_ECHOLN("Search X span 0 - found"); a = current_position[X_AXIS]; enable_z_endstop(false); - go_xy(init_x_position, current_position[Y_AXIS], feedrate / 3); + go_xy(init_x_position, current_position[Y_AXIS], feedrate / 5); enable_z_endstop(true); - go_xy(x1, current_position[Y_AXIS], feedrate / 3); + go_xy(x1, current_position[Y_AXIS], feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search X span 1 - not found"); @@ -1078,13 +1079,13 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) // Go to the center. enable_z_endstop(false); current_position[X_AXIS] = 0.5f * (a + b); - go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 3); + go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 5); found = true; // Search in the Y direction along a cross. found = false; enable_z_endstop(true); - go_xy(current_position[X_AXIS], y0, feedrate / 3); + go_xy(current_position[X_AXIS], y0, feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search Y2 span 0 - not found"); @@ -1095,9 +1096,9 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) // SERIAL_ECHOLN("Search Y2 span 0 - found"); a = current_position[Y_AXIS]; enable_z_endstop(false); - go_xy(current_position[X_AXIS], init_y_position, feedrate / 3); + go_xy(current_position[X_AXIS], init_y_position, feedrate / 5); enable_z_endstop(true); - go_xy(current_position[X_AXIS], y1, feedrate / 3); + go_xy(current_position[X_AXIS], y1, feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search Y2 span 1 - not found"); @@ -1109,9 +1110,10 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) //lcd_update_enable(true); // Go to the center. - enable_z_endstop(false, false); + enable_z_endstop(false); + invert_z_endstop(false); current_position[Y_AXIS] = 0.5f * (a + b); - go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 3); + go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 5); #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { @@ -1124,17 +1126,20 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } #endif //SUPPORT_VERBOSITY - if (iteration > 3) { - // Average the last 4 measurements. + if (iteration > 0) { + // Average the last 7 measurements. avg[X_AXIS] += current_position[X_AXIS]; avg[Y_AXIS] += current_position[Y_AXIS]; } + init_x_position = current_position[X_AXIS]; + init_y_position = current_position[Y_AXIS]; + found = true; } - avg[X_AXIS] *= (1.f / 4.f); - avg[Y_AXIS] *= (1.f / 4.f); + avg[X_AXIS] *= (1.f / 7.f); + avg[Y_AXIS] *= (1.f / 7.f); current_position[X_AXIS] = avg[X_AXIS]; current_position[Y_AXIS] = avg[Y_AXIS]; @@ -2111,7 +2116,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level #endif // SUPPORT_VERBOSITY if (!find_bed_induction_sensor_point_xy(verbosity_level)) return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; -#if 1 +#ifndef HEATBED_V2 if (k == 0 || k == 1) { // Improve the position of the 1st row sensor points by a zig-zag movement. @@ -2132,7 +2137,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level // not found return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; } -#endif +#endif //HEATBED_V2 #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) delay_keep_alive(3000); @@ -2548,16 +2553,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 } #endif // SUPPORT_VERBOSITY - //make space - current_position[Z_AXIS] += 150; - go_to_current(homing_feedrate[Z_AXIS] / 60); - //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);); - - lcd_show_fullscreen_message_and_wait_P(MSG_PLACE_STEEL_SHEET); - - // Sample Z heights for the mesh bed leveling. - // In addition, store the results into an eeprom, to be used later for verification of the bed leveling process. - if (! sample_mesh_and_store_reference()) + if(!sample_z()) goto canceled; enable_endstops(endstops_enabled); @@ -2579,6 +2575,22 @@ canceled: return result; } +bool sample_z() { + bool sampled = true; + //make space + current_position[Z_AXIS] += 150; + go_to_current(homing_feedrate[Z_AXIS] / 60); + //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);); + + lcd_show_fullscreen_message_and_wait_P(MSG_PLACE_STEEL_SHEET); + + // Sample Z heights for the mesh bed leveling. + // In addition, store the results into an eeprom, to be used later for verification of the bed leveling process. + if (!sample_mesh_and_store_reference()) sampled = false; + + return sampled; +} + void go_home_with_z_lift() { // Don't let the manage_inactivity() function remove power from the motors. diff --git a/Firmware/mesh_bed_calibration.h b/Firmware/mesh_bed_calibration.h index 4f6ebd724..5f5a98aa2 100644 --- a/Firmware/mesh_bed_calibration.h +++ b/Firmware/mesh_bed_calibration.h @@ -187,5 +187,6 @@ extern void babystep_undo(); // Reset the current babystep counter without moving the axes. extern void babystep_reset(); extern void count_xyz_details(); +extern bool sample_z(); #endif /* MESH_BED_CALIBRATION_H */ diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 27c200817..28aee746e 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -611,7 +611,7 @@ void isr() { // Stall guard homing turned on z_min_endstop = (READ(Z_MIN_PIN) != z_endstop_invert) || (READ(Z_TMC2130_DIAG) != 0); #else - z_min_endstop = (READ(Z_MIN_PIN) != z_endstop_invert); + z_min_endstop = (READ(Z_MIN_PIN) != z_endstop_invert); #endif //TMC2130_SG_HOMING if(z_min_endstop && old_z_min_endstop) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; From 5254044816125488af89f2a166e94555071b71aa Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 5 Mar 2018 00:17:43 +0100 Subject: [PATCH 10/19] no points on first row for new xyz cal. version, waiting for user to press knob on found points when verbosity level >=20 --- Firmware/mesh_bed_calibration.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 044df2349..2a942da1b 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -104,10 +104,17 @@ const float bed_ref_points[] PROGMEM = { static inline float sqr(float x) { return x * x; } +#ifdef HEATBED_V2 static inline bool point_on_1st_row(const uint8_t i) { - return (i < 2); + return false; } +#else //HEATBED_V2 +static inline bool point_on_1st_row(const uint8_t i) +{ + return (i < 3); +} +#endif //HEATBED_V2 // Weight of a point coordinate in a least squares optimization. // The first row of points may not be fully reachable @@ -1152,8 +1159,12 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } #endif // SUPPORT_VERBOSITY go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate); - lcd_show_fullscreen_message_and_wait_P(PSTR("Final position")); - lcd_update_enable(true); + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 20) { + lcd_show_fullscreen_message_and_wait_P(PSTR("Final position")); + lcd_update_enable(true); + } + #endif //SUPPORT_VERBOSITY break; } From ca3ba55ca7e1198a4494c8334db592ba24e16aac Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Fri, 15 Sep 2017 18:04:19 +0200 Subject: [PATCH 11/19] initial version --- Firmware/Marlin_main.cpp | 38 ++++++++++++++++++++++++++++++++++++++ Firmware/language_all.cpp | 5 +++++ Firmware/language_en.h | 5 +++-- Firmware/ultralcd.cpp | 35 +++++++++++++++++------------------ Firmware/ultralcd.h | 1 + 5 files changed, 64 insertions(+), 20 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3b51a67c4..6f93df246 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6438,6 +6438,43 @@ void ClearToSend() SERIAL_PROTOCOLLNRPGM(MSG_OK); } +update_currents() { + float current_high[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD; + float current_low[3] = DEFAULT_PWM_MOTOR_CURRENT; + float tmp_motor[3]; + + SERIAL_ECHOLNPGM("Currents updated: "); + + if (destination[Z_AXIS] < Z_SILENT) { + SERIAL_ECHOLNPGM("LOW"); + for (uint8_t i = 0; i < 3; i++) { + digipot_current(i, current_low[i]); + MYSERIAL.print(int(i)); + SERIAL_ECHOPGM(": "); + MYSERIAL.println(current_low[i]); + } + } + else if (destination[Z_AXIS] > Z_HIGH_POWER) { + SERIAL_ECHOLNPGM("HIGH"); + for (uint8_t i = 0; i < 3; i++) { + digipot_current(i, current_high[i]); + MYSERIAL.print(int(i)); + SERIAL_ECHOPGM(": "); + MYSERIAL.println(current_high[i]); + } + } + else { + for (uint8_t i = 0; i < 3; i++) { + float q = current_low[i] - Z_SILENT*((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT)); + tmp_motor[i] = ((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT))*destination[Z_AXIS] + q; + digipot_current(i, tmp_motor[i]); + MYSERIAL.print(int(i)); + SERIAL_ECHOPGM(": "); + MYSERIAL.println(tmp_motor[i]); + } + } +} + void get_coordinates() { bool seen[4]={false,false,false,false}; @@ -6459,6 +6496,7 @@ void get_coordinates() if (relative) destination[i] += current_position[i]; seen[i]=true; + if (i == Z_AXIS && SilentModeMenu == 2) update_currents(); } else destination[i] = current_position[i]; //Are these else lines really needed? } diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp index 6d72bb189..b9d056b88 100644 --- a/Firmware/language_all.cpp +++ b/Firmware/language_all.cpp @@ -60,6 +60,11 @@ const char * const MSG_AUTO_HOME_LANG_TABLE[1] PROGMEM = { MSG_AUTO_HOME_EN }; +const char MSG_AUTO_MODE_ON_EN[] PROGMEM = "Mode [auto power]"; +const char * const MSG_AUTO_MODE_ON_LANG_TABLE[1] PROGMEM = { + MSG_AUTO_MODE_ON_EN +}; + const char MSG_A_RETRACT_EN[] PROGMEM = "A-retract"; const char * const MSG_A_RETRACT_LANG_TABLE[1] PROGMEM = { MSG_A_RETRACT_EN diff --git a/Firmware/language_en.h b/Firmware/language_en.h index c22d9fb40..1a576d426 100644 --- a/Firmware/language_en.h +++ b/Firmware/language_en.h @@ -102,8 +102,9 @@ #define(length=20) MSG_CHANGING_FILAMENT "Changing filament!" -#define MSG_SILENT_MODE_ON "Mode [Stealth]" -#define MSG_SILENT_MODE_OFF "Mode [Normal]" +#define MSG_SILENT_MODE_ON "Mode [silent]" +#define MSG_SILENT_MODE_OFF "Mode [high power]" +#define MSG_AUTO_MODE_ON "Mode [auto power]" #define(length=20) MSG_REBOOT "Reboot the printer" #define(length=20) MSG_TAKE_EFFECT " for take effect" diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3b3d0706c..35e95468e 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3412,7 +3412,12 @@ static void lcd_fsensor_fail() static void lcd_silent_mode_set() { - SilentModeMenu = !SilentModeMenu; + switch (SilentModeMenu) { + case 0: SilentModeMenu = 1; break; + case 1: SilentModeMenu = 2; break; + case 2: SilentModeMenu = 0; break; + default: SilentModeMenu = 0; break; + } eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu); #ifdef TMC2130 // Wait until the planner queue is drained and the stepper routine achieves @@ -3891,6 +3896,13 @@ static void lcd_settings_menu() { MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84")); } + if (!farm_mode) { //dont show in menu if we are in farm mode + switch (SilentModeMenu) { + case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break; + case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break; + case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break; + default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break; + } #ifdef PAT9125 #ifndef DEBUG_DISABLE_FSENSORCHECK @@ -3951,6 +3963,7 @@ static void lcd_settings_menu() MENU_ITEM(function, MSG_SECOND_SERIAL_ON, lcd_second_serial_set); } + if (!isPrintPaused && !homing_flag) { MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z); @@ -5281,24 +5294,10 @@ static void lcd_tune_menu() MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7 #endif -#ifdef PAT9125 -#ifndef DEBUG_DISABLE_FSENSORCHECK - if (FSensorStateMenu == 0) { - MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set); + if (SilentModeMenu == 0) { + MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune); } else { - MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set); - } -#endif //DEBUG_DISABLE_FSENSORCHECK -#endif //PAT9125 - -#ifdef TMC2130 - if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); - else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); - - if (SilentModeMenu == 0) - { - if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set); - else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set); + MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune); } else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info); #endif //TMC2130 diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 1dde5128c..87a589346 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -118,6 +118,7 @@ void lcd_mylang(); extern int farm_no; extern int farm_timer; extern int farm_status; + extern int8_t SilentModeMenu; #ifdef SNMM extern uint8_t snmm_extruder; From a369c7900e3fec504938bf424a71470db34789c5 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 18 Sep 2017 12:46:50 +0200 Subject: [PATCH 12/19] tune menu updated --- Firmware/stepper.cpp | 5 ++--- Firmware/ultralcd.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 8510daf9b..0ee53e0d5 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -1361,10 +1361,9 @@ void EEPROM_read_st(int pos, uint8_t* value, uint8_t size) void digipot_init() //Initialize Digipot Motor Current -{ - +{ EEPROM_read_st(EEPROM_SILENT,(uint8_t*)&SilentMode,sizeof(SilentMode)); - + SilentModeMenu = SilentMode; #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1 if(SilentMode == 0){ const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT_LOUD; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 35e95468e..a0e269b49 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5264,6 +5264,18 @@ static void lcd_autostart_sd() +static void lcd_silent_mode_set_tune() { + switch (SilentModeMenu) { + case 0: SilentModeMenu = 1; break; + case 1: SilentModeMenu = 2; break; + case 2: SilentModeMenu = 0; break; + default: SilentModeMenu = 0; break; + } + eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu); + digipot_init(); + lcd_goto_menu(lcd_tune_menu, 9); +} + static void lcd_colorprint_change() { enquecommand_P(PSTR("M600")); From 1033bd3cf94a47d58bc40128d6fbccdf04160537 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 18 Sep 2017 12:48:49 +0200 Subject: [PATCH 13/19] info on serial not used --- Firmware/Marlin_main.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6f93df246..e09cdad31 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6443,24 +6443,24 @@ update_currents() { float current_low[3] = DEFAULT_PWM_MOTOR_CURRENT; float tmp_motor[3]; - SERIAL_ECHOLNPGM("Currents updated: "); + //SERIAL_ECHOLNPGM("Currents updated: "); if (destination[Z_AXIS] < Z_SILENT) { - SERIAL_ECHOLNPGM("LOW"); + //SERIAL_ECHOLNPGM("LOW"); for (uint8_t i = 0; i < 3; i++) { digipot_current(i, current_low[i]); - MYSERIAL.print(int(i)); + /*MYSERIAL.print(int(i)); SERIAL_ECHOPGM(": "); - MYSERIAL.println(current_low[i]); + MYSERIAL.println(current_low[i]);*/ } } else if (destination[Z_AXIS] > Z_HIGH_POWER) { - SERIAL_ECHOLNPGM("HIGH"); + //SERIAL_ECHOLNPGM("HIGH"); for (uint8_t i = 0; i < 3; i++) { digipot_current(i, current_high[i]); - MYSERIAL.print(int(i)); + /*MYSERIAL.print(int(i)); SERIAL_ECHOPGM(": "); - MYSERIAL.println(current_high[i]); + MYSERIAL.println(current_high[i]);*/ } } else { @@ -6468,9 +6468,9 @@ update_currents() { float q = current_low[i] - Z_SILENT*((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT)); tmp_motor[i] = ((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT))*destination[Z_AXIS] + q; digipot_current(i, tmp_motor[i]); - MYSERIAL.print(int(i)); + /*MYSERIAL.print(int(i)); SERIAL_ECHOPGM(": "); - MYSERIAL.println(tmp_motor[i]); + MYSERIAL.println(tmp_motor[i]);*/ } } } From 917689b5ce4ee4405a06c3d29a2d2b58bf10aad0 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 5 Mar 2018 01:23:18 +0100 Subject: [PATCH 14/19] tune menu --- Firmware/Marlin.h | 1 + Firmware/Marlin_main.cpp | 2 +- Firmware/language_all.cpp | 4 +-- Firmware/language_all.h | 2 ++ Firmware/ultralcd.cpp | 63 +++++++++++++++++++++++++-------------- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index a576a1f26..c79513833 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -218,6 +218,7 @@ enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5}; void FlushSerialRequestResend(); void ClearToSend(); +void update_currents(); void get_coordinates(); void prepare_move(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e09cdad31..793dfdd15 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6438,7 +6438,7 @@ void ClearToSend() SERIAL_PROTOCOLLNRPGM(MSG_OK); } -update_currents() { +void update_currents() { float current_high[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD; float current_low[3] = DEFAULT_PWM_MOTOR_CURRENT; float tmp_motor[3]; diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp index b9d056b88..3eb8ba85b 100644 --- a/Firmware/language_all.cpp +++ b/Firmware/language_all.cpp @@ -1985,14 +1985,14 @@ const char * const MSG_SHOW_END_STOPS_LANG_TABLE[LANG_NUM] PROGMEM = { MSG_SHOW_END_STOPS_CZ }; -const char MSG_SILENT_MODE_OFF_EN[] PROGMEM = "Mode [Normal]"; +const char MSG_SILENT_MODE_OFF_EN[] PROGMEM = "Mode [high power]"; const char MSG_SILENT_MODE_OFF_CZ[] PROGMEM = "Mod [Normal]"; const char * const MSG_SILENT_MODE_OFF_LANG_TABLE[LANG_NUM] PROGMEM = { MSG_SILENT_MODE_OFF_EN, MSG_SILENT_MODE_OFF_CZ }; -const char MSG_SILENT_MODE_ON_EN[] PROGMEM = "Mode [Stealth]"; +const char MSG_SILENT_MODE_ON_EN[] PROGMEM = "Mode [silent]"; const char MSG_SILENT_MODE_ON_CZ[] PROGMEM = "Mod [Stealth]"; const char * const MSG_SILENT_MODE_ON_LANG_TABLE[LANG_NUM] PROGMEM = { MSG_SILENT_MODE_ON_EN, diff --git a/Firmware/language_all.h b/Firmware/language_all.h index a055e3612..bbc8e6fef 100644 --- a/Firmware/language_all.h +++ b/Firmware/language_all.h @@ -40,6 +40,8 @@ extern const char* const MSG_AUTOLOAD_FILAMENT_LANG_TABLE[LANG_NUM]; #define MSG_AUTOLOAD_FILAMENT LANG_TABLE_SELECT(MSG_AUTOLOAD_FILAMENT_LANG_TABLE) extern const char* const MSG_AUTO_HOME_LANG_TABLE[1]; #define MSG_AUTO_HOME LANG_TABLE_SELECT_EXPLICIT(MSG_AUTO_HOME_LANG_TABLE, 0) +extern const char* const MSG_AUTO_MODE_ON_LANG_TABLE[1]; +#define MSG_AUTO_MODE_ON LANG_TABLE_SELECT_EXPLICIT(MSG_AUTO_MODE_ON_LANG_TABLE, 0) extern const char* const MSG_A_RETRACT_LANG_TABLE[1]; #define MSG_A_RETRACT LANG_TABLE_SELECT_EXPLICIT(MSG_A_RETRACT_LANG_TABLE, 0) extern const char* const MSG_BABYSTEPPING_X_LANG_TABLE[1]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a0e269b49..df8276f60 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3902,6 +3902,7 @@ static void lcd_settings_menu() case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break; case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break; default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break; + } } #ifdef PAT9125 @@ -5289,37 +5290,55 @@ static void lcd_colorprint_change() { static void lcd_tune_menu() { - EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu)); + EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu)); - - START_MENU(); - MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1 - MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2 - MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3 - MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4 + START_MENU(); + MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1 + MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2 - MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5 - MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6 + MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3 + MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4 + + MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5 + MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6 #ifdef FILAMENTCHANGEENABLE - MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7 + MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7 #endif - - if (SilentModeMenu == 0) { - MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune); - } else { - MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune); - } - else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info); + +#ifndef DEBUG_DISABLE_FSENSORCHECK + if (FSensorStateMenu == 0) { + MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set); + } + else { + MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set); + } +#endif //DEBUG_DISABLE_FSENSORCHECK + +#ifdef TMC2130 + if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); + else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); + + if (SilentModeMenu == 0) + { + if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set); + else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set); + } + else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info); +#else //TMC2130 + if (!farm_mode) { //dont show in menu if we are in farm mode + switch (SilentModeMenu) { + case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break; + case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break; + case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break; + default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break; + } + } #endif //TMC2130 - - END_MENU(); + END_MENU(); } - - - static void lcd_move_menu_01mm() { move_menu_scale = 0.1; From 74fa599f48c40b3f73e9dce79f5f0bc579b6a3d2 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 2 Mar 2018 18:50:16 +0100 Subject: [PATCH 15/19] Remove Rpi port menu item for MK25. --- Firmware/ultralcd.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3b3d0706c..3754d0a88 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3944,12 +3944,14 @@ static void lcd_settings_menu() else { MENU_ITEM(function, MSG_TEMP_CALIBRATION_ON, lcd_temp_calibration_set); } +#ifdef HAS_SECOND_SERIAL_PORT if (selectedSerialPort == 0) { MENU_ITEM(function, MSG_SECOND_SERIAL_OFF, lcd_second_serial_set); } else { MENU_ITEM(function, MSG_SECOND_SERIAL_ON, lcd_second_serial_set); } +#endif //HAS_SECOND_SERIAL if (!isPrintPaused && !homing_flag) { From c9b5ab0e88174753f8e69f5585c20e3bb934d836 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 5 Mar 2018 18:09:48 +0100 Subject: [PATCH 16/19] area for improving calibration point enlarged --- Firmware/mesh_bed_calibration.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 2a942da1b..564cf5067 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -1053,59 +1053,51 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) // Do nsteps_y zig-zag movements. float a, b; float avg[2] = { 0,0 }; - + invert_z_endstop(true); for (int iteration = 0; iteration < 8; iteration++) { - found = false; - invert_z_endstop(true); + found = false; enable_z_endstop(true); - go_xy(x0, current_position[Y_AXIS], feedrate / 5); + go_xy(init_x_position + 16.0f, current_position[Y_AXIS], feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search X span 0 - not found"); continue; } - - //lcd_show_fullscreen_message_and_wait_P(PSTR("X1 found")); - //lcd_update_enable(true); // SERIAL_ECHOLN("Search X span 0 - found"); a = current_position[X_AXIS]; enable_z_endstop(false); go_xy(init_x_position, current_position[Y_AXIS], feedrate / 5); enable_z_endstop(true); - go_xy(x1, current_position[Y_AXIS], feedrate / 5); + go_xy(init_x_position - 16.0f, current_position[Y_AXIS], feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search X span 1 - not found"); continue; } - //lcd_show_fullscreen_message_and_wait_P(PSTR("X2 found")); - //lcd_update_enable(true); // SERIAL_ECHOLN("Search X span 1 - found"); b = current_position[X_AXIS]; // Go to the center. enable_z_endstop(false); current_position[X_AXIS] = 0.5f * (a + b); - go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 5); + go_xy(current_position[X_AXIS], init_y_position, feedrate / 5); found = true; // Search in the Y direction along a cross. found = false; enable_z_endstop(true); - go_xy(current_position[X_AXIS], y0, feedrate / 5); + go_xy(current_position[X_AXIS], init_y_position + 16.0f, feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search Y2 span 0 - not found"); continue; } - //lcd_show_fullscreen_message_and_wait_P(PSTR("Y1 found")); - //lcd_update_enable(true); // SERIAL_ECHOLN("Search Y2 span 0 - found"); a = current_position[Y_AXIS]; enable_z_endstop(false); go_xy(current_position[X_AXIS], init_y_position, feedrate / 5); enable_z_endstop(true); - go_xy(current_position[X_AXIS], y1, feedrate / 5); + go_xy(current_position[X_AXIS], init_y_position - 16.0f, feedrate / 5); update_current_position_xyz(); if (!endstop_z_hit_on_purpose()) { // SERIAL_ECHOLN("Search Y2 span 1 - not found"); @@ -1113,12 +1105,8 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) } // SERIAL_ECHOLN("Search Y2 span 1 - found"); b = current_position[Y_AXIS]; - //lcd_show_fullscreen_message_and_wait_P(PSTR("Y2 found")); - //lcd_update_enable(true); - // Go to the center. enable_z_endstop(false); - invert_z_endstop(false); current_position[Y_AXIS] = 0.5f * (a + b); go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 5); @@ -1145,6 +1133,7 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) found = true; } + invert_z_endstop(false); avg[X_AXIS] *= (1.f / 7.f); avg[Y_AXIS] *= (1.f / 7.f); @@ -1169,8 +1158,9 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) break; } } - + enable_z_endstop(false); + invert_z_endstop(false); return found; } From 67fd467ebe6f1b6f56667c06ce55fb55e26fe99b Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Mon, 5 Mar 2018 21:42:04 +0100 Subject: [PATCH 17/19] Add fail statistics menu item for MK25. As there is only filament sensor and no crash and power interruption detection, squash everything into single screen. --- Firmware/Configuration_prusa.h | 2 +- Firmware/Marlin_main.cpp | 4 +-- Firmware/ultralcd.cpp | 46 +++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Firmware/Configuration_prusa.h b/Firmware/Configuration_prusa.h index 46c751046..014c2f7f4 100644 --- a/Firmware/Configuration_prusa.h +++ b/Firmware/Configuration_prusa.h @@ -168,7 +168,7 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed -#define PAT9125 +#define PAT9125 //!< Filament sensor #define FANCHECK diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index baa618fe0..e71c99576 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -681,6 +681,7 @@ void crashdet_cancel() card.closefile(); tmc2130_sg_stop_on_crash = true; } +#endif //TMC2130 void failstats_reset_print() { @@ -690,7 +691,6 @@ void failstats_reset_print() eeprom_update_byte((uint8_t *)EEPROM_POWER_COUNT, 0); } -#endif //TMC2130 #ifdef MESH_BED_LEVELING @@ -4081,10 +4081,8 @@ void process_commands() card.openFile(strchr_pointer + 4,true); break; case 24: //M24 - Start SD print -#ifdef TMC2130 if (!card.paused) failstats_reset_print(); -#endif //TMC2130 card.startFileprint(); starttime=millis(); break; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index df8276f60..eb44ef368 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -204,9 +204,9 @@ static void prusa_stat_temperatures(); static void prusa_stat_printinfo(); static void lcd_farm_no(); static void lcd_menu_extruder_info(); -#ifdef TMC2130 +#if defined(TMC2130) || defined(PAT9125) static void lcd_menu_fails_stats(); -#endif //TMC2130 +#endif //TMC2130 or PAT9125 void lcd_finishstatus(); @@ -1537,7 +1537,7 @@ static void lcd_menu_extruder_info() } } -#ifdef TMC2130 +#if defined(TMC2130) && defined(PAT9125) static void lcd_menu_fails_stats_total() { //01234567890123456789 @@ -1579,7 +1579,13 @@ static void lcd_menu_fails_stats_print() lcd_goto_menu(lcd_menu_fails_stats, 2); } } - +/** + * @brief Open fail statistics menu + * + * This version of function is used, when there is filament sensor, + * power failure and crash detection. + * There are Last print and Total menu items. + */ static void lcd_menu_fails_stats() { START_MENU(); @@ -1588,6 +1594,34 @@ static void lcd_menu_fails_stats() MENU_ITEM(submenu, PSTR("Total"), lcd_menu_fails_stats_total); END_MENU(); } +#else if defined(PAT9125) +/** + * @brief Print last print and total filament run outs + * + * This version of function is used, when there is filament sensor, + * but no other sensors (e.g. power failure, crash detection). + * + * Example screen: + * @code + * 01234567890123456789 + * Last print failures + * Filam. runouts 0 + * Total failures + * Filam. runouts 5 + * @endcode + */ +static void lcd_menu_fails_stats() +{ + uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); + uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); + fprintf_P(lcdout, PSTR(ESC_H(0,0)"Last print failures"ESC_H(1,1)"Filam. runouts %-3d"ESC_H(0,2)"Total failures"ESC_H(1,3)"Filam. runouts %-3d"), filamentLast, filamentTotal); + if (lcd_clicked()) + { + lcd_quick_feedback(); + //lcd_return_to_status(); + lcd_goto_menu(lcd_main_menu, 8); //TODO: Remove hard coded encoder value. + } +} #endif //TMC2130 @@ -5221,9 +5255,9 @@ static void lcd_main_menu() MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics); } -#ifdef TMC2130 +#if defined(TMC2130) || defined(PAT9125) MENU_ITEM(submenu, PSTR("Fail stats"), lcd_menu_fails_stats); -#endif //TMC2130 +#endif MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu); From ee2de71d266316340f7294e9a47ef647e83fbb68 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Tue, 6 Mar 2018 11:51:31 +0100 Subject: [PATCH 18/19] searching for point xy updated to be more reliable, max z error enlarged to speed up calibration --- Firmware/Configuration.h | 2 +- Firmware/mesh_bed_calibration.cpp | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 322ea8b22..20296e399 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -8,7 +8,7 @@ // Firmware version #define FW_VERSION "3.1.2-alpha" -#define FW_COMMIT_NR 201 +#define FW_COMMIT_NR 255 // FW_VERSION_UNKNOWN means this is an unofficial build. // The firmware should only be checked into github with this symbol. #define FW_DEV_VERSION FW_VERSION_UNKNOWN diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 564cf5067..8db94cd42 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -913,7 +913,7 @@ error: #define FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP (1.f) #ifdef HEATBED_V2 #define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (2.f) -#define FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR (0.01f) +#define FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR (0.03f) #else //HEATBED_V2 #define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (0.2f) #endif //HEATBED_V2 @@ -971,45 +971,46 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) // Continously lower the Z axis. endstops_hit_on_purpose(); enable_z_endstop(true); + bool direction = false; while (current_position[Z_AXIS] > -10.f && z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { // Do nsteps_y zig-zag movements. - //SERIAL_ECHOPGM("z_error: "); - //MYSERIAL.println(z_error); - current_position[Y_AXIS] = y0; + SERIAL_ECHOPGM("z_error: "); + MYSERIAL.println(z_error); + current_position[Y_AXIS] = direction ? y1 : y0; initial_z_position = current_position[Z_AXIS]; - for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1), ++i) { + for (i = 0; i < (nsteps_y - 1); (direction == false) ? (current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1)) : (current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1)), ++i) { // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); dir_positive = !dir_positive; if (endstop_z_hit_on_purpose()) { update_current_position_xyz(); - z_error = 2 * (initial_z_position - current_position[Z_AXIS]); + z_error = initial_z_position - current_position[Z_AXIS] + find_bed_induction_sensor_point_z_step; if (z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { find_bed_induction_sensor_point_z_step = z_error / 2; current_position[Z_AXIS] += z_error; enable_z_endstop(false); - go_xyz(x0, y0, current_position[Z_AXIS], feedrate); + (direction == false) ? go_xyz(x0, y0, current_position[Z_AXIS], feedrate) : go_xyz(x0, y1, current_position[Z_AXIS], feedrate); enable_z_endstop(true); } goto endloop; } } - initial_z_position = current_position[Z_AXIS]; - for (i = 0; i < (nsteps_y - 1); current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1), ++i) { + for (i = 0; i < (nsteps_y - 1); (direction == false) ? (current_position[Y_AXIS] -= (y1 - y0) / float(nsteps_y - 1)) : (current_position[Y_AXIS] += (y1 - y0) / float(nsteps_y - 1)), ++i) { // Run with a slightly decreasing Z axis, zig-zag movement. Stop at the Z end-stop. current_position[Z_AXIS] -= find_bed_induction_sensor_point_z_step / float(nsteps_y - 1); go_xyz(dir_positive ? x1 : x0, current_position[Y_AXIS], current_position[Z_AXIS], feedrate); dir_positive = !dir_positive; if (endstop_z_hit_on_purpose()) { update_current_position_xyz(); - z_error = 2 * (initial_z_position - current_position[Z_AXIS]); + z_error = initial_z_position - current_position[Z_AXIS]; if (z_error > FIND_BED_INDUCTION_SENSOR_POINT_MAX_Z_ERROR) { find_bed_induction_sensor_point_z_step = z_error / 2; current_position[Z_AXIS] += z_error; enable_z_endstop(false); - go_xyz(x0, y0, current_position[Z_AXIS], feedrate); + direction = !direction; + (direction == false) ? go_xyz(x0, y0, current_position[Z_AXIS], feedrate) : go_xyz(x0, y1, current_position[Z_AXIS], feedrate); enable_z_endstop(true); } goto endloop; From 2b7e50e45b50d5ee52b170fb47f1a978d6dafb71 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 5 Mar 2018 21:31:31 +0100 Subject: [PATCH 19/19] Fix of calculate_extrusion_multipliers(). This is a fix of a bug made in the previous commit. --- Firmware/ConfigurationStore.cpp | 2 +- Firmware/Marlin_main.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 253452fed..26cbc8228 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -378,8 +378,8 @@ bool Config_RetrieveSettings(uint16_t offset, uint8_t level) EEPROM_READ_VAR(i, extruder_advance_k); EEPROM_READ_VAR(i, advance_ed_ratio); } - calculate_volumetric_multipliers(); #endif //LIN_ADVANCE + calculate_extruder_multipliers(); // Call updatePID (similar to when we have processed M301) updatePID(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e71c99576..f6327fc78 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7021,11 +7021,14 @@ void save_statistics(unsigned long _total_filament_used, unsigned long _total_pr } float calculate_extruder_multiplier(float diameter) { - bool enabled = volumetric_enabled && diameter > 0; - float area = enabled ? (M_PI * pow(diameter * .5, 2)) : 0; - return (extrudemultiply == 100) ? - (enabled ? (1.f / area) : 1.f) : - (enabled ? ((float(extrudemultiply) * 0.01f) / area) : 1.f); + float out = 1.f; + if (volumetric_enabled && diameter > 0.f) { + float area = M_PI * diameter * diameter * 0.25; + out = 1.f / area; + } + if (extrudemultiply != 100) + out *= float(extrudemultiply) * 0.01f; + return out; } void calculate_extruder_multipliers() {