Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tydying python code based on issues found by linter #57

Merged
merged 16 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SPDX-License-Identifier: CERN-OHL-S-2.0

## Overview

Nimble hardware models are generated using Python. For CAD we used [CadQuery](https://cadquery.readthedocs.io/en/latest/intro.html). CadQuery scripts can be found in the `mechanical` directory, with individual components in the `mechanical/components/cadquery` directory. Our CadQuery scripts also our `nimble-builder` module of helper functions.
Nimble hardware models are generated using Python. For CAD we used [CadQuery](https://cadquery.readthedocs.io/en/latest/intro.html). CadQuery scripts can be found in the `mechanical` directory, with individual components in the `mechanical/components/cadquery` directory. Our CadQuery scripts also use the `nimble-builder` module of helper functions.

Our preferred way to generate the models needed for a nimble configuration is via our orchestration module `nimble-orchestration`. This can be used to generate trays for networking components, nimble-rack components, and a final CAD assembly. The orchestration system uses [cq-cli](https://github.com/CadQuery/cq-cli) to execute CadQuery scripts, and [ExSource Tools](https://gitlab.com/gitbuilding/exsource-tools) to manage the process of turning scripts into useable models. The orchestration script will eventually use [GitBuilding](https://gitbuilding.io) to generate assembly manuals.

Expand All @@ -32,7 +32,7 @@ Run:

## Running the code

As the code is very much a work in progress we do not have detailed documentation of how to it for custom configurations.
As the code is very much a work in progress we do not have detailed documentation of how to run it for custom configurations.

For now the best way to run the code is with the two scripts in this repository.

Expand All @@ -42,7 +42,7 @@ The script `generate-static.py` is used to create a number of example components

To run this script, run the following command:

python generate-static.py
python generate_static.py

This should create the `build` directory. Inside this the `printed_components` directory should contain a number of `stl` files that can be 3D printed.

Expand All @@ -53,7 +53,7 @@ It also creates a number of files that are used by the orchestration script.
If you don't want to run this locally you can see a [hosted version of the output](https://wakoma.github.io/nimble/).


### Generate static
### Generate configuration

The script `generate.py` is our test-bed script for generating a complete set of information for a nimble configuration.

Expand Down
14 changes: 7 additions & 7 deletions generate_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_component_list():
)
)

for (shelf_type, hole_count) in [
for (shelf_type, height_in_u) in [
("stuff", 3),
("stuff-thin", 3),
("nuc", 3),
Expand All @@ -80,7 +80,7 @@ def get_component_list():
("dual-ssd", 2),
("raspi", 2)]:

components.append(generate_shelf(shelf_type, hole_count))
components.append(generate_shelf(shelf_type, height_in_u))

return components

Expand All @@ -106,21 +106,21 @@ def generate_leg(length, mounting_holes_dia, name, out_file):
)


def generate_shelf(shelf_type, hole_count):
def generate_shelf(shelf_type, height_in_u):
"""
Helper function to generate a shelf/tray. Returns a GeneratedMechanicalComponent
object which contains the data for the shelf.
"""
out_file = f"./printed_components/shelf_6in_{shelf_type}u_{hole_count}.stl"
out_file = f"./printed_components/shelf_6in_{shelf_type}u_{height_in_u}.stl"
source = os.path.join(REL_MECH_DIR, "components/cadquery/tray_6in.py")
device_name = shelf_type.replace('-', ' ')
return GeneratedMechanicalComponent(
key=f"{shelf_type}_{hole_count}u",
key=f"{shelf_type}_{height_in_u}u",
name=f"Tray for {device_name}",
description=f"Tray for {device_name}, height = {hole_count}u",
description=f"Tray for {device_name}, height = {height_in_u}u",
output_files=[out_file],
source_files=[source],
parameters={'shelf_type': shelf_type, 'hole_count': hole_count},
parameters={'shelf_type': shelf_type, 'height_in_u': height_in_u},
application="cadquery"
)

Expand Down
2 changes: 0 additions & 2 deletions lint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ def lint(pylint_args):
something needs doing in the future and you want to push to master then make an issue.
"""




output = Run(pylint_args, exit=False)

Expand Down
18 changes: 11 additions & 7 deletions mechanical/assembly_renderer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
cadquery module that takes an assembly-def.yaml file and generate an assembly from it.

The assembly-def.yaml file is a yaml file that contains a list of parts and their positions in the assembly.
The assembly-def.yaml file is a yaml file that contains a list of parts and their
positions in the assembly.
Example file:
assembly:
parts:
Expand All @@ -15,9 +16,6 @@
assembly-step: '2'

"""
# parameters
# can be set in exsource-def.yaml file
assembly_definition_file = "assembly-def.yaml"

import os
from pathlib import Path
Expand Down Expand Up @@ -55,7 +53,7 @@ class AssemblyRederer:

def __init__(self, assembly_def_file: str):

with open(assembly_def_file, "r") as f:
with open(assembly_def_file, "r", encoding="utf-8") as f:
assembly_def = yaml.load(f, Loader=yaml.FullLoader)
for part_def in assembly_def["assembly"]["parts"]:
self._parts.append(PartDefinition(part_def))
Expand All @@ -71,20 +69,26 @@ def generate(self) -> cq.Assembly:
cq_part = cq.importers.importStep(part.step_file)
for tag in part.tags:
cq_part = cq_part.tag(tag)
assembly.add(cq_part, name=part.name, loc=cq.Location(part.position))
#Pylint appears to be confused by the multimethod __init__ used by cq.Location
julianstirling marked this conversation as resolved.
Show resolved Hide resolved
assembly.add(
cq_part,
name=part.name,
loc=cq.Location(part.position) #pylint: disable=no-value-for-parameter
)

return assembly


# Handle different execution environments, including ExSource-Tools
if "show_object" in globals() or __name__ == "__cqgi__":
# CQGI should execute this whenever called
assembly_definition_file = "assembly-def.yaml"
assembly = AssemblyRederer(assembly_definition_file).generate()
show_object(assembly)

if __name__ == "__main__":
# for debugging
folder = (Path(__file__).resolve().parent.parent)
folder = Path(__file__).resolve().parent.parent
os.chdir(folder)
assembly = AssemblyRederer("assembly-def.yaml").generate()
assembly.save("assembly.stl", "STL")
11 changes: 8 additions & 3 deletions mechanical/components/cadquery/base_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

"""
cq-cli script using cadscript to generate the baseplate of a nimble rack
julianstirling marked this conversation as resolved.
Show resolved Hide resolved
"""
import cadscript as cad
from nimble_builder.nimble_end_plate import create_end_plate


# parameters to be set in exsource-def.yaml file
width = 100
Expand All @@ -13,13 +16,15 @@


def create(width, depth, height):
# create end plate, turn it over and move it to the correct position
"""
create end plate, turn it over and move it to the correct position
"""
plate = create_end_plate(width, depth, height)
plate = plate.rotate("X", 180)
plate = plate.move((0, 0, height))
return plate


if __name__ == "__cqgi__":
if __name__ == "__main__" or __name__ == "__cqgi__" or "show_object" in globals():
result = create(width, depth, height)
cad.show(result) # when run in cq-cli, will return result
94 changes: 0 additions & 94 deletions mechanical/components/cadquery/nimble_tray.py

This file was deleted.

45 changes: 32 additions & 13 deletions mechanical/components/cadquery/rack_leg.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,62 @@
from math import e, floor
"""
cq-cli script using cadscript to generate the rack legs of a nimble rack
"""
julianstirling marked this conversation as resolved.
Show resolved Hide resolved

from math import floor
import cadscript as cad

import nimble_builder


# parameters to be set in exsource-def.yaml file
length = 294.0
hole_spacing = 14.0
long_axis_hole_dia = 4.6
mounting_holes_dia = 3.6


def make_rack_leg(length, hole_spacing, long_axis_hole_dia, mounting_holes_dia) -> cad.Body:
def make_rack_leg(
length,
long_axis_hole_dia,
mounting_holes_dia,
rack_params=None
) -> cad.Body:
"""
Create the rack legs of given length
"""
julianstirling marked this conversation as resolved.
Show resolved Hide resolved

if not rack_params:
rack_params = nimble_builder.RackParameters()

# Construct the overall shape
leg = cad.make_box(nimble_builder.beam_width, nimble_builder.beam_width, length)
leg = leg.fillet("|Z", nimble_builder.corner_fillet)
leg = cad.make_box(rack_params.beam_width, rack_params.beam_width, length)
leg = leg.fillet("|Z", rack_params.corner_fillet)

# Long-axis hole for connecting multiple leg sections together
long_axis_hole = cad.make_sketch()
long_axis_hole.add_circle(diameter=long_axis_hole_dia)
leg = leg.cut_extrude(">Z", long_axis_hole, -length)

# Calculate the count of the holes in the Y direction based on the total length
number_of_holes = int(floor(length / hole_spacing))
number_of_holes = int(floor(length / rack_params.mounting_hole_spacing))

# Mounting holes
mount_hole_ptn = cad.pattern_grid(count_x=1, count_y=number_of_holes, spacing_y=hole_spacing)
mount_hole_ptn = cad.pattern_grid(
count_x=1,
count_y=number_of_holes,
spacing_y=rack_params.mounting_hole_spacing
)
sketch = cad.make_sketch()
sketch.add_circle(diameter=mounting_holes_dia, positions=mount_hole_ptn)

leg.cut_extrude("<Y", sketch, -nimble_builder.beam_width)
leg.cut_extrude("<X", sketch, -nimble_builder.beam_width)
leg.cut_extrude("<Y", sketch, -rack_params.beam_width)
leg.cut_extrude("<X", sketch, -rack_params.beam_width)

# move the lower end of the beam to the origin
leg.move_to_origin("Z")

return leg


print(f"Creating rack leg with length: {length}, hole spacing: {hole_spacing}")
result = make_rack_leg(length, hole_spacing, long_axis_hole_dia, mounting_holes_dia)
cad.show(result) # when run in cq-cli, will return result
if __name__ == "__main__" or __name__ == "__cqgi__" or "show_object" in globals():
print(f"Creating rack leg with length: {length}")
julianstirling marked this conversation as resolved.
Show resolved Hide resolved
result = make_rack_leg(length, long_axis_hole_dia, mounting_holes_dia)
cad.show(result) # when run in cq-cli, will return result
15 changes: 10 additions & 5 deletions mechanical/components/cadquery/top_plate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# SPDX-FileCopyrightText: 2023 Andreas Kahler <mail@andreaskahler.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

"""
cq-cli script using cadscript to generate the topplate of a nimble rack.
As of yet this cannot hold an instrument.
"""
import cadscript as cad

from nimble_builder.nimble_end_plate import create_end_plate
Expand All @@ -13,9 +16,11 @@


def create(width, depth, height):
# just create end plate, not further changes needed
"""
just create end plate, not further changes needed
"""
return create_end_plate(width, depth, height)


result = create(width, depth, height)
cad.show(result) # when run in cq-cli, will return result
if __name__ == "__main__" or __name__ == "__cqgi__" or "show_object" in globals():
result = create(width, depth, height)
cad.show(result) # when run in cq-cli, will return result
Loading
Loading