Example #1
0
def change_epilog(self, **words):
    try:
        if not self.value_returned:
            r = self.blocks[self.remap_level].executing_remap
            self.set_errormsg("the %s remap procedure %s did not return a value"
                             % (r.name,r.remap_ngc if r.remap_ngc else r.remap_py))
            yield INTERP_ERROR
        # this is relevant only when using iocontrol-v2.
        if self.params[5600] > 0.0:
            if self.params[5601] < 0.0:
                self.set_errormsg("Toolchanger hard fault %d" % (int(self.params[5601])))
                yield INTERP_ERROR
            print("change_epilog: Toolchanger soft fault %d" % int(self.params[5601]))

        if self.blocks[self.remap_level].builtin_used:
            #print "---------- M6 builtin recursion, nothing to do"
            yield INTERP_OK
        else:
            if self.return_value > 0.0:
                # commit change
                self.selected_pocket =  int(self.params["selected_pocket"])
                emccanon.CHANGE_TOOL(self.selected_pocket)
                self.current_pocket = self.selected_pocket
                self.selected_pocket = -1
                self.selected_tool = -1
                # cause a sync()
                self.set_tool_parameters()
                self.toolchange_flag = True
                yield INTERP_EXECUTE_FINISH
            else:
                self.set_errormsg("M6 aborted (return code %.1f)" % (self.return_value))
                yield INTERP_ERROR
    except Exception as e:
        self.set_errormsg("M6/change_epilog: %s" % (e))
        yield INTERP_ERROR
Example #2
0
def change_epilog(self, userdata,**words):
	retval = self.return_value
	print "change_epilog retval=% selected_pocket=%d" %(retval,self.selected_pocket)
	if retval > 0:
		# commit change
		#emccanon.CHANGE_TOOL(self.selected_pocket)
		emccanon.CHANGE_TOOL(self.selected_tool)
		self.current_pocket = self.selected_pocket
		# cause a sync()
		self.tool_change_flag = True
		self.set_tool_parameters()
		return INTERP_OK
	else:
		self.set_errormsg("M6 aborted (return code %.4f)" % (retval))
		return INTERP_ERROR
def change_epilog(self, **words):
    try:
        #print("Change epilog executing....")
        if self.return_value > 0.0:
            print("pass return value")
            self.selected_pocket = int(self.params["selected_pocket"])
            print("before emccannon CHANGE TOOL")
            emccanon.CHANGE_TOOL(self.selected_pocket)
            print("emccannon CHANGE TOOL sent")
            self.current_pocket = self.selected_pocket
            self.selected_pocket = -1
            self.selected_tool = -1
            # cause a sync()
            print("Lets Sync this Bitch, NOW")
            self.set_tool_parameters()
            self.toolchange_flag = True
            yield INTERP_EXECUTE_FINISH
        else:
            self.set_errormsg("M6 aborted (return code %.1f)" %
                              (self.return_value))
            return
    except Exception, e:
        self.set_errormsg("M6/change_epilog: %s" % (e))
        return
Example #4
0
def tool_probe_m6(self, **words):

    # only run this if we are really moving the machine
    # skip this if running task for the screen
    if not self.task:
        yield INTERP_OK

    IMPERIAL_BASED = not (bool(self.params['_metric_machine']))

    try:
        # we need to be in machine based units
        # if we aren't - switch
        # remember so we can switch back later
        switchUnitsFlag = False
        if bool(self.params["_imperial"]) != IMPERIAL_BASED:
            print("not right Units: {}".format(bool(self.params["_imperial"])))
            if IMPERIAL_BASED:
                print("switched Units to imperial")
                self.execute("G20")
            else:
                print("switched Units to metric")
                self.execute("G21")
            switchUnitsFlag = True

        self.params["tool_in_spindle"] = self.current_tool
        self.params["selected_tool"] = self.selected_tool
        self.params["current_pocket"] = self.current_pocket
        self.params["selected_pocket"] = self.selected_pocket

        # cancel tool offset
        self.execute("G49")

        # change tool where ever we are
        # user sets toolchange position prior to toolchange
        # we will return here after

        try:
            self.selected_pocket = int(self.params["selected_pocket"])
            emccanon.CHANGE_TOOL(self.selected_pocket)
            self.current_pocket = self.selected_pocket
            self.selected_pocket = -1
            self.selected_tool = -1
            # cause a sync()
            self.set_tool_parameters()
            self.toolchange_flag = True
        except InterpreterException as e:
            self.set_errormsg("tool_probe_m6 remap error: %s" % (e))
            yield INTERP_ERROR

        yield INTERP_EXECUTE_FINISH

        # record current position; probably should record every axis
        self.params[4990] = emccanon.GET_EXTERNAL_POSITION_X()
        self.params[4998] = emccanon.GET_EXTERNAL_POSITION_Y()
        self.params[4997] = emccanon.GET_EXTERNAL_POSITION_Z()

        try:
            # move to tool probe position (from INI)
            self.execute("G90")
            self.execute(
                "G53 G0 X[#<_ini[TOOLSENSOR]X>] Y[#<_ini[TOOLSENSOR]Y>]")
            self.execute("G53 G0 Z[#<_ini[TOOLSENSOR]Z>]")

            # set incremental mode
            self.execute("G91")

            # course probe
            self.execute("F [#<_ini[TOOLSENSOR]SEARCH_VEL>]")
            self.execute("G38.2 Z [#<_ini[TOOLSENSOR]MAXPROBE>]")

            # Wait for results
            yield INTERP_EXECUTE_FINISH

            # FIXME if there is an error it never comes back
            # which leaves linuxcnc in g91 state
            if self.params[5070] == 0 or self.return_value > 0.0:
                self.execute("G90")
                self.set_errormsg("tool_probe_m6 remap error:")
                yield INTERP_ERROR

            # rapid up off trigger point to do it again
            if bool(self.params["_imperial"]):
                f = 0.25
            else:
                f = 4.0
            self.execute("G0 Z{}".format(f))

            self.execute("F [#<_ini[TOOLSENSOR]PROBE_VEL>]")
            self.execute("G38.2 Z-0.5")
            yield INTERP_EXECUTE_FINISH

            # FIXME if there is an error it never comes back
            # which leaves linuxcnc in g91 state
            if self.params[5070] == 0 or self.return_value > 0.0:
                self.execute("G90")
                self.set_errormsg("tool_probe_m6 remap error:")
                yield INTERP_ERROR

            # set back absolute state
            self.execute("G90")

            # return to recorded tool change position
            self.execute("G53 G0 Z[#4997]")
            yield INTERP_EXECUTE_FINISH
            self.execute("G53 G0 X[#4999] Y[#4998]")

            # adjust tool offset from calculations
            proberesult = self.params[5063]
            probeheight = self.params["_ini[TOOLSENSOR]PROBEHEIGHT"]
            workheight = self.params[5000]

            adj = proberesult - probeheight + workheight
            self.execute("G10 L1 P#<selected_tool> Z{}".format(adj))

            # apply tool offset
            self.execute("G43")

            # if we switched units for tool change - switch back
            if switchUnitsFlag:
                if IMPERIAL_BASED:
                    self.execute("G21")
                    print("switched Units back to metric")
                else:
                    self.execute("G20")
                    print("switched Units back to imperial")

        except InterpreterException as e:
            msg = "%d: '%s' - %s" % (e.line_number, e.line_text,
                                     e.error_message)
            print(msg)
            yield INTERP_ERROR

    except:
        self.set_errormsg("tool_probe_m6 remap error.")
        yield INTERP_ERROR
Example #5
0
def index_lathe_tool_with_wear(self, **words):
    # only run this if we are really moving the machine
    # skip this if running task for the screen
    if not self.task:
        yield INTERP_OK
    try:
        # check there is a tool number from the Gcode
        cblock = self.blocks[self.remap_level]
        if not cblock.t_flag:
            self.set_errormsg("T requires a tool number")
            yield INTERP_ERROR
        tool_raw = int(cblock.t_number)

        # interpet the raw tool number into tool and wear number
        # If it's less then 100 someone forgot to add the wear #, so we added it automatically
        # separate out tool number (tool) and wear number (wear), add 10000 to wear number
        if tool_raw < 100:
            tool_raw = tool_raw * 100
        tool = int(tool_raw / 100)
        wear = 10000 + tool_raw % 100

        # uncomment for debugging
        #print'***tool#',cblock.t_number,'toolraw:',tool_raw,'tool split:',tool,'wear split',wear
        if tool:
            # check for tool number entry in tool file
            (status, pocket) = self.find_tool_pocket(tool)
            if status != INTERP_OK:
                self.set_errormsg("T%d: tool entry not found" % (tool))
                yield status
        else:
            tool = -1
            pocket = -1
            wear = -1
        self.params["tool"] = tool
        self.params["pocket"] = pocket
        self.params["wear"] = wear
        try:
            self.hal_tool_comp['tool'] = tool_raw
            self.hal_tool_comp['wear'] = wear
        except:
            pass
        # index tool immediately to tool number
        self.selected_tool = int(self.params["tool"])
        self.selected_pocket = int(self.params["pocket"])
        emccanon.SELECT_TOOL(self.selected_tool)
        if self.selected_pocket < 0:
            self.set_errormsg("T0 not valid")
            yield INTERP_ERROR
        if self.cutter_comp_side:
            self.set_errormsg(
                "Cannot change tools with cutter radius compensation on")
            yield INTERP_ERROR
        self.params["tool_in_spindle"] = self.current_tool
        self.params["selected_tool"] = self.selected_tool
        self.params["current_pocket"] = self.current_pocket
        self.params["selected_pocket"] = self.selected_pocket

        # change tool
        try:
            self.selected_pocket = int(self.params["selected_pocket"])
            emccanon.CHANGE_TOOL(self.selected_pocket)
            self.current_pocket = self.selected_pocket
            self.selected_pocket = -1
            self.selected_tool = -1
            # cause a sync()
            self.set_tool_parameters()
            self.toolchange_flag = True
        except:
            self.set_errormsg("T change aborted (return code %.1f)" %
                              (self.return_value))
            yield INTERP_ERROR

        # add tool offset
        self.execute("g43 h%d" % tool)
        # if the wear offset is specified, add it's offset
        try:
            if wear > 10000:
                self.execute("g43.2 h%d" % wear)
            yield INTERP_OK
        except:
            self.set_errormsg(
                "Tool change aborted - No wear %d entry found in tool table" %
                wear)
            yield INTERP_ERROR
    except:
        self.set_errormsg("Tool change aborted (return code %.1f)" %
                          (self.return_value))
        yield INTERP_ERROR
        # all fine, return ok !
        #-----------------------
        # This is the change_epilog within remap body
        print 'Final!'
        print("Self return value = %s" % self.return_value)
        print 'calling epilog'
        print 'Returned form epilog journey'
        print("Current pocket = %s" % self.current_pocket)
        print("Selected pocket = %s" % self.selected_pocket)
        print("Param.Selected pocket = %s" %
              int(self.params["selected_pocket"]))
        print("Current tool in spindle = %s" % self.current_tool)
        print("Selected tool = %s" % self.selected_tool)
        self.selected_pocket = int(self.params["selected_pocket"])
        print("before emccannon CHANGE TOOL")
        emccanon.CHANGE_TOOL(self.selected_pocket)
        print("emccannon CHANGE TOOL sent")
        self.current_pocket = self.selected_pocket
        #self.selected_pocket = -1
        #self.selected_tool = -1
        # cause a sync()
        print("Lets Sync this Bitch, NOW")
        self.set_tool_parameters()
        self.toolchange_flag = True

    return INTERP_OK


#----------------------------------------------------------
#----------------------------------------------------------
def change_prolog1(self, **words):