Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Program Event or Function Call for 3D Printing Extruder Control

#9
(02-14-2020, 02:37 PM)JFCh Wrote:Hi Albert. I am using an Arduino controler with the Marlin Firmware to drive the extruder. I would like to interpret the RoboDK's Extruder(x.xxx) function to send my own G-code to the Marlin Firmware.

Hi JF,

sorry about not replying sooner. To be fair I was printing. My extruder is controlled by a duet2 so it can recieve gcode through http get requests. that makes it pretty straight forward. You can adapt the speed using a pre-processor to insert a function call after each robot speed change, then calling a funtion that works the same as the extruder call but transforms the mm/s from robodk to the mm/min in gcode and corrects for the crosssection of the extruded line compared to your filament crosssection.
Below you'll find the code, you'll have to use the ip's of your respective boards.

Extruder
Code:
e_value = None
from robolink import * #nur fuer Nutzung in RoboDK
RDK = Robolink()
#检查如果我们运行this program inside another program and passing arguments
import sys
if len(sys.argv) > 1:
e_value = float(sys.argv[1])
code = 'G1 E' + str(e_value)
#print(message) #for test purposes
RDK.ShowMessage(code, popup=False) # for test purpose set to True for popup, set to false or comment out for use to avoid blocking
if RDK.RunMode() == RUNMODE_SIMULATE:
quit()

import requests
params = {"gcode": code }
r = requests.get("http://192.168.2.114/rr_status?type=1")

# print(r.json()) # for test purpose
r = requests.get("http://192.168.2.114/rr_gcode", params=params) # this works!
# r = requests.get("http://192.168.0.100/rr_gcode?gcode=G1 Z100") # this works!
#print(r.json())
Speed
Code:
f_value = None
from robolink import * #nur fuer Nutzung in RoboDK
RDK = Robolink()
#检查如果我们运行this program inside another program and passing arguments
import sys
if len(sys.argv) > 1:
e_value = float(sys.argv[1])
f_transform=f_value * 60 * 1.5676 # mm/s in mm/min und adaptation for line crossection Q to fed filament Q/pi*(2.85/2)²
code = 'G1 F' + str(f_transform)
#print(message) #for test purposes
RDK.ShowMessage(code, popup=False) # for test purpose set to True for popup, set to false or comment out for use to avoid blocking
if RDK.RunMode() == RUNMODE_SIMULATE:
quit()

import requests
params = {"gcode": code }
r = requests.get("http://192.168.2.114/rr_status?type=1")

#print(r.json()) # for test purpose
r = requests.get("http://192.168.2.114/rr_gcode", params=params) # this works!
# r = requests.get("http://192.168.0.100/rr_gcode?gcode=G1 Z100") # this also works!
#print(r.json())

Pre-Processor:
Code:
from robolink import * # API to communicate with RoboDK
from robodk import * # basic matrix operations
RDK = Robolink()

# Ask the user to select a program:
prog = RDK.ItemUserPick("Select a Program to modify", ITEM_TYPE_PROGRAM)
if not prog.Valid():
print("Operation cancelled or no programs available")
quit()

# Ask the user to enter a function call that will be added after each movement:
print("Program selected: " + prog.Name())
ins_call = 'SetExtSpeed'
#mbox("Enter a program call to add after each movement", entry="SynchRobot")
if not ins_call:
print("Operation cancelled")
quit()

# Iterate through all the instructions in a program:
ins_id = 0
ins_count = prog.InstructionCount()
while ins_id < ins_count:
# Retrieve instruction
ins_nom, ins_type, move_type, isjointtarget, pose, joints = prog.Instruction(ins_id)
if ins_type == INS_TYPE_CHANGESPEED:
# Select the movement instruction as a reference
prog.InstructionSelect(ins_id)
value = prog.Instruction(ins_id)
name = value[0]
import re
matches = re.findall("[+-]?\d+\.\d+", name)

# Add a new program call
prog.RunInstruction(ins_call + '(' + matches[0] + ')', INSTRUCTION_CALL_PROGRAM)

# Advance one additional instruction as we just added another instruction
ins_id = ins_id + 1
ins_count = ins_count + 1

ins_id = ins_id + 1


Messages In This Thread
RE: Program Event or Function Call for 3D Printing Extruder Control - byPatrickC- 06-18-2020, 12:50 PM



Users browsing this thread:
1 Guest(s)