Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeicor committed Mar 10, 2024
1 parent 871266b commit 3672226
Show file tree
Hide file tree
Showing 9 changed files with 1,038 additions and 52 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ jobs:
steps:
# Prepare
- uses: "actions/checkout@v4"
- run: "pip install poetry"
- uses: "actions/setup-python@v5"
with:
python-version: "3.11"
cache: "pip"
- run: "pip install -r requirements.txt"
cache: "poetry"
- run: "poetry install"

# Build
- run: "echo 'YACV_DISABLE_SERVER=True' >> $GITHUB_ENV"
#- run: "python src/conn_grid.py"
#- run: "python src/screwable_cylinder.py"
- run: "python src/core.py"
- run: "python src/module_allen_box.py"
#- run: "poetry run python src/conn_grid.py"
#- run: "poetry run python src/screwable_cylinder.py"
- run: "poetry run python src/core.py"
- run: "poetry run python src/module_allen_box.py"

# Deploy
- uses: "actions/configure-pages@v4"
Expand Down
966 changes: 966 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "bike-stem-mount-v2"
version = "0.1.0"
description = ""
authors = ["Yeicor <[email protected]>"]
readme = "README.md"
packages = [{ include = "src" }]

[tool.poetry.dependencies]
python = "^3.11"
build123d = "^0.4.0"
yacv-server = "^0.6.14"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

20 changes: 11 additions & 9 deletions src/conn_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import os
from abc import abstractmethod
from dataclasses import dataclass
from math import cos, radians
from typing import NamedTuple, Optional, Union
from math import *
from global_params import *
from screwable_cylinder import ScrewableCylinder

import build123d as bd
import yacv_server as yacv

from src.global_params import wall, tol
from src.screwable_cylinder import ScrewableCylinder

# ================== MODELLING ==================


Expand Down Expand Up @@ -41,7 +43,7 @@ def build_sketch(self, *workplanes, inverted: bool = False) -> bd.Sketch:
if not inverted:
if self.rounded:
bd.RectangleRounded(self.total_dimensions.x, self.total_dimensions.y,
(self.dimensions.x + self.dimensions.y)/2 / 2)
(self.dimensions.x + self.dimensions.y) / 2 / 2)
else:
bd.Rectangle(self.total_dimensions.x, self.total_dimensions.y)
with bd.GridLocations(self.dimensions.x, self.dimensions.y, self.repeat.x, self.repeat.y):
Expand All @@ -63,9 +65,9 @@ class GridNutHoles(GridBase):
depth: float = ScrewableCylinder.nut_height

def _build_sketch(self, mode: bd.Mode):
major_radius = self.minor_radius / cos(radians(360/6/2))
assert major_radius + tol < self.dimensions.x/2
assert major_radius + tol < self.dimensions.y/2
major_radius = self.minor_radius / cos(radians(360 / 6 / 2))
assert major_radius + tol < self.dimensions.x / 2
assert major_radius + tol < self.dimensions.y / 2
bd.RegularPolygon(major_radius, 6, mode=mode)

@property
Expand All @@ -75,7 +77,7 @@ def sketch_depth(self):

@dataclass(kw_only=True)
class GridScrewHeadHoles(GridBase):
radius = ScrewableCylinder.screw_head_diameter/2
radius = ScrewableCylinder.screw_head_diameter / 2
depth: float = ScrewableCylinder.screw_head_height

def _build_sketch(self, mode: bd.Mode):
Expand All @@ -88,7 +90,7 @@ def sketch_depth(self):

@dataclass(kw_only=True)
class GridScrewThreadHoles(GridScrewHeadHoles):
radius = ScrewableCylinder.screw_diameter/2
radius = ScrewableCylinder.screw_diameter / 2
wrapped_screw_length: float

def _build_sketch(self, mode: bd.Mode):
Expand Down
11 changes: 8 additions & 3 deletions src/core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# %%
import os
from math import cos, radians, sin, degrees, atan2

from build123d import *
from yacv_server import *
from yacv_server import show_all, export_all

from conn_grid import *
from src.conn_grid import GridBase, GridStack, GridScrewThreadHoles, Grid2D, Grid2DF, GridNutHoles
from src.global_params import wall, bbox_to_box, tol
from src.screwable_cylinder import ScrewableCylinder

stem_max_width = 38
stem_max_height = 38
Expand Down Expand Up @@ -136,4 +141,4 @@ def build_core():
logging.basicConfig(level=logging.DEBUG)
show_all()
if os.getenv('CI', '') != '':
yacv.export_all(os.path.join(os.path.dirname(__file__), '..', 'export'))
export_all(os.path.join(os.path.dirname(__file__), '..', 'export'))
12 changes: 6 additions & 6 deletions src/global_params.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import build123d as bd
from build123d import *

# 3D printing basics
tol = 0.1 * bd.MM # Tolerance (tighter than usual)
wall_min = 0.4 * bd.MM # Minimum wall width
tol = 0.1 * MM # Tolerance (tighter than usual)
wall_min = 0.4 * MM # Minimum wall width
wall = 3 * wall_min # Recommended width for most walls of this print
eps = 1e-5 * bd.MM # A small number
eps = 1e-5 * MM # A small number


# Some common utilities

def bbox_to_box(bb: bd.BoundBox) -> bd.Box:
return bd.Box(bb.size.X, bb.size.Y, bb.size.Z, mode=bd.Mode.PRIVATE).translate(bb.center())
def bbox_to_box(bb: BoundBox) -> Box:
return Box(bb.size.X, bb.size.Y, bb.size.Z, mode=Mode.PRIVATE).translate(bb.center())
16 changes: 6 additions & 10 deletions src/module_allen_box.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# %%

# Ensure python path is set to the root of the project
import sys
import os

from build123d import *
from yacv_server import *

sys.path.append(os.path.join(os.path.abspath(''), 'src')) # FIXME
from yacv_server import show, show_all, export_all

from core import grid, grid_dim
from conn_grid import GridStack, GridScrewHeadHoles, GridScrewThreadHoles
from global_params import wall
from src.conn_grid import GridStack, GridScrewHeadHoles, GridScrewThreadHoles
from src.core import grid, grid_dim
from src.global_params import wall

# %% ================== MODELLING ==================

Expand Down Expand Up @@ -42,7 +38,7 @@
conn_core.joints["conn_core"].connect_to(box.joints["top_conn_core"])
part = conn_core.part + box.part
del conn_core, box
show(part, 'conn_core')
show(part, names='conn_core')

# %% ================== EXPORT ==================

Expand Down
33 changes: 17 additions & 16 deletions src/screwable_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
from math import *
from typing import Union

from build123d import *
import yacv_server as yacv

from global_params import *
from src.global_params import wall, tol


# ================== MODELLING ==================


@dataclass(kw_only=True)
class ScrewableCylinder(bd.BasePartObject):
class ScrewableCylinder(BasePartObject):
screw_length: float = 12
screw_diameter: float = 5 # M5
screw_head_diameter: float = 8.5 # M5
Expand All @@ -24,32 +25,32 @@ class ScrewableCylinder(bd.BasePartObject):
wall_size: float = wall
round: bool = False

rotation: bd.RotationLike = (0, 0, 0)
align: Union[bd.Align, tuple[bd.Align, bd.Align, bd.Align]] = None
mode: bd.Mode = bd.Mode.ADD
rotation: RotationLike = (0, 0, 0)
align: Union[Align, tuple[Align, Align, Align]] = None
mode: Mode = Mode.ADD

def __post_init__(self):
with bd.BuildPart() as part:
with BuildPart() as part:
total_height = self.screw_length + self.screw_head_height
max_hole_diameter = max(
self.screw_diameter + 2 * tol, self.screw_head_diameter + 2 * tol,
(self.nut_inscribed_diameter + 2 * tol) / cos(radians(360 / 6 / 2)))
# Core
bd.Cylinder(max_hole_diameter / 2 + self.wall_size, total_height)
Cylinder(max_hole_diameter / 2 + self.wall_size, total_height)
if self.round:
bd.fillet(bd.edges(), radius=self.wall_size)
fillet(edges(), radius=self.wall_size)
# Top hole
with bd.BuildSketch(bd.faces() >> bd.Axis.Z):
bd.Circle(self.screw_head_diameter / 2 + tol)
bd.extrude(amount=-self.screw_head_height, mode=bd.Mode.SUBTRACT)
with BuildSketch(faces() >> Axis.Z):
Circle(self.screw_head_diameter / 2 + tol)
extrude(amount=-self.screw_head_height, mode=Mode.SUBTRACT)
# Screw hole
bd.Cylinder(self.screw_diameter / 2 + tol,
self.screw_length, mode=bd.Mode.SUBTRACT)
Cylinder(self.screw_diameter / 2 + tol,
self.screw_length, mode=Mode.SUBTRACT)
# Nut hole
with bd.BuildSketch(bd.faces() << bd.Axis.Z):
bd.RegularPolygon(self.nut_inscribed_diameter / 2 +
with BuildSketch(faces() << Axis.Z):
RegularPolygon(self.nut_inscribed_diameter / 2 +
tol, 6, major_radius=False)
bd.extrude(amount=-self.nut_height, mode=bd.Mode.SUBTRACT)
extrude(amount=-self.nut_height, mode=Mode.SUBTRACT)
super().__init__(part=part.part, rotation=self.rotation,
align=self.align, mode=self.mode)

Expand Down

0 comments on commit 3672226

Please sign in to comment.