stepconf.py

来自「CNC 的开放码,EMC2 V2.2.8版」· Python 代码 · 共 1,576 行 · 第 1/4 页

PY
1,576
字号
	    print >>file, "AXES = 4"	    print >>file, "COORDINATES = X Y Z A"	    print >>file, "MAX_ANGULAR_VELOCITY = %.2f" % self.amaxvel	    defvel = min(60, self.amaxvel/10.)	    print >>file, "DEFAULT_ANGULAR_VELOCITY = %.2f" % defvel	elif self.axes == 0:	    print >>file, "AXES = 3"	    print >>file, "COORDINATES = X Y Z"	else:	    print >>file, "AXES = 3"	    print >>file, "COORDINATES = X Z"	if self.units:	    print >>file, "LINEAR_UNITS = mm"	else:	    print >>file, "LINEAR_UNITS = inch"        print >>file, "ANGULAR_UNITS = degree"	print >>file, "CYCLE_TIME = 0.010"	maxvel = max(self.xmaxvel, self.ymaxvel, self.zmaxvel)		hypotvel = (self.xmaxvel**2 + self.ymaxvel**2 + self.zmaxvel**2) **.5	defvel = min(maxvel, max(.1, maxvel/10.))	print >>file, "DEFAULT_VELOCITY = %.2f" % defvel	print >>file, "MAX_LINEAR_VELOCITY = %.2f" % maxvel	print >>file	print >>file, "[EMCIO]"	print >>file, "EMCIO = io"	print >>file, "CYCLE_TIME = 0.100"	print >>file, "TOOL_TABLE = tool.tbl"        all_homes = self.home_sig(0) and self.home_sig(2)        if self.axes != 2: all_homes = all_homes and self.home_sig(1)        if self.axes == 4: all_homes = all_homes and self.home_sig(3)	self.write_one_axis(file, 0, "x", "LINEAR", all_homes)	if self.axes != 2:	    self.write_one_axis(file, 1, "y", "LINEAR", all_homes)	self.write_one_axis(file, 2, "z", "LINEAR", all_homes)	if self.axes == 1:	    self.write_one_axis(file, 3, "a", "ANGULAR", all_homes)	file.close()	self.add_md5sum(filename)    def hz(self, axname):        steprev = getattr(self, axname+"steprev")        microstep = getattr(self, axname+"microstep")        pulleynum = getattr(self, axname+"pulleynum")        pulleyden = getattr(self, axname+"pulleyden")        leadscrew = getattr(self, axname+"leadscrew")        maxvel = getattr(self, axname+"maxvel")        if self.units or axname == 'a': leadscrew = 1./leadscrew        pps = leadscrew * steprev * microstep * (pulleynum/pulleyden) * maxvel        return abs(pps)    def minperiod(self):        return self.latency + self.steptime + self.stepspace + 5000    def maxhz(self):        return 1e9 / self.minperiod()    def ideal_period(self):        xhz = self.hz('x')        yhz = self.hz('y')        zhz = self.hz('z')        ahz = self.hz('a')	if self.axes == 1:            pps = max(xhz, yhz, zhz, ahz)        elif self.axes == 0:            pps = max(xhz, yhz, zhz)        else:            pps = max(xhz, zhz)	base_period = 1e9 / pps	if base_period > 100000: base_period = 100000        if base_period < self.minperiod(): base_period = self.minperiod()        return int(base_period)    def write_one_axis(self, file, num, letter, type, all_homes):	order = "1203"	def get(s): return self[letter + s]        scale = get("scale")        vel = min(get("maxvel"), abs(.95 * 1e9 / self.ideal_period() / scale))	print >>file	print >>file, "[AXIS_%d]" % num	print >>file, "TYPE = %s" % type	print >>file, "HOME = %s" % get("homepos")	print >>file, "MAX_VELOCITY = %s" % vel	print >>file, "MAX_ACCELERATION = %s" % get("maxacc")	print >>file, "STEPGEN_MAXACCEL = %s" % (1.25 * get("maxacc"))	print >>file, "SCALE = %s" % scale	if num == 3:	    print >>file, "FERROR = 1"	    print >>file, "MIN_FERROR = .25"	elif self.units:	    print >>file, "FERROR = 1"	    print >>file, "MIN_FERROR = .25"	else:	    print >>file, "FERROR = 0.05"	    print >>file, "MIN_FERROR = 0.01"	# emc2 doesn't like having home right on an end of travel,	# so extend the travel limit by up to .01in or .1mm	minlim = get("minlim")	maxlim = get("maxlim")	home = get("homepos")	if self.units: extend = .001	else: extend = .01	minlim = min(minlim, home - extend)	maxlim = max(maxlim, home + extend)	print >>file, "MIN_LIMIT = %s" % minlim	print >>file, "MAX_LIMIT = %s" % maxlim	inputs = set((self.pin10,self.pin11,self.pin12,self.pin13,self.pin15))	thisaxishome = set((ALL_HOME, HOME_X + num, MIN_HOME_X + num,			    MAX_HOME_X + num, BOTH_HOME_X + num))	ignore = set((MIN_HOME_X + num, MAX_HOME_X + num, BOTH_HOME_X + num))	homes = bool(inputs & thisaxishome)    	if homes:	    print >>file, "HOME_OFFSET = %f" % get("homesw")	    print >>file, "HOME_SEARCH_VEL = %f" % get("homevel")	    latchvel = get("homevel") / abs(get("homevel"))	    if get("latchdir"): latchvel = -latchvel	    # set latch velocity to one step every two servo periods	    # to ensure that we can capture the position to within one step	    latchvel = latchvel * 500 / get("scale")	    # don't do the latch move faster than the search move	    if abs(latchvel) > abs(get("homevel")):		latchvel = latchvel * (abs(get("homevel"))/abs(latchvel))	    print >>file, "HOME_LATCH_VEL = %f" % latchvel	    if inputs & ignore:		print >>file, "HOME_IGNORE_LIMITS = YES"            if all_homes:                print >>file, "HOME_SEQUENCE = %s" % order[num]	else:	    print >>file, "HOME_OFFSET = %s" % get("homepos")    def home_sig(self, axnum):	inputs = set((self.pin10,self.pin11,self.pin12,self.pin13,self.pin15))	thisaxishome = set((ALL_HOME, HOME_X + axnum, MIN_HOME_X + axnum,			    MAX_HOME_X + axnum, BOTH_HOME_X + axnum))	for i in inputs:	    if i in thisaxishome: return hal_input_names[i]    def min_lim_sig(self, axnum):   	inputs = set((self.pin10,self.pin11,self.pin12,self.pin13,self.pin15))	thisaxishome = set((ALL_LIMIT, MIN_X + axnum, MIN_HOME_X + axnum,			    BOTH_X + axnum, BOTH_HOME_X + axnum))	for i in inputs:	    if i in thisaxishome: return hal_input_names[i]    def max_lim_sig(self, axnum):   	inputs = set((self.pin10,self.pin11,self.pin12,self.pin13,self.pin15))	thisaxishome = set((ALL_LIMIT, MAX_X + axnum, MAX_HOME_X + axnum,			    BOTH_X + axnum, BOTH_HOME_X + axnum))	for i in inputs:	    if i in thisaxishome: return hal_input_names[i]     def connect_axis(self, file, num, let):	axnum = "xyza".index(let)        lat = self.latency	print >>file	print >>file, "setp stepgen.%d.position-scale [AXIS_%d]SCALE" % (num, axnum)	print >>file, "setp stepgen.%d.steplen 1" % num	print >>file, "setp stepgen.%d.stepspace 0" % num	print >>file, "setp stepgen.%d.dirhold %d" % (num, self.dirhold + lat)	print >>file, "setp stepgen.%d.dirsetup %d" % (num, self.dirsetup + lat)	print >>file, "setp stepgen.%d.maxaccel [AXIS_%d]STEPGEN_MAXACCEL" % (num, axnum)	print >>file, "net %spos-cmd axis.%d.motor-pos-cmd => stepgen.%d.position-cmd" % (let, axnum, num)	print >>file, "net %spos-fb stepgen.%d.position-fb => axis.%d.motor-pos-fb" % (let, num, axnum)	print >>file, "net %sstep <= stepgen.%d.step" % (let, num)	print >>file, "net %sdir <= stepgen.%d.dir" % (let, num)	print >>file, "net %senable axis.%d.amp-enable-out => stepgen.%d.enable" % (let, axnum, num)	homesig = self.home_sig(axnum)	if homesig:	    print >>file, "net %s => axis.%d.home-sw-in" % (homesig, axnum)	min_limsig = self.min_lim_sig(axnum)	if min_limsig:	    print >>file, "net %s => axis.%d.neg-lim-sw-in" % (min_limsig, axnum)	max_limsig = self.max_lim_sig(axnum)	if max_limsig:	    print >>file, "net %s => axis.%d.pos-lim-sw-in" % (max_limsig, axnum)    def connect_input(self, file, num):	p = self['pin%d' % num]	i = self['pin%dinv' % num]	if p == UNUSED_INPUT: return	if i:	    print >>file, "net %s <= parport.0.pin-%02d-in-not" \		% (hal_input_names[p], num)	else:	    print >>file, "net %s <= parport.0.pin-%02d-in" \		% (hal_input_names[p], num)    def find_input(self, input):	inputs = set((10, 11, 12, 13, 15))	for i in inputs:	    pin = getattr(self, "pin%d" % i)	    inv = getattr(self, "pin%dinv" % i)	    if pin == input: return i	return None    def find_output(self, output):	outputs = set((1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 16, 17))	for i in outputs:	    pin = getattr(self, "pin%d" % i)	    inv = getattr(self, "pin%dinv" % i)	    if pin == output: return i	return None    def connect_output(self, file, num):	p = self['pin%d' % num]	i = self['pin%dinv' % num]	if p == UNUSED_OUTPUT: return	if i: print >>file, "setp parport.0.pin-%02d-out-invert 1" % num	print >>file, "net %s => parport.0.pin-%02d-out" % (hal_output_names[p], num)        if p in (XSTEP, YSTEP, ZSTEP, ASTEP):            print >>file, "setp parport.0.pin-%02d-out-reset 1" % num    def write_halfile(self, base):	inputs = set((self.pin10,self.pin11,self.pin12,self.pin13,self.pin15))	outputs = set((self.pin1, self.pin2, self.pin3, self.pin4, self.pin5,	    self.pin6, self.pin7, self.pin8, self.pin9, self.pin14, self.pin16,	    self.pin17))	filename = os.path.join(base, self.machinename + ".hal")	file = open(filename, "w")	print >>file, _("# Generated by stepconf at %s") % time.asctime()	print >>file, _("# If you make changes to this file, they will be")	print >>file, _("# overwritten when you run stepconf again")	print >>file, "loadrt trivkins"	print >>file, "loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD traj_period_nsec=[EMCMOT]SERVO_PERIOD key=[EMCMOT]SHMEM_KEY num_joints=[TRAJ]AXES"	print >>file, "loadrt probe_parport"	print >>file, "loadrt hal_parport cfg=%s" % self.ioaddr        print >>file, "setp parport.0.reset-time %d" % self.steptime	encoder = PHA in inputs	counter = PHB not in inputs	probe = PROBE in inputs	pwm = PWM in outputs	pump = PUMP in outputs	if self.axes == 2:	    print >>file, "loadrt stepgen step_type=0,0"	elif self.axes == 1:	    print >>file, "loadrt stepgen step_type=0,0,0,0"	else:	    print >>file, "loadrt stepgen step_type=0,0,0"	if encoder:	    print >>file, "loadrt encoder num_chan=1"	if pump:	    print >>file, "loadrt charge_pump"	    print >>file, "net estop-out charge-pump.enable iocontrol.0.user-enable-out"	    print >>file, "net charge-pump <= charge-pump.out"	if pwm:	    print >>file, "loadrt pwmgen output_type=0"	print >>file	print >>file, "addf parport.0.read base-thread"	print >>file, "addf stepgen.make-pulses base-thread"	if encoder: print >>file, "addf encoder.update-counters base-thread"	if pump: print >>file, "addf charge-pump base-thread"	if pwm: print >>file, "addf pwmgen.make-pulses base-thread"	print >>file, "addf parport.0.write base-thread"	print >>file, "addf parport.0.reset base-thread"	print >>file	print >>file, "addf stepgen.capture-position servo-thread"	if encoder: print >>file, "addf encoder.capture-position servo-thread"	print >>file, "addf motion-command-handler servo-thread"	print >>file, "addf motion-controller servo-thread"	print >>file, "addf stepgen.update-freq servo-thread"	if pwm: print >>file, "addf pwmgen.update servo-thread"	if pwm:	    x1 = self.spindlepwm1	    x2 = self.spindlepwm2	    y1 = self.spindlespeed1	    y2 = self.spindlespeed2	    scale = (y2-y1) / (x2-x1)	    offset = x1 - y1 / scale	    print >>file	    print >>file, "net spindle-cmd <= motion.spindle-speed-out => pwmgen.0.value"	    print >>file, "net spindle-enable <= motion.spindle-on => pwmgen.0.enable"	    print >>file, "net spindle-pwm <= pwmgen.0.pwm"	    print >>file, "setp pwmgen.0.pwm-freq %s" % self.spindlecarrier		    print >>file, "setp pwmgen.0.scale %s" % scale	    print >>file, "setp pwmgen.0.offset %s" % offset	    print >>file, "setp pwmgen.0.dither-pwm true"        if CW in outputs:            print >>file, "net spindle-cw <= motion.spindle-forward"        if CCW in outputs:            print >>file, "net spindle-ccw <= motion.spindle-reverse"	if MIST in outputs:	    print >>file, "net coolant-mist <= iocontrol.0.coolant-mist"	if FLOOD in outputs:	    print >>file, "net coolant-flood <= iocontrol.0.coolant-flood"	if encoder:	    print >>file	    if PHB not in inputs:		print >>file, "setp encoder.0.position-scale %f"\		     % self.spindlecpr		print >>file, "setp encoder.0.counter-mode 1"	    else:		print >>file, "setp encoder.0.position-scale %f" \		    % ( 4.0 * int(self.spindlecpr))	    print >>file, "net spindle-position encoder.0.position => motion.spindle-revs"	    print >>file, "net spindle-velocity encoder.0.velocity => motion.spindle-speed-in"	    print >>file, "net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable"	    print >>file, "net spindle-phase-a encoder.0.phase-A"	    print >>file, "net spindle-phase-b encoder.0.phase-B"	    print >>file, "net spindle-index encoder.0.phase-Z"	if probe:	    print >>file	    print >>file, "net probe-in => motion.probe-input"	print >>file	for o in (1,2,3,4,5,6,7,8,9,14,16,17): self.connect_output(file, o)	print >>file	for i in (10,11,12,13,15): self.connect_input(file, i)	if self.axes == 2:	    self.connect_axis(file, 0, 'x')	    self.connect_axis(file, 1, 'z')	elif self.axes == 0:	    self.connect_axis(file, 0, 'x')	    self.connect_axis(file, 1, 'y')	    self.connect_axis(file, 2, 'z')	elif self.axes == 1:	    self.connect_axis(file, 0, 'x')	    self.connect_axis(file, 1, 'y')	    self.connect_axis(file, 2, 'z')	    self.connect_axis(file, 3, 'a')	print >>file	print >>file, "net estop-out <= iocontrol.0.user-enable-out"	if ESTOP_IN in inputs:	    print >>file, "net estop-ext => iocontrol.0.emc-enable-in"	else:	    print >>file, "net estop-out => iocontrol.0.emc-enable-in"	print >>file	if self.manualtoolchange:	    print >>file, "loadusr -W hal_manualtoolchange"	    print >>file, "net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change"	    print >>file, "net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed"	    print >>file, "net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number"	else:	    print >>file, "net tool-change-loopback iocontrol.0.tool-change => iocontrol.0.tool-changed"	print >>file, "net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared"        if self.pyvcp:	    vcp = os.path.join(base, "panel.xml")            if not os.path.exists(vcp):                f1 = open(vcp, "w")                print >>f1, "<?xml version='1.0' encoding='UTF-8'?>"                print >>f1, "<!-- "                print >>f1, _("Include your PyVCP panel here.\nThe contents of this file will not be overwritten when you run stepconf again.")                print >>f1, "-->"                print >>f1, "<pyvcp>"                print >>f1, "</pyvcp>"        if self.pyvcp or self.customhal:	    custom = os.path.join(base, "custom_postgui.hal")	    if not os.path.exists(custom):		f1 = open(custom, "w")		print >>f1, _("# Include your customized HAL commands here")                print >>f1, _("""\# The commands in this file are run after the AXIS GUI (including PyVCP panel)# starts# This file will not be overwritten when you run stepconf again""")	if self.customhal:	    custom = os.path.join(base, "custom.hal")	    if not os.path.exists(custom):		f1 = open(custom, "w")		print >>f1, _("# Include your customized HAL commands here")		print >>f1, _("# This file will not be overwritten when you run stepconf again") 	file.close()	self.add_md5sum(filename)    def write_readme(self, base):	filename = os.path.join(base, "README")	file = open(filename, "w")

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?