0.1.5
* adjust M220 feed rate modifier calculations
This commit is contained in:
		| @@ -474,19 +474,51 @@ class BambuVirtualPrinter: | |||||||
|             gcode_command = commands.SEND_GCODE_TEMPLATE |             gcode_command = commands.SEND_GCODE_TEMPLATE | ||||||
|             percent = int(data.replace("M220 S", "")) |             percent = int(data.replace("M220 S", "")) | ||||||
|  |  | ||||||
|             if percent is None or percent < 1 or percent > 166: |             def speed_fraction(speed_percent): | ||||||
|                 return True |                 return math.floor(10000 / speed_percent) / 100 | ||||||
|  |  | ||||||
|             speed_fraction = 100 / percent |             def acceleration_magnitude(speed_percent): | ||||||
|             acceleration = math.exp((speed_fraction - 1.0191) / -0.814) |                 return math.exp((speed_fraction(speed_percent) - 1.0191) / -0.8139) | ||||||
|             feed_rate = ( |  | ||||||
|                 2.1645 * (acceleration**3) |             def feed_rate(speed_percent): | ||||||
|                 - 5.3247 * (acceleration**2) |                 return 6.426e-5 * speed_percent ** 2 - 2.484e-3 * speed_percent + 0.654 | ||||||
|                 + 4.342 * acceleration |  | ||||||
|                 - 0.181 |             def linear_interpolate(x, x_points, y_points): | ||||||
|             ) |                 if x <= x_points[0]: return y_points[0] | ||||||
|             speed_level = 1.539 * (acceleration**2) - 0.7032 * acceleration + 4.0834 |                 if x >= x_points[-1]: return y_points[-1] | ||||||
|             speed_command = f"M204.2 K${acceleration:.2f} \nM220 K${feed_rate:.2f} \nM73.2 R${speed_fraction:.2f} \nM1002 set_gcode_claim_speed_level ${speed_level:.0f}\n" |                 for i in range(len(x_points) - 1): | ||||||
|  |                     if x_points[i] <= x < x_points[i + 1]: | ||||||
|  |                         t = (x - x_points[i]) / (x_points[i + 1] - x_points[i]) | ||||||
|  |                         return y_points[i] * (1 - t) + y_points[i + 1] * t | ||||||
|  |  | ||||||
|  |             def scale_to_data_points(func, data_points): | ||||||
|  |                 data_points.sort(key=lambda x: x[0]) | ||||||
|  |                 speeds, values = zip(*data_points) | ||||||
|  |                 scaling_factors = [v / func(s) for s, v in zip(speeds, values)] | ||||||
|  |                 return lambda x: func(x) * linear_interpolate(x, speeds, scaling_factors) | ||||||
|  |  | ||||||
|  |             def speed_adjust(speed_percentage): | ||||||
|  |                 if not 30 <= speed_percentage <= 180: | ||||||
|  |                     speed_percentage = 100 | ||||||
|  |  | ||||||
|  |                 bambu_params = { | ||||||
|  |                     "speed": [50, 100, 124, 166], | ||||||
|  |                     "acceleration": [0.3, 1.0, 1.4, 1.6], | ||||||
|  |                     "feed_rate": [0.7, 1.0, 1.4, 2.0] | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 acc_mag_scaled = scale_to_data_points(acceleration_magnitude, | ||||||
|  |                                                       list(zip(bambu_params["speed"], bambu_params["acceleration"]))) | ||||||
|  |                 feed_rate_scaled = scale_to_data_points(feed_rate, | ||||||
|  |                                                         list(zip(bambu_params["speed"], bambu_params["feed_rate"]))) | ||||||
|  |  | ||||||
|  |                 speed_frac = speed_fraction(speed_percentage) | ||||||
|  |                 acc_mag = acc_mag_scaled(speed_percentage) | ||||||
|  |                 feed = feed_rate_scaled(speed_percentage) | ||||||
|  |                 # speed_level = 1.539 * (acc_mag**2) - 0.7032 * acc_mag + 4.0834 | ||||||
|  |                 return f"M204.2 K{acc_mag:.2f}\nM220 K{feed:.2f}\nM73.2 R{speed_frac:.2f}\n" # M1002 set_gcode_claim_speed_level ${speed_level:.0f}\n | ||||||
|  |  | ||||||
|  |             speed_command = speed_adjust(percent) | ||||||
|  |  | ||||||
|             gcode_command["print"]["param"] = speed_command |             gcode_command["print"]["param"] = speed_command | ||||||
|             if self.bambu_client.publish(gcode_command): |             if self.bambu_client.publish(gcode_command): | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								setup.py
									
									
									
									
									
								
							| @@ -14,7 +14,7 @@ plugin_package = "octoprint_bambu_printer" | |||||||
| plugin_name = "OctoPrint-BambuPrinter" | plugin_name = "OctoPrint-BambuPrinter" | ||||||
|  |  | ||||||
| # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module | # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module | ||||||
| plugin_version = "0.1.4" | plugin_version = "0.1.5" | ||||||
|  |  | ||||||
| # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin | # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin | ||||||
| # module | # module | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user