Move Volumetric methods to Planner
This commit is contained in:
		
							parent
							
								
									6f92ab7eed
								
							
						
					
					
						commit
						a10451ceed
					
				| @ -159,9 +159,6 @@ bool axis_homed[XYZ] = { false }, axis_known_position[XYZ] = { false }; | ||||
|   TempUnit input_temp_units = TEMPUNIT_C; | ||||
| #endif | ||||
| 
 | ||||
| // Initialized by settings.load()
 | ||||
| float filament_size[EXTRUDERS], volumetric_multiplier[EXTRUDERS]; | ||||
| 
 | ||||
| #if FAN_COUNT > 0 | ||||
|   int16_t fanSpeeds[FAN_COUNT] = { 0 }; | ||||
|   #if ENABLED(PROBING_FANS_OFF) | ||||
| @ -336,16 +333,6 @@ void quickstop_stepper() { | ||||
| 
 | ||||
| #endif // FILAMENT_RUNOUT_SENSOR
 | ||||
| 
 | ||||
| float calculate_volumetric_multiplier(const float diameter) { | ||||
|   if (!parser.volumetric_enabled || diameter == 0) return 1.0; | ||||
|   return 1.0 / (M_PI * sq(diameter * 0.5)); | ||||
| } | ||||
| 
 | ||||
| void calculate_volumetric_multipliers() { | ||||
|   for (uint8_t i = 0; i < COUNT(filament_size); i++) | ||||
|     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]); | ||||
| } | ||||
| 
 | ||||
| void enable_all_steppers() { | ||||
|   enable_X(); | ||||
|   enable_Y(); | ||||
|  | ||||
| @ -174,9 +174,6 @@ extern bool Running; | ||||
| inline bool IsRunning() { return  Running; } | ||||
| inline bool IsStopped() { return !Running; } | ||||
| 
 | ||||
| extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
 | ||||
| extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
 | ||||
| 
 | ||||
| extern bool axis_known_position[XYZ]; | ||||
| extern bool axis_homed[XYZ]; | ||||
| extern volatile bool wait_for_heatup; | ||||
| @ -223,8 +220,6 @@ extern millis_t max_inactive_time, stepper_inactive_time; | ||||
|   extern int lpq_len; | ||||
| #endif | ||||
| 
 | ||||
| void calculate_volumetric_multipliers(); | ||||
| 
 | ||||
| bool pin_is_protected(const int8_t pin); | ||||
| 
 | ||||
| #endif // __MARLIN_H__
 | ||||
|  | ||||
| @ -124,7 +124,7 @@ void FWRetract::retract(const bool retracting | ||||
| 
 | ||||
|     // Retract by moving from a faux E position back to the current E position
 | ||||
|     feedrate_mm_s = retract_feedrate_mm_s; | ||||
|     current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) / volumetric_multiplier[active_extruder]; | ||||
|     current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) / planner.volumetric_multiplier[active_extruder]; | ||||
|     sync_plan_position_e(); | ||||
|     prepare_move_to_destination(); | ||||
| 
 | ||||
| @ -149,7 +149,7 @@ void FWRetract::retract(const bool retracting | ||||
|     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s; | ||||
| 
 | ||||
|     const float move_e = swapping ? swap_retract_length + swap_retract_recover_length : retract_length + retract_recover_length; | ||||
|     current_position[E_AXIS] -= move_e / volumetric_multiplier[active_extruder]; | ||||
|     current_position[E_AXIS] -= move_e / planner.volumetric_multiplier[active_extruder]; | ||||
|     sync_plan_position_e(); | ||||
| 
 | ||||
|     prepare_move_to_destination();  // Recover E
 | ||||
|  | ||||
| @ -22,6 +22,7 @@ | ||||
| 
 | ||||
| #include "../gcode.h" | ||||
| #include "../../Marlin.h" | ||||
| #include "../../module/planner.h" | ||||
| 
 | ||||
| /**
 | ||||
|  * M200: Set filament diameter and set E axis units to cubic units | ||||
| @ -37,13 +38,8 @@ void GcodeSuite::M200() { | ||||
|     // setting any extruder filament size disables volumetric on the assumption that
 | ||||
|     // slicers either generate in extruder values as cubic mm or as as filament feeds
 | ||||
|     // for all extruders
 | ||||
|     parser.volumetric_enabled = (parser.value_linear_units() != 0.0); | ||||
|     if (parser.volumetric_enabled) { | ||||
|       filament_size[target_extruder] = parser.value_linear_units(); | ||||
|       // make sure all extruders have some sane value for the filament size
 | ||||
|       for (uint8_t i = 0; i < COUNT(filament_size); i++) | ||||
|         if (! filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA; | ||||
|     } | ||||
|     if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) ) | ||||
|       planner.set_filament_size(target_extruder, parser.value_linear_units()); | ||||
|   } | ||||
|   calculate_volumetric_multipliers(); | ||||
|   planner.calculate_volumetric_multipliers(); | ||||
| } | ||||
|  | ||||
| @ -76,7 +76,7 @@ void GcodeSuite::M405() { | ||||
|  */ | ||||
| void GcodeSuite::M406() { | ||||
|   filament_sensor = false; | ||||
|   calculate_volumetric_multipliers();   // Restore correct 'volumetric_multiplier' value
 | ||||
|   planner.calculate_volumetric_multipliers();   // Restore correct 'volumetric_multiplier' value
 | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | ||||
| @ -3442,20 +3442,20 @@ void kill_screen(const char* lcd_msg) { | ||||
|       MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999); | ||||
|     #endif | ||||
| 
 | ||||
|     MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, calculate_volumetric_multipliers); | ||||
|     MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, planner.calculate_volumetric_multipliers); | ||||
| 
 | ||||
|     if (parser.volumetric_enabled) { | ||||
|       #if EXTRUDERS == 1 | ||||
|         MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers); | ||||
|         MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers); | ||||
|       #else // EXTRUDERS > 1
 | ||||
|         MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers); | ||||
|         MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers); | ||||
|         MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers); | ||||
|         MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &planner.filament_size[1], 1.5, 3.25, planner.calculate_volumetric_multipliers); | ||||
|         #if EXTRUDERS > 2 | ||||
|           MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers); | ||||
|           MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &planner.filament_size[2], 1.5, 3.25, planner.calculate_volumetric_multipliers); | ||||
|           #if EXTRUDERS > 3 | ||||
|             MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers); | ||||
|             MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &planner.filament_size[3], 1.5, 3.25, planner.calculate_volumetric_multipliers); | ||||
|             #if EXTRUDERS > 4 | ||||
|               MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers); | ||||
|               MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &planner.filament_size[4], 1.5, 3.25, planner.calculate_volumetric_multipliers); | ||||
|             #endif // EXTRUDERS > 4
 | ||||
|           #endif // EXTRUDERS > 3
 | ||||
|         #endif // EXTRUDERS > 2
 | ||||
|  | ||||
| @ -637,7 +637,7 @@ static void lcd_implementation_status_screen() { | ||||
|     strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS]))); | ||||
|     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT) | ||||
|       strcpy(wstring, ftostr12ns(filament_width_meas)); | ||||
|       strcpy(mstring, itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM])); | ||||
|       strcpy(mstring, itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM])); | ||||
|     #endif | ||||
|   } | ||||
| 
 | ||||
| @ -726,7 +726,7 @@ static void lcd_implementation_status_screen() { | ||||
|         lcd_print(ftostr12ns(filament_width_meas)); | ||||
|         lcd_printPGM(PSTR("  " LCD_STR_FILAM_MUL)); | ||||
|         u8g.print(':'); | ||||
|         lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM])); | ||||
|         lcd_print(itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM])); | ||||
|         u8g.print('%'); | ||||
|       } | ||||
|     #else | ||||
|  | ||||
| @ -853,7 +853,7 @@ static void lcd_implementation_status_screen() { | ||||
|       lcd_printPGM(PSTR("Dia ")); | ||||
|       lcd.print(ftostr12ns(filament_width_meas)); | ||||
|       lcd_printPGM(PSTR(" V")); | ||||
|       lcd.print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM])); | ||||
|       lcd.print(itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM])); | ||||
|       lcd.write('%'); | ||||
|       return; | ||||
|     } | ||||
|  | ||||
| @ -138,7 +138,7 @@ | ||||
|  * | ||||
|  * Volumetric Extrusion:                            21 bytes | ||||
|  *  537  M200 D    parser.volumetric_enabled        (bool) | ||||
|  *  538  M200 T D  filament_size                    (float x5) (T0..3) | ||||
|  *  538  M200 T D  planner.filament_size            (float x5) (T0..3) | ||||
|  * | ||||
|  * HAVE_TMC2130:                                    20 bytes | ||||
|  *  558  M906 X    Stepper X current                (uint16_t) | ||||
| @ -224,7 +224,7 @@ void MarlinSettings::postprocess() { | ||||
|     thermalManager.updatePID(); | ||||
|   #endif | ||||
| 
 | ||||
|   calculate_volumetric_multipliers(); | ||||
|   planner.calculate_volumetric_multipliers(); | ||||
| 
 | ||||
|   #if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE) | ||||
|     // Software endstops depend on home_offset
 | ||||
| @ -509,7 +509,7 @@ void MarlinSettings::postprocess() { | ||||
| 
 | ||||
|     // Save filament sizes
 | ||||
|     for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) { | ||||
|       if (q < COUNT(filament_size)) dummy = filament_size[q]; | ||||
|       if (q < COUNT(planner.filament_size)) dummy = planner.filament_size[q]; | ||||
|       EEPROM_WRITE(dummy); | ||||
|     } | ||||
| 
 | ||||
| @ -895,7 +895,7 @@ void MarlinSettings::postprocess() { | ||||
| 
 | ||||
|       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) { | ||||
|         EEPROM_READ(dummy); | ||||
|         if (q < COUNT(filament_size)) filament_size[q] = dummy; | ||||
|         if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy; | ||||
|       } | ||||
| 
 | ||||
|       uint16_t val; | ||||
| @ -1260,8 +1260,8 @@ void MarlinSettings::reset() { | ||||
|       false | ||||
|     #endif | ||||
|   ; | ||||
|   for (uint8_t q = 0; q < COUNT(filament_size); q++) | ||||
|     filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA; | ||||
|   for (uint8_t q = 0; q < COUNT(planner.filament_size); q++) | ||||
|     planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA; | ||||
| 
 | ||||
|   endstops.enable_globally( | ||||
|     #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT) | ||||
| @ -1388,23 +1388,23 @@ void MarlinSettings::reset() { | ||||
|     } | ||||
| 
 | ||||
|     CONFIG_ECHO_START; | ||||
|     SERIAL_ECHOPAIR("  M200 D", filament_size[0]); | ||||
|     SERIAL_ECHOPAIR("  M200 D", planner.filament_size[0]); | ||||
|     SERIAL_EOL(); | ||||
|     #if EXTRUDERS > 1 | ||||
|       CONFIG_ECHO_START; | ||||
|       SERIAL_ECHOPAIR("  M200 T1 D", filament_size[1]); | ||||
|       SERIAL_ECHOPAIR("  M200 T1 D", planner.filament_size[1]); | ||||
|       SERIAL_EOL(); | ||||
|       #if EXTRUDERS > 2 | ||||
|         CONFIG_ECHO_START; | ||||
|         SERIAL_ECHOPAIR("  M200 T2 D", filament_size[2]); | ||||
|         SERIAL_ECHOPAIR("  M200 T2 D", planner.filament_size[2]); | ||||
|         SERIAL_EOL(); | ||||
|         #if EXTRUDERS > 3 | ||||
|           CONFIG_ECHO_START; | ||||
|           SERIAL_ECHOPAIR("  M200 T3 D", filament_size[3]); | ||||
|           SERIAL_ECHOPAIR("  M200 T3 D", planner.filament_size[3]); | ||||
|           SERIAL_EOL(); | ||||
|           #if EXTRUDERS > 4 | ||||
|             CONFIG_ECHO_START; | ||||
|             SERIAL_ECHOPAIR("  M200 T4 D", filament_size[4]); | ||||
|             SERIAL_ECHOPAIR("  M200 T4 D", planner.filament_size[4]); | ||||
|             SERIAL_EOL(); | ||||
|           #endif // EXTRUDERS > 4
 | ||||
|         #endif // EXTRUDERS > 3
 | ||||
|  | ||||
| @ -105,6 +105,10 @@ float Planner::max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second | ||||
| 
 | ||||
| int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
 | ||||
| 
 | ||||
| // Initialized by settings.load()
 | ||||
| float Planner::filament_size[EXTRUDERS],         // As a baseline for the multiplier, filament diameter
 | ||||
|       Planner::volumetric_multiplier[EXTRUDERS]; // May be auto-adjusted by a filament width sensor
 | ||||
| 
 | ||||
| uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N], | ||||
|          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
 | ||||
| 
 | ||||
| @ -539,6 +543,16 @@ void Planner::check_axes_activity() { | ||||
|   #endif | ||||
| } | ||||
| 
 | ||||
| inline float calculate_volumetric_multiplier(const float &diameter) { | ||||
|   if (!parser.volumetric_enabled || diameter == 0) return 1.0; | ||||
|   return 1.0 / CIRCLE_AREA(diameter * 0.5); | ||||
| } | ||||
| 
 | ||||
| void Planner::calculate_volumetric_multipliers() { | ||||
|   for (uint8_t i = 0; i < COUNT(filament_size); i++) | ||||
|     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]); | ||||
| } | ||||
| 
 | ||||
| #if PLANNER_LEVELING | ||||
|   /**
 | ||||
|    * lx, ly, lz - logical (cartesian, not delta) positions in mm | ||||
|  | ||||
| @ -151,6 +151,10 @@ class Planner { | ||||
| 
 | ||||
|     static int16_t flow_percentage[EXTRUDERS];  // Extrusion factor for each extruder
 | ||||
| 
 | ||||
|     static float filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
 | ||||
|                  volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
 | ||||
|                                                     // May be auto-adjusted by a filament width sensor
 | ||||
| 
 | ||||
|     static float max_feedrate_mm_s[XYZE_N],     // Max speeds in mm per second
 | ||||
|                  axis_steps_per_mm[XYZE_N], | ||||
|                  steps_to_mm[XYZE_N]; | ||||
| @ -254,6 +258,16 @@ class Planner { | ||||
| 
 | ||||
|     static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); } | ||||
| 
 | ||||
|     // Update multipliers based on new diameter measurements
 | ||||
|     static void calculate_volumetric_multipliers(); | ||||
| 
 | ||||
|     FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) { | ||||
|       filament_size[e] = v; | ||||
|       // make sure all extruders have some sane value for the filament size
 | ||||
|       for (uint8_t i = 0; i < COUNT(filament_size); i++) | ||||
|         if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA; | ||||
|     } | ||||
| 
 | ||||
|     #if PLANNER_LEVELING | ||||
| 
 | ||||
|       #define ARG_X float lx | ||||
|  | ||||
| @ -775,7 +775,7 @@ void Temperature::manage_heater() { | ||||
|       // Get the delayed info and add 100 to reconstitute to a percent of
 | ||||
|       // the nominal filament diameter then square it to get an area
 | ||||
|       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0; | ||||
|       volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot); | ||||
|       planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot); | ||||
|     } | ||||
|   #endif // FILAMENT_WIDTH_SENSOR
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user