Try to make a 3D printing filament welding device for fused filament fabrication for multi-color printing April 04, 2024 09:52AM |
Registered: 9 months ago Posts: 2 |
import time from motion import Step from machine import Pin # Preset values for lengths x_heat_forward = 15 x_heat_backward = -5 x_heat_home1 = -20 x_heat_home2 = -15 y_heat_forward = 17 y_heat_backward = -16 z_change_dis = 18.5 # Initial loading distance load_dis = 180 # Minimum feed length before the next welding min_forward_dis = 20 # Initialization stepper = Step() heat = Pin(17, Pin.OUT) ready = Pin(39, Pin.IN) # 1 for not loaded, 0 for loaded limit = Pin(36, Pin.IN) j = 0 k = 1 stepper.move_to_x_y_z(0, 0, -1) def start(): ''' while true # Not loaded with filament if j = 0: time.sleep(1) if limit.value(): for i in range(30): stepper.move_to_x_y_z(1, 0, 0) if limit.value(): # Initial loading stepper.move_to_x_y_z(load_dis, load_dis, 0) j += 1 break ''' k = 1 while True: num = 0 # Turn on heating heat.value(1) if ready.value(): time.sleep(2) # Melting stepper.move_to_x_y_z(x_heat_backward, -y_heat_forward, 0) # Wait for the melting to solidify time.sleep_ms(1000) for i in range(60): num += 1 stepper.move_to_x_y_z(-1, 0, 0) if limit.value(): # Park the filament and switch stepper.move_to_x_y_z(x_heat_home2, -y_heat_backward, 0) k *= -1 stepper.move_to_x_y_z(0, 0, z_change_dis*k) stepper.move_to_x_y_z(0, 0, -2*k) for i in range(40): stepper.move_to_x_y_z(1, 0, 0) if not limit.value(): break break # Welding stepper.move_to_x_y_z(42, 0, 0) print(num) heat.value(0) time.sleep(3) # Turn off heating and turn on fan cooling time.sleep(20) stepper.move_to_x_y_z(12, -10, 0) stepper.move_to_x_y_z(min_forward_dis, -min_forward_dis, 0) start()
Re: Try to make a 3D printing filament welding device for fused filament fabrication for multi-color printing April 04, 2024 10:27AM |
Admin Registered: 17 years ago Posts: 13,954 |
Re: Try to make a 3D printing filament welding device for fused filament fabrication for multi-color printing April 29, 2024 09:36AM |
Registered: 9 months ago Posts: 2 |
import re def parse_gcode(gcode_path): try: with open(gcode_path, 'r') as file: lines = file.readlines() except FileNotFoundError: print(f"Error: The file '{gcode_path}' does not exist.") return {} current_tool = None tool_changes = 0 tool_extrusion_history = [] # This will track extrusion per tool per usage for line in lines: line = line.strip() if line.startswith(';'): # Skip comment lines continue if line.startswith('T'): # Tool change command tool = line.split()[0] # Get the tool identifier (e.g., T0, T1) if current_tool != tool: if current_tool is not None: # Record the tool change tool_changes += 1 current_tool = tool # Start a new extrusion record for this tool tool_extrusion_history.append((current_tool, 0)) elif line.startswith('G1') and 'E' in line: match = re.search(r'E([-\d\.]+)', line) if match: extrusion = float(match.group(1)) # Add the extrusion value to the last record for the current tool if current_tool is not None: last_record = tool_extrusion_history.pop() new_extrusion = last_record[1] + extrusion tool_extrusion_history.append((last_record[0], new_extrusion)) return tool_changes, tool_extrusion_history # Call the function gcode_file_path = r'C:\Users\86137\Desktop\KVP 86711488_p0_master1200_cyan-0g-2h48m.gcode' tool_changes, tool_extrusion_history = parse_gcode(gcode_file_path) print(f"Total tool changes: {tool_changes}") print("\nDetailed extrusion history per tool usage:") for i, (tool, length) in enumerate(tool_extrusion_history, 1): print(f"Usage {i} - {tool}: {length:.2f}mm")