Filters
12 Mar 2010 09:47 #2288
by bkubicek
Hi!
I have developed some filters that can scale, flip, rotate, and do other things with gcode.
Is there a way of having emc sending the current gcode to an external program as text stream, have emc read the programs output, and replace the current gcode by that?
This would be different to create gcodes with programms depending to the extension, as it exists currently. These programs don't obtain knowledge of the currently loaded gcode, as far as i understand.
I have developed some filters that can scale, flip, rotate, and do other things with gcode.
Is there a way of having emc sending the current gcode to an external program as text stream, have emc read the programs output, and replace the current gcode by that?
This would be different to create gcodes with programms depending to the extension, as it exists currently. These programs don't obtain knowledge of the currently loaded gcode, as far as i understand.
Please Log in or Create an account to join the conversation.
12 Mar 2010 17:53 #2291
by BigJohnT
Replied by BigJohnT on topic Re:Filters
You can do a lot of things like that with the M100's
John
John
Please Log in or Create an account to join the conversation.
12 Mar 2010 18:14 #2292
by bkubicek
Replied by bkubicek on topic Re:Filters
as far as I understand, with the G100++ codes I can call a script file with two parameters.
But I have no acess over the complete currently loaded gcode.
If I understand correctly.
But I have no acess over the complete currently loaded gcode.
If I understand correctly.
Please Log in or Create an account to join the conversation.
13 Mar 2010 11:57 #2295
by BigJohnT
Replied by BigJohnT on topic Re:Filters
Please Log in or Create an account to join the conversation.
13 Mar 2010 12:09 #2296
by bkubicek
Replied by bkubicek on topic Re:Filters
thats what I meant, and what I had already read. Sorry for writing G instead of M.
I can only hand the script two measly parameters, and return nothing. While I want to change the complete program of Gcodes.
E.g. center it, or scale, rotate, truncate, flip,..., remove all N..., make all relative moves absolute, ...
I would find it very cool if there would be a menu entry "filters", in which the sub-items are all the executable scriptfiles in one special directory.
By activating one item in the filter menu, the currently opened gcode-program is piped to the script, and the script is expected to return a potentially changed gcode-program as output on the output stream. Everything from the error stream could be also processed somehow.
This can not be accomplished by scripts in the open file menu, because they don't know which gcode is currently opened.
I can only hand the script two measly parameters, and return nothing. While I want to change the complete program of Gcodes.
E.g. center it, or scale, rotate, truncate, flip,..., remove all N..., make all relative moves absolute, ...
I would find it very cool if there would be a menu entry "filters", in which the sub-items are all the executable scriptfiles in one special directory.
By activating one item in the filter menu, the currently opened gcode-program is piped to the script, and the script is expected to return a potentially changed gcode-program as output on the output stream. Everything from the error stream could be also processed somehow.
This can not be accomplished by scripts in the open file menu, because they don't know which gcode is currently opened.
Please Log in or Create an account to join the conversation.
14 Mar 2010 08:38 #2305
by bkubicek
Replied by bkubicek on topic Re:Filters
ok, i actually spend this morning programming this filtering. I tried to send it over to the developer mailing list, but it is either moderated, or not accepting my mails yet (I suscribed).
Anyway, below is the difference to a git-download I did yesterday.
diff --git a/configs/Sherline3Axis/Sherline3Axis_mm.ini b/configs/Sherline3Axis/Sherline3Axis_mm.ini
index 580791d..3032c57 100644
--- a/configs/Sherline3Axis/Sherline3Axis_mm.ini
+++ b/configs/Sherline3Axis/Sherline3Axis_mm.ini
@@ -22,7 +22,7 @@ MACHINE = EMC-HAL-STEP-MM
DEBUG = 0
# DEBUG = 0x00000007
# DEBUG = 0x7FFFFFFF
-
+FILTER_DIRECTORY = /hobe/bkubicek/bin/
###############################################################################
# Sections for display options
###############################################################################
diff --git a/share/axis/tcl/axis.tcl b/share/axis/tcl/axis.tcl
index 24f0174..ca99be5 100644
--- a/share/axis/tcl/axis.tcl
+++ b/share/axis/tcl/axis.tcl
@@ -60,6 +60,11 @@ setup_menu_accel .menu.file end [_ "_Edit..."]
setup_menu_accel .menu.file end [_ "_Reload"]
.menu.file add command \
+-accelerator [_ "Ctrl-F"] \
+-command do_filter
+setup_menu_accel .menu.file end [_ "_Filter..."]
+
+.menu.file add command \
-accelerator [_ "Ctrl-S"] \
-command save_gcode
setup_menu_accel .menu.file end [_ "_Save gcode as..."]
diff --git a/src/emc/usr_intf/axis/scripts/axis.py b/src/emc/usr_intf/axis/scripts/axis.py
index edabbf1..1302ec2 100755
--- a/src/emc/usr_intf/axis/scripts/axis.py
+++ b/src/emc/usr_intf/axis/scripts/axis.py
@@ -1828,6 +1828,28 @@ class TclCommands(nf.TclCommands):
f = str(f)
open_directory = os.path.dirname(f)
commands.open_file_name(f)
+ def do_filter(*event):
+ if running(): return
+ global open_directory
+ global filter_directory
+ global loaded_file
+ if not filter_directory: filter_directory=open_directory
+ types = ((_("All files"), "*"),)
+ f = root_window.tk.call("tk_getOpenFile", "-initialdir", filter_directory,
+ "-filetypes", types)
+ if not f: return
+ o.set_highlight_line(None)
+ f = str(f)
+ tempfile = os.path.join(tempdir, "filter.ngc")
+ exitcode, stderr = filter_program(f, loaded_file, tempfile)
+ if exitcode:
+ root_window.tk.call("nf_dialog", (".error", "-ext", stderr),_("Filter failed"),
+ _("The program %(program)r exited with code %(code)d. "
+ "Any error messages it produced are shown below:")
+ % {'program': program_filter, 'code': exitcode},
+ "error",0,_("OK"))
+ return
+ return open_file_guts(tempfile, True, False)
def remote (cmd,arg=""):
if cmd == "clear_live_plot":
@@ -2689,6 +2711,7 @@ vars.emcini.set(sys.argv[2])
open_directory = inifile.find("DISPLAY", "PROGRAM_PREFIX")
vars.machine.set(inifile.find("EMC", "MACHINE"))
extensions = inifile.findall("FILTER", "PROGRAM_EXTENSION")
+filter_directory = inifile.find("EMC", "FILTER_DIRECTORY")
extensions = [e.split(None, 1) for e in extensions]
extensions = tuple([(v, tuple(k.split(","))) for k, v in extensions])
postgui_halfile = inifile.find("HAL", "POSTGUI_HALFILE")
Anyway, below is the difference to a git-download I did yesterday.
diff --git a/configs/Sherline3Axis/Sherline3Axis_mm.ini b/configs/Sherline3Axis/Sherline3Axis_mm.ini
index 580791d..3032c57 100644
--- a/configs/Sherline3Axis/Sherline3Axis_mm.ini
+++ b/configs/Sherline3Axis/Sherline3Axis_mm.ini
@@ -22,7 +22,7 @@ MACHINE = EMC-HAL-STEP-MM
DEBUG = 0
# DEBUG = 0x00000007
# DEBUG = 0x7FFFFFFF
-
+FILTER_DIRECTORY = /hobe/bkubicek/bin/
###############################################################################
# Sections for display options
###############################################################################
diff --git a/share/axis/tcl/axis.tcl b/share/axis/tcl/axis.tcl
index 24f0174..ca99be5 100644
--- a/share/axis/tcl/axis.tcl
+++ b/share/axis/tcl/axis.tcl
@@ -60,6 +60,11 @@ setup_menu_accel .menu.file end [_ "_Edit..."]
setup_menu_accel .menu.file end [_ "_Reload"]
.menu.file add command \
+-accelerator [_ "Ctrl-F"] \
+-command do_filter
+setup_menu_accel .menu.file end [_ "_Filter..."]
+
+.menu.file add command \
-accelerator [_ "Ctrl-S"] \
-command save_gcode
setup_menu_accel .menu.file end [_ "_Save gcode as..."]
diff --git a/src/emc/usr_intf/axis/scripts/axis.py b/src/emc/usr_intf/axis/scripts/axis.py
index edabbf1..1302ec2 100755
--- a/src/emc/usr_intf/axis/scripts/axis.py
+++ b/src/emc/usr_intf/axis/scripts/axis.py
@@ -1828,6 +1828,28 @@ class TclCommands(nf.TclCommands):
f = str(f)
open_directory = os.path.dirname(f)
commands.open_file_name(f)
+ def do_filter(*event):
+ if running(): return
+ global open_directory
+ global filter_directory
+ global loaded_file
+ if not filter_directory: filter_directory=open_directory
+ types = ((_("All files"), "*"),)
+ f = root_window.tk.call("tk_getOpenFile", "-initialdir", filter_directory,
+ "-filetypes", types)
+ if not f: return
+ o.set_highlight_line(None)
+ f = str(f)
+ tempfile = os.path.join(tempdir, "filter.ngc")
+ exitcode, stderr = filter_program(f, loaded_file, tempfile)
+ if exitcode:
+ root_window.tk.call("nf_dialog", (".error", "-ext", stderr),_("Filter failed"),
+ _("The program %(program)r exited with code %(code)d. "
+ "Any error messages it produced are shown below:")
+ % {'program': program_filter, 'code': exitcode},
+ "error",0,_("OK"))
+ return
+ return open_file_guts(tempfile, True, False)
def remote (cmd,arg=""):
if cmd == "clear_live_plot":
@@ -2689,6 +2711,7 @@ vars.emcini.set(sys.argv[2])
open_directory = inifile.find("DISPLAY", "PROGRAM_PREFIX")
vars.machine.set(inifile.find("EMC", "MACHINE"))
extensions = inifile.findall("FILTER", "PROGRAM_EXTENSION")
+filter_directory = inifile.find("EMC", "FILTER_DIRECTORY")
extensions = [e.split(None, 1) for e in extensions]
extensions = tuple([(v, tuple(k.split(","))) for k, v in extensions])
postgui_halfile = inifile.find("HAL", "POSTGUI_HALFILE")
Please Log in or Create an account to join the conversation.
14 Mar 2010 11:16 #2307
by BigJohnT
Replied by BigJohnT on topic Re:Filters
I saw it this morning on the Developers e mail list so it was there.
John
John
Please Log in or Create an account to join the conversation.
16 Mar 2010 20:05 #2324
by eslavko
Replied by eslavko on topic Re:Filters
When I today rebuild emc the filter menu apear. Nice. But it's empty. Where actual filter program's is? A lot of time I need rotate filter..
How to use that new feature... Some sample filter?
How to use that new feature... Some sample filter?
Please Log in or Create an account to join the conversation.
16 Mar 2010 21:13 - 16 Mar 2010 21:27 #2326
by bkubicek
Replied by bkubicek on topic Re:Filters
i have some c++ programmed filters on a machine i cannot access right now.
however, some (improvised and untested) examples are quite simple:ok this last is a bit more complexPlease remember, this were done created in the last 4 minutes, and have not been tested with e.g. circle moves
trivial: of course they should be executeable: chmod +x whatever.sh
---
at the remote machine I have a "centergcode" which takes the algebraic average of all (X,Y) vectors and shift the position X0Y0 to this average.
maybe i will try to improve my python by doing some filters with them.
And one that replaces relative moves by absolute ones.
however, some (improvised and untested) examples are quite simple:
removeNs.sh:
#!/bin/bash
cat $1|sed 's/N[0-9]* //g'
A very simple mirrored rotate actually just exchanges X and Y coordinates.
exchangeXY.sh
#!/bin/bash
cat $1 |sed 's/X/§/g' |sed 's/Y/X/g' |sed 's/§/Y/g'
rotateCCW.sh:
#!/bin/bash
cat $1 |sed 's/X/§/g' |sed 's/Y\([ ]*\)\([-0-9\.]*\)/X[-1*[\2]]/g' |sed 's/§/Y/g
flipX.sh:
#!/bin/bash
cat $1 |sed 's/X\([ ]*\)\([-0-9\.]*\)/X[-1*[\2]]/g'
flipY.sh:
#!/bin/bash
cat $1 |sed 's/Y\([ ]*\)\([-0-9\.]*\)/Y[-1*[\2]]/g'
parameterizeZ.sh:
#!/bin/bash
###edit this list to your usual z values
###ZLIST="2.0 -5.0 0.1"
ZLIST="2.0 -5.0 0.1"
#####
ori=`cat $1|tr '\n' '§'`
number=500
cur="$ori"
count=0
for i in $ZLIST;
do
echo "#$[$number+$count] = $i; Z originally $i "
count=$[$count+1]
done
count=0
for i in $ZLIST;
do
t=`echo $i |sed 's/\./\\\./g' |sed 's/\-/\\\-/g'`
sedstring="s/Z[ ]*$t/Z #$[$number+$count]/g"
#echo "TT=$t sed: $sedstring"
new=`echo $cur |sed -e "$sedstring"`
cur=$new
count=$[$count+1]
done
echo $cur |tr '§' '\n'
trivial: of course they should be executeable: chmod +x whatever.sh
---
at the remote machine I have a "centergcode" which takes the algebraic average of all (X,Y) vectors and shift the position X0Y0 to this average.
maybe i will try to improve my python by doing some filters with them.
And one that replaces relative moves by absolute ones.
Last edit: 16 Mar 2010 21:27 by bkubicek.
Please Log in or Create an account to join the conversation.
17 Mar 2010 12:49 - 17 Mar 2010 12:52 #2336
by eslavko
Replied by eslavko on topic Re:Filters
Can't get that to work.
Maybe I just miss something..
and permision is set to be executable.
The filter option in axis menu appear with submenu ExchangeXY but if I click them nothing happend.
Slavko.
Maybe I just miss something..
I'm added in my ini file
section [EMC]
FILTER_DIRECTORY = /home/slavko/emc2/filters
section [FILTERS]
PROGRAM=ExchangeXY
And have script "ExchangeXY.sh" in filters folders and inside is
#!/bin/bash
cat $1 |sed 's/X/§/g' |sed 's/Y/X/g' |sed 's/§/Y/g'
and permision is set to be executable.
The filter option in axis menu appear with submenu ExchangeXY but if I click them nothing happend.
Slavko.
Last edit: 17 Mar 2010 12:52 by eslavko.
Please Log in or Create an account to join the conversation.
Time to create page: 0.127 seconds