Skip to content

Commit

Permalink
Converting to assembly-driven orchestration
Browse files Browse the repository at this point in the history
  • Loading branch information
julianstirling committed Aug 5, 2024
1 parent bdaa260 commit 1a3d3f5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cadorchestration.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
configuration-class:
configuration-function:
module: nimble_build_system.orchestration.configuration
class: NimbleConfiguration
function: create_assembly
configuration-options: OrchestratorConfigOptions.json
site-title: Wakoma Nimble Configurator
site-tagline: Select Components for Your Nimble
Expand Down
10 changes: 3 additions & 7 deletions mechanical/assembly_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
- name: baseplate
step-file: ./step/baseplate.step
position: (0, 0, 0)
assembly-step: '1'
- name: rack_leg1
step-file: ./step/beam.step
position: (-67.5, -67.5, 3)
assembly-step: '2'
"""

Expand All @@ -32,20 +30,18 @@ class PartDefinition:
name: str
step_file: str
position: tuple
assembly_step: str
tags: list

def __init__(self, definition: dict):
self.name = definition["name"]
self.step_file = definition["step-file"]
# convert position from string like "(1,2,3)" to tuple
self.position = tuple(map(float, definition["position"].strip("()").split(",")))
self.assembly_step = definition["assembly-step"]
self.tags = definition.get("tags", [])
self.color = definition.get("color", "gray95")


class AssemblyRederer:
class AssemblyRenderer:
"""
create a cq assembly from an assembly definition file.
"""
Expand Down Expand Up @@ -86,12 +82,12 @@ def generate(self) -> cq.Assembly:
# Handle different execution environments, including ExSource-Tools
if __name__ == "__main__" or __name__ == "__cqgi__" or "show_object" in globals():
# CQGI should execute this whenever called
assembly = AssemblyRederer(assembly_definition_file).generate()
assembly = AssemblyRenderer(assembly_definition_file).generate()
show_object(assembly)

if __name__ == "__main__":
# for debugging
folder = Path(__file__).resolve().parent.parent
os.chdir(folder)
assembly = AssemblyRederer(assembly_definition_file).generate()
assembly = AssemblyRenderer(assembly_definition_file).generate()
assembly.save("assembly.stl", "STL")
60 changes: 40 additions & 20 deletions nimble_build_system/orchestration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
import posixpath
import json

from cadorchestrator.configuration import Configuration
from cadorchestrator.components import (GeneratedMechanicalComponent,
AssembledComponent)
AssembledComponent,
Assembly)

from nimble_build_system.cad import RackParameters
from nimble_build_system.orchestration.shelf import Shelf
from nimble_build_system.orchestration.device import Device
from nimble_build_system.orchestration.paths import MODULE_PATH, REL_MECH_DIR

class NimbleConfiguration(Configuration):
def create_assembly(selected_devices_ids):
config = NimbleConfiguration(selected_devices_ids)
return config.main_assembly

class NimbleConfiguration:
"""
This class represents a specific nimble configuration
"""
Expand All @@ -29,7 +33,6 @@ class NimbleConfiguration(Configuration):

def __init__(self, selected_devices_ids):

super().__init__()

self._rack_params = RackParameters()
devices_filename = os.path.join(MODULE_PATH, "devices.json")
Expand All @@ -45,7 +48,39 @@ def find_device(device_id):

self._devices = deepcopy(selected_devices)
self._shelves = self._generate_shelf_list
self._assembled_components = self._generate_assembled_components_list()

source = os.path.join(REL_MECH_DIR, "assembly_renderer.py")
source = posixpath.normpath(source)

self.main_assembly = Assembly(
key='nimble_rack',
name='Nimble Rack',
description='Assembled nimble rack',
output_files=[
"./assembly/assembly.stl",
"./assembly/assembly.step",
"./assembly/assembly.glb",
],
source_files=[source],
parameters={"assembly": {"parts": []}},
application="cadquery"
)

self.main_assembly.set_parameter_file(
file_id="assembly_definition_file",
filename="assembly-def.yaml"
)

for assm_component in self._generate_assembled_components_list():
self.main_assembly.add_component(assm_component)

assembly_pars = {
'name': assm_component.key,
'step-file': assm_component.component.step_representation,
'position': assm_component.position,
'color': assm_component.color
}
self.main_assembly.append_to_parameter('assembly.parts', assembly_pars)


@property
Expand Down Expand Up @@ -119,7 +154,6 @@ def _legs(self):
key=key,
component=component,
position = (x_pos, y_pos, self._rack_params.base_plate_thickness),
step=2,
color="gray82"
)
)
Expand Down Expand Up @@ -148,7 +182,6 @@ def _baseplate(self):
key="baseplate",
component=component,
position = (0, 0, 0),
step=1
)


Expand Down Expand Up @@ -178,7 +211,6 @@ def _topplate(self):
key="topplate",
component=component,
position = (0, 0, top_pos),
step=3
)

@property
Expand Down Expand Up @@ -219,22 +251,10 @@ def _generate_shelf_list(self):
key=f"shelf_{i}",
component=component,
position = (x_pos, y_pos, z_pos),
step=4,
color=color
)

shelves.append(Shelf(assm_component, device))

height_in_u += device.height_in_u
return shelves

@property
def assembly_source_file(self):
"""
This is a bit ad hoc until we we work out how best to specify assemblies.
Currently we just pass a Cadquery file that should pass the assembly def.
We should move away from this with classes for assemblies and sub assemblies.
"""
source = os.path.join(REL_MECH_DIR, "assembly_renderer.py")
source = posixpath.normpath(source)
return source

0 comments on commit 1a3d3f5

Please sign in to comment.