diff --git a/freecad/LaserCladdingWorkbench/commands.py b/freecad/LaserCladdingWorkbench/commands.py index 91dd658..d7a806e 100644 --- a/freecad/LaserCladdingWorkbench/commands.py +++ b/freecad/LaserCladdingWorkbench/commands.py @@ -169,18 +169,30 @@ class LCSaveProg(): if re.match('Contour*', progpart.Name): # do Conoutes face = pad.ref_body.getSubObject(pad.ref_surface) - edges = Part.__sortEdges__(progpart.Shape.Edges) - vlist = [] - for edge in edges: - vlist.extend([v.Point for v in edge.Vertexes]) - poly = Part.makePolygon(vlist) - #Part.show(poly, "ContourPath") - poses = get_list_of_poses(face, poly.Edges) - if not hasattr(progpart, 'pathtype'): - pathtype = 'LIN' - else: - pathtype = progpart.pathtype - prog.append_contour(poses, pathtype) + #edges = Part.__sortEdges__(progpart.Shape.Edges) + wires = progpart.Shape.Wires + print("Number Contourlines (should be 1): ", len(wires)) + counter = 0 + for wire in wires: + line = [] + for edge in Part.__sortEdges__(wire.Edges): + p0 = edge.Vertexes[0].Point + p1 = edge.Vertexes[1].Point + for p in [p0, p1]: + uv = face.Surface.parameter(p) + normal = face.normalAt(uv[0], uv[1]) + pose = Kuka_Pose.from_point_and_normal(p, normal) + line.append(pose) + print("append contour line (segment): ", counter) + counter += 1 + pathtype = getattr(progpart, 'pathtype', 'LIN') + prog.append_contour(line, pathtype) + #vlist = [] + #for edge in edges: + # vlist.extend([v.Point for v in edge.Vertexes]) + #poly = Part.makePolygon(vlist) + ##Part.show(poly, "ContourPath") + #poses = get_list_of_poses(face, poly.Edges) elif re.match('Hatch*', progpart.Name): face = pad.ref_body.getSubObject(pad.ref_surface) wires = progpart.Shape.Wires diff --git a/freecad/LaserCladdingWorkbench/kuka.py b/freecad/LaserCladdingWorkbench/kuka.py index 68a60e1..3ac6d5d 100644 --- a/freecad/LaserCladdingWorkbench/kuka.py +++ b/freecad/LaserCladdingWorkbench/kuka.py @@ -15,7 +15,7 @@ header_src = """&ACCESS RVP &PARAM EDITMASK = * """ -z_up_pose = """{X 0.0, Y 0.0, Z 50.0, A 0.0, B 0.0, C 0.0, E1 0.0, E2 0.0}""" +z_up_pose = """{X 0.0, Y 0.0, Z 30.0, A 0.0, B 0.0, C 0.0, E1 0.0, E2 0.0}""" class Kuka_Layer: def __init__(self): @@ -168,28 +168,34 @@ class Kuka_Prog: if len(layer.hatchlines): print("Number Hatchlines: ", len(layer.hatchlines)) f.write(";- Hatchlines\n") - f.write("$VEL.CP = %f ; m/s ; m/s \n" % self.vmax) + f.write("$VEL.CP = TRAVELSPEED ; m/s (vmax)\n") f.write("LIN_REL {Z 90.0} C_VEL; just move up \n") + # to first point on part + (first_hatch_line, _) = layer.hatchlines[0] + segment = first_hatch_line[0] + f.write("LIN refpose:{}:{} C_VEL; move to first hatch point but with z_up\n".format(segment.translate_with(self.baseorigin).to_string(), z_up_pose)) + for (line, seg_type) in layer.hatchlines: # a line has many segments # start laser at first segment # stop with last f.write(";- Hatchline\n") - segment = line[0] - f.write("$VEL.CP = %f ; m/s ; m/s \n" % self.vmax) - f.write("LIN refpose:{}:{} C_VEL; move to first hatch point but with z_up\n".format(segment.translate_with(self.baseorigin).to_string(), z_up_pose)) - # One Hatchline f.write(";- First Point in line \n") + segment = line[0] + f.write("$VEL.CP = TRAVELSPEED ; m/s (vproc)\n") f.write("LIN refpose:{} C_VEL; GENERATED\n".format(segment.translate_with(self.baseorigin).to_string())) f.write("TRIGGER WHEN DISTANCE=0 DELAY=0 DO $OUT[%d]=True; Turn on Laser at point \n" % self.use_laser_out) + f.write("$VEL.CP = WELDSPEED ; m/s (vproc)\n") # each segment for segment in line[1:-1]: - f.write("$VEL.CP = %f ; m/s ; m/s \n" % self.vproc) f.write("LIN refpose:{} C_VEL; GENERATED\n".format(segment.translate_with(self.baseorigin).to_string())) segment = line[-1] f.write(";- Last Point in line \n") f.write("LIN refpose:{} C_VEL; GENERATED\n".format(segment.translate_with(self.baseorigin).to_string())) f.write("TRIGGER WHEN DISTANCE=0 DELAY=0 DO $OUT[%d]=FALSE; Turn off Laser at point\n" % self.use_laser_out) + # if z height difference between this and next point, we should move up, else it's faster to just go on. + #f.write("$VEL.CP = %f ; m/s ; m/s \n" % self.vmax) + #f.write("LIN refpose:{}:{} C_VEL; move up from last hatch point \n".format(segment.translate_with(self.baseorigin).to_string(), z_up_pose)) f.write(";- End line \n") diff --git a/freecad/LaserCladdingWorkbench/pad.py b/freecad/LaserCladdingWorkbench/pad.py index b27865f..44fb119 100644 --- a/freecad/LaserCladdingWorkbench/pad.py +++ b/freecad/LaserCladdingWorkbench/pad.py @@ -102,13 +102,21 @@ class LaserPad: contours = create_contour_lines(contours_geoms) hatchlines = create_hatch_lines(hatch_geoms) + for debug1 in contours: + Part.show(debug1, "Debug_Contours") + proj_contours = project_to_face(contours, face) proj_hatchlines = project_to_face(hatchlines, face) # DEBUG Part.show(Part.makeCompound(hatchlines)) obj.purgeTouched() - for pc in proj_contours: - p = Part.makeCompound(pc) + for debug_shape in proj_contours: + Part.show(debug_shape, "Debug_Projected_Contours") + + for contourline in proj_contours: + p = Part.makeCompound([]) + wire = Part.makePolygon(contourline.Wires[0].discretize(Distance=3.0)) + p.add(wire) contours_comp = obj.newObject("Part::Feature", "Contours") LaserPath(contours_comp) contours_comp.Shape = p @@ -120,10 +128,9 @@ class LaserPad: p = Part.makeCompound([]) for hatchline in proj_hatchlines: # discretize by length - for line in hatchline: - wire_sections = line.Wires[0].discretize(Distance=3.0) - wire = Part.makePolygon(wire_sections) - p.add(wire) + wire_sections = hatchline.Wires[0].discretize(Distance=3.0) + wire = Part.makePolygon(wire_sections) + p.add(wire) LaserPath(hatches_comp) hatches_comp.Shape = p diff --git a/freecad/LaserCladdingWorkbench/templates/lasercladding.dat b/freecad/LaserCladdingWorkbench/templates/lasercladding.dat index 846403c..45e5565 100644 --- a/freecad/LaserCladdingWorkbench/templates/lasercladding.dat +++ b/freecad/LaserCladdingWorkbench/templates/lasercladding.dat @@ -20,5 +20,5 @@ DECL INT SUCCESS DECL BASIS_SUGG_T LAST_BASIS={POINT1[] "P1 ",POINT2[] "P1 ",CP_PARAMS[] "CPDAT0 ",PTP_PARAMS[] "PDAT1 ",CONT[] " ",CP_VEL[] "2.0 ",PTP_VEL[] "100 ",SYNC_PARAMS[] "SYNCDAT ",SPL_NAME[] "S0 "} DECL E6POS XP1={X 1007.93701,Y 220.6707,Z 616.796082,A -59.0254211,B -89.0309219,C -120.955002,S 6,T 27,E1 4.45351398E-05,E2 12600.0,E3 0.0,E4 0.0,E5 0.0,E6 0.0} DECL FDAT FP1={TOOL_NO 6,BASE_NO 6,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE} -DECL PDAT PPDAT1={VEL 100.0,ACC 100.0,APO_DIST 100.0,GEAR_JERK 50.0} +DECL PDAT PPDAT1={VEL 60.0,ACC 100.0,APO_DIST 100.0,GEAR_JERK 50.0} ENDDAT diff --git a/freecad/LaserCladdingWorkbench/utils.py b/freecad/LaserCladdingWorkbench/utils.py index 805674d..1558de5 100644 --- a/freecad/LaserCladdingWorkbench/utils.py +++ b/freecad/LaserCladdingWorkbench/utils.py @@ -17,11 +17,8 @@ def project_to_face(compounds, face): # proj = Part.makeCompound([]) proj = [] for c in compounds: - projection_result = [] - for e in c.Edges: - projection_result.append(face.makeParallelProjection(e, App.Vector(0, 0, 1))) - # proj.add(Part.makeCompound(projection_result)) - proj.append(projection_result) + shape = face.makeParallelProjection(c, App.Vector(0, 0, 1)) + proj.append(shape) return proj