COMPLETE GCode post processing with Perl

Discussion in 'Guides, Mods, and Upgrades' started by Steven, Jul 20, 2016.

  1. Steven

    Steven Well-Known Member

    Joined:
    Sep 4, 2015
    Messages:
    185
    Likes Received:
    19
  2. Alex9779

    Alex9779 Moderator
    Staff Member

    Joined:
    Sep 4, 2015
    Messages:
    2,405
    Likes Received:
    731
    Some crazy shit :D

    I thought about doing post-processing to implement functionality the slicer has no feature for.
    For example I like the "Avoid crossing outlines for travel moves" but unfortunately this does the travel moves on already existing outer most perimeter lines and depending on material this has sometimes negative effects. So in this case I was thinking about pushing the travel moves over infilled areas or at least a little more "into" the part so the outer appearance is not influenced.

    I might have a look into this... Thanks for sharing!
     
  3. Stefan

    Stefan Well-Known Member

    Joined:
    Feb 17, 2016
    Messages:
    323
    Likes Received:
    43
    ok so this is can be used for automating stuff like temperature calibration cube thing... where every 10 mm the print is paused until the new temp is reached and print continues... maybe add g-code to make a mark there.....
    but pearl... I do not want to learn a new lang for one task... I know I'm lazy :p

    But should work with any other language too except the slicer integration... and I now use S3D... ahahahah all those options :)
     
  4. Alex9779

    Alex9779 Moderator
    Staff Member

    Joined:
    Sep 4, 2015
    Messages:
    2,405
    Likes Received:
    731
    You can do this with S3D too... IN the Scripts tab you can add post-processing, S3D support own, we do this to add the layer message to the LCD for the BB but you can call any executable from there. Point to the input field, there is a help text, you can use two variable for the output path and the output filename to pass them to your executable which can be anything, a beach file calling something else, the perl interpreter so execute a perl script, or PHP if you wanna write something in PHP...
     
  5. Stefan

    Stefan Well-Known Member

    Joined:
    Feb 17, 2016
    Messages:
    323
    Likes Received:
    43
    Ah thx.. I think I saw this scripts tab but not thought of using it until to day :)
    btw I'm into python right now and I tried a little with slic3r and python a while back but it did not work... but was a hard try.
     
  6. tohara

    tohara Well-Known Member

    Joined:
    Sep 5, 2015
    Messages:
    128
    Likes Received:
    59
    It just tested post script in S3D using python to add the LCD message for layers.
    I have got the below code working.

    Command in S3D script tab:
    Code:
    python "D:\3d Projects\S3DPost\postScriptTest.py" "[output_filepath]"
    Python code:
    Code:
    import sys
    
    f = open(sys.argv[1], mode='r')
    orgG = f.readlines()
    f.close()
    
    newG = []
    for line in orgG:
        #modify each line here before writing back to new gCode list
      
        newG.append(line.replace('; layer', 'M117 Layer').replace(' Z = ', ' Z='))
      
    
    f = open(sys.argv[1], mode='w')
    
    f.writelines(newG)
    f.write(';Modified by postScript!\n')
    f.flush()
    f.close()
     
    Stefan likes this.
  7. Alex9779

    Alex9779 Moderator
    Staff Member

    Joined:
    Sep 4, 2015
    Messages:
    2,405
    Likes Received:
    731
    @tohara is this just to prove it works? Because in the default profiles this is included with just two lines because some simple things can be done with the syntax built into S3D:
    Code:
    {REPLACE "; layer" "M117 Layer"}
    {REPLACE " Z = " " Z="}
    I would be interested in an improved version of https://github.com/manticorp/GCodeArcOptimiser
    I tried it but the results were not as expected, seems it has to be tweaked for every slicer output...
     
  8. tohara

    tohara Well-Known Member

    Joined:
    Sep 5, 2015
    Messages:
    128
    Likes Received:
    59
    It was just to get a working template for further experimenting and I didn't come up with any better idea than to replicate the default profile function. :)
     
  9. Alex9779

    Alex9779 Moderator
    Staff Member

    Joined:
    Sep 4, 2015
    Messages:
    2,405
    Likes Received:
    731
    Ahhh yeah, thats what I thought but I had to ask :D
     
  10. Alex9779

    Alex9779 Moderator
    Staff Member

    Joined:
    Sep 4, 2015
    Messages:
    2,405
    Likes Received:
    731
  11. tohara

    tohara Well-Known Member

    Joined:
    Sep 5, 2015
    Messages:
    128
    Likes Received:
    59
    Ahhh, no I did not see the link to github, only the code posted in the blog.
     
  12. Alex9779

    Alex9779 Moderator
    Staff Member

    Joined:
    Sep 4, 2015
    Messages:
    2,405
    Likes Received:
    731
    With that you can just focus on what you wanna do with what lines... The rest is already there... Pretty cool, maybe some changes are needed to work with S3D but I didn't check that...
     
  13. tohara

    tohara Well-Known Member

    Joined:
    Sep 5, 2015
    Messages:
    128
    Likes Received:
    59
    What would we gain from this, other than a smaller gcode file?
    I thought we would be able to run circular movements with higher speed since there is less lines to process, but when i tested G2/G3 commands from a terminal by running a full circle with r=20mm the rumba seems to go into a limit and I get stuttering movements above 3-4000mm/min.

    I made a small test for detecting circles using NumPy and SciPy, but as he also mentioned in the link you posted, it gets very slow if you want high accuracy.
     
  14. mike01hu

    mike01hu Well-Known Member

    Joined:
    Apr 22, 2014
    Messages:
    957
    Likes Received:
    166
    As with all arcs, they are still produced as a defined series of straight lines, either by gcode from the slicer or from a firmware algorithm but in the latter there is a hit on processor time as it has to calculate the moves first then execute them.
     
  15. Alex9779

    Alex9779 Moderator
    Staff Member

    Joined:
    Sep 4, 2015
    Messages:
    2,405
    Likes Received:
    731
    @tohara That was meant regarding the serial connection getting saturated by a lot of commands on circles or arcs. Using G2/G3 is only one command.
    You're right, if the processor is then not able to process the moves the firmware generates itself it won't help much...
     

Share This Page