Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'squirrel'
- from pycad.primitives import Import, Cylinder, Cube, Cone
- from pycad.groups import Union, Difference, Intersection, Hull
- from pycad.formats.scad import fast_scad_export
- from pycad.tools.part import Part
- from pycad.tools.screws import HexagonScrew
- from pycad.tools.bearing import Bearing
- from pycad.tools import colors
- from math import *
- #test =Import("B+_Model_v4.stl").translate([100, -70, 0])
- class TrackGearedWheel(Part):
- def __init__(self, chain, n, thickness, hub_d, screw, screw_distance, fn=8):
- super().__init__()
- self.chain = chain
- self.n = n
- self.height = chain.space_w
- self.thickness = thickness
- self.hub_d = hub_d
- self.screw = screw
- self.screw_distance = screw_distance
- self.chain_scale = 1.2
- self.fn=fn
- self.inner_angle = 360/n
- self.track_angle = 180 - self.inner_angle
- self.r = ( chain.length/2 ) / sin( radians(self.inner_angle/2) )
- def create_part(self):
- self.add(main_d=Difference())
- positive = Union().add(
- Cylinder(d= self.r*2, h= self.height, center=True)
- )
- self.main_d.add(
- positive,
- Cylinder(d=self.hub_d, h=self.height + 2, fn=self.fn, center=True)
- )
- for i in [0, 120, -120]:
- self.main_d.add(
- Cylinder(d=self.screw.d, h=self.height + 2, center=True, fn=self.fn).translate([self.screw_distance, 0, 0]).rotate([0, 0, i])
- )
- for i in range(self.n):
- chain_c = [self.r-self.chain.d/2+(self.chain.d*self.chain_scale)/2, 0]
- space_angle = self.inner_angle/2
- space_c = [self.r*cos(radians(space_angle)), self.r*sin(radians(space_angle))]
- distance = sqrt( (chain_c[0] - space_c[0])*(chain_c[0] - space_c[0]) + (chain_c[1] - space_c[1])*(chain_c[1] - space_c[1]) )
- space_r = distance - (self.chain.d*self.chain_scale)/2
- self.main_d.add(
- Cylinder(d=self.chain.d*self.chain_scale, h=self.height + 2, center=True, fn=self.fn)
- .translate([self.r-self.chain.d/2+(self.chain.d*self.chain_scale)/2, 0, 0])
- .rotate([0, 0, i*360/self.n])
- )
- positive.add(
- Cylinder(r=space_r, h=self.height, center=True, fn=self.fn)
- .translate([self.r, 0, 0])
- .rotate([0, 0, (i+0.5)*360/self.n])
- )
- for i in [-1, 1]:
- self.main_d.add(
- Difference().add(
- Cylinder(r=self.r+space_r+10, h=self.height/2 + 0.5, fn=self.fn*2),
- Cone(r1=self.r+space_r, r2=self.r, h=self.height/2, fn=self.fn*2).translate([0, 0, 0])
- ).rotate([90+i*90, 0, 0])
- )
- class Chain(Part):
- def __init__(self, length, t, space_w, space_gap, width, screw_d, teeth_h, fn):
- super().__init__()
- self.teeth_h = teeth_h
- self.length = length
- self.d = t
- self.t = t
- self.space_w = space_w
- self.space_gap = space_gap
- self.width = width
- self.screw_d = screw_d
- self.fn =fn
- def create_part(self):
- self.side_width = self.width/2 - (self.space_w + 0.2) - self.space_gap/2
- positive = Union()
- positive.add(
- Cylinder(d=self.d, h=self.width - self.side_width, center=True, fn=self.fn).rotate([90, 0, 0]),
- Hull().add(
- Cylinder(d=self.d, h=self.space_gap, center=True, fn=self.fn).rotate([90, 0, 0]),
- Cylinder(d=self.d, h=self.space_gap, center=True, fn=self.fn).rotate([90, 0, 0]).translate([self.length, 0, 0])
- )
- )
- for i in [-1, 1]:
- positive.add(
- Difference().add(
- Hull().add(
- Cylinder(d=self.d, h=self.side_width, fn=self.fn).rotate([-90*i, 0, 0]).translate([self.length, i*(self.width/2 - self.side_width), 0]),
- Cylinder(d=self.d, h=self.side_width, fn=self.fn).rotate([-90*i, 0, 0]).translate([0, i*(self.width/2 - self.side_width), 0])
- ),
- Cylinder(d=self.d*1.2, h=self.side_width/2 + 1, fn=self.fn).rotate([-90*i, 0, 0]).translate([0, i*(self.width/2 - self.side_width/2), 0]),
- )
- )
- self.add(
- Hull().add(
- Cylinder(d=self.d, h=self.space_gap, center=True).rotate([90, 0, 0]).translate([self.d*1.2, 0, 0]),
- Cylinder(d=self.d, h=self.space_gap, center=True).rotate([90, 0, 0]).translate([self.length - self.d*1.2, 0, 0]),
- Cylinder(d=self.d, h=self.space_gap - 2, center=True, fn=self.fn).rotate([90, 0, 0]).translate([self.length/2, 0, self.teeth_h])
- )
- )
- self.add(
- Difference().add(
- positive,
- Cylinder(d=self.screw_d, h=self.width + 2, center=True, fn=self.fn).rotate([90, 0, 0]),
- Cylinder(d=self.screw_d, h=self.width + 2, center=True, fn=self.fn).rotate([90, 0, 0]).translate([self.length, 0, 0]),
- Cylinder(d=self.d*1.2, h=self.space_gap/4 + (self.space_w + 0.2) + self.side_width/2, fn=self.fn).rotate([-90, 0, 0]).translate([self.length, self.space_gap/4, 0]),
- Cylinder(d=self.d*1.2, h=self.space_gap/4 + (self.space_w + 0.2) + self.side_width/2, fn=self.fn).rotate([90, 0, 0]).translate([self.length, -self.space_gap/4, 0]),
- Cylinder(d=self.d*1.2, h=self.space_gap/2, center=True, fn=self.fn).rotate([90, 0, 0]),
- )
- )
- class TrackWheel(Part):
- def __init__(self, track, d, screw, bearing, t, fn=16):
- super().__init__()
- self.bearing = bearing
- self.track = track
- self.d = d
- self.screw = screw
- self.t = t
- self.base_height = self.track.width/2 - self.track.space_gap/2
- self.fn = fn
- def create_holes(self, diff, min_r, max_r):
- hole_d = max_r-min_r
- hole_r = (max_r+min_r)/2
- hole_n = round( ( 2*pi*hole_r ) / ( hole_d + self.t ) )
- for i in range(hole_n):
- diff.add(
- Cylinder(d=hole_d, h=self.base_height +2, fn=self.fn).translate([hole_r, 0, -1]).rotate([0, 0, i*360/hole_n])
- )
- def create_part(self):
- self.color(colors.Brass)
- main_d = Difference()
- main_d.translate([0, 0, self.track.space_gap/2])
- base = Cylinder(d=self.d, h=self.base_height, fn=self.fn*2)
- main_d.add(base)
- min_r = self.screw.d/2 + self.t
- max_r = self.d/2 - self.t
- self.create_holes(main_d, min_r, max_r)
- for i in [-1, 1]:
- main_d.add(
- Difference().add(
- Cylinder(r=self.d/2 + 2, h=4, fn=self.fn*2).translate([0, 0, self.base_height/2 - 2]),
- Cone(r1=self.d/2 + 1 , r2=self.d/2 - 2, h=3, fn=self.fn*2).translate([0, 0, self.base_height/2 - 2])
- ).rotate([90+i*90, 0, 0])
- .translate([0, 0, self.base_height/2])
- )
- self.add(
- Difference().add(
- Union().add(
- main_d,
- Cylinder(d=self.bearing.d, h=self.track.space_gap/2, fn=self.fn),
- Cylinder(d=self.bearing.d2 - 2, h=self.track.space_gap/2 - self.bearing.height/2, fn=self.fn).translate([0, 0, self.bearing.height/2])
- ),
- Cylinder(d=self.screw.d, h=self.base_height + 2, fn=self.fn).translate([0, 0, -1]),
- Cylinder(d=self.screw.e, h=self.track.width, fn=self.fn).translate([0, 0, self.screw.l/2])
- )
- )
- fn = 128
- track = Chain(
- length = 15,
- t=6,
- space_w=5,
- space_gap=10-0.2,
- width = 40,
- screw_d=2,
- teeth_h = 6,
- fn=fn
- )
- geared_wheel = TrackGearedWheel(
- chain = track,
- n=8,
- thickness=3,
- hub_d=6,
- screw = HexagonScrew("M3", l=20),
- screw_distance=8,
- fn=fn
- )
- bearing = Bearing(5, 10, 5, fn=fn)
- bearing.translate([0, 0, -bearing.height/2]).rotate([90, 0, 0])
- bearing.color(colors.Aluminum)
- wheel = TrackWheel(track=track, d=30, screw=HexagonScrew("M3", l=20), t=4, bearing=bearing, fn=fn)
- wheel2 = wheel.copy()
- set = Union().add(
- wheel.rotate([90, 0, 0]),
- wheel2.rotate([-90, 0, 0]),
- bearing
- ).translate([0, 0, wheel.d/2 + track.d/2])
- print(("raidus", geared_wheel.r))
- fast_scad_export(
- [
- set.translate([50, 0, 0]),
- set.copy().translate([40, 0, 0]),
- geared_wheel.copy().rotate([90, 0, 0]).translate([0, track.space_gap/2 + geared_wheel.height/2, geared_wheel.r]),
- geared_wheel.copy().rotate([90, 0, 0]).translate([0, -track.space_gap/2 - geared_wheel.height/2, geared_wheel.r]),
- #wheel
- track,
- track.copy().translate([track.length, 0, 0]),
- track.copy().translate([2*track.length, 0, 0]),
- track.copy().translate([3*track.length, 0, 0]),
- track.copy().translate([4*track.length, 0, 0])
- ],
- "main.scad"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement