Gcodetools - Postprocessing

cnc-club.ru for English speaking users
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Gcodetools - Postprocessing

Сообщение Nick »

Post-processing

Post-processing is a function which allows to change already generated Gcode to fit your hardware requirements.

Functions that we want to appear in Post-processing (those one who ready marked with bold):

  • Remap: does string replace in gcode. Coud do several replaces at the time.
  • Axis remap: to change one axis to another
  • Axis Flip: to change one axis to another
  • Make Gcode parametric
  • Scale and offset
  • Round float values to specified degree
  • Regexp: makes regular expression replace on each string
  • ...

Syntax:

Postprocesing look like a script with commands that are executed one by one. Each command affects whole Gcode.
Commands should be separated by semicolon.

Example:

Код: Выделить всё

scale(2,2,1);move(10);parameterize();

Descrpition of the commands

remap

Syntax:

remap("change from"->"change to",...,"change from"->"change to").
Remap works very like replace function the only difference that all replaces are done together not one after another.

Example:

Lets take the one line of Gcode: "x 10 y 20".
remap("x"->"y","y"->"z"); will give "y10 z20"
But if we'll do to consecutive replaces we'll have the following:
Original: "x 10 y 20"
after replace "x" -> "y" : "y 10 y 20"
after replace "y" -> "z" : "z 10 z 20"
See the difference?

round

Syntax:

round(int precision)
Rounds all floating point values to specified precision. Some controllers raises an error if it sees a floating point with long fraction part.

Example:

round(4);
will change "G01 Y 3.9912333333 X 11.0000003233 F 400.0000000000" to "G01 Y 3.9912 X 11.0000 F 400.0000"

regexp

Syntax:

regexp (str patern, str replacement);
Makes regular expression replace on each string. For regular expression syntax see the python's re. manual: http://docs.python.org/library/re.html .
You can use pythons r" " string format to escape "\" correctly. (Ex. regexp(r"G0(\d)", r"G\1");)

Example:

regexp(r"G0(\d)", r"G\1");
Replaces all G01, G02 ... G09 to G1, G2 ... G9.
Will change "G01 Y 3 X 11 F 400" to "G1 Y 3 X 11 F 400"
alfcnc
Кандидат
Сообщения: 98
Зарегистрирован: 02 апр 2010, 19:10
Репутация: 0
Заслуга: Tester
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение alfcnc »

Ok i start to make my own...

First of all i add entry in the gui... i Know i have the feeling to start from the end of work but it's the easy parts... :lol:

So in gcodetools_all_in_one.inx adding my postprocessor entry:

At line 154 :
<item value="round(5)">Plunge to work Z heigh to speed G00</item>

then i save and reload gcodetools ! And ok the entry is shown in postprocessor choice...good start :hehehe:
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение Nick »

I've added regex postprocessor, which was almost done.

But bazaar seems to not working right now.

example: regexp("G0(\d)", "G\1"); - replaces all G01, G02 ... G09 to G1, G2 ... G9.

So here's the code:
Вложения
gcodetools.tar.gz
(120.91 КБ) 1858 скачиваний
alfcnc
Кандидат
Сообщения: 98
Зарегистрирован: 02 апр 2010, 19:10
Репутация: 0
Заслуга: Tester
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение alfcnc »

Ok nice... I think that's be nice for you to do some doc for all post-processor function.
That's make win some time for you !
alfcnc
Кандидат
Сообщения: 98
Зарегистрирован: 02 апр 2010, 19:10
Репутация: 0
Заслуга: Tester
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение alfcnc »

You have implement the python regex type ?
alfcnc
Кандидат
Сообщения: 98
Зарегистрирован: 02 апр 2010, 19:10
Репутация: 0
Заслуга: Tester
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение alfcnc »

alfcnc писал(а):You have implement the python regex type ?
Yes it is... by the re module of python...
for those want more help go to :

http://docs.python.org/howto/regex.html

citation:

The re module was added in Python 1.5, and provides Perl-style regular expression patterns. Earlier versions of Python came with the regex module, which provided Emacs-style patterns. The regex module was removed completely in Python 2.5.

Regular expressions (called REs, or regexes, or regex patterns) are essentially a tiny, highly specialized programming language embedded inside Python and made available through the re module. Using this little language, you specify the rules for the set of possible strings that you want to match; this set might contain English sentences, or e-mail addresses, or TeX commands, or anything you like. You can then ask questions such as “Does this string match the pattern?”, or “Is there a match for the pattern anywhere in this string?”. You can also use REs to modify a string or to split it apart in various ways.

Regular expression patterns are compiled into a series of bytecodes which are then executed by a matching engine written in C. For advanced use, it may be necessary to pay careful attention to how the engine will execute a given RE, and write the RE in a certain way in order to produce bytecode that runs faster. Optimization isn’t covered in this document, because it requires that you have a good understanding of the matching engine’s internals.

The regular expression language is relatively small and restricted, so not all possible string processing tasks can be done using regular expressions. There are also tasks that can be done with regular expressions, but the expressions turn out to be very complicated. In these cases, you may be better off writing Python code to do the processing; while Python code will be slower than an elaborate regular expression, it will also probably be more understandable.
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение Nick »

Exactly! In fact
regexp(pattern,replace) executes re.sub(pattern,replace, line) on each line of Gcode.
alfcnc
Кандидат
Сообщения: 98
Зарегистрирован: 02 апр 2010, 19:10
Репутация: 0
Заслуга: Tester
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение alfcnc »

So finally the regex is:

regex("G01 Z[0-9\-\.]+ F100.0","G00 Z0 \n \g<0>");

If you want use this just one time you can add it directly in gcodetools gui to the "additional postprocessor" zone in the setting tab.

Or add directly it in code like tell previous to have it always but ask to root to set it in launchpad... become:

So in gcodetools_all_in_one.inx adding my postprocessor entry:

At line 154 :
<item value="regex("G01 Z[0-9\-\.]+ F100.0","G00 Z0 \n \g<0>")">Plunge to work Z heigh to speed G00</item>
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение Nick »

I've got amazing idea! About penetration speed postprocessor!

It appears that we can use a function callback as the second argument for the re.sub... so ...
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение Nick »

so...
Here's regex for more complicated post-processor:

Код: Выделить всё

"G01 Z([0-9\.\-]+).*\(Penetrate\)", lambda match: "G00 Z%f (Fast pre-penetrate)\n%s" %(float(match.group(1))+5, match.group(0))
It will penetrate to cutting Z +5 units using G0 and then use G01 and penetration feed.

So it will change

Код: Выделить всё

G01 Z-100 F100 (Penetrate) 
to:

Код: Выделить всё

G00 Z-95.000000 (Fast pre-penetrate)
G01 Z-100 F100 (Penetrate)
You can change "+5" value by changing this to desired value:
"G01 Z([0-9\.\-]+).*\(Penetrate\)", lambda match: "G00 Z%f (Fast pre-penetrate)\n%s" %(float(match.group(1))+5, match.group(0))

float(match.group(1)) is the value that has been set by gcode.

It will work only on gcodetools-dev rev 180 and later. I've added a comment string (Penetrate) to definitely match penetration process.

And I've added it as a standard post-processor: Fast pre-penetrate.


:attention: But be extremely careful to not crush into the material at rapid speed.
alfcnc
Кандидат
Сообщения: 98
Зарегистрирован: 02 апр 2010, 19:10
Репутация: 0
Заслуга: Tester
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение alfcnc »

Yes very cool !
This add a little security that's we can tweak...

I renew the advertisement....

:attention: But be extremely careful to not crush into the material at rapid speed.
migoupil
Новичок
Сообщения: 16
Зарегистрирован: 09 мар 2011, 08:48
Репутация: 0
Откуда: Bordeaux, FRANCE
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение migoupil »

Hi,

Another question for you team. I try the expression regex, but i've the error below
Unrecognized function 'regexp' while postprocessing.
(Command: 'regexp("G0(\d)", "G\1")')
I've read the post and i don't understand why. and You?
For information i've the latest version of gcode tools on ubuntu 10.04 EMC2.
I try with Regexp - Regex -RE.sub but nothing is working.
Do I something wrong? Am i completly silly ? In fact i don't know python language....can you explain to me How to exactly....

Thanks

regards
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Gcodetools - Postprocessing

Сообщение Nick »

That's because regex is not available in stable version yet. It's only in gcodetools-dev.

How to get Gcodetools-dev
Ответить

Вернуться в «English forum»