Teach-in for 5 DOF Manipulator
17 May 2016 14:09 #74790
by jstoquica
Teach-in for 5 DOF Manipulator was created by jstoquica
Hi Everyone,
I find two scripts in python to teaching the joint and world position of my project. I am using this:
I copied it to /usr/bin folder and after run LinuxCNC, I typed in the terminal "python teach-in.py", and I can read the joint and world positions. But I don't know how generate the output file (teach.ngc). I suppose these python file is trying to generate the file here:
Q1. Is it right? I modify "outfile" for "/tmp/teach.ngc" but after that it didn't generate a output file. How can I do that?
Q2. Is it the correct way to execute the *.py file?
Q3. Can I call the *.py file from my axis interface, e.g. with a button?
Thanks a lot.
I find two scripts in python to teaching the joint and world position of my project. I am using this:
#!/usr/bin/python
"""Usage:
python teach.py nmlfile outputfile
If outputfile is not specified, writes to standard output.
"""
# Copyright 2007 Jeff Epler <jepler@unpythonic.net>
import linuxcnc
import Tkinter
import sys
linenumber = 1;
if len(sys.argv) > 1:
linuxcnc.nmlfile = sys.argv[1]
if len(sys.argv) > 2:
outfile = sys.argv[2]
sys.stdout = open(outfile, 'w')
s = linuxcnc.stat()
def get_cart():
s.poll()
position = " ".join(["%-8.4f"] * s.axes)
return position % s.position[:s.axes]
def get_joint():
s.poll()
position = " ".join(["%-8.4f"] * s.axes)
return position % s.joint_actual_position[:s.axes]
def log():
global linenumber;
if world.get():
p = get_cart()
else:
p = get_joint()
label1.configure(text='Learned: %s' % p)
print linenumber, p, s.flood, s.mist, s.lube, s.spindle_enabled;
linenumber += 1;
def show():
s.poll()
if world.get():
p = get_cart()
else:
p = get_joint()
label2.configure(text='Position: %s' % p)
app.after(100, show)
app = Tkinter.Tk(); app.wm_title('LinuxCNC Teach-In')
world = Tkinter.IntVar(app)
button = Tkinter.Button(app, command=log, text='Learn', font=("helvetica", 14))
button.pack(side='left')
label2 = Tkinter.Label(app, width=60, font='fixed', anchor="w")
label2.pack(side='top')
label1 = Tkinter.Label(app, width=60, font='fixed', text="Learned: (nothing yet)", anchor="w")
label1.pack(side='top')
r1 = Tkinter.Radiobutton(app, text="Joint", variable=world, value=0)
r1.pack(side='left')
r2 = Tkinter.Radiobutton(app, text="World", variable=world, value=1)
r2.pack(side='left')
show()
app.mainloop()
I copied it to /usr/bin folder and after run LinuxCNC, I typed in the terminal "python teach-in.py", and I can read the joint and world positions. But I don't know how generate the output file (teach.ngc). I suppose these python file is trying to generate the file here:
if len(sys.argv) > 2:
outfile = sys.argv[2]
sys.stdout = open(outfile, 'w')
Q1. Is it right? I modify "outfile" for "/tmp/teach.ngc" but after that it didn't generate a output file. How can I do that?
Q2. Is it the correct way to execute the *.py file?
Q3. Can I call the *.py file from my axis interface, e.g. with a button?
Thanks a lot.
Please Log in or Create an account to join the conversation.
17 May 2016 15:41 #74799
by andypugh
Replied by andypugh on topic Teach-in for 5 DOF Manipulator
As the script begins #!/usr/bin/python you can actually call it with just "teach.py"
It takes two arguments, the second one being the output file name that you want.
Rather awkwardly the first argument is the NML file name, and this is almost certainly never going to be anything but /usr/share/linuxcnc/linuxcnc.nml
So, you can start it and log output to a file with [code]
teach.py /usr/share/linuxcnc/linuxcnc.nml myoutputfile.txt
You might want to consider changing the script a bit, it doesn't need the nml file, the default will be fine. So make outputfile sys.argv(1) and do away with nmlfile.
It takes two arguments, the second one being the output file name that you want.
Rather awkwardly the first argument is the NML file name, and this is almost certainly never going to be anything but /usr/share/linuxcnc/linuxcnc.nml
So, you can start it and log output to a file with [code]
teach.py /usr/share/linuxcnc/linuxcnc.nml myoutputfile.txt
You might want to consider changing the script a bit, it doesn't need the nml file, the default will be fine. So make outputfile sys.argv(1) and do away with nmlfile.
Please Log in or Create an account to join the conversation.
17 May 2016 18:46 - 17 May 2016 19:07 #74801
by jstoquica
Replied by jstoquica on topic Teach-in for 5 DOF Manipulator
Hi Andy,
Thanks, It is generating the output file.
Can I call the *.py file from my axis interface, e.g. with a button?
Thanks.
Thanks, It is generating the output file.
Can I call the *.py file from my axis interface, e.g. with a button?
Thanks.
Last edit: 17 May 2016 19:07 by jstoquica.
Please Log in or Create an account to join the conversation.
17 May 2016 20:12 #74802
by andypugh
Replied by andypugh on topic Teach-in for 5 DOF Manipulator
I saw the first message you posted in an an email, and was trying to figure out how we could rescue your system from having over-written the linuxcnc.nml file....
It seems you have spotted what went wrong, and rescued the situation, though.
I don't see an easy way to launch the script from Axis. You could potentially add it to a menu, in the same way as Axis knows how to launch the tool table editor and halshow etc.
github.com/LinuxCNC/linuxcnc/blob/2957cc...is/tcl/axis.tcl#L168
It seems you have spotted what went wrong, and rescued the situation, though.
I don't see an easy way to launch the script from Axis. You could potentially add it to a menu, in the same way as Axis knows how to launch the tool table editor and halshow etc.
github.com/LinuxCNC/linuxcnc/blob/2957cc...is/tcl/axis.tcl#L168
Please Log in or Create an account to join the conversation.
17 May 2016 20:29 #74803
by jstoquica
Replied by jstoquica on topic Teach-in for 5 DOF Manipulator
Hi Andy,
I recompile from the source. Thanks.
Now, talking about launch from my gui project:
Q1:
How can I do that? I need edit axis.tcl file from source and compile entire linuxcnc?
Q2:
Is there any other option?
Thanks a lot.
I recompile from the source. Thanks.
Now, talking about launch from my gui project:
Q1:
You could potentially add it to a menu, in the same way as Axis knows how to launch the tool table editor and halshow etc.
How can I do that? I need edit axis.tcl file from source and compile entire linuxcnc?
Q2:
Is there any other option?
Thanks a lot.
Please Log in or Create an account to join the conversation.
17 May 2016 21:20 #74804
by andypugh
Replied by andypugh on topic Teach-in for 5 DOF Manipulator
No, Python and Tcl are interpreted languages. You can just change the code ad re-start the application to see the changes immediately.
If I was doing what you propose I think I would alter the teach.py script to ask for a file-name when it starts.
If I was doing what you propose I think I would alter the teach.py script to ask for a file-name when it starts.
Please Log in or Create an account to join the conversation.
18 May 2016 13:11 #74812
by BigJohnT
Replied by BigJohnT on topic Teach-in for 5 DOF Manipulator
You might want to take a look at my position logger I just uploaded.
forum.linuxcnc.org/forum/21-axis/30986-a...osition-logger#74810
JT
forum.linuxcnc.org/forum/21-axis/30986-a...osition-logger#74810
JT
Please Log in or Create an account to join the conversation.
Time to create page: 0.081 seconds