diff --git a/amworkflow/gcode/gcode.py b/amworkflow/gcode/gcode.py index 4cb2b28..f4d37a2 100644 --- a/amworkflow/gcode/gcode.py +++ b/amworkflow/gcode/gcode.py @@ -182,8 +182,6 @@ def create(self, in_file: Path, out_gcode: Path = None) -> None: self.init_gcode() - if self.standard == 'ConcretePrinter_BAM': - self.gcode.append(self.SpindleOn + "\n") # for BAM printer if self.layer_num == 'given by file': # points include full path/all layers @@ -196,7 +194,12 @@ def create(self, in_file: Path, out_gcode: Path = None) -> None: self.move(coord, e=np.round(E, 5), f=self.feedrate) elif self.standard == 'ConcretePrinter_BAM': # BAM printer needs no extrusion info for j, coord in enumerate(coordinates): - self.move(coord, f=self.feedrate, s=self.pumpspeed) + if j==0: # first point differently + self.move([coord[0],coord[1]], f=self.feedrate) + self.elevate(coord[-1]) + self.gcode.append(self.SpindleOn + "\n") # for BAM printer + else: + self.move(coord, f=self.feedrate, s=self.pumpspeed) else: # repeat on given layer for the given layer number and z accoring layer height z = 0 @@ -204,13 +207,21 @@ def create(self, in_file: Path, out_gcode: Path = None) -> None: self.gcode.append(f';==========Layer {i+1}==========\n') z += self.layer_height + coordinates = self.points + coordinates = np.round(np.vstack((coordinates, coordinates[0])), 5) if not self.ramp: self.elevate(z) # stepping + if self.standard == 'ConcretePrinter': self.reset_extrusion() # for TU printer - coordinates = self.points - coordinates = np.round(np.vstack((coordinates, coordinates[0])), 5) + elif self.standard == 'ConcretePrinter_BAM': + if i == 0: + self.move(coordinates[0],f=self.feedrate) + self.elevate(z) # stepping + self.gcode.append(self.SpindleOn + "\n") # for BAM printer + + if self.standard == 'ConcretePrinter': # TU printer needs extrusion info E = 0 for j, coord in enumerate(coordinates): @@ -232,7 +243,11 @@ def create(self, in_file: Path, out_gcode: Path = None) -> None: for j, coord in enumerate(coordinates): if self.ramp: coord = list(coord) + [z] # ramping in z direction - self.move(coord,f=self.feedrate, s=self.pumpspeed) + + if i==0 and j==0: + print('start with second point here') + else: + self.move(coord,f=self.feedrate, s=self.pumpspeed) self.write_gcode(out_gcode, self.gcode) diff --git a/examples/Cylinder/dodo_cylinder.py b/examples/Cylinder/dodo_cylinder.py new file mode 100644 index 0000000..1b7059f --- /dev/null +++ b/examples/Cylinder/dodo_cylinder.py @@ -0,0 +1,93 @@ +import datetime +import logging +from pathlib import Path + +import numpy as np +import pandas as pd +from doit import create_after, get_var +from doit.task import clean_targets +from doit.tools import config_changed + +from fenicsxconcrete.util import ureg + +from amworkflow.geometry import GeometryCenterline +from amworkflow.gcode import GcodeFromPoints + +# > doit -f # for execution of all task +# > doit -f s # for specific task +# > doit -f clean # for deleting task output + +logging.basicConfig(level=logging.INFO) + +# define required parameters +params = { # geometry parameters + "layer_thickness": 10, # mm + "height": 40, # mm + "radius": 20, # mm +} +params_gcode = { # gcode parameters + "layer_num": 4, + "layer_height": 10, #mm + "layer_width": params["layer_thickness"], + "offset_from_origin": [0, 0], # Offset from origin in mm + "unit": "mm", # Unit of the geometry + "standard": "ConcretePrinter", # Standard of the printer firmware TU printer + "coordinate_system": "absolute", # Coordinate system of the printer firmware + "nozzle_diameter": 0.4, # Diameter of the nozzle in mm + #"kappa": 100, # Parameter for the calculation of the extrusion width + "tool_number": 0, # Tool number of the extruder. Expected to be an integer + #"feedrate": 1800, +} + +# TODO datastore stuff?? +OUTPUT_NAME = Path(__file__).parent.name +OUTPUT = ( + Path(__file__).parent / "output" +) # / f'{datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}' + + +def task_create_design(): + """create the design of a centerline model""" + + OUTPUT.mkdir(parents=True, exist_ok=True) + + out_file_step = OUTPUT / f"{OUTPUT_NAME}.stp" + out_file_stl = OUTPUT / f"{OUTPUT_NAME}.stl" + out_file_points = OUTPUT / f"{OUTPUT_NAME}.csv" + + # define center line points here for this example: + points = [[0., 0., 0.], + [0., 150., 0.], + [10., 150., 0], + [75., 75., 0.], + [140., 150., 0.], + [150., 150., 0.], + [150., 0., 0.]] + params["points"] = points # TODO create points representing a cylinder line + geometry = GeometryCenterline(**params) + + return { + "actions": [(geometry.create, [out_file_step, out_file_points, out_file_stl])], + "targets": [out_file_step, out_file_stl, out_file_points], + "clean": [clean_targets], + "uptodate": [config_changed(params)], + } + +@create_after(executed="create_design") +def task_gcode(): + """Generate machine code (gcode) for design from a point csv file.""" + + OUTPUT.mkdir(parents=True, exist_ok=True) + + in_file_points = OUTPUT / f"{OUTPUT_NAME}.csv" + out_file_gcode = OUTPUT / f"{OUTPUT_NAME}.gcode" + + gcd = GcodeFromPoints(**params_gcode) + + return { + "file_dep": [in_file_points], + "actions": [(gcd.create, [in_file_points, out_file_gcode])], + "targets": [out_file_gcode], + "clean": [clean_targets], + "uptodate": [config_changed(params_gcode)], + } diff --git a/examples/Umrandung/dodo_Umrandung.py b/examples/Umrandung/dodo_Umrandung.py new file mode 100644 index 0000000..9840105 --- /dev/null +++ b/examples/Umrandung/dodo_Umrandung.py @@ -0,0 +1,58 @@ +import datetime +import logging +from pathlib import Path + +import numpy as np +import pandas as pd +from doit import create_after, get_var +from doit.task import clean_targets +from doit.tools import config_changed + +from fenicsxconcrete.util import ureg + +from amworkflow.geometry import GeometryCenterline +from amworkflow.meshing import MeshingGmsh +from amworkflow.gcode import GcodeFromPoints +from amworkflow.simulation import SimulationFenicsXConcrete + +# > doit -f # for execution of all task +# > doit -f s # for specific task +# > doit -f clean # for deleting task output + +logging.basicConfig(level=logging.INFO) + +params_gcode = { # gcode parameters + "layer_width": 10, + "unit": "mm", # Unit of the geometry + "standard": "ConcretePrinter_BAM", # Standard of the printer firmware TU printer + "coordinate_system": "absolute", # Coordinate system of the printer firmware + "nozzle_diameter": 10, # Diameter of the nozzle in mm + "feedrate": 10800, + "fixed_feedrate": True, + "pumpspeed": 0 +} + +# TODO datastore stuff?? +OUTPUT_NAME = Path(__file__).parent.name +OUTPUT = ( + Path(__file__).parent / "output" +) # / f'{datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}' + + +def task_gcode(): + """Generate machine code (gcode) for design from a point csv file.""" + + OUTPUT.mkdir(parents=True, exist_ok=True) + + in_file_points = Path(__file__).parent / f"{OUTPUT_NAME}.csv" + out_file_gcode = OUTPUT / f"{OUTPUT_NAME}.nc" + + gcd = GcodeFromPoints(**params_gcode) + + return { + "file_dep": [in_file_points], + "actions": [(gcd.create, [in_file_points, out_file_gcode])], + "targets": [out_file_gcode], + "clean": [clean_targets], + "uptodate": [config_changed(params_gcode)], + } diff --git a/examples/toy/dodo_toy.py b/examples/toy/dodo_toy.py index ab4350a..e9d2f12 100644 --- a/examples/toy/dodo_toy.py +++ b/examples/toy/dodo_toy.py @@ -36,12 +36,13 @@ "layer_width": params["layer_thickness"], "offset_from_origin": [0, 0], # Offset from origin in mm "unit": "mm", # Unit of the geometry - "standard": "ConcretePrinter", # Standard of the printer firmware + "standard": "ConcretePrinter", # Standard of the printer firmware TU printer "coordinate_system": "absolute", # Coordinate system of the printer firmware "nozzle_diameter": 0.4, # Diameter of the nozzle in mm #"kappa": 100, # Parameter for the calculation of the extrusion width "tool_number": 0, # Tool number of the extruder. Expected to be an integer - #"feedrate": 1800, + "feedrate": 1800, + "fixed_feedrate": True, } # simulation parameters needs to be in pint units!! @@ -105,7 +106,7 @@ def task_gcode(): in_file_points = OUTPUT / f"{OUTPUT_NAME}.csv" out_file_gcode = OUTPUT / f"{OUTPUT_NAME}.gcode" - print('check task',params_gcode) + gcd = GcodeFromPoints(**params_gcode) return { diff --git a/tests/test_gcode.py b/tests/test_gcode.py index 12b9a5e..0dd5597 100644 --- a/tests/test_gcode.py +++ b/tests/test_gcode.py @@ -67,9 +67,9 @@ def test_gcode_3dpoints(tmp_path, standard:str): assert file_gcode.exists() # main -# if __name__ == "__main__": -# test_gcode(Path.cwd(), 'ConcretePrinter',True) -# test_gcode(Path.cwd(), 'ConcretePrinter_BAM', True) -# -# test_gcode_3dpoints(Path.cwd(), 'ConcretePrinter') -# test_gcode_3dpoints(Path.cwd(), 'ConcretePrinter_BAM') \ No newline at end of file +if __name__ == "__main__": + test_gcode(Path.cwd(), 'ConcretePrinter',True) + test_gcode(Path.cwd(), 'ConcretePrinter_BAM', True) + + test_gcode_3dpoints(Path.cwd(), 'ConcretePrinter') + test_gcode_3dpoints(Path.cwd(), 'ConcretePrinter_BAM') \ No newline at end of file