Gcode questions

Discussions about firmware/slicing software, tweaks and settings
Post Reply
kerog
Posts: 117
Joined: Mon Jun 09, 2014 1:54 am

Gcode questions

Post by kerog »

I've lately been futzing around with the Cura plugin capability. I wanted to do two things:

(1) Allow a switch from one extruder to the other at a certain height, good for two-color JPEG-based signs.

(2) Have a skirt that becomes an enclosing wall. This is easy in Slic3r, KISSlicer, or SFACT, but for some reason not in Cura.

The first one has already been done to some extent, but the plugin that's available doesn't do any of the things you'd expect when switching extruders, so I added that. The weird thing is, the first M104 command (to put the extruder not in use at a rest temperature) seems to be ignored when I run the gcode. Editing the gcode by hand, I have been able to get it to work under some circumstances, but even then I find it sets the temperature *before* performing a move, while the gcode that sets the temperature is clearly located *after* that move. Anyone understand why that happens?

The second one is also strange. In my naivety, I started by copying by hand the ;TYPE:SKIRT section from the first layer to after each ;LAYER comment. This worked fine. Then, when I put that into a plugin, I found that no longer worked: it was ejecting the filament after the first layer. Looking at the Gcode, I saw that the moves were specifying an absolute gcode position, so this made sense. But I couldn't understand why the earlier manual copy/paste had worked. Gcode enclosed.

I'd appreciate it if someone who understands Gcode better than me could explain what's going on.

Can't seem to upload the plugin code, as the extensions are being rejected. Tried .py, .txt, and no extension.
Attachments
ArrowheadSwitchOnly.gcode
This one the switch works, but the initial temp setting is ignored
(778.58 KiB) Downloaded 39 times
ArrowheadBoth.gcode
This has both plugins, skirt copy causes filament ejection
(786.68 KiB) Downloaded 38 times
SevenMarkers.gcode
This one has multi-layer skirt code that shouldn't work, but does, and hand-edited extruder switch
(2.47 MiB) Downloaded 40 times

User avatar
DDME-Marc
Posts: 71
Joined: Sun Nov 24, 2013 11:04 pm
Location: New Zealand

Post by DDME-Marc »

Hi Kerog,

Although you set the target temperature for T1 at the program start via M104, there is no set temperature value for T0? Possibly without a set value it looks to the last assigned temperature in memory?

I would suggest setting specific extruder target temperature (M104) every time you call a new tool, and if preferred complete with a wait command (M109) until the temperature is reached.
Temp set start.jpg
Temp set change over.jpg
Cheers,

Marc
Felix 3.0 Dual Head * E3D Titan V6 * Repetier-Host V2.1.3 * Repetier-Firmware 0.92.9 (01/08/17 - Modified) * KISSlicer Pro - 1.6.3 * Arduino 1.8.5 *

User avatar
DDME-Marc
Posts: 71
Joined: Sun Nov 24, 2013 11:04 pm
Location: New Zealand

Post by DDME-Marc »

Hi Kerog,

In terms of your inserted blocks you have omitted to adjust the filament length via the G92 command.

Try adding the command above and below the inserted block, as this will synchronise the filament to each program section accordingly (see attached)
Filament callibration .jpg
Just don't forget to compensate for any additional retract or prime that may also be active with the current E value

Cheers,

Marc
Felix 3.0 Dual Head * E3D Titan V6 * Repetier-Host V2.1.3 * Repetier-Firmware 0.92.9 (01/08/17 - Modified) * KISSlicer Pro - 1.6.3 * Arduino 1.8.5 *

kerog
Posts: 117
Joined: Mon Jun 09, 2014 1:54 am

Post by kerog »

Yes, that's great. For some reason I had forgotten that you could set anything besides zero with the G92 command. :-)

That fixed the skirt plugin.

I don't understand your other reply, though. If you were going to do a M109, why would you do M104 first? M109 both changes the set point and waits.

When I'm changing to the rest temperature, I don't really want to wait.
Tried a few more things on this front, and was still getting ignored switches.

Here are my revised plugins as text:

#Name: Use skirt on every layer
#Info: Use this plugin before others
#Depend: GCode
#Type: postprocess


import re

def getValue(line, key, default = None):
if not key in line or (';' in line and line.find(key) > line.find(';')):
return default
subPart = line[line.find(key) + 1:]
m = re.search('^[0-9]+\.?[0-9]*', subPart)
if m is None:
return default
try:
return float(m.group(0))
except:
return default

"""
filename= "Cone.gcode"
firstHeight = 2
changeHeight = 4
firstExtruder = 0
secondExtruder = 1
"""

with open(filename, "r") as f:
lines = f.readlines()

skirtCode = []
newLayer = int(0)
oldLayer = int(0)

"""
filename= "Cone.gcode.txt"
"""

E = 0

with open(filename, "w") as f:
for line in lines:
if line.startswith(';'):
if line.startswith(';LAYER:'):
newLayer = int(line[7:].strip())
if line.startswith(';TYPE:'):
currentSectionType = line[6:].strip()
if currentSectionType == 'SKIRT':
skirtCode.append(line)
if newLayer <> oldLayer:
oldLayer = newLayer
f.write("G92 E0\n");
for skirtLine in skirtCode:
f.write(skirtLine)
f.write("G92 E" + str(E) + "\n");
f.write(line)
continue
else:
myValue = getValue(line, 'G', None)
if myValue != None:
E = getValue(line, 'E', E)
if currentSectionType == 'SKIRT':
skirtCode.append(line)

f.write(line)

Now 2nd:

#Name: Switch extruder at height with ooze prevention
#Info: Switch the extruder at a certain heights
#Depend: GCode
#Type: postprocess
#Param: firstHeight(float:2.01) First change height (mm)
#Param: changeHeight(float:4) After that, change height at x (mm)
#Param: firstExtruder(int:0) First extruder number
#Param: secondExtruder(int:1) Second extruder number
#Param: restTemperature(int:160) Temperature for extruder not in use (prevent ooze)
#Param: baseTemperature(int:200) Operating temperature
#Param: retraction(float:1.5) Retraction when switching extruders


import re

def getValue(line, key, default = None):
if not key in line or (';' in line and line.find(key) > line.find(';')):
return default
subPart = line[line.find(key) + 1:]
m = re.search('^[0-9]+\.?[0-9]*', subPart)
if m is None:
return default
try:
return float(m.group(0))
except:
return default

"""
filename= "Cone.gcode"
firstHeight = 2
changeHeight = 4
firstExtruder = 0
secondExtruder = 1
"""

with open(filename, "r") as f:
lines = f.readlines()

z = 0
changeState = 0
modExtruder = 0
currentExtruder = -1
currentSectionType = ""
myValue = None

"""
filename= "Cone.gcode.txt"
"""

with open(filename, "w") as f:
for line in lines:
if line.startswith(';'):
if line.startswith(';TYPE:'):
currentSectionType = line[6:].strip()
f.write(line)
continue
myValue = getValue(line, 'G', None)
if myValue != None:
newZ = getValue(line, 'Z', z)
if newZ != z and currentSectionType != 'CUSTOM':
z = newZ
if z < firstHeight:
modExtruder = firstExtruder
elif z < firstHeight+changeHeight:
modExtruder = secondExtruder
else:
modExtruder = int((z-firstHeight) / changeHeight) % 2
if currentExtruder == -1 :
f.write(";TYPE:CUSTOM\n")
f.write(";ModExtruder="+ str(modExtruder)+ " \n")
f.write(";M117 Starting with Extruder #" + str(firstExtruder) + "\n")
f.write("T" + str(secondExtruder) + "\n")
f.write("M109 S" + str(int(restTemperature)+20) + "\n")
f.write("M104 S" + str(restTemperature) + "\n")
f.write("G1 E-" + str(retraction) +" F3000 ; Retract a bit\n")
f.write("T" + str(firstExtruder) + "\n")
f.write("M109 S" + str(baseTemperature) + "\n")
currentExtruder = firstExtruder
elif (int(modExtruder)<>int(currentExtruder)) and (modExtruder == 1) :
f.write(";TYPE:CUSTOM\n")
f.write(";M117 Changing to Extruder #" + str(firstExtruder) + "\n")
f.write("G1 E-" + str(retraction) +" F3000 ; Retract a bit\n")
f.write("G0 X0 Y0 F9000 ; Go to 0,0 and wait\n")
f.write("M109 S" + str(int(restTemperature)+20) + "\n")
f.write("M104 S" + str(restTemperature) + "\n")
f.write("T" + str(firstExtruder) + "\n")
f.write("M109 S" + str(baseTemperature) + "\n")
currentExtruder = firstExtruder
elif (int(modExtruder)<>int(currentExtruder)) :
f.write(";TYPE:CUSTOM\n")
f.write(";M117 Changing to Extruder #" + str(secondExtruder) + "\n")
f.write("G1 E-" + str(retraction) +" F3000 ; Retract a bit\n")
f.write("G0 X0 Y0 F9000 ; Go to 0,0 and wait\n")
f.write("M109 S" + str(int(restTemperature)+20) + "\n")
f.write("M104 S" + str(restTemperature) + "\n")
f.write("T" + str(secondExtruder) + "\n")
f.write("M109 S" + str(baseTemperature) + "\n")
currentExtruder = secondExtruder
f.write(line)

User avatar
DDME-Marc
Posts: 71
Joined: Sun Nov 24, 2013 11:04 pm
Location: New Zealand

Post by DDME-Marc »

Hi Kerog,

In some respects you have answered your own question with regards to the M104 versus the M109.

If you do not wish to wait for the retired extruder to achieve the rest temperature then only use the M104 command. This way you can set the rest temperature prior to switching to the next extruder to be called in the program. The retired extruder will continue to cool to the rest temp target whilst your program continues.

The new extruder should be set using the M109 Snnn command to initiate the pause until 'nnn' print temperature is achieved.

Cheers,
Felix 3.0 Dual Head * E3D Titan V6 * Repetier-Host V2.1.3 * Repetier-Firmware 0.92.9 (01/08/17 - Modified) * KISSlicer Pro - 1.6.3 * Arduino 1.8.5 *

Post Reply