Re: Tip of the Day 30 - Using 3DTouch, CubeX,CubePro and Rap
Posted: Tue Aug 11, 2015 4:18 pm
Below is a Python script I wrote to go through the gcode generated by S3D and insert a flow control command (M108 Sxx) whenever the feed rate changes. The "FeedFlowRatio" multiplier can be adjusted to get the best result. This script is especially helpful on parts that have some areas that need to be printed more slowly than the rest of the part.
I have glanced at the source code for CubitMod, which is used with KISSlicer, and it's doing more sophisticated post-processing. First, it adjusts both flow rate and feed rate to work around the Cubex firmware's inability to handle fractional flow rates. That could be added to my script. Without it, the roundoff error can be problematic at very low flow rates. As I recall, CubitMod also adjusts prime/suck parameters (M227/M228) based on KISSlicer's heavily commented gcode. Unfortunately, it seems that S3D doesn't generate enough info (in gcode comments) for the post-processor to do that.
I have glanced at the source code for CubitMod, which is used with KISSlicer, and it's doing more sophisticated post-processing. First, it adjusts both flow rate and feed rate to work around the Cubex firmware's inability to handle fractional flow rates. That could be added to my script. Without it, the roundoff error can be problematic at very low flow rates. As I recall, CubitMod also adjusts prime/suck parameters (M227/M228) based on KISSlicer's heavily commented gcode. Unfortunately, it seems that S3D doesn't generate enough info (in gcode comments) for the post-processor to do that.
Code: Select all
#!/usr/bin/env python
"""
Massage gcode generated by Simplify3D for Cubex
s3d2cubex.py <FILE>
v0.1 by Michael Hauser
"""
import os
import re
import sys
import string
FeedFlowRatio = 0.006
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.exit('usage: s3d2cubex.py <filename>')
infilename = sys.argv[1]
outfilename = '{}.flowfix{}'.format(os.path.splitext(infilename)[0],os.path.splitext(infilename)[1])
readFeedRate = False
previousFeedRate = 0.0
with open(infilename) as infile:
with open(outfilename,"w") as outfile:
for line in infile:
code = string.split(line)
if code:
if readFeedRate and code[0]=='G1' and code[-1][0] == 'F':
feedRate = float(code[-1][1:])
if feedRate != previousFeedRate:
previousFeedRate = feedRate
flowRate = feedRate * FeedFlowRatio
outfile.write('M108 S{:.1f}\r\n'.format(flowRate))
readFeedRate = False
if code[0]=='M101':
readFeedRate = True
outfile.write(line)