boxespy/boxes/generators/pulley.py

83 lines
2.9 KiB
Python
Raw Normal View History

2016-07-13 19:55:54 +02:00
#!/usr/bin/python3
# Copyright (C) 2013-2016 Florian Festi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from boxes import *
from boxes import pulley
import math
2016-08-17 15:07:41 +02:00
2016-07-13 19:55:54 +02:00
class Pulley(Boxes):
"""Timing belt pulleys for different profiles"""
2016-08-17 15:07:41 +02:00
ui_group = "Part"
2016-07-13 19:55:54 +02:00
def __init__(self):
Boxes.__init__(self)
# remove cli params you do not need
self.buildArgParser(h=6.)
2016-07-13 19:55:54 +02:00
self.argparser.add_argument(
2016-08-17 15:07:41 +02:00
"--profile", action="store", type=str, default="GT2_2mm",
2016-07-13 19:55:54 +02:00
choices=pulley.Pulley.getProfiles(),
help="profile of the teeth/belt")
self.argparser.add_argument(
2016-08-17 15:07:41 +02:00
"--teeth", action="store", type=int, default=20,
2016-07-13 19:55:54 +02:00
help="number of teeth")
self.argparser.add_argument(
2016-08-17 15:07:41 +02:00
"--axle", action="store", type=float, default=5,
2016-07-13 19:55:54 +02:00
help="diameter of the axle")
self.argparser.add_argument(
"--insideout", action="store", type=BoolArg(), default=False,
help="create a ring gear with the belt being pushed against from within")
2016-07-13 19:55:54 +02:00
self.argparser.add_argument(
2016-08-17 15:07:41 +02:00
"--top", action="store", type=float, default=0,
2016-07-13 19:55:54 +02:00
help="overlap of top rim (zero for none)")
2016-08-17 15:07:41 +02:00
2016-07-13 19:55:54 +02:00
# Add non default cli params if needed (see argparse std lib)
2016-08-17 15:07:41 +02:00
# self.argparser.add_argument(
2016-07-13 19:55:54 +02:00
# "--XX", action="store", type=float, default=0.5,
# help="DESCRIPTION")
def disk(self, diameter, hole, callback=None, move=""):
2016-08-17 15:07:41 +02:00
w = diameter + 2 * self.spacing
2016-07-13 19:55:54 +02:00
if self.move(w, w, move, before=True):
return
2016-08-17 15:07:41 +02:00
self.moveTo(w / 2, w / 2)
2016-07-13 19:55:54 +02:00
self.cc(callback, None, 0.0, 0.0)
2016-08-17 15:07:41 +02:00
2016-07-13 19:55:54 +02:00
if hole:
2016-08-17 15:07:41 +02:00
self.hole(0, 0, hole / 2.0)
self.moveTo(diameter / 2 + self.burn, 0, 90)
self.corner(360, diameter / 2)
2016-07-13 19:55:54 +02:00
self.move(w, w, move)
2016-08-17 15:07:41 +02:00
2016-07-13 19:55:54 +02:00
def render(self):
# adjust to the variables you want in the local scope
t = self.thickness
2016-08-17 15:07:41 +02:00
2016-07-13 19:55:54 +02:00
if self.top:
self.disk(
2016-08-17 15:07:41 +02:00
self.pulley.diameter(self.teeth, self.profile) + 2 * self.top,
2016-07-13 19:55:54 +02:00
self.axle, move="right")
2016-08-17 15:07:41 +02:00
for i in range(int(math.ceil(self.h / self.thickness))):
self.pulley(self.teeth, self.profile, insideout=self.insideout, r_axle=self.axle / 2.0, move="right")
2016-07-13 19:55:54 +02:00
2016-08-17 15:07:41 +02:00