Skip to content

Commit

Permalink
add example from Anthony Umrandung
Browse files Browse the repository at this point in the history
  • Loading branch information
aradermacher committed Apr 30, 2024
1 parent e66db12 commit 9cb7d5a
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 15 deletions.
27 changes: 21 additions & 6 deletions amworkflow/gcode/gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -196,21 +194,34 @@ 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
for i in range(self.layer_num):
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):
Expand All @@ -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)
Expand Down
93 changes: 93 additions & 0 deletions examples/Cylinder/dodo_cylinder.py
Original file line number Diff line number Diff line change
@@ -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 <filename> # for execution of all task
# > doit -f <filename> s <taskname> # for specific task
# > doit -f <filename> 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)],
}
58 changes: 58 additions & 0 deletions examples/Umrandung/dodo_Umrandung.py
Original file line number Diff line number Diff line change
@@ -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 <filename> # for execution of all task
# > doit -f <filename> s <taskname> # for specific task
# > doit -f <filename> 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)],
}
7 changes: 4 additions & 3 deletions examples/toy/dodo_toy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions tests/test_gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
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')

0 comments on commit 9cb7d5a

Please sign in to comment.