I'm trying to create a script to add G93 to some XZA G code. I assumed I
just needed to calculate the length of the move using right angle
triangle calculations then create the F word but I'm getting following
errors in sim so I assume I'm not calculating the F word correctly. The
radius of A is pretty constant so I just use an average radius in my
calculations.
I attached what I have so far for your amusement.
Does anyone have any ideas about how to calculate the F word?
Thanks
JT
#!/usr/bin/env python
# -*- coding: utf-8 -*-
version = '0.0.00'
# Copyright John Thornton 2014
'''
Arc Length = (θ à Ï/180) à r
a = X distance
b = A distance
parse a line
check for axis words
if an axis word store it in current variable for each axis
if m2 quit
determine which axes moved to select the forumula needed
calculate the distance and convert that to the F word
write new line to
copy current variables that changed to past variables
'''
import math
class convert:
def __init__(self):
self.radius = 3.0
self.feed = 36.0
#length = (degrees * math.pi / 180) * self.radius
#print str(length_d)
#self.tip_depth = (self.diameter/2)/math.tan(math.radians(self.angle/2))
#self.side_a = 1.0
#self.side_b = 1.0
#self.side_c = math.sqrt(math.pow(self.side_a,2)+math.pow(self.side_b,2))
#print 'side c ' + str(self.side_c)
line_1 = 'X0.1683 Z-0.1465 A2.68'
line_2 = 'X0.169 Z-0.1465 A2.73'
split1 = line_1.split()
split2 = line_2.split()
#print split1
#print len(split1)
#print len(split2)
new_x = 0.0
new_z = 0.0
new_a = 0.0
self.diff_x = 0.0
self.diff_z = 0.0
self.diff_a = 0.0
list = ['X', 'Z', 'A']
dic1 = {}
for items in split1:
#print items[0]
#print items[1:]
if items[0] in list:
dic1[items[0]] = float(items[1:])
dic2 = {}
for items in split2:
#print items[0]
#print items[1:]
if items[0] in list:
dic2[items[0]] = float(items[1:])
self.changed = ''
if 'X' in dic2:
old_x = dic1['X']
new_x = dic2['X']
self.diff_x = abs(old_x - new_x)
if self.diff_x <> 0: self.changed += 'x'
if 'Z' in dic2:
old_z = dic1['Z']
new_z = dic2['Z']
self.diff_z = abs(old_z - new_z)
if self.diff_z <> 0: self.changed += 'z'
if 'A' in dic2:
old_a = dic1['A']
new_a = dic2['A']
self.diff_a = abs(old_a - new_a)
if self.diff_a <> 0: self.changed += 'a'
if self.changed == 'x':self.x()
elif self.changed == 'xz':self.xz()
elif self.changed == 'xa':self.xa()
elif self.changed == 'xza':self.xza()
elif self.changed == 'z':self.z()
elif self.changed == 'za':self.za()
elif self.changed == 'a':self.a()
def x(self):
print 'x'
print self.diff_x
print 'F' + str(abs(self.feed / self.diff_x))
def xz(self):
print 'xz'
print self.diff_x
print self.diff_z
self.length = math.sqrt(math.pow(self.diff_x,2)+math.pow(self.diff_z,2))
print self.length
print 'F' + str(round(abs(self.feed /self.length),1))
def xa(self):
print 'xa'
print self.diff_x
print self.diff_a
self.length_a = (self.diff_a / 360) * (self.radius * 2) * math.pi
print self.length_a
self.length = math.sqrt(math.pow(self.diff_x,2)+math.pow(self.length_a,2))
print self.length
print 'F' + str(round(abs(self.feed /self.length),1))
def xza(self):
print 'xza'
print self.diff_x
print self.diff_z
print self.diff_a
self.length_xz = math.sqrt(math.pow(self.diff_x,2)+math.pow(self.diff_z,2))
print self.length_xz
self.length_a = (self.diff_a / 360) * (self.radius * 2) * math.pi
self.length_xza = math.sqrt(math.pow(self.length_xz,2)+math.pow(self.length_a,2))
print self.length_xza
print 'F' + str(round(abs(self.feed /self.length_xza),1))
def z(self):
print 'z'
print self.diff_z
print 'F' + str(round(abs(self.feed /self.diff_z),1))
def za(self):
print 'za'
print self.diff_z
print self.diff_a
self.length_a = (self.diff_a / 360) * (self.radius * 2) * math.pi
print self.length_a
self.length = math.sqrt(math.pow(self.diff_z,2)+math.pow(self.length_a,2))
print str(self.length)
print 'F' + str(round(abs(self.feed /self.length),1))
def a(self):
print 'a'
print str(self.diff_a)
# correct for length of the arc
self.length_a = (self.diff_a / 360) * (self.radius * 2) * math.pi
print self.length_a
print 'F' + str(round(abs((self.feed / self.length_a))))
main = convert()
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries. Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users