5axisgui.py
1 #!/usr/bin/env python 2 # Copyright 2007 Chris Radek 3 # Derived from a work by John Kasunich and Jeff Epler 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 2 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 19 20 from vismach import * 21 import hal 22 import math 23 import sys 24 25 # give endpoint Z values and radii 26 # resulting cylinder is on the Z axis 27 class HalToolCylinder(CylinderZ): 28 def __init__(self, comp, *args): 29 CylinderZ.__init__(self, *args) 30 self.comp = comp 31 32 def coords(self): 33 return -self.comp.tool_length, 20, 0, 20 34 35 c = hal.component("5axisgui") 36 c.newpin("jx", hal.HAL_FLOAT, hal.HAL_IN) 37 c.newpin("jy", hal.HAL_FLOAT, hal.HAL_IN) 38 c.newpin("jz", hal.HAL_FLOAT, hal.HAL_IN) 39 c.newpin("jb", hal.HAL_FLOAT, hal.HAL_IN) 40 c.newpin("jc", hal.HAL_FLOAT, hal.HAL_IN) 41 c.newpin("tool_length", hal.HAL_FLOAT, hal.HAL_IN) 42 c.ready() 43 44 pivot_len=100 45 tool_radius=25 46 47 for setting in sys.argv[1:]: exec setting 48 49 tooltip = Capture() 50 tool = Collection([HalTranslate([tooltip], c, "tool_length", 0,0,-1), 51 HalToolCylinder(c), 52 CylinderZ(pivot_len, 100, 0.0, 50), 53 Box(-100,-100,pivot_len, 100,100,pivot_len+50), 54 Box(-50,25,pivot_len+50, 50,100,pivot_len+150) 55 ]) 56 57 tool = Translate([tool], 0, 0, -pivot_len-150) 58 59 tool = Collection([tool, 60 CylinderY(-100,75, -10,75), 61 CylinderY(-50,60,50,60), 62 ]) 63 64 65 tool = HalRotate([tool],c,"jb",1,0,-1,0) 66 67 wrist = Collection([tool, 68 CylinderY(100,75, 10,75), 69 Box(-50,-100,0, 50,-25,100), 70 Box(-100,-100,100, 100,100,150), 71 CylinderZ(150,75, 200, 75) 72 ]) 73 74 wrist = HalRotate([wrist],c,"jc",1,0,0,1) 75 76 ram = Collection([wrist, 77 Box(-100,-100,200, 100,100,900), 78 ]) 79 80 ram = Translate([ram], 0,0,150) 81 82 ram = HalTranslate([ram],c,"jz",0,0,1) 83 84 ram = Collection([ram, 85 Box(-100,100,350, 100,200,550) 86 ]) 87 88 ram = HalTranslate([ram],c,"jx",1,0,0) 89 90 ram = Collection([ram, 91 Box(-800,200,350, 800,400,550), 92 Box(-1000,200,-900, -800,400,550), 93 Box(800,200,-900, 1000,400,550) 94 ]) 95 96 ram = HalTranslate([ram],c,"jy",0,1,0) 97 98 ram = Collection([ram, 99 Box(-1000,1000,-1000, -800, -1000,-900), 100 Box(800,1000,-1000, 1000,-1000,-900) 101 ]) 102 103 work = Capture() 104 table = Collection([ 105 work, 106 Box(-500,-500,-400, 500,500,-450) 107 ]) 108 109 model = Collection([ram, table]) 110 111 main(model, tooltip, work, 1500)