mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Implemented clamping of the acceleration when extruding for the Marlin
firmware, both for the G-code export and the time estimator.
This commit is contained in:
		
							parent
							
								
									3bebe9f954
								
							
						
					
					
						commit
						9d027a558e
					
				
					 5 changed files with 33 additions and 7 deletions
				
			
		|  | @ -412,7 +412,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) | |||
|     // resets time estimators
 | ||||
|     m_normal_time_estimator.reset(); | ||||
|     m_normal_time_estimator.set_dialect(print.config.gcode_flavor); | ||||
|     m_normal_time_estimator.set_acceleration(print.config.machine_max_acceleration_extruding.values[0]); | ||||
|     m_normal_time_estimator.set_max_acceleration(print.config.machine_max_acceleration_extruding.values[0]); | ||||
|     m_normal_time_estimator.set_retract_acceleration(print.config.machine_max_acceleration_retracting.values[0]); | ||||
|     m_normal_time_estimator.set_minimum_feedrate(print.config.machine_min_extruding_rate.values[0]); | ||||
|     m_normal_time_estimator.set_minimum_travel_feedrate(print.config.machine_min_travel_rate.values[0]); | ||||
|  | @ -434,7 +434,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) | |||
|     { | ||||
|         m_silent_time_estimator.reset(); | ||||
|         m_silent_time_estimator.set_dialect(print.config.gcode_flavor); | ||||
|         m_silent_time_estimator.set_acceleration(print.config.machine_max_acceleration_extruding.values[1]); | ||||
|         m_silent_time_estimator.set_max_acceleration(print.config.machine_max_acceleration_extruding.values[1]); | ||||
|         m_silent_time_estimator.set_retract_acceleration(print.config.machine_max_acceleration_retracting.values[1]); | ||||
|         m_silent_time_estimator.set_minimum_feedrate(print.config.machine_min_extruding_rate.values[1]); | ||||
|         m_silent_time_estimator.set_minimum_travel_feedrate(print.config.machine_min_travel_rate.values[1]); | ||||
|  |  | |||
|  | @ -414,7 +414,7 @@ namespace Slic3r { | |||
| 
 | ||||
|     void GCodeTimeEstimator::set_acceleration(float acceleration_mm_sec2) | ||||
|     { | ||||
|         _state.acceleration = acceleration_mm_sec2; | ||||
|         _state.acceleration = std::min(_state.max_acceleration, acceleration_mm_sec2); | ||||
|     } | ||||
| 
 | ||||
|     float GCodeTimeEstimator::get_acceleration() const | ||||
|  | @ -422,6 +422,17 @@ namespace Slic3r { | |||
|         return _state.acceleration; | ||||
|     } | ||||
| 
 | ||||
|     void GCodeTimeEstimator::set_max_acceleration(float acceleration_mm_sec2) | ||||
|     { | ||||
|         _state.max_acceleration = acceleration_mm_sec2; | ||||
|         _state.acceleration = acceleration_mm_sec2; | ||||
|     } | ||||
| 
 | ||||
|     float GCodeTimeEstimator::get_max_acceleration() const | ||||
|     { | ||||
|         return _state.max_acceleration; | ||||
|     } | ||||
| 
 | ||||
|     void GCodeTimeEstimator::set_retract_acceleration(float acceleration_mm_sec2) | ||||
|     { | ||||
|         _state.retract_acceleration = acceleration_mm_sec2; | ||||
|  | @ -540,7 +551,7 @@ namespace Slic3r { | |||
|         set_e_local_positioning_type(Absolute); | ||||
| 
 | ||||
|         set_feedrate(DEFAULT_FEEDRATE); | ||||
|         set_acceleration(DEFAULT_ACCELERATION); | ||||
|         set_max_acceleration(DEFAULT_ACCELERATION); | ||||
|         set_retract_acceleration(DEFAULT_RETRACT_ACCELERATION); | ||||
|         set_minimum_feedrate(DEFAULT_MINIMUM_FEEDRATE); | ||||
|         set_minimum_travel_feedrate(DEFAULT_MINIMUM_TRAVEL_FEEDRATE); | ||||
|  |  | |||
|  | @ -72,6 +72,8 @@ namespace Slic3r { | |||
|             Axis axis[Num_Axis]; | ||||
|             float feedrate;                     // mm/s
 | ||||
|             float acceleration;                 // mm/s^2
 | ||||
|             // hard limit for the acceleration, to which the firmware will clamp.
 | ||||
|             float max_acceleration;             // mm/s^2
 | ||||
|             float retract_acceleration;         // mm/s^2
 | ||||
|             float additional_time;              // s
 | ||||
|             float minimum_feedrate;             // mm/s
 | ||||
|  | @ -263,6 +265,10 @@ namespace Slic3r { | |||
|         void set_acceleration(float acceleration_mm_sec2); | ||||
|         float get_acceleration() const; | ||||
| 
 | ||||
|         // Maximum acceleration for the machine. The firmware simulator will clamp the M204 Sxxx to this maximum.
 | ||||
|         void set_max_acceleration(float acceleration_mm_sec2); | ||||
|         float get_max_acceleration() const; | ||||
| 
 | ||||
|         void set_retract_acceleration(float acceleration_mm_sec2); | ||||
|         float get_retract_acceleration() const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -18,7 +18,9 @@ void GCodeWriter::apply_print_config(const PrintConfig &print_config) | |||
| { | ||||
|     this->config.apply(print_config, true); | ||||
|     m_extrusion_axis = this->config.get_extrusion_axis(); | ||||
|     this->m_single_extruder_multi_material = print_config.single_extruder_multi_material.value; | ||||
|     m_single_extruder_multi_material = print_config.single_extruder_multi_material.value; | ||||
|     m_max_acceleration = (print_config.gcode_flavor.value == gcfMarlin) ? | ||||
|         print_config.machine_max_acceleration_extruding.value : 0; | ||||
| } | ||||
| 
 | ||||
| void GCodeWriter::set_extruders(const std::vector<unsigned int> &extruder_ids) | ||||
|  | @ -85,7 +87,7 @@ std::string GCodeWriter::set_temperature(unsigned int temperature, bool wait, in | |||
|     } | ||||
|     gcode << temperature; | ||||
|     if (tool != -1 &&  | ||||
|         ( (this->multiple_extruders && ! this->m_single_extruder_multi_material) || | ||||
|         ( (this->multiple_extruders && ! m_single_extruder_multi_material) || | ||||
|           FLAVOR_IS(gcfMakerWare) || FLAVOR_IS(gcfSailfish)) ) { | ||||
|         gcode << " T" << tool; | ||||
|     } | ||||
|  | @ -170,6 +172,10 @@ std::string GCodeWriter::set_fan(unsigned int speed, bool dont_save) | |||
| 
 | ||||
| std::string GCodeWriter::set_acceleration(unsigned int acceleration) | ||||
| { | ||||
|     // Clamp the acceleration to the allowed maximum.
 | ||||
|     if (m_max_acceleration > 0 && acceleration > m_max_acceleration) | ||||
|         acceleration = m_max_acceleration; | ||||
| 
 | ||||
|     if (acceleration == 0 || acceleration == m_last_acceleration) | ||||
|         return std::string(); | ||||
|      | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ public: | |||
|     GCodeWriter() :  | ||||
|         multiple_extruders(false), m_extrusion_axis("E"), m_extruder(nullptr), | ||||
|         m_single_extruder_multi_material(false), | ||||
|         m_last_acceleration(0), m_last_fan_speed(0),  | ||||
|         m_last_acceleration(0), m_max_acceleration(0), m_last_fan_speed(0),  | ||||
|         m_last_bed_temperature(0), m_last_bed_temperature_reached(true),  | ||||
|         m_lifted(0) | ||||
|         {} | ||||
|  | @ -74,6 +74,9 @@ private: | |||
|     bool            m_single_extruder_multi_material; | ||||
|     Extruder*       m_extruder; | ||||
|     unsigned int    m_last_acceleration; | ||||
|     // Limit for setting the acceleration, to respect the machine limits set for the Marlin firmware.
 | ||||
|     // If set to zero, the limit is not in action.
 | ||||
|     unsigned int    m_max_acceleration; | ||||
|     unsigned int    m_last_fan_speed; | ||||
|     unsigned int    m_last_bed_temperature; | ||||
|     bool            m_last_bed_temperature_reached; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 bubnikv
						bubnikv