Creating a Script

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
15 Feb 2013 02:44 #30065 by Todd Zuercher
Creating a Script was created by Todd Zuercher
I am not a programer and know nothing about writing programs.
I could use some help trying to write a small script file that can modify existing g-code files for my purposes.
I would want it to find all of the Z axis commands and create an identical W command after them.
Unless someone has a better idea to achieve the same end.

What I would like is something that can take code like this:

G1 X7.286672 Y10.920909 Z-0.165422
G1 X7.290075 Y10.882176 Z-0.162863
G1 X7.289496 Y0.985702 Z-0.161858
G1 X7.286561 Y0.942836 Z-0.161923
G1 X7.280504 Y0.912766 Z-0.166510
G1 X7.256354 Y0.833603 Z-0.159223
G00 Z0.25
G00 X7.006710 Y0.939417 Z0.25
G00 Z0.0
G1 X7.006710 Y0.939417 Z-0.079312
G1 X6.995858 Y0.916412 Z-0.086247
G1 X6.980558 Y0.899274 Z-0.080125
G1 X6.937673 Y0.867952 Z-0.085329
G1 X6.918087 Y0.863142 Z-0.087211
G1 X6.889543 Y0.859730 Z-0.086135

and turn it into code like this:

G1 X7.286672 Y10.920909 Z-0.165422 W-0.165422
G1 X7.290075 Y10.882176 Z-0.162863 W-0.162863
G1 X7.289496 Y0.985702 Z-0.161858 W-0.161858
G1 X7.286561 Y0.942836 Z-0.161923 W-0.161923
G1 X7.280504 Y0.912766 Z-0.166510 W-0.166510
G1 X7.256354 Y0.833603 Z-0.159223 W-0.159223
G00 Z0.25 W0.25
G00 X7.006710 Y0.939417 Z0.25 W0.25
G00 Z0.0 W0.0
G1 X7.006710 Y0.939417 Z-0.079312 W-0.079312
G1 X6.995858 Y0.916412 Z-0.086247 W-0.086247
G1 X6.980558 Y0.899274 Z-0.080125 W-0.080125
G1 X6.937673 Y0.867952 Z-0.085329 W-0.085329
G1 X6.918087 Y0.863142 Z-0.087211 W-0.087211
G1 X6.889543 Y0.859730 Z-0.086135 W-0.086135

Please Log in or Create an account to join the conversation.

More
15 Feb 2013 05:05 #30071 by alan_3301
Replied by alan_3301 on topic Creating a Script
I know this doesnt answer your question, but you could link the W axis to the same pins as the Z axis? Send 2 drivers the same signal. That way you wouldnt have to edit your gcode.

Please Log in or Create an account to join the conversation.

More
15 Feb 2013 07:17 #30075 by BigJohnT
Replied by BigJohnT on topic Creating a Script
I might be able to cobble something up in python in the next few days... if I forget remind me.

Is the Z word always last in your code?

John

Please Log in or Create an account to join the conversation.

More
15 Feb 2013 20:45 - 15 Feb 2013 20:46 #30108 by Rick G
Replied by Rick G on topic Creating a Script
Another option would be to export your code to a spread sheet, copy the z coordinate column to a new column, add the w.
Extra steps, but should work.

Rick G
Last edit: 15 Feb 2013 20:46 by Rick G.

Please Log in or Create an account to join the conversation.

More
15 Feb 2013 21:33 #30114 by andypugh
Replied by andypugh on topic Creating a Script

I know this doesnt answer your question, but you could link the W axis to the same pins as the Z axis? Send 2 drivers the same signal. That way you wouldnt have to edit your gcode.


Depending on the reason this is required, Gantrykins might be appropriate.
I suspect that this is a twin-spindle machine.
I can imagine situations where Gantrykins would be a good way to do this. (though I don't think it allows you to switch configurations on-the-fly)

Please Log in or Create an account to join the conversation.

More
15 Feb 2013 21:47 #30116 by alan_3301
Replied by alan_3301 on topic Creating a Script
I bet you are right. I was imagining a single z axis with 2 motors.
Maybe a checkbox could be made that would link and unlink the 2 pins.
Unlinked for touching off, and linking back when ready to run code.

Please Log in or Create an account to join the conversation.

More
15 Feb 2013 21:49 #30117 by BigJohnT
Replied by BigJohnT on topic Creating a Script
I made some progress this morning but ran out of time to finish it up...

The raw output of the conversion.
john@zotac:~/linuxcnc/python/todd$ ./todd.py
line read from file
G1 X7.286672 Y10.920909 Z-0.165422

split into a list
['G1', 'X7.286672', 'Y10.920909', 'Z-0.165422']
append W coordinate
['G1', 'X7.286672', 'Y10.920909', 'Z-0.165422', 'W-0.165422']
new line of code converted back to a string
G1 X7.286672 Y10.920909 Z-0.165422 W-0.165422

The python code to get this far.
#! /usr/bin/env python

openfile = open('todd.ngc', 'r')
temp = openfile.readline()

print 'line read from file'
print temp

if temp.find('Z') != -1:
  words = temp.rstrip('\n')
  words = words.split(' ')
  print 'split into a list'
  print words

newword = ''

for i in words:
  if i[0] == 'Z':
    newword = 'W'+ i[1:]

if len(newword) > 0:
  words.append(newword)
  print 'append W coordinate'
  print words
  newline = ' '.join(words)
  print 'new line of code converted back to a string'
  print newline

openfile.close()

John
The following user(s) said Thank You: Todd Zuercher

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
15 Feb 2013 21:59 - 15 Feb 2013 22:02 #30118 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
Thanks
Last edit: 15 Feb 2013 22:02 by Todd Zuercher. Reason: Duplicate post

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
15 Feb 2013 22:00 #30119 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
Yes this is a twin spindle router and It uses analog tourque mode servos. I need both W and Z to be able to use their own offsets for setting depth on the tools and to allow for varriations in material thickness between parts. For these reasons I don't think just slaving one axis to the others signal and gantrykins will work for me. Maybe I am wrong about Gantrykins, I have not played with it alot (i dismissed it as unusable pretty early). I'll have to set up another sim configuration to play with it a little more. In the mean time I still feal that setting up a filter program will give me my best results.

Please Log in or Create an account to join the conversation.

More
15 Feb 2013 23:38 #30126 by BigJohnT
Replied by BigJohnT on topic Creating a Script
I'll put some more time on this at lunch, It does depend on the space being between the axis words to work. Is that the case in your G code files?

John

Please Log in or Create an account to join the conversation.

Time to create page: 0.086 seconds
Powered by Kunena Forum