Separate feed rate for G0 and G1 movements

Issue #228 new
Victor Bolshakov created an issue

Add second Feed Rate field for G1 movements in "Create CNC Job" section.

Comments (94)

  1. Juan Pablo Caram repo owner

    @vbolshakov , what do you mean by "second" feed rate? Feed rate is always for G1. G0 is always "as fast as the machine will go". Also, do you me "Create CNC Job" for a Geometry Object?

  2. Red Bull

    I'm using FlatCAM in combination with a machine running on Marlin firmware.

    To use the generated gcode from FlatCAM directly with a machine running Marlin Firmware you need to give the feed rate along with G0 / G1 at least always when you want to change the feed rate. Marlin does not have a default feed rate for G0. G0 uses the given feed rate or if not given with the G0 command the feed rate from the last G0 / G1 command.

    Behaviour of Marlin:

    G1 X50 Y25 F3000

    G0 X50 Y50 <--- G0 is moving with F3000

    G1 X50 Y25 F2000

    G0 X50 Y25 <--- G0 is moving with F2000

    G0 X50 Y50 F1500 <--- G0 is moving with F1500

  3. Mike Evans

    I see similar behaviour using ncstudio. I have to specify the feed on each G1, G0 line. No doubt this is due to buggy ncstudio however.

  4. Victor Bolshakov reporter

    I use smoothieware on smothieboard. And speed from G0/1 stored for next G0/1 unless F specified.

  5. Piotr Curious

    +1 on this one . I am also using marlin and cutting and movements are not separated.

    also it would be wise to set separate jerk and accel values for movement vs feed.

  6. Squiggles

    I believe Victor is referring to the two common feed rates, one used for fast traversing between cutting operations (G0 rapid move) and the other used for the cutting operation (G1 linear move).

  7. Marius Stanciu

    I still don't get it (I don't use Marlin).

    What you need is something like this?

    G00 X_pos Y_pos F_rapid

    G01 X_pos Y_pos F_normal

    Are you saying that if F parameter is specified at the end of the line, then this Feedrate is used for the current line and also used until next Feedrate command is encountered?

    Is this GCode passable for Marlin?

    G21
    G90
    G94
    G17
    
    G01 F500.00
    G00 Z3.0000 F1500.00
    G00 Z30.0000
    T 1
    M5
    M6
    (MSG, Change to tool dia=1)
    M0
    M03 S12000
    G4 P1
    G00 X3.0000 Y5.0000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    G00 X3.0000 Y5.0000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    G00 X3.0000 Y12.5000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    G00 X3.0000 Y19.5000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    M05
    G00 Z30.00
    G00 X0Y0 F1500.00
    
  8. X3msnake

    G0 is suppost to issue a fast move and runs at your machine defined fast speed, so no need and no use for a F here

  9. Marius Stanciu

    X3msnake, I know that most (if not all) of the systems are like this but for Marlin (which by default it's a 3D printer) seems that is not. Or maybe I got it wrong ... That's why I am asking ... how Marlin works.

    Read the comment of Redbull above.

  10. KASA

    The problem is: Marlin and other Firmwares dont use the maximum speed for G0 but use the speed that the last G1 command used

  11. Marius Stanciu

    Ok ... now I get it. What is required is something like this:

    If a line with G0 is encountered in parsing the Gerber file it will have to add 2 Gcode lines:

    First: a G01 F rapid_value

    Second a G00 X_value Y_value

    For a line with G01 will need to be:

    G01 F_normal_value

    G01 X_value Y_value

    Is this correct?

  12. KASA

    No, its ok to specify target and feedrate in one statement like

    G1 X90.6 Y13.8 F22.4

    but it is not ok to not specify F when using G0 like this

    G0 X90.6 Y13.8

    It would be enough to add

    F TravelSpeed

    to every G0 and make an Input box so the user can enter TravelSpeed

  13. Marius Stanciu

    Give me a Gcode snippet that works on Marlin with the F2000 for rapids (G00) and F50 for normal_moves (G01).

  14. Marius Stanciu

    In that case, wouldn't you say that the code snippet posted by me above (nicely formatted :) ) is suitable for Marlin? F500 is for G01 and F1500 is for G00. Is G00 (double zero) suitable or it needs to be specifically G0 (single zero)?

    I post it again down this post. Please confirm if it will work on Marlin or if it needs something more.

    I already have done the required changes and I will post a Nightly (windows installer) in the FlatCAM Discussions area. For those that use the python files, they can use the marlin branch in my fork of FlatCAM.

    If JP is reading this and if he wants me to make a pull request with this modification (and others) on the MPL version that's the FlatCAM master, please tell.

    But I fear that those modifications are not part of the philosophy behind FC. That's why I never even tried to duplicate my efforts on the MPL master ...

    G21
    G90
    G94
    G17
    
    G01 F500.00
    G00 Z3.0000 F1500.00
    G00 Z30.0000
    T 1
    M5
    M6
    (MSG, Change to tool dia=1)
    M0
    M03 S12000
    G4 P1
    G00 X3.0000 Y5.0000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    G00 X3.0000 Y5.0000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    G00 X3.0000 Y12.5000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    G00 X3.0000 Y19.5000 F1500.00
    G01 Z-3.3000 F500.00
    G01 Z0 F500.00
    G00 Z3.0000 F1500.00
    M05
    G00 Z30.00
    G00 X0Y0 F1500.00
    
  15. Marius Stanciu

    Hi JP, nice to hear from you :)

    You could look on the topic in Flatcam Discussions and if there is anything there that you would like to add to the Flatcam master just tell.

    I'm afraid that I was not careful enough to create a commit for each of those features, I'm still learning on how to use the concepts behind bitbucket (GIT) but I could try to reproduce those features.

    I could start with this post-processor for Marlin but that requires to add a new field in the Excellon/Geometry Objects UI for the Rapids feedrate and I know that you are against adding to the interface, to not "bloat" it.

    An easy thing is moving the "follow" command to the new format, it's one of the last that is still in FlatCamApp.py.

    But if you agree, I could try to make pull requests to the VisPy branch that you have. Everything I built until now is built upon that branch. The reason is that I've created some of the Transform Object commands (Move, Rotate, Skew, Mirror) based on whatever I could find in shapely.affinity. And using those, benefit from the 3D acceleration from VisPy especially for larger Gerbers/Geom's.

    Right now I'm looking in doing 3 things, don't know who will get my attention first:

    1. An Excellon Editor with the ability to add/delete drill holes. Sort of the like of geometry editor but much simpler. In the end the target will be to help create "mouse bites" in the cutout or create fixing holes. Those things of course rely in having the grid available everywhere (one of the features already implemented)

    2. An Excellon slot file parser (in the beginning for the Altium output). Doesn't seem to be very difficult task but what I need is to have it fit harmoniously into the FC structure.

    3. A new tool for solderpaste dispenser. Creating the geometry in each shape of a top(bottom) solder Gerber (GTS, GBS) and then the Gcode.

    4. In the distant future, adding the ability to edit pads in a Gerber Geometry. Adding buffers on the selected pad.

  16. Marius Stanciu

    @x3msnake , @JakobStaudt,

    I made the last modifications and the output is like bellow, Please confirm and I'll make that Nightly :)

    G21
    G90
    
    G1 F300.00
    G0 Z3.0000 F1800.00
    M3 S12000
    G0 X18.7768 Y14.8020 F1800.00
    G1 F300.00
    G1 Z-0.1000 F300.00
    G1 F300.00
    G1 X18.7587 Y14.8217 F300.00
    G1 X18.7053 Y14.8702 F300.00
    G1 X18.6473 Y14.9131 F300.00
    G1 X18.5855 Y14.9502 F300.00
    
    # I've deteled some GCODE so it will not be a long post
    
    G1 X29.1057 Y18.9098 F300.00
    G1 X29.1486 Y18.9813 F300.00
    G1 X29.1843 Y19.0567 F300.00
    G1 X29.2124 Y19.1353 F300.00
    G1 X29.2327 Y19.2162 F300.00
    G1 X29.2449 Y19.2987 F300.00
    G1 X29.2490 Y19.3845 F300.00
    G0 Z3.0000 F1800.00
    M5
    G0 Z3.0000 F1800.00
    G0 Z30.00 F1800.00
    G0 X0Y0 F1800.00
    
  17. Juan Pablo Caram repo owner

    @MariusStanciu ,

    The way I envision post-processors, are as something that you only do when you export g-code. So it would make sense to me to add something to the GUI only in the CNCJobObject GUI section, and have it do something only when you are saving the g-code. For example, add a field to provide the path to a "post-processor file".

    I know that you have written some code for this, and your post-processors are in fact Python code. Which might be okay, even though my original though was to have something that did not require any coding for the user.

    Maybe you can load a "Python post-processor" using execfile("my_post_processor.py").

    But I suspect that you are not really "post-processing", am I right? You are "pre-processing"? Which goes much deeper into the FlatCAM code.

    Just to share my idea (not that I want to discard yours and impose mine), I though a post processor would be just a text file like this:

    G0 [coord] >>> G0 [coord] F1800.00
    G1 [coord] >>> G1 [coord] F300.0
    

    Then in FlatCAM we interpret this as two rules, that apply to every line of g-code before saving. The example above only include the most simple replacements, but we could add complexity if we wanted to.

    Is there any way that we can meet in the middle, i.e. try to reuse as much as we can of what you have already done, and have it look to the user more like what I'm proposing?

    Thanks.

  18. KASA

    I think both Ideas are very good, a simple format for users that just want to work with FlatCam and a Scripting format with python for more advanced users and use cases. I would like both ways to be accessible through the "create G-Code" Gut though, not only the terminal. When using jpcgt´s idea, I would first look if there is already an Industry standard for this kind of syntax so user that have experience don't have to relearn everything.

  19. Juan Pablo Caram repo owner

    @JakobStaudt , I was thinking to have this in the GUI. Either a textbox where you input this directly, or a "load-file" option to choose a text file with the instructions.

    When you say "Industry standard", to what industry do you refer? The CNC industry? I don't think there is such a thing. The "standard" for specifying text replacements in the software industry I think is Regular Expressions, which is way too complicated for non-coders. I will try a search and see what I can find, but I think it would be the easiest to create our own syntax, keep it specific to g-code and as simple as possible.

  20. KASA

    Of course there are some standards almost everybody agrees on, the simplest example is Gcode-Syntax. I had a quick look and it looks like the concept you/we want to implement seems not to be used anywhere else so there is no standard yet. I think you Syntax is good for beginners but Regular Expressions are so much more powerful and are not that hard to learn (atleast not the basics). Maybe it would be possible to support both ways?

  21. Marius Stanciu

    @jpcgt I totally agree with you. At some point I was thinking that by hard coding this post(pre)processing into python files we make everybody dependent on the developers time.

    But as you may have guessed, my efforts were mostly superficial focusing in bringing to GUI some of the features buried into the inner workings of FC. Mostly I learned PC programming (not only Python itself) as my background knowledge is C embedded programming.

    So it was the same with this post(pre)processing: I've built upon the work of others, I was not the one to implement this feature but it was @MatthieuBerthomé

    I agree that we should focus our efforts (time is limited) into one direction, so having some files saved into a folder in the root directory of FC is one solution that will work. Building a GUI that also offer hints on what to write is not an easy task (I think) and we might just start with a file (text is easy to parse in Python) and later we might change the way it works if people needs to do it in GUI rather than in a text editor. In GUI I think we should have a combobox that gets populated with the files found in that specific folder (just like now it search for python files).

    We could brake down in pieces (more than there are now) the GCODE process (letting people change them as they see fit) like: z_down_to_zero with feedrate_down_to_zero with G[01] or whatever and so on.

    But my main question is (and is burning): what was the reason that you did not used the VisPy canvas? It should be fundamental to get this solved first as the moment the geometry increase in complexity, matplotlib is no longer able to work properly (by today standards, we dont want to see choppy movements when moving things on screen).

    Some sort of 3D acceleration is vital if we want to have panelization (big geometry) and pan around and make verifiactions and so on. Though it will still be a challange due to the shapely buffer process that is so slow (though much more faster than cascaded union).

  22. Juan Pablo Caram repo owner

    @MariusStanciu , @JakobStaudt , I cannot do any coding right not. But I can guide whomever wants to play with this.

    I suggest starting with the absolute simplest solution:

    1. Add a text box in the GUI for the CNCJob object where the user can type in the rules.
    2. Write some code that will support the example that I gave earlier. We might need to discuss the syntax.
    3. Send a pull request. Make sure it does not break anything and if the textbox is empty, that nobody will even notice that this feature is there.
  23. KASA

    I would love to to do this and I have some general python experience but not really GUI stuff. If you could tell me where all the GUI stuff is located and where the processing of the Gcode takes place, I can try to familiarize myself with the code tomorrow. Until then, good night.

  24. Marius Stanciu

    Hi Jakob,

    Basically what you need to know to get started is:

    camlib.py CAM processing is done here

    FlatCAMGUI.py and ObjectUI.py almost all the graphical stuff GUI is here. There is some more GUI in FlatCAMDraw.

    FlatCAMApp is the application. Where most of the signals from GUI are connected. Creating new objects of various kinds is here, too. It's the main file to look for things that you need. Loading files, exporting files have methods here.

    ObjCollection.py is where the object model is built and methods to access the various geometrical objects (Gerber, Excellon, Geometry, CNC)

    FlatCAMObj.py is where all the functions behind ObjectUI.py are stored. Each FlatCAM object has a class here.

    I would first add a menu entry (action) in EDIT naming is something like Edit PostProcessor. Connect that action to a Qwidget, let's say QPlainTextEdit (http://pyqt.sourceforge.net/Docs/PyQt4/qplaintextedit.html) - scroll down a bit for explanation.

    Create a QPushButton and connect it to a method to save the file as .txt file

    Break the possible CNC router process in small units.

    Something like there is currently done in Python postprocessors or the like (but not limited to):

    • comments section (describe what you can do)
    • header

    • start move with feedrate_start and X,Y,Z coords

    • rapid moves with feedrate_rapid

    • linear moves

    • z_down_to_zero with feedrate_down_to_zero. z_down_to_cutz with feedrate_down_to_cutz. z_up_to_zero with feedrate_up_to_zero. z_up_to_travelz with feedrate_up_to_travelz

    • toolchange_action with feedrate_toolchange and x,y,z coords

    • spindle start with delay_param

    • spindle_stop with delay_param

    • stop move with x,y,z coords

    • footer

    Then you have to imagine how to parse the text (maybe an start_line, end_line combination of char's as markers in case that the line spans over multiple text lines: something like block comments in C - since we are in Python, slash - star and star-slash ).

  25. KASA

    Wait, is the seperate Feedrate thing combined with the Post-processor? I would find it better if there was just a text field where you could enter the Feedrate for G0 and if it was empty it would behave as it does now. Should this be combined so to have seperate feedrates you have to use a postprocessor now?

  26. Marius Stanciu

    Sorry, I was still thinking within the concept named by @jpcgt as pre - processing. We may need a working example from JP on how he envision the processing done (more than one line :) )

    About the GUI, if you like I can make it really fast and create also the placeholders for the handlers.

  27. KASA

    I added a Textbox in the "create CNC Job" - GUI now, but is that really what we want? Is it better if you import a script or if there is a textbox to enter it?

    https://imgur.com/a/Sja1Ju4

    I also had a look at camlib.py and I would add the postprocessor there to line 3103. Then you could iterate through "gcode" and modify it.

  28. Marius Stanciu

    Jakob,

    I think that it should be a child window (with close, maximize, minimize, save button etc) if any. Something big enough to hold the entire text without much wrapping.

    Personally I would go for just creating files externally and copying them into a certain folder in FlatCAM rootdirectory or in a localapp directory. Then in the interface all you need is to search for the files, populate a combobox items with the result and select them (use them). Of course if no files are found in that directory, a default file should be used (stored inside FlatCAM but elsewhere, not easily deleted by the user).

  29. KASA

    Ok, that sounds like a good Idea. What filetype would you use? Just accept everything, txt or something custom? .post?

    I would love to help but I am a beginner without much experience so it will take me a lot of time to get this working.

    Oh and regarding the default file:

    Wouldnt it be easier to just check if there was a file selected and if not just do nothing like currently?

    I just had a quick look at GUIElements.py and didnt see a file select object, do we need to create one first?

  30. Marius Stanciu

    I too am a beginner :)

    In what I developed (vispy based branch) I made it a default setting (which pre-processor to use, one for Excellon and one for Geometry).

    We need a positive expected behavior. The user might not know that a postprocessor is missing ...this is why we should use a default file. FlatCAM should always work. Sort of: if there are no items in the seclection combobox use the default_file.

    Using the .TXT file extension I think is fine since the postprocessor file(s) will need to be readily available to the user.

  31. KASA

    Yeah, I didnt want the G-Code creation to not work if there was no file specified but to just not use a Postprocessor and work like it currently does.

    Can you tell me how to add a File Selection Dialog for the GUI?

  32. Marius Stanciu

    You mean a combobox?

    Look in the work done here on how to automatically search for files on instantation : https://bitbucket.org/jpcgt/flatcam/src/6966bccc2778b5c09383526427d4f9ca07387ed3/FlatCAMPostProc.py?at=new-camlib-2

    As for how to add a QComboBox, there are plenty of examples on the web or you can inspire also from FlatCAM. Search in the ObjectUI for the name: FCComboBox (a 'wrapper' if I say it correctly for QComboBox).

    You'll see something like this:

     # postprocessor selection
            postprocessor_label = QtGui.QLabel("Postprocessor")
            postprocessor_label.setToolTip(
                "The json file that dictates\n"
                "gcode output."
            )
            self.custom_box.addWidget(postprocessor_label)
            self.postprocessor_name_entry = FCComboBox()
            self.custom_box.addWidget(self.postprocessor_name_entry)
    
  33. Marius Stanciu

    But if what you want is a Open button and then get the FIle Browser, that's a different story. Look for on_opengerber() method in FlatCAMApp.py It's not for a button but it can be adapted for a QPushBUtton.

  34. KASA

    There is no FCComboBox in ObjectUI.py or any other File... Your code doesnt work because FCComboBox doesnt exist

  35. KASA

    Ok I did it, I now have a Button in the "Export G-Code" GUI and when I click it the File Explorer opens. It returns the filepath to the selected file. Can you give me some help on how to Do the actual processing?

    My first step would be to add another argument "processorFile" to the "export_gcode" Function in FlatCAMobj.py, right? the "export_gcode"-Function iterates through every line in the g-Code so that would be a good place to add a postprocessor

  36. Juan Pablo Caram repo owner

    @JakobStaudt , @MariusStanciu , lets stick to just a text box in the CNCJob UI for now. We are not reading a file yet.

    To add this, edit ObjectUI.py, class CNCJobObjectUI. Keep things similar to what you can see there already. You will be making an almost exact copy of lines 176-185. Put it in the same section "Export...".

    Optional at this point: We need to link the new textbox with the data of the object. In FlatCAMObject.py, class FlatCAMCNCJob. Need to update self.options and self.form_fields.

    Then, on export_button_click() there is a call to export_gcode(). We want to pass an additional parameter, postproc. So read it from the GUI, just like we read preamble, and pass it in. Then edit export_gcode() to accept the new parameter.

    In export_gcode(), line 1127, it iterates over every before writing it to file. This is where the magic happens.... Create another method in the class, call it post_process(line, rules). This will take each line and the rules we read from the GUI and return a post-processed line. For now, make this method return the line intact, without modification, regardless of rules. The for every line we call:

    line = self.post_process(line, rules)
    

    We can pull this in to the master.

    After this is ready we can discuss the syntax.

  37. KASA

    I already added the open file dialog so I think it’s ok like it is. I already modified export_gcode but the hard part is defining the rules and processing them with post_process. How can I upload the files I modified to my fork? Where should I define post_process?

  38. Juan Pablo Caram repo owner

    @JakobStaudt , @MariusStanciu , also we need to update the defaults and per-project options.

    In FlatCAMApp.py, FlatCAMApp.__init__(), we need to update self.defaults, self.defaults_form_fields, self.options, and self.options_form_fields, to include the new textbox.

    Next, edit FlatCAMGUI.py, class CNCJobOptionsGroupUI to include the new textbox in the GUI.

  39. Juan Pablo Caram repo owner

    @JakobStaudt , we will discuss the rules later, when I can verify that everything else is okay.

    Please post a screenshot of your GUI so far.

  40. Juan Pablo Caram repo owner

    @JakobStaudt , to create a "pull request", first you need to have your own clone of the project in Bitbucket. You can do that on this website.

    Then clone your repository into your machine. Make the necessary changes. The you need to do git add <list of files changed> and git commit -m "Descriptions of changes". Finally, push back to your repository by doing git push.

    Now go back to the the website, and in your clone of the repository you can make a "pull request". That will send me an email, and I take it over from there.

    Please don't make pull requests with things that break anything in the project. So test your changes well. It is also important that you run the tests that are part of the repository. I can waive that if your changes are small.

  41. KASA

    I finally got Git to push it but I cant test it because files like FlatCAM.py are missing and if I copy it into the Folder it creates some .py files but still doesnt run...

    heres the repo: https://bitbucket.org/JakobStaudt/postprocessing/src/master/

    The question is: How do I get the repo in a state where it is runnable? I tried the changes in my runnable files on my pc and it worked but Im not confident enough that it worked with all the git trouble so I would like to test them first.

  42. KASA

    Regarding defaults and settings:

    Why do we need to change this? Currently you can select an postprocessing file and if you dont do it, it just doesnt get applied. What do I need to change in the defaults?

  43. Juan Pablo Caram repo owner

    Jakob, there is no FlatCAM.py. The executable is simply flatcam.

    Please stick to creating the textbox we discussed. It is going to make everything much easier to test. If you want to also have the option to load a file that populates the textbox, that's fine, but let's keep the pre-processing rules visible in the GUI.

    Also, the defaults are there so that you can have persistence. Look at the code I mentioned earlier, it should be quite self-explanatory how to do this. If you have more specific questions I'm here to help, but get familiar with the architecture of FlatCAM first.

  44. KASA

    Wow, Im really confused because I installed Flatcam and always start it with "python FlatCAM.py", its in the drectory...

    I will do the textbox now

    https://imgur.com/a/GiQ9KzI here it is.

    I also managed to hand over the content of the text field to the export_gcode() function.

  45. Juan Pablo Caram repo owner

    Let me know when you want me to look at your code. Just make sure you have pushed to your repository and I will look at it.

  46. KASA

    It would be good if you would look at it, I currently use print() for debugging, is there a better way to do that?

    My fork is here: https://bitbucket.org/JakobStaudt/postprocessing/src/master/

    If it is ok I can make a pull request, it is tested and works.

    Currently you can enter stuff into the Postprocessing-Inputfield and if you press export gcode it prints the content of the textfield. the content gets handed over to the export_gcode() function as an argument so it can be used to extract and apply the rules there aswell.

    I made the Pullrequest but I noticed that my PEP8 checker corrected many Style Errors that may have been deliberate, Is this ok or should I disable it and modify it again?

  47. Juan Pablo Caram repo owner

    Use something like this for printing debug messages:

    FlatCAMApp.App.log.debug("setup_axes(): Clearing and attaching axes")
    

    Yes, I saw the PEP8 corrections. Please disable them. Some of the changes were correct, other not, like chnginf the number of "#" for comments.

  48. KASA

    I just did the Pullrequest

    You said

    Next, edit FlatCAMGUI.py, class CNCJobOptionsGroupUI to include the new textbox in the GUI.

    But I edited ObjectUI.py, but it works. What does FlatCAMGUI do? It seems like there are many duplicates between the 2

  49. Juan Pablo Caram repo owner

    Hi Jakob,

    I just pulled in your request.

    Now you need to establish a connection between the GUI and the object, As I said before:

    We need to link the new textbox with the data of the object. In FlatCAMObject.py, class FlatCAMCNCJob. Need to update self.options and self.form_fields.

    This will make the contents of the textbox persistent to the object. Otherwise, you enter some text, go and work on a different object, and the contents are gone.

    After that we can add this to the per-project defaults, and per-app defaults. This is what I was referring to with FlatCAMGUI.py/CNCJobOptionsGroupUI. This is a different part of the GUI, in the "Options" tab.

    Yes, there is some duplication there. You can look at that if you want, but it is not a direct copy, so be careful.

  50. KASA

    I now linked the Processor Textbox like the Append and Prepend Textboxes were done, but the Content disappears when I select the Geometry Object for example. This also happens to the Append and Prepend Textbox. When I enter stuff in any of the Textboxes, select the Geometry Object and come back to the CNC Job Object, all Textfields are empty.

  51. Juan Pablo Caram repo owner

    Jakob,

    I think you are correct and that the form is stored in the object only when the user click on "Export GCode". See:

    https://bitbucket.org/jpcgt/flatcam/src/master/FlatCAMObj.py#lines-1067

    It is possible to read the form on every keystroke, or perhaps when the tab changes. But it is not implemented. There's another project you can look at.

    If you export the GCode, you should see that the contents of the textboxes is correct when you leave and come back to this part of the GUI.

  52. KASA

    Yes, once I export the G-Code the content of the Textbox stays there, even when I switch to another Object and come Back. I also added the Textbox in the Options Menu. Its time to think about the Syntax now, I think.

  53. Juan Pablo Caram repo owner

    @MariusStanciu , you have been working on this for a while, could you share some of the post-processing that people have been requesting?

  54. Marius Stanciu

    From what I've read on the FC discussions forum they requested:

    • custom feedrate for the rapids movement (G00) - Marlin firmware

    • ability to replace G00 with G0, G01 with G1, M03 with M3 and so on

    • ability to replace the Zdown_to_cutz with spindle_off( M5) and Z_lift_to_travelz with spindle_on (M3) - for laser

    • some requested recently for spaces between coordinates (instead X123456Y123456 to be like X123456__Y123456_ (formatting is killing me, added 2 underscores instead of a 'space')

    • I don't remember exactly but some requested that the Feedrate to be on each line at the end (on Marlin also)

    • I personally use manual_toolchange for drill operation with sequence like this:

    G00 Z_toolchange
    T0
    M5
    G00 X0Y0    
    (MSG, Change to Tool Dia = 1.00
    M0
    G01 Z0
    M0
    G00 Z_toolchange
    M0
    
  55. KASA

    To be honest I would find it better if you wouldn’t have to do custom Toolchanges with a Postprocessor but if there was just a Textfield like the ones to Prepend and Append. That would make things much easier, especially for people that don’t want to learn a new syntax but just want to add some Gcode. I would use the Postprocessor as a simpler regular expression set to modify the G-Code to your Machine flavor.

  56. Juan Pablo Caram repo owner

    Okay, some initial thoughts for those same cases:

    Case 1:

    • Regex: G00?(.*) to G00\1 F1234 (Note the \1 represent the first term found between () in the search). This assumes there is no F option originally, otherwise we would end up with G00 ... F5678 F1234.
    • Custom syntax: G00{any} to G00{any} F1234.

    Case 2:

    • Regex G01 to G0. Pretty easy.
    • Custom Syntax G01 to G0.

    Case 3:

    • Custom Syntax G01 Z{cutlevel} to M3. We can internally define "cutlevel" to anything <0, or the actual value that we are using.

    Case 4: This one already has an existing solution. Anyway:

    • Regex: (\d)([XYZxyz]) to \1 \2. Not too bad.
    • Custom Syntax: I don't know... :-(

    Case 5: In this one, we want to add the F code, but not when it is already present.

    • Regex: ^G01([^Ff])*$ to G01\1 F1234

    Case 6: @MariusStanciu , what is it exactly that you are doing? Adding a whole set of lines after G00 Z_toolchange?

  57. KASA

    I would add a custom Syntax for case 2 that lets you replace every double digit G-Code so that you don’t have to enter every G-Code from G01 to G09

  58. Juan Pablo Caram repo owner

    Something like: G0{digit} to {digit}?

    I'm debating in my head about regex versus custom. The benefit of custom is that we can define custom keywords like {cutlevel}, which refer to internal variables. The benefit of regex's is that it so many features already built in. Food for thought.

  59. KASA

    Yeah, G0{digit} to G{digit}. Maybe we can make a mix, the regex syntax combined with keywords? And what do you think about the toolchange Code without postprocessor?

  60. KASA

    @jpcgt Can you please help me, Im so confused right now:

    I have two forks of Flatcam, EntrySave and postprocessing. They should be exactly the same, but If I enter something in the Postprocessor Textfield, change the tab and come back, it is still there with EntrySave but the Field is empty with postprocessing. I already pulled both forks to make sure they are up to date. Is there a way to view the diff between the two?

  61. Juan Pablo Caram repo owner

    Git takes some effort to learn...

    It looks to me that you made 2 clones (not 2 forks). So, you have 2 separate repositories. Ideally, you clone somebody else's repository, and then you can add "branches" or "forks" in the same repository. Git has features that let you compare 2 branches in the same repository.

    Anyway, with what you have now, you can make a pull request from one of your repositories to the other. When you look at the pull request on the web page, it show you the differences.

    For the toolchange case, I don't really care if it is a tool change or not, but we want to have the ability to insert new lines after a given line is found, like G0{any} to G0{any}\n(New line 1)\n(New line 2). We can talk later is we want to add a specific input to the GUI just for the toolchange code. Right now anyway, I'm not too inclined to be adding more to the GUI.

  62. KASA

    I just deleted the second fork and started over and did branches now, thanks for the help!

    I agree that you should be able to replace one line with several others, but I am not sure I like the \n syntax. I think it would be easier to understand for "casual users" if the Syntax was something like

    G0{digit} >>>
        G{digit} F10
        G39
    

    Which would make the Postprocessor replace every Gcode which has a 0 in front of the first nonzero digit with the Gcode without the 0 with an added F10 and a G39 for example.

    I made some progress on the "Input save when changing tabs", I figured out that "self.read_form()" saves the current state of the tab, but how can I call this every time the tab is changed? Is there a function that gets called when a new Tab is selected? I added a Dummybutton "Save Input" that just calls "self.read_form()" and it works, I just need to connect that to the tabchange or userinteraction (Like typing in the textboxes or toggling checkboxes)

  63. KASA

    I now added this

            self.app.ui.notebook.currentChanged.connect(self.on_TabChange)
    
        def on_TabChange(self):
            if self.app.ui.notebook.currentIndex() is 0:
                print("switched to Project Tab")
                self.read_form()
    

    to FlatCAMObj.py and this works but it breaks the initial setup of the tab, when you create a new CNC Job there arent the standards filled in but everything is empty and it throw some Errors in the log, can you have a look at this @jpcgt ? Its in my fork in the tabStateSave branch.

  64. Juan Pablo Caram repo owner

    @JakobStaudt , you want to do this only when you leave the tab, but never when opening the tab.

    Sorry for taking so long to respond.

    I think to get things moving quickly we should start with a regex version and later see if we want to create our own syntax.

    For example, with just regex we can do regex1 >>> replacement, and use internally re.sub(regex1, replacement, line) to edit each line.

  65. KASA

    Sorry for taking so long too, I think my current implementation should save the Input of the user if he changes the tab from the "selected" tab.

    I agree with the Regex thing, I will try to work on that the day after tomorrow. Is there an easy way to parse

    regex1 >>> replacement
    

    to regex1 and replacement as a string? My naive way of trying would be line.split(">>>")

  66. Juan Pablo Caram repo owner

    Yes, rgx, rpl = line.split(">>>") should do it. The only ambiguity that I see here is what do we do with the white spaces in rgx and rpl. We can try to fully ignore them, i.e. rgx = rgx.strip(). But then the user won't be able to search or replace any spaces at the beginning or the end... That is fine. Later we can check for things like:

    " X123" >>> X123
    

    That would remove any spaces before X123. Of course, we can do the same with the replacement string.

  67. KASA

    I just added code that extracts all the Pairs of Regex Rules and Replacements and puts them in a regex[] and replacement[] array (index 0 in both arrays is one rule for example) and when exporting loops through every rule and applies it to the line before it is exported. One Bug/Feature I noticed when I thought about his way of doing it was that the rules interact, that means if you have two rules that replace every "a" with a "b" and every "b" with a "c", the input "a" will give you "c" and not "b". I dont know if this is a problem and if it is, if there is an easy way around this. I didnt test the code yet but I will do this later or tomorrow..

  68. KASA

    I couldnt resist and did a simple Test, "G >>> X" as a Postprocessing Script, and it did in fact change every G to an X without throwing any error. I will do some better testing with real Regex and edgecases tomorrow. BTW regarding the

    #!
    
    " X123" >>> X123
    

    , wouldnt it be more intuitive if we would change the Syntax to

    #!
    
    "regex" >>> "replacement"
    

    then and not

    regex >>> replacement
    

    ?

  69. KASA

    I just did some more testing and noticed that the processed line was written after a rule was applied for every rule so with five rules you would have the original line 5 times with the different rules applied. I did a new Commit that fixes this.

    If you do G >>> X X >>> Y now, every G and X will become a Y

  70. KASA

    Hello, My Pull request hasnt been accepted right? Is this feature implemented now?

    If not, I would like to work on it again. Can someone tell me what the current state of this is?

  71. Juan Pablo Caram repo owner

    Hi @KASA , welcome back. Please go ahead. Just make sure that when you make a pull request that it is fully functional and tested, and that you provide some documentation of how to use it. Maybe just posting to this thread would be enough for now.

  72. KASA

    Ok, Thanks! Is there a Guide on how to setup your Enviroment in Windows for development? I did it in Ubuntu last time and that was easier. I tried downloading the Sources and running it but its giving me “no module named …”, after each Module I install, there is another one after that. I already ran the requirements.txt Install but there are still all the Modules pip cant install missing. Is there a ways to install all of these at once too, should I do them manually or am I doing it completely wrong?

  73. Juan Pablo Caram repo owner

    Try “python3 flatcam” in Ubuntu. What you are reporting sounds like you are using Python2.7 and we moved to Python 3 many months ago. Please use Ubuntu for developments if possible.

  74. KASA

    Thank you, Ive now got everything setup in Ubuntu. If I want to make changes, should I fork the master branch and then commit to that in my fork and make a pull request if its ready? I dont use Git a lot so im not sure how all of this works.

    I still have the open Pull request from a year ago, can I continue working from there or do I have to make a new fork?

  75. Juan Pablo Caram repo owner

    You can continue to work on the master branch, but I will only pull it in if it is perfectly clean and tested. Alternatively, you can start a new branch just for the postprocessing. In such case I can pull in changes that are not ready for the master.

  76. KASA

    Hm, It looks like the Changes I made last year didnt survive the switch to Python3 or something, I have a Postprocessing branch in my own fork but if i try to run it it fails because there is some print without brackets, it looks like I will have to redo it.

    Also, How exactly is the Options Tab supposed to work? What do the Prepend and Append Text fields do if the corresponding fields are empty when you export a G-Code from a CNC Job Object?

  77. KASA

    I think I figured it out now, can you check here: https://bitbucket.org/JakobStaudt/flatcamnew/src/67f2e02784122e30401a6912ae17ec040d1ce756/?at=feature%2FPostprocessing If I made a mistake?

    I made a new branch and comitted my changes, is that the right way to do it?

    Ive got another question: Is it possible that the “raise StopIteration” Needs to be removed at the end of the dwell_generator in FlatCAMObj.py? I f i export gcode it is always giving me the Stopiteration as an Runtime Error.

  78. KASA

    I have the Processing implemented now and stuff like Removing the leading zeros for G and M Commands (G01 becomes G1 for example) works with this command: “(G|M)0([0-9]) >>> \1\2”

    I think regex is a good way because it is really powerful and can be used for a lot of stuff.

    Would it be a good idea to add some Comment in the G-Code everytime the Laser should be turned on so you could have a simple Rule like “;laserOn >>> M03” to enable the Laser?

    This would allow users to use Whatever G-Code they like for enabling the Laser, no matter how weird their setup is. I, for example Laser with a modified 3D-Printer and Use the Fan Pin for controlling it so I need a different Command than other Users.

    Edit:

    I think the Laser can actually be achieved with the Postprocessing with the Rules

    “G01 Z-.*\n >>> M03\n”, “G01 Z.*\n >>> M05\n” and “G00 Z.*\n >>> M05\n” (In this Order!)

  79. Juan Pablo Caram repo owner

    Do you have a diff, pull request or specific commit? Otherwise, it is hard to figure out what you would like people to look at.

  80. Log in to comment