def setup_stepper_multiplexer(stepgenIndex, sections, selSignal, thread): num = len(sections) sigBase = 'stepgen-%i' % stepgenIndex unsignedSignals = [['dirsetup', 'DIRSETUP'], ['dirhold', 'DIRHOLD'], ['steplen', 'STEPLEN'], ['stepspace', 'STEPSPACE']] floatSignals = [['scale', 'SCALE'], ['max-vel', 'STEPGEN_MAX_VEL'], ['max-acc', 'STEPGEN_MAX_ACC']] for item in unsignedSignals: signal = hal.Signal('%s-%s' % (sigBase, item[0]), hal.HAL_U32) mux = rt.newinst('muxn_u32', 'mux%i.%s' % (num, signal.name), pincount=num) hal.addf(mux.name, thread) for n, section in enumerate(sections): mux.pin('in%i' % n).set(c.find(section, item[1])) mux.pin('sel').link(selSignal) mux.pin('out').link(signal) for item in floatSignals: signal = hal.Signal('%s-%s' % (sigBase, item[0]), hal.HAL_FLOAT) mux = rt.newinst('muxn', 'mux%i.%s' % (num, signal.name), pincount=num) hal.addf(mux.name, thread) for n, section in enumerate(sections): mux.pin('in%i' % n).set(c.find(section, item[1])) mux.pin('sel').link(selSignal) mux.pin('out').link(signal)
def setup_motion(kinematics='trivkins'): rt.loadrt(kinematics) rt.loadrt('tp') # motion controller, get name and thread periods from ini file rt.loadrt(c.find('EMCMOT', 'EMCMOT'), servo_period_nsec=c.find('EMCMOT', 'SERVO_PERIOD'), num_joints=c.find('TRAJ', 'AXES'), num_aio=51, num_dio=21)
def setup_system_fan(replicape): en = config.find('FDM', 'SYSTEM_FAN', 0) if int(en) == 0: return fan_sig = hal.newsig('fan-output', hal.HAL_FLOAT) replicape.get_fan_pwm_pin(3).link(fan_sig) fan_sig.set(1.0)
def setup_system_fan(replicape): en = config.find('FDM','SYSTEM_FAN', 0) if int(en) == 0: return fan_sig = hal.newsig('fan-output', hal.HAL_FLOAT) replicape.get_fan_pwm_pin(3).link(fan_sig) fan_sig.set(1.0)
def setup_motion(kinematics='trivkins'): rt.loadrt(kinematics) rt.loadrt('tp') rt.loadrt('hostmot2') # rt.newinst(c.find('HOSTMOT2', 'DRIVER'), # c.find('HOSTMOT2', 'DEVNAME'), # c.find('HOSTMOT2', 'CONFIG')) os.system( 'halcmd newinst hm2_soc_ol hm2-socfpga0 -- config="firmware=socfpga/dtbo/DE0_Nano_SoC_Cramps.3x24.dtbo num_pwmgens=6 num_stepgens=8 enable_adc=1" debug=1' ) # motion controller, get name and thread periods from ini file rt.loadrt(c.find('EMCMOT', 'EMCMOT'), servo_period_nsec=c.find('EMCMOT', 'SERVO_PERIOD'), num_joints=c.find('TRAJ', 'AXES'), num_aio=51, num_dio=21)
def setup_servo_toggle(servoIndex, section, pwm, selectSignal, thread=None): servo = '%s.%02i' % ('rc_servo', servoIndex) mux2 = rt.newinst('mux2', '%s-mux2' % servo) hal.addf(mux2.name, thread) pwmout = hal.newsig('%s-pwm-out' % servo, hal.HAL_FLOAT) mux2.pin('out').link(pwmout) hal.Pin('%s.value' % pwm).link(pwmout) enable = hal.Signal('emcmot-0-enable', hal.HAL_BIT) hal.Pin('%s.enable' % pwm).link(enable) sigBase = 'rc-servo-%i' % servoIndex smin = hal.newsig('%s-min' % sigBase, hal.HAL_FLOAT) smax = hal.newsig('%s-max' % sigBase, hal.HAL_FLOAT) hal.Pin('%s-mux2.in1' % servo).link(smin) hal.Pin('%s-mux2.in0' % servo).link(smax) smin.set(c.find(section, 'SERVO_MIN', 0.1)) smax.set(c.find(section, 'SERVO_MAX', 0.2)) mux2.pin('sel').link('%s' % selectSignal)
def configure_stepgen(): # stepgen config hal.Pin('hpg.stepgen.00.steppin').set(812) hal.Pin('hpg.stepgen.00.dirpin').set(811) hal.Pin('hpg.stepgen.00.control-type').set(1) # velocity mode hal.Pin('hpg.stepgen.00.position-scale').set(c.find('STEPPER', 'SCALE')) hal.Pin('hpg.stepgen.00.dirsetup').set(c.find('STEPPER', 'DIRSETUP')) hal.Pin('hpg.stepgen.00.dirhold').set(c.find('STEPPER', 'DIRHOLD')) hal.Pin('hpg.stepgen.00.steplen').set(c.find('STEPPER', 'STEPLEN')) hal.Pin('hpg.stepgen.00.stepspace').set(c.find('STEPPER', 'STEPSPACE')) hal.Pin('hpg.stepgen.00.velocity-cmd').link( hal.Signal('motor-vel', hal.HAL_FLOAT)) hal.Pin('hpg.stepgen.00.enable').link( hal.Signal('motor-enable', hal.HAL_BIT)) # machine power hal.Pin('bb_gpio.p9.out-26').link(hal.Signal('motor-enable', hal.HAL_BIT)) hal.Pin('bb_gpio.p8.out-07').link(hal.Signal('motor-enable', hal.HAL_BIT)) hal.Pin('bb_gpio.p8.out-07.invert').set(True)
def __init__(self): self.gpio = rtapi.loadrt('hal_bb_gpio', output_pins='', input_pins='810,809,924,818,923,925,916,918,911,913') self.dac = hal.loadusr(USR_HAL_PATH + 'hal_replicape_dac', name='replicape_dac', wait_name='replicape_dac') self.hwconfig = hal.loadusr(USR_HAL_PATH + 'hal_replicape_A4_hwconfig', name='replicape_hwconfig', wait_name='replicape_hwconfig') for i in xrange(5): # Default: microstepping=1/32, fast decay self.hwconfig.pin('stepper.%i.microstepping' % i).set(config.find('FDM','STEPPER_%i_MICROSTEPPING' % i, 5)) self.hwconfig.pin('stepper.%i.decay' % i).set(config.find('FDM','STEPPER_%i_DECAY' % i, 0)) super(ReplicapeA4A, self).__init__()
def setup_axis(replicape, command, feedback, nr): section = 'AXIS_%d' % nr port_str = config.find(section, 'PORT', str(nr)) ports = re.split('\s*,\s*', port_str) replicape.get_pru_pin('%s.position-fb' % replicape.get_stepgen(ports[0])).link(feedback) for port in ports: sg = replicape.get_stepgen(port) replicape.get_pru_pin('%s.position-cmd' % (sg)).link(command) replicape.get_pru_pin('%s.position-scale' % (sg)) \ .set(float( config.find(section, 'SCALE_PORT_%s' % port, config.find(section, 'SCALE', 'SCALE must be defined')) )) replicape.get_pru_pin('%s.enable' % (sg)).link('main-enable') replicape.set_motor_current( replicape.get_motor_port(port), float( config.find(section, 'CURRENT_PORT_%s' % port, config.find(section, 'CURRENT', DEFAULT_CURRENT)) ))
def setup_extruder(replicape, extruder, nr): section = 'EXTRUDER_%d' % nr port_str = str(config.find(section, 'PORT', str(nr + 3))) # Extruder starts at port 3, after XYZ ports = re.split('\s*,\s*', port_str) for port in ports: sg = replicape.get_stepgen(port) replicape.get_pru_pin('%s.control-type' % (sg)).set(1) replicape.get_pru_pin('%s.velocity-cmd' % (sg)).link(extruder.extrude_vel_sig) replicape.get_pru_pin('%s.position-scale' % (sg)) \ .set(float( config.find(section, 'SCALE_PORT_%s' % port, config.find(section, 'SCALE', 'SCALE must be defined')) )) replicape.get_pru_pin('%s.enable' % (sg)).link('main-enable') replicape.set_motor_current( replicape.get_motor_port(port), float( config.find(section, 'CURRENT_PORT_%s' % port, config.find(section, 'CURRENT', DEFAULT_CURRENT)) ))
def setup_stepper(stepgenIndex, section, axisIndex=None, stepgenType='hpg.stepgen', gantry=False, gantryJoint=0, velocitySignal=None, thread=None): stepgen = '%s.%01i' % (stepgenType, stepgenIndex) if axisIndex is not None: axis = 'axis.%i' % axisIndex hasMotionAxis = (axisIndex is not None) and (not gantry or gantryJoint == 0) velocityControlled = velocitySignal is not None # axis enable chain enableIndex = axisIndex if axisIndex is None: enableIndex = 0 # use motor enable signal enable = hal.Signal('emcmot-%i-enable' % enableIndex, hal.HAL_BIT) if hasMotionAxis: enable.link('%s.amp-enable-out' % axis) enable.link('%s.enable' % stepgen) # expose timing parameters so we can multiplex them later sigBase = 'stepgen.%i' % stepgenIndex assign_param(sigBase, "position-scale", c.find(section, 'SCALE')) assign_param(sigBase, "maxaccel", c.find(section, 'STEPGEN_MAXACC')) #assign_param(sigBase,"maxvel",c.find("ABP", 'STEPGEN_MAXVEL')) # position command and feedback limitHome = hal.newsig('limit-%i-home' % axisIndex, hal.HAL_BIT) limitMin = hal.newsig('limit-%i-min' % axisIndex, hal.HAL_BIT) limitMax = hal.newsig('limit-%i-max' % axisIndex, hal.HAL_BIT) limitHome.link('%s.home-sw-in' % axis) limitMin.link('%s.neg-lim-sw-in' % axis) limitMax.link('%s.pos-lim-sw-in' % axis) if velocityControlled: hal.net(velocitySignal, '%s.velocity-cmd' % stepgen)
def init_hardware(): watchList = [] # Python user-mode HAL module to read ADC value and generate a thermostat output for PWM defaultThermistor = 'semitec_103GT_2' hal.loadusr('hal_temp_atlas', name='temp', filter_size=20, channels='00:%s,01:%s,02:%s,03:%s' % (c.find('HBP', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_0', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_1', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_2', 'THERMISTOR', defaultThermistor)), wait_name='temp') watchList.append(['temp', 0.1]) base.usrcomp_status('temp', 'temp-hw', thread='servo-thread') base.usrcomp_watchdog(watchList, 'estop-reset', thread='servo-thread', errorSignal='watchdog-error')
def init_hardware(): watchList = [] # load low-level drivers rt.loadrt('hal_bb_gpio', output_pins='816,822,823,824,825,826,914,923,925', input_pins='807,808,809,810,817,911,913') prubin = '%s/%s' % (c.Config().EMC2_RTLIB_DIR, c.find('PRUCONF', 'PRUBIN')) rt.loadrt(c.find('PRUCONF', 'DRIVER'), pru=0, num_stepgens=6, num_pwmgens=6, prucode=prubin, halname='hpg') # Python user-mode HAL module to read ADC value and generate a thermostat output for PWM defaultThermistor = 'semitec_103GT_2' hal.loadusr('hal_temp_bbb', name='temp', interval=0.05, filter_size=1, cape_board='CRAMPS', channels='04:%s,05:%s,02:%s,03:%s' % (c.find('HBP', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_0', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_1', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_2', 'THERMISTOR', defaultThermistor)), wait_name='temp') watchList.append(['temp', 0.1]) base.usrcomp_status('temp', 'temp-hw', thread='servo-thread') base.usrcomp_watchdog(watchList, 'estop-reset', thread='servo-thread', errorSignal='watchdog-error')
def __init__(self): self.gpio = rtapi.loadrt('hal_bb_gpio', output_pins='941', input_pins='810,809,924,818,923,925,928,918,911,913') self.hwconfig = hal.loadusr(USR_HAL_PATH + 'hal_replicape_B3_hwconfig', name='replicape_hwconfig', wait_name='replicape_hwconfig') for i in xrange(5): # Default: spreadMode, microstepping=1/16 self.hwconfig.pin('stepper.%i.mode' % i).set(config.find('FDM','STEPPER_%i_MODE' % i, 0x80)) super(ReplicapeB3A, self).__init__()
def setup_motion(kinematics='trivkins', tp='tp', num_aio=50, num_dio=21): rt.loadrt(kinematics) # rt.loadrt(tp) # hostmot2 setup get names and config from ini file hostmot2 = bool(c.find('HOSTMOT2', 'DRIVER')) if hostmot2: rt.loadrt('hostmot2') os.system( 'halcmd newinst hm2_soc_ol hm2-socfpga0 already_programmed=1 -- config="num_pwmgens=1 num_stepgens=4"' ) # rt.newinst(c.find('HOSTMOT2', 'DRIVER'), # c.find('HOSTMOT2', 'DEVNAME'), # "-- ", # c.find('HOSTMOT2', 'CONFIG')) # motion controller, get name and thread periods from ini file rt.loadrt(c.find('EMCMOT', 'EMCMOT'), servo_period_nsec=c.find('EMCMOT', 'SERVO_PERIOD'), num_joints=c.find('TRAJ', 'AXES'), num_aio=num_aio, num_dio=num_dio)
def setup_limit_switches(replicape): limit_x_sig = hal.newsig('limit-x', hal.HAL_BIT) limit_x_sig.link('axis.0.home-sw-in') limit_x_pos = config.find('AXIS_0', 'HOME_SEARCH_VEL', 0) if limit_x_pos < 0: replicape.get_limit_pin('X', False).link(limit_x_sig) limit_x_sig.link('axis.0.neg-lim-sw-in') if limit_x_pos > 0: replicape.get_limit_pin('X', True).link(limit_x_sig) limit_x_sig.link('axis.0.pos-lim-sw-in') limit_y_sig = hal.newsig('limit-y', hal.HAL_BIT) limit_y_sig.link('axis.1.home-sw-in') limit_y_pos = config.find('AXIS_1', 'HOME_SEARCH_VEL', 0) if limit_y_pos < 0: replicape.get_limit_pin('Y', False).link(limit_y_sig) limit_y_sig.link('axis.1.neg-lim-sw-in') if limit_y_pos > 0: replicape.get_limit_pin('Y', True).link(limit_y_sig) limit_y_sig.link('axis.1.pos-lim-sw-in') limit_z_sig = hal.newsig('limit-z', hal.HAL_BIT) limit_z_sig.link('axis.2.home-sw-in') limit_z_pos = config.find('AXIS_2', 'HOME_SEARCH_VEL', 0) if limit_z_pos < 0: replicape.get_limit_pin('Z', False).link(limit_z_sig) limit_z_sig.link('axis.2.neg-lim-sw-in') if limit_z_pos > 0: replicape.get_limit_pin('Z', True).link(limit_z_sig) limit_z_sig.link('axis.2.pos-lim-sw-in') probe_pin = replicape.get_probe_pin(); if probe_pin is not None: probe_sig = hal.newsig('limit-probe', hal.HAL_BIT) probe_sig.link(probe_pin) probe_sig.link('motion.probe-input')
def __init__(self, replicape, enable_sig, estop_reset_sig): config_name = 'HBP' thermistor = config.find(config_name, 'THERMISTOR', '') if thermistor == '': raise ValueError('[%s] THERMISTOR must be defined' % (config_name)) temp_hal = hal.loadusr(USR_HAL_PATH + 'hal_bbb_temp', name='ThermHbp', wait_name='ThermHbp', cape_board='Replicape', channel=replicape.get_hbp_adc_channel(), thermistor=thermistor) super(HbpTemperature, self).__init__( temp_hal, replicape.get_hbp_pwm_pin(), replicape.get_hbp_on_pin(), enable_sig, estop_reset_sig, config_name, 'fdm-hbp', 'temp.hbp', 0)
def setup_linearDeltaKins(c): # c.load_ini(os.environ['INI_FILE_NAME']) deltaCfRod = c.find('MACHINE', 'CF_ROD') deltaRadius = c.find('MACHINE', 'DELTA_R') deltaJoin0Offset = c.find('MACHINE', 'JOINT_0_OFFSET', 0) deltaJoin1Offset = c.find('MACHINE', 'JOINT_1_OFFSET', 0) deltaJoin2Offset = c.find('MACHINE', 'JOINT_2_OFFSET', 0) deltaJoin1AngleOffset = c.find('MACHINE', 'JOINT_1_ANGLE_OFFSET', 0) deltaJoin2AngleOffset = c.find('MACHINE', 'JOINT_2_ANGLE_OFFSET', 0) deltaJoin1RadiusOffset = c.find('MACHINE', 'JOINT_1_RADIUS_OFFSET', 0) deltaJoin2RadiusOffset = c.find('MACHINE', 'JOINT_2_RADIUS_OFFSET', 0) c.load_ini(os.environ['INI_FILE_NAME']) hal.Pin('lineardeltakins.L').set(deltaCfRod) hal.Pin('lineardeltakins.R').set(deltaRadius) hal.Pin('lineardeltakins.J0off').set(deltaJoin0Offset) hal.Pin('lineardeltakins.J1off').set(deltaJoin1Offset) hal.Pin('lineardeltakins.J2off').set(deltaJoin2Offset) hal.Pin('lineardeltakins.A1off').set(deltaJoin1AngleOffset) hal.Pin('lineardeltakins.A2off').set(deltaJoin2AngleOffset) hal.Pin('lineardeltakins.R1off').set(deltaJoin1RadiusOffset) hal.Pin('lineardeltakins.R2off').set(deltaJoin2RadiusOffset)
def setup_linearDeltaKins(c): # c.load_ini(os.environ['INI_FILE_NAME']) deltaCfRod = c.find('MACHINE', 'CF_ROD') deltaRadius = c.find('MACHINE', 'DELTA_R') deltaJoin0Offset = c.find('MACHINE', 'JOINT_0_OFFSET',0) deltaJoin1Offset = c.find('MACHINE', 'JOINT_1_OFFSET',0) deltaJoin2Offset = c.find('MACHINE', 'JOINT_2_OFFSET',0) deltaJoin1AngleOffset = c.find('MACHINE', 'JOINT_1_ANGLE_OFFSET',0) deltaJoin2AngleOffset = c.find('MACHINE', 'JOINT_2_ANGLE_OFFSET',0) deltaJoin1RadiusOffset = c.find('MACHINE', 'JOINT_1_RADIUS_OFFSET',0) deltaJoin2RadiusOffset = c.find('MACHINE', 'JOINT_2_RADIUS_OFFSET',0) c.load_ini(os.environ['INI_FILE_NAME']) hal.Pin('lineardeltakins.L').set(deltaCfRod) hal.Pin('lineardeltakins.R').set(deltaRadius) hal.Pin('lineardeltakins.J0off').set(deltaJoin0Offset) hal.Pin('lineardeltakins.J1off').set(deltaJoin1Offset) hal.Pin('lineardeltakins.J2off').set(deltaJoin2Offset) hal.Pin('lineardeltakins.A1off').set(deltaJoin1AngleOffset) hal.Pin('lineardeltakins.A2off').set(deltaJoin2AngleOffset) hal.Pin('lineardeltakins.R1off').set(deltaJoin1RadiusOffset) hal.Pin('lineardeltakins.R2off').set(deltaJoin2RadiusOffset)
def __init__(self, replicape, index, enable_sig, estop_reset_sig): config_name = 'EXTRUDER_%s' % (index) thermistor = config.find(config_name, 'THERMISTOR', '') if thermistor == '': raise ValueError('[%s] THERMISTOR must be defined' % (config_name)) temp_hal = hal.loadusr(USR_HAL_PATH + 'hal_bbb_temp', name='Therm%s' % (index), wait_name='Therm%s' % (index), cape_board='Replicape', channel=replicape.get_extruder_adc_channel(index), thermistor=thermistor) super(ExtruderTemperature, self).__init__( temp_hal, replicape.get_extruder_pwm_pin(index), replicape.get_extruder_on_pin(index), enable_sig, estop_reset_sig, config_name, 'fdm-e%s' % (index), 'temp.e%s' % (index), index + 2 )
def check_version(): global BOARD_REV # we use a 4.14.18-ti-rt-r33 kernel and have enable_uboot_overlays=1 # in /boot/uEnv.txt # u-boot overlays do not use the slots file, so we take the board # version from the INI file # is there any way to find not just the loaded cape name, but also # its version (short of reading the cape eeprom)? # we check in /sys/proc/cmdline for the REPLICAPE cape # # with open('/sys/devices/platform/bone_capemgr/slots', 'r') as file: # content = file.read() content = subprocess.check_output(['cat','/proc/cmdline']) if re.search('capes=BB-BONE-REPLICAP', content) is None: raise RuntimeError('Replicape not found. Is the cape mounted?') content = config.find('FDM','BOARD_REV') if (content is not None) and (content in ['B3A', 'A4A']): BOARD_REV = content else: raise RuntimeError('BOARD_REV not set in ini file. Set to B3A or A4A!')
def setup_motion(kinematics='trivkins', tp='tp', num_aio=50, num_dio=21): rt.loadrt(kinematics) # rt.loadrt(tp) # hostmot2 setup get names and config from ini file hostmot2 = bool(c.find('HOSTMOT2', 'DRIVER')) if hostmot2: rt.loadrt('hostmot2') rt.newinst(c.find('HOSTMOT2', 'DRIVER'), c.find('HOSTMOT2', 'DEVNAME'), "-- ", c.find('HOSTMOT2', 'CONFIG')) # motion controller, get name and thread periods from ini file rt.loadrt(c.find('EMCMOT', 'EMCMOT'), servo_period_nsec=c.find('EMCMOT', 'SERVO_PERIOD'), num_joints=c.find('TRAJ', 'AXES'), num_aio=num_aio, num_dio=num_dio, tp=tp, kins=kinematics)
def setup_fans(replicape): if NUM_FANS == 0: return en = config.find('FDM','SYSTEM_FAN', 0) fan_out = [None] * NUM_FANS fan_scale = [None] * NUM_FANS fan_in = [None] * NUM_FANS #on-board pwm input is 0.0 to 1.0, M106 sends 0 to 255 for i in xrange(NUM_FANS): fan_out[i] = hal.newsig('fan-out-%d' % i, hal.HAL_FLOAT) replicape.get_fan_pwm_pin(i).link(fan_out[i]) # the system fan is connected to the last fan pwm output if (int(en) > 0) and (i == NUM_FANS-1): fan_out[i].set(1.0) else: fan_in[i] = hal.newsig('fan-in-%d' % i, hal.HAL_FLOAT) fan_in[i].link('motion.analog-out-io-%d' % (FAN_IO_START + i)) fan_scale[i] = rtapi.newinst('div2', 'fan%d.div2.scale-pwm' % i) hal.addf(fan_scale[i].name, SERVO_THREAD) fan_scale[i].pin('in0').link(fan_in[i]) fan_scale[i].pin('in1').set(255.0) fan_scale[i].pin('out').link(fan_out[i])
def _init_config(self, config): configs = [ (self.filament_dia_sig, ['FILAMENT_DIAMETER', 'FILAMENT_DIA'], '3'), (self.extrude_scale_sig, ['EXTRUDE_SCALE'], '1'), (self.accel_gain_sig, ['ACCELERATION_GAIN'], '0.05'), (self.max_jog_vel_sig, ['MAX_JOG_VELOCITY', 'MAX_VELOCITY'], '40'), (self.retract_len_sig, ['RETRACT_LENGTH', 'RETRACT_LEN'], '3'), (self.retract_vel_sig, ['RETRACT_VELOCITY', 'RETRACT_VEL'], '60') ] for i in configs: (signal, config_names, config_default) = i v = None for config_name in config_names: v = config.find('EXTRUDER_%d' % self.nr, config_name) if v is not None: break if v is None: v = config_default if v is None: raise ValueError('Config [EXTRUDER_%d] %s must be defined' % (self.nr, config_nammes[0])) float_v = float(v) signal.set(float_v)
def setup_fans(replicape): if NUM_FANS == 0: return en = config.find('FDM', 'SYSTEM_FAN', 0) fan_out = [None] * NUM_FANS fan_scale = [None] * NUM_FANS fan_in = [None] * NUM_FANS #on-board pwm input is 0.0 to 1.0, M106 sends 0 to 255 for i in xrange(NUM_FANS): fan_out[i] = hal.newsig('fan-out-%d' % i, hal.HAL_FLOAT) replicape.get_fan_pwm_pin(i).link(fan_out[i]) # the system fan is connected to the last fan pwm output if (int(en) > 0) and (i == NUM_FANS - 1): fan_out[i].set(1.0) else: fan_in[i] = hal.newsig('fan-in-%d' % i, hal.HAL_FLOAT) fan_in[i].link('motion.analog-out-io-%d' % (FAN_IO_START + i)) fan_scale[i] = rtapi.newinst('div2', 'fan%d.div2.scale-pwm' % i) hal.addf(fan_scale[i].name, SERVO_THREAD) fan_scale[i].pin('in0').link(fan_in[i]) fan_scale[i].pin('in1').set(255.0) fan_scale[i].pin('out').link(fan_out[i])
def __init__(self): self.pru = rtapi.loadrt('hal_pru_generic', pru=0, num_stepgens=5, num_pwmgens=0, halname='hpg', prucode='%s/rt-preempt/pru_generic.bin' % (config.Config().EMC2_RTLIB_DIR)) # 4.14.18-ti-rt-r33 kernel and rt-preempt hal.addf('hpg.capture-position', SERVO_THREAD) hal.addf('hpg.update', SERVO_THREAD) hal.addf('bb_gpio.read', SERVO_THREAD) hal.addf('bb_gpio.write', SERVO_THREAD) minvel = config.find('TRAJ','MIN_VELOCITY', 0.001) for i in xrange(5): self.get_pru_pin('stepgen.%02i.dirsetup' % i).set(200) self.get_pru_pin('stepgen.%02i.dirhold' % i).set(200) self.get_pru_pin('stepgen.%02i.steplen' % i).set(1000) self.get_pru_pin('stepgen.%02i.stepspace' % i).set(1000) self.get_pru_pin('stepgen.%02i.dirpin' % i).set(self.pru_dir_pin(i)) self.get_pru_pin('stepgen.%02i.steppin' % i).set(self.pru_step_pin(i)) # setting to zero: pru_generic adapts to maximum velocity and acceleration # see http://www.machinekit.io/docs/man/man9/hal_pru_generic/ self.get_pru_pin('stepgen.%02i.maxvel' % i).set(0) self.get_pru_pin('stepgen.%02i.maxaccel' % i).set(0) # use new pru stepgen minvel pin to avoid pru hunting problem (without PID loop) # see this discussion https://groups.google.com/forum/#!topic/machinekit/ATEwvfgoIb4 # except for extruder(s) if i < 3 : self.get_pru_pin('stepgen.%02i.minvel' % i).set(minvel) self.pwm = hal.loadusr(USR_HAL_PATH + 'hal_replicape_pwm', name='replicape_pwm', wait_name='replicape_pwm') self.watchdog_sigs = [] for pin in self.get_watchdog_pins(): s = hal.newsig('replicape.watchdog.%d' % len(self.watchdog_sigs), hal.HAL_BIT) pin.link(s) self.watchdog_sigs.append(s)
def _init_config(self, config): configs = [ (self.filament_dia_sig, ['FILAMENT_DIAMETER', 'FILAMENT_DIA'], '3'), (self.extrude_scale_sig, ['EXTRUDE_SCALE'], '1'), (self.accel_gain_sig, ['ACCELERATION_GAIN'], '0.05'), (self.max_jog_vel_sig, ['MAX_JOG_VELOCITY', 'MAX_VELOCITY'], '40'), (self.retract_len_sig, ['RETRACT_LENGTH', 'RETRACT_LEN'], '3'), (self.retract_vel_sig, ['RETRACT_VELOCITY', 'RETRACT_VEL'], '60') ] for i in configs: (signal, config_names, config_default) = i v = None for config_name in config_names: v = config.find('EXTRUDER_%d' % self.nr, config_name) if v is not None: break if v is None: v = config_default if v is None: raise ValueError('Config [EXTRUDER_%d] %s must be defined' % (self.nr, config_names[0])) float_v = float(v) signal.set(float_v)
def setup_stepper(stepgenIndex, section, axisIndex=None, stepgenType='hpg.stepgen', gantry=False, gantryJoint=0, velocitySignal=None, thread=None): stepgen = '%s.%02i' % (stepgenType, stepgenIndex) if axisIndex is not None: axis = 'axis.%i' % axisIndex hasMotionAxis = (axisIndex is not None) and (not gantry or gantryJoint == 0) velocityControlled = velocitySignal is not None # axis enable chain enableIndex = axisIndex if axisIndex is None: enableIndex = 0 # use motor enable signal enable = hal.Signal('emcmot-%i-enable' % enableIndex, hal.HAL_BIT) if hasMotionAxis: enable.link('%s.amp-enable-out' % axis) enable.link('%s.enable' % stepgen) # expose timing parameters so we can multiplex them later sigBase = 'stepgen-%i' % stepgenIndex dirsetup = hal.newsig('%s-dirsetup' % sigBase, hal.HAL_U32) dirhold = hal.newsig('%s-dirhold' % sigBase, hal.HAL_U32) steplen = hal.newsig('%s-steplen' % sigBase, hal.HAL_U32) stepspace = hal.newsig('%s-stepspace' % sigBase, hal.HAL_U32) scale = hal.newsig('%s-scale' % sigBase, hal.HAL_FLOAT) maxVel = hal.newsig('%s-max-vel' % sigBase, hal.HAL_FLOAT) maxAcc = hal.newsig('%s-max-acc' % sigBase, hal.HAL_FLOAT) controlType = hal.newsig('%s-control-type' % sigBase, hal.HAL_BIT) hal.Pin('%s.dirsetup' % stepgen).link(dirsetup) hal.Pin('%s.dirhold' % stepgen).link(dirhold) dirsetup.set(c.find(section, 'DIRSETUP')) dirhold.set(c.find(section, 'DIRHOLD')) hal.Pin('%s.steplen' % stepgen).link(steplen) hal.Pin('%s.stepspace' % stepgen).link(stepspace) steplen.set(c.find(section, 'STEPLEN')) stepspace.set(c.find(section, 'STEPSPACE')) hal.Pin('%s.position-scale' % stepgen).link(scale) scale.set(c.find(section, 'SCALE')) hal.Pin('%s.maxvel' % stepgen).link(maxVel) hal.Pin('%s.maxaccel' % stepgen).link(maxAcc) maxVel.set(c.find(section, 'STEPGEN_MAX_VEL')) maxAcc.set(c.find(section, 'STEPGEN_MAX_ACC')) hal.Pin('%s.control-type' % stepgen).link(controlType) # position command and feedback if not velocityControlled: if hasMotionAxis: # per axis fb and cmd posCmd = hal.newsig('emcmot-%i-pos-cmd' % axisIndex, hal.HAL_FLOAT) posCmd.link('%s.motor-pos-cmd' % axis) if not gantry: posCmd.link('%s.position-cmd' % stepgen) else: posCmd.link('gantry.%i.position-cmd' % axisIndex) posFb = hal.newsig('emcmot-%i-pos-fb' % axisIndex, hal.HAL_FLOAT) posFb.link('%s.motor-pos-fb' % axis) if not gantry: posFb.link('%s.position-fb' % stepgen) else: posFb.link('gantry.%i.position-fb' % axisIndex) if gantry: # per joint fb and cmd posCmd = hal.newsig( 'emcmot-%i-%i-pos-cmd' % (axisIndex, gantryJoint), hal.HAL_FLOAT) posCmd.link('gantry.%i.joint.%02i.pos-cmd' % (axisIndex, gantryJoint)) posCmd.link('%s.position-cmd' % stepgen) posFb = hal.newsig( 'emcmot-%i-%i-pos-fb' % (axisIndex, gantryJoint), hal.HAL_FLOAT) posFb.link('%s.position-fb' % stepgen) posFb.link('gantry.%i.joint.%02i.pos-fb' % (axisIndex, gantryJoint)) else: # velocity control hal.net(velocitySignal, '%s.velocity-cmd' % stepgen) controlType.set(1) # enable velocity control # limits if hasMotionAxis: limitHome = hal.newsig('limit-%i-home' % axisIndex, hal.HAL_BIT) limitMin = hal.newsig('limit-%i-min' % axisIndex, hal.HAL_BIT) limitMax = hal.newsig('limit-%i-max' % axisIndex, hal.HAL_BIT) limitHome.link('%s.home-sw-in' % axis) limitMin.link('%s.neg-lim-sw-in' % axis) limitMax.link('%s.pos-lim-sw-in' % axis) if gantry: if gantryJoint == 0: axisHoming = hal.newsig('emcmot-%i-homing' % axisIndex, hal.HAL_BIT) axisHoming.link('%s.homing' % axis) hal.Pin('gantry.%i.search-vel' % axisIndex).set( c.find(section, 'HOME_SEARCH_VEL')) hal.Pin('gantry.%i.homing' % axisIndex).link(axisHoming) hal.Pin('gantry.%i.home' % axisIndex).link(limitHome) or2 = rt.newinst('or2', 'or2.limit-%i-min' % axisIndex) hal.addf(or2.name, thread) or2.pin('out').link(limitMin) or2 = rt.newinst('or2', 'or2.limit-%i-max' % axisIndex) hal.addf(or2.name, thread) or2.pin('out').link(limitMax) limitHome = hal.newsig('limit-%i-%i-home' % (axisIndex, gantryJoint), hal.HAL_BIT) limitMin = hal.newsig('limit-%i-%i-min' % (axisIndex, gantryJoint), hal.HAL_BIT) limitMax = hal.newsig('limit-%i-%i-max' % (axisIndex, gantryJoint), hal.HAL_BIT) homeOffset = hal.Signal('home-offset-%i-%i' % (axisIndex, gantryJoint), hal.HAL_FLOAT) limitHome.link('gantry.%i.joint.%02i.home' % (axisIndex, gantryJoint)) limitMin.link('or2.limit-%i-min.in%i' % (axisIndex, gantryJoint)) limitMax.link('or2.limit-%i-max.in%i' % (axisIndex, gantryJoint)) homeOffset.link('gantry.%i.joint.%02i.home-offset' % (axisIndex, gantryJoint)) storage.setup_gantry_storage(axisIndex, gantryJoint)
def create_temperature_control(name, section, thread, hardwareOkSignal=None, coolingFan=None, hotendFan=None): tempSet = hal.newsig('%s-temp-set' % name, hal.HAL_FLOAT) tempMeas = hal.newsig('%s-temp-meas' % name, hal.HAL_FLOAT) tempInRange = hal.newsig('%s-temp-in-range' % name, hal.HAL_BIT) tempPwm = hal.newsig('%s-temp-pwm' % name, hal.HAL_FLOAT) tempPwmMax = hal.newsig('%s-temp-pwm-max' % name, hal.HAL_FLOAT) tempLimitMin = hal.newsig('%s-temp-limit-min' % name, hal.HAL_FLOAT) tempLimitMax = hal.newsig('%s-temp-limit-max' % name, hal.HAL_FLOAT) tempStandby = hal.newsig('%s-temp-standby' % name, hal.HAL_FLOAT) tempInLimit = hal.newsig('%s-temp-in-limit' % name, hal.HAL_BIT) tempThermOk = hal.newsig('%s-temp-therm-ok' % name, hal.HAL_BIT) error = hal.newsig('%s-error' % name, hal.HAL_BIT) active = hal.newsig('%s-active' % name, hal.HAL_BIT) tempPidPgain = hal.newsig('%s-temp-pid-Pgain' % name, hal.HAL_FLOAT) tempPidIgain = hal.newsig('%s-temp-pid-Igain' % name, hal.HAL_FLOAT) tempPidDgain = hal.newsig('%s-temp-pid-Dgain' % name, hal.HAL_FLOAT) tempPidMaxerrorI = hal.newsig('%s-temp-pid-maxerrorI' % name, hal.HAL_FLOAT) tempPidOut = hal.newsig('%s-temp-pid-out' % name, hal.HAL_FLOAT) tempPidBias = hal.newsig('%s-temp-pid-bias' % name, hal.HAL_FLOAT) tempRangeMin = hal.newsig('%s-temp-range-min' % name, hal.HAL_FLOAT) tempRangeMax = hal.newsig('%s-temp-range-max' % name, hal.HAL_FLOAT) noErrorIn = hal.newsig('%s-no-error-in' % name, hal.HAL_BIT) errorIn = hal.newsig('%s-error-in' % name, hal.HAL_BIT) tempPidBiasOut = tempPidBias # coolingFan compensation if coolingFan: tempPidFanBias = hal.newsig('%s-temp-pid-fan-bias' % name, hal.HAL_FLOAT) tempPidBiasOut = hal.newsig('%s-temp-pid-bias-out' % name, hal.HAL_FLOAT) scale = rt.newinst('scale', 'scale.%s-temp-pid-fan-bias' % name) hal.addf(scale.name, thread) scale.pin('in').link('%s.pwm' % coolingFan) scale.pin('out').link(tempPidFanBias) scale.pin('gain').set(c.find(section, 'FAN_BIAS')) sum2 = rt.newinst('sum2', 'sum2.%s-temp-pid-bias' % name) hal.addf(sum2.name, thread) sum2.pin('in0').link(tempPidBias) sum2.pin('in1').link(tempPidFanBias) sum2.pin('out').link(tempPidBiasOut) # PID pid = rt.newinst('pid', 'pid.%s' % name) hal.addf('%s.do-pid-calcs' % pid.name, thread) pid.pin('enable').link('emcmot-0-enable') # motor enable pid.pin('feedback').link(tempMeas) pid.pin('command').link(tempSet) pid.pin('output').link(tempPidOut) pid.pin('maxoutput').link(tempPwmMax) pid.pin('bias').link(tempPidBias) pid.pin('Pgain').link(tempPidPgain) pid.pin('Igain').link(tempPidIgain) pid.pin('Dgain').link(tempPidDgain) pid.pin('maxerrorI').link(tempPidMaxerrorI) # Limit heater PWM to positive values # PWM mimics hm2 implementation, which generates output for negative values limit1 = rt.newinst('limit1', 'limit.%s-temp-heaterl' % name) hal.addf(limit1.name, thread) limit1.pin('in').link(tempPidOut) limit1.pin('out').link(tempPwm) limit1.pin('min').set(0.0) limit1.pin('max').link(tempPwmMax) # Temperature checking sum2 = rt.newinst('sum2', 'sum2.%s-temp-range-pos' % name) hal.addf(sum2.name, thread) sum2.pin('in0').link(tempSet) sum2.pin('in1').set(c.find(section, 'TEMP_RANGE_POS_ERROR')) sum2.pin('out').link(tempRangeMax) sum2 = rt.newinst('sum2', 'sum2.%s-temp-range-neg' % name) hal.addf(sum2.name, thread) sum2.pin('in0').link(tempSet) sum2.pin('in1').set(c.find(section, 'TEMP_RANGE_NEG_ERROR')) sum2.pin('out').link(tempRangeMin) #the output of this component will say if measured temperature is in range of set value wcomp = rt.newinst('wcomp', 'wcomp.%s-temp-in-range' % name) hal.addf(wcomp.name, thread) wcomp.pin('min').link(tempRangeMin) wcomp.pin('max').link(tempRangeMax) wcomp.pin('in').link(tempMeas) wcomp.pin('out').link(tempInRange) # limit the output temperature to prevent damage when thermistor is broken/removed wcomp = rt.newinst('wcomp', 'wcomp.%s-temp-in-limit' % name) hal.addf(wcomp.name, thread) wcomp.pin('min').link(tempLimitMin) wcomp.pin('max').link(tempLimitMax) wcomp.pin('in').link(tempMeas) wcomp.pin('out').link(tempInLimit) # check the thermistor # net e0.temp.meas => thermistor-check.e0.temp # net e0.temp.in-range => not.e0-temp-range.in # net e0.temp.in-range_n <= not.e0-temp-range.out # net e0.temp.in-range_n => thermistor-check.e0.enable # net e0.heaterl => thermistor-check.e0.pid # net e0.therm-ok <= thermistor-check.e0.no-error # no error chain and3 = rt.newinst('andn', 'and3.%s-no-error-in' % name, pincount=3) hal.addf(and3.name, thread) and3.pin('in0').link(tempThermOk) and3.pin('in1').link(tempInLimit) if hardwareOkSignal: and3.pin('in2').link(hardwareOkSignal) else: and3.pin('in2').set(True) and3.pin('out').link(noErrorIn) tempThermOk.set(True) # thermistor checking for now disabled notComp = rt.newinst('not', 'not.%s-error-in' % name) hal.addf(notComp.name, thread) notComp.pin('in').link(noErrorIn) notComp.pin('out').link(errorIn) safetyLatch = rt.newinst('safety_latch', 'safety-latch.%s-error' % name) hal.addf(safetyLatch.name, thread) safetyLatch.pin('error-in').link(errorIn) safetyLatch.pin('error-out').link(error) safetyLatch.pin('reset').link('estop-reset') safetyLatch.pin('threshold').set(500) # 500ms error safetyLatch.pin('latching').set(True) # active chain comp = rt.newinst('comp', 'comp.%s-active' % name) hal.addf(comp.name, thread) comp.pin('in0').set(0.0001) comp.pin('hyst').set(0.0) comp.pin('in1').link(tempPwm) comp.pin('out').link(active) # Thermistor checking # setp thermistor-check.e0.wait 9.0 # setp thermistor-check.e0.min-pid 1.5 # disable0.25 # setp thermistor-check.e0.min-temp 1.5 # net e0.pid.bias => thermistor-check.e0.bias # Hotend fan if hotendFan: comp = rt.newinst('comp', 'comp.%s-pwm-enable' % hotendFan) hal.addf(comp.name, thread) comp.pin('in0').set(c.find(section, 'HOTEND_FAN_THRESHOLD', 50.0)) comp.pin('in1').link(tempMeas) comp.pin('hyst').set(c.find(section, 'HOTEND_FAN_HYST', 2.0)) comp.pin('out').link('%s-pwm-enable' % hotendFan) hal.Signal('%s-pwm' % hotendFan).set(1.0) rcomps.create_temperature_rcomp(name) motion.setup_temperature_io(name) # init parameter signals tempLimitMin.set(c.find(section, 'TEMP_LIMIT_MIN')) tempLimitMax.set(c.find(section, 'TEMP_LIMIT_MAX')) tempStandby.set(c.find(section, 'TEMP_STANDBY')) tempPwmMax.set(c.find(section, 'PWM_MAX')) tempPidPgain.set(c.find(section, 'PID_PGAIN')) tempPidIgain.set(c.find(section, 'PID_IGAIN')) tempPidDgain.set(c.find(section, 'PID_DGAIN')) tempPidMaxerrorI.set(c.find(section, 'PID_MAXERRORI')) tempPidBias.set(c.find(section, 'PID_BIAS'))
# HAL file for BeagleBone + TCT paralell port cape with 5 steppers and 3D printer board import os from machinekit import rtapi as rt from machinekit import hal from machinekit import config as c from config import base from config import motion # initialize the RTAPI command client rt.init_RTAPI() # loads the ini file passed by linuxcnc c.load_ini(os.environ["INI_FILE_NAME"]) motion.setup_motion(kinematics=c.find("KINS", "KINEMATICS")) # reading functions hal.addf("motion-command-handler", "servo-thread") # define gantry joints base.init_gantry(axisIndex=1, joints=2, latching=True) # Axis-of-motion Specific Configs (not the GUI) # X [J0] Axis base.setup_stepper(section="AXIS_0", axisIndex=0, stepgenIndex=0, stepgenType="sim") # Y [J1] Axis base.setup_stepper(section="AXIS_1", axisIndex=1, stepgenIndex=1, gantry=True, gantryJoint=0, stepgenType="sim") # YY[J2] Axis base.setup_stepper(section="AXIS_1", axisIndex=1, stepgenIndex=2, gantry=True, gantryJoint=1, stepgenType="sim") # Z [J3] Axis
def velocity_extrusion(extruders, thread): ''' Velocity extrusion support ''' # from motion/ui crossSection = hal.newsig('ve-cross-section', hal.HAL_FLOAT) crossSectionIn = hal.newsig('ve-cross-section-in', hal.HAL_FLOAT) lineWidth = hal.newsig('ve-line-width', hal.HAL_FLOAT) lineHeight = hal.newsig('ve-line-height', hal.HAL_FLOAT) filamentDia = hal.newsig('ve-filament-dia', hal.HAL_FLOAT) extrudeScale = hal.newsig('ve-extrude-scale', hal.HAL_FLOAT) extrudeAccelAdjGain = hal.newsig('ve-extrude-accel-adj-gain', hal.HAL_FLOAT) retractVel = hal.newsig('ve-retract-vel', hal.HAL_FLOAT) retractLen = hal.newsig('ve-retract-len', hal.HAL_FLOAT) maxVelocity = hal.newsig('ve-max-velocity', hal.HAL_FLOAT) # helper signals nozzleVel = hal.newsig('ve-nozzle-vel', hal.HAL_FLOAT) nozzleDischarge = hal.newsig('ve-nozzle-discharge', hal.HAL_FLOAT) filamentDiaSquared = hal.newsig('ve-filament-dia-squared', hal.HAL_FLOAT) filamentArea = hal.newsig('ve-filament-area', hal.HAL_FLOAT) extrudeRate = hal.newsig('ve-extrude-rate', hal.HAL_FLOAT) extrudeRateScaled = hal.newsig('ve-extrude-rate-scaled', hal.HAL_FLOAT) extrudeAccel = hal.newsig('ve-extrude-accel', hal.HAL_FLOAT) extrudeAccelAdj = hal.newsig('ve-extrude-accel-adj', hal.HAL_FLOAT) extrudeRateAdj = hal.newsig('ve-extrude-rate-adj', hal.HAL_FLOAT) extruderEn = hal.newsig('ve-extruder-en', hal.HAL_BIT) retractVelNeg = hal.newsig('ve-retract-vel-neg', hal.HAL_FLOAT) retractTime = hal.newsig('ve-retract-time', hal.HAL_FLOAT) retract = hal.newsig('ve-retract', hal.HAL_BIT) extrudeVel = hal.newsig('ve-extrude-vel', hal.HAL_FLOAT) baseVel = hal.newsig('ve-base-vel', hal.HAL_FLOAT) nozzleVel.link('motion.current-vel') mult2 = rt.newinst('mult2', 'mult2.ve-cross-section') hal.addf(mult2.name, thread) mult2.pin('in0').link(lineWidth) mult2.pin('in1').link(lineHeight) mult2.pin('out').link(crossSectionIn) outToIo = rt.newinst('out_to_io', 'out-to-io.ve-cross-section') hal.addf(outToIo.name, thread) outToIo.pin('in-float').link(crossSectionIn) outToIo.pin('out-float').link(crossSection) # multiply area with speed and we get discharge (mm^3 per second) mult2 = rt.newinst('mult2', 'mult2.ve-nozzle-discharge') hal.addf(mult2.name, thread) mult2.pin('in0').link(crossSection) mult2.pin('in1').link(nozzleVel) mult2.pin('out').link(nozzleDischarge) # calculate filament cross section area # PI divided by 4 mult2 = rt.newinst('mult2', 'mult2.ve-filament-dia') hal.addf(mult2.name, thread) mult2.pin('in0').link(filamentDia) mult2.pin('in1').link(filamentDia) mult2.pin('out').link(filamentDiaSquared) mult2 = rt.newinst('mult2', 'mult2.ve-filament-area') hal.addf(mult2.name, thread) mult2.pin('in0').set(math.pi / 4) mult2.pin('in1').link(filamentDiaSquared) mult2.pin('out').link(filamentArea) # calculate extrude rate div2 = rt.newinst('div2', 'div2.ve-extrude-rate') hal.addf(div2.name, thread) div2.pin('in0').link(nozzleDischarge) div2.pin('in1').link(filamentArea) div2.pin('out').link(extrudeRate) # scale extrude rate mult2 = rt.newinst('mult2', 'mult2.ve-extrude-rate-scaled') hal.addf(mult2.name, thread) mult2.pin('in0').link(extrudeRate) mult2.pin('in1').link(extrudeScale) mult2.pin('out').link(extrudeRateScaled) # these are used for a small offset in velocity during acceleration (buildup pressure inside # the nozzle because of the current speed. Take the maximum accel you've specified in .ini # get acceleration into lincurve ddt = rt.newinst('ddt', 'ddt.ve-extruder-accel') hal.addf(ddt.name, thread) ddt.pin('in').link(extrudeRateScaled) ddt.pin('out').link(extrudeAccel) mult2 = rt.newinst('mult2', 'mult2.ve-extrude-accel-adj') hal.addf(mult2.name, thread) mult2.pin('in0').link(extrudeAccel) mult2.pin('in1').link(extrudeAccelAdjGain) mult2.pin('out').link(extrudeAccelAdj) # get adjusted speed for adding to current speed during acceleration sum2 = rt.newinst('sum2', 'sum2.ve-extrude-rate-adj') hal.addf(sum2.name, thread) sum2.pin('in0').link(extrudeRateScaled) sum2.pin('in1').link(extrudeAccelAdj) sum2.pin('out').link(extrudeRateAdj) # negative retract velocity neg = rt.newinst('neg', 'neg.ve-rectract-vel-neg') hal.addf(neg.name, thread) neg.pin('in').link(retractVel) neg.pin('out').link(retractVelNeg) # calculate retract time div2 = rt.newinst('div2', 'div2.ve-retract-time') hal.addf(div2.name, thread) div2.pin('in0').link(retractLen) div2.pin('in1').link(retractVel) div2.pin('out').link(retractTime) # We want the retract-charge to run for a fixed time: # when sel0 set to "1" meaning motion with extrusion" the on the rising edge # there will temporarily be also sel1 which is high, meaning a pre-charge because the # sel combination is 11 # when sel1 set to "0" meaning decoupling motion with extrusion" then the falling edge # will trigger a 01 combination, meaning a retract # trigger a retract/unretract move when extruder is enable or disabled oneshot = rt.newinst('oneshot', 'oneshot.ve-retract') hal.addf(oneshot.name, thread) oneshot.pin('rising').set(True) oneshot.pin('falling').set(True) oneshot.pin('retriggerable').set(True) oneshot.pin('width').link(retractTime) oneshot.pin('in').link(extruderEn) oneshot.pin('out').link(retract) retract += 'motion.feed-hold' # stop motion until retract/unretract finished # jogging needs to be inserted here velocity_jog(extruders, thread) # now the solution of Andy Pugh for automatically retracting/priming #00 = motion without extrusion, jog #01 = retract #10 = motion with extrusion #11 = unretract, pre-charge mux4 = rt.newinst('mux4', 'mux4.ve-extrude-vel') hal.addf(mux4.name, thread) mux4.pin('in0').link(baseVel) mux4.pin('in1').link(retractVelNeg) mux4.pin('in2').link(extrudeRateAdj) mux4.pin('in3').link(retractVel) mux4.pin('out').link(extrudeVel) mux4.pin('sel0').link(retract) mux4.pin('sel1').link(extruderEn) sections = [[retractLen, 'RETRACT_LEN'], [retractVel, 'RETRACT_VEL'], [filamentDia, 'FILAMENT_DIA'], [maxVelocity, 'MAX_VELOCITY'], [extrudeScale, 'EXTRUDE_SCALE']] for section in sections: ioMux = rt.newinst('io_muxn', 'io-mux%i.%s' % (extruders, section[0].name), pincount=extruders) hal.addf(ioMux.name, thread) ioMux.pin('out').link(section[0]) ioMux.pin('sel').link('extruder-sel') for n in range(0, extruders): signal = hal.newsig('%s-e%i' % (section[0].name, n), hal.HAL_FLOAT) ioMux.pin('in%i' % n).link(signal) signal.set(c.find('EXTRUDER_%i' % n, section[1])) extrudeAccelAdjGain.set(0.05) if baseVel.writers < 1: # can only write when jogging not configured baseVel.set(0.0) rcomps.create_ve_params_rcomp() storage.setup_ve_storage(extruders=extruders) motion.setup_ve_io()
def setup_hardware(thread): # PWM #hal.Pin('hm2_5i25.0.pwmgen.00.pwm_frequency').set(20000) # 100Hz # os.system('halcmd setp hm2_5i25.0.pwmgen.00.pwm_frequency 20000') # HBP # hal.Pin('hm2_5i25.0.pwmgen.00.enable').set(True) # hal.Pin('hm2_5i25.0.pwmgen.00.value').link('hbp-temp-pwm') # Spindle spindlespeed = hal.newsig('spindle-speed', hal.HAL_FLOAT) spindleon = hal.newsig('spindle-on', hal.HAL_BIT) spindlespeeddiv = hal.newsig('spindle-speed-20', hal.HAL_FLOAT) spindlepwmspeed = hal.newsig('spindle-pwm-speed', hal.HAL_FLOAT) spindlepwmspeedlimited = hal.newsig('spindle-pwm-speed-limited', hal.HAL_FLOAT) # spindlespeed.link('motion.spindle-speed-out-rps') spindlespeed.link('motion.spindle-speed-out') spindleon.link('motion.spindle-on') os.system('halcmd setp hm2_5i25.0.gpio.070.is_output true') # halold.Param('hm2_5i25.0.gpio.070.is_output').set(true) # os.system('halcmd setp hm2_5i25.0.gpio.071.invert_output true') hal.Pin('hm2_5i25.0.gpio.070.out').link(spindleon) ## hal.Pin('hm2_5i25.0.pwmgen.02.enable').set(True) hal.Pin('hm2_5i25.0.pwmgen.00.enable').link(spindleon) div2 = rt.newinst('div2', 'div2.spindlespeed-divfac') hal.addf(div2.name, 'servo-thread') div2.pin('in0').link(spindlespeed) div2.pin('in1').set(c.find('SPINDLE', 'DIVFACTOR')) div2.pin('out').link(spindlespeeddiv) sum2 = rt.newinst('sum2', 'sum2.spindle-speed-add') hal.addf(sum2.name, 'servo-thread') sum2.pin('in0').set(c.find('SPINDLE', 'ADDFACTOR')) sum2.pin('in1').link(spindlespeeddiv) sum2.pin('out').link(spindlepwmspeed) # limit1 = rt.newinst('limit1', 'limit1.spindle-pwm-speed-limited') # hal.addf(limit1.name, thread) # limit1.pin('in').link(spindlepwmspeed) # limit1.pin('out').link(spindlepwmspeedlimited) # limit1.pin('min').set(0.05) # prevent users from setting 0 as jog velocity # limit1.pin('max').set(c.find('SPINDLE', 'LIMIT')) # hal.Pin('hm2_5i25.0.pwmgen.00.value').link(spindlepwmspeedlimited) hal.Pin('hm2_5i25.0.pwmgen.00.value').link(spindlepwmspeed) os.system('halcmd setp hm2_5i25.0.gpio.018.invert_output true') # hal.Pin('hm2_5i25.0.gpio.018.invert_output').set(true) # hal.Param('hm2_5i25.0.pwmgen.00.scale').set(c.find('SPINDLE', 'MAXRPM')) # os.system('halcmd setp hm2_5i25.0.pwmgen.00.scale 12000') # cmd = "halcmd setp hm2_5i25.0.pwmgen.00.scale %s "%(c.find('SPINDLE', 'MAXRPM')) # os.system(cmd) os.system("halcmd setp hm2_5i25.0.pwmgen.00.scale %s " % (c.find('SPINDLE', 'MAXRPM'))) # configure extruders # for n in range(0, 1): # hal.Pin('hm2_5i25.0.pwmgen.%02i.enable' % (n + 1)).set(True) # hal.Pin('hm2_5i25.0.pwmgen.%02i.value' % (n + 1)).link('e%i-temp-pwm' % n) # configure fans # for n in range(0, 2): # hal.Pin('hm2_5i25.0.pwmgen.%02i.enable' % (n + 3)).link('f%i-pwm-enable' % n) # hal.Pin('hm2_5i25.0.pwmgen.%02i.value' % (n + 3)).link('f%i-pwm' % n) # hal.Signal('f%i-pwm-enable' % n).set(True) # configure exps # for n in range(0, 1): # hal.Pin('hm2_5i25.0.pwmgen.%02i.enable' % (n + 5)).link('exp%i-pwm-enable' % n) # hal.Pin('hm2_5i25.0.pwmgen.%02i.value' % (n + 5)).link('exp%i-pwm' % n) # hal.Signal('exp%i-pwm' % n).set(1.0) # configure leds # none # GPIO # Adjust as needed for your switch polarity hal.Pin('hm2_5i25.0.gpio.024.in_not').link('limit-0-home') # X hal.Pin('hm2_5i25.0.gpio.025.in').link('limit-1-0-home') # YL hal.Pin('hm2_5i25.0.gpio.026.in').link('limit-1-1-home') # YR hal.Pin('hm2_5i25.0.gpio.027.in_not').link('limit-2-home') # Z # hal.Pin('hm2_5i25.0.gpio.036.in_not').link('limit-0-max') # X # hal.Pin('hm2_5i25.0.gpio.026.in_not').link('limit-1-home') # Y # hal.Pin('hm2_5i25.0.gpio.030.in_not').link('limit-0-home') # X # hal.Pin('hm2_5i25.0.gpio.071.in_not').link('limit-0-home') # X # hal.Pin('hm2_5i25.0.gpio.024.in').link('limit-2-0-home') # ZLF # hal.Pin('hm2_5i25.0.gpio.025.in').link('limit-2-1-home') # ZRF # hal.Pin('hm2_5i25.0.gpio.026.in').link('limit-2-2-home') # ZLB # hal.Pin('hm2_5i25.0.gpio.027.in').link('limit-2-3-home') # ZRB # hal.Pin('hm2_5i25.0.gpio.024.in_not').link('limit-2-0-home') # ZLF # hal.Pin('hm2_5i25.0.gpio.025.in_not').link('limit-2-1-home') # ZRF # hal.Pin('hm2_5i25.0.gpio.026.in_not').link('limit-2-2-home') # ZLB # hal.Pin('hm2_5i25.0.gpio.027.in_not').link('limit-2-3-home') # ZRB # hal.Pin('hm2_5i25.0.gpio.025.in').link('limit-0-max') # X # hal.Pin('hm2_5i25.0.gpio.026.in').link('limit-1-home') # Y # hal.Pin('hm2_5i25.0.gpio.028.in').link('limit-2-0-home') # ZR # hal.Pin('hm2_5i25.0.gpio.029.in').link('limit-2-1-home') # ZL # probe ... 74CBTD3861 hal.Pin('hm2_5i25.0.capsense.00.trigged').link('probe-signal') # os.system('halcmd setp hm2_5i25.0.capsense.00.hysteresis 0x44444444') # hm2_5i25.0.pin('capsense.00.hysteresis').set(c.find('PROBE', 'HYSTERESIS')) # hm2_5i25.0.pin('capsense.00.hysteresis').set(0x44444444)) # hm2_5i25.0.pin('hysteresis').set(c.find('PROBE', 'HYSTERESIS')) # hm2_5i25.0.pin('hysteresis').set(17476) # hal.pin('hm2_5i25.0.capsense.00.hysteresis').set(1000)) # ADC # hal.Pin('hm2_5i25.0.nano_soc_adc.ch.0.out').link('temp.ch-00.input') # hal.Pin('hm2_5i25.0.nano_soc_adc.ch.1.out').link('temp.ch-01.input') # hal.Pin('hm2_5i25.0.nano_soc_adc.ch.2.out').link('temp.ch-02.input') # hal.Pin('hm2_5i25.0.nano_soc_adc.ch.3.out').link('temp.ch-03.input') # hal.Pin('temp.ch-00.value').link('hbp-temp-meas') # hal.Pin('temp.ch-01.value').link('e0-temp-meas') # hal.Pin('temp.ch-02.value').link('e1-temp-meas') # hal.Pin('temp.ch-03.value').link('e2-temp-meas') # machine power os.system('halcmd setp hm2_5i25.0.gpio.033.is_output true') hal.Pin('hm2_5i25.0.gpio.033.out').link('emcmot-0-enable') # Monitor estop input from hardware hal.Pin('hm2_5i25.0.gpio.034.in_not').link('estop-in') # drive estop-sw os.system('halcmd setp hm2_5i25.0.gpio.035.is_output true') os.system('halcmd setp hm2_5i25.0.gpio.035.invert_output true') hal.Pin('hm2_5i25.0.gpio.035.out').link('estop-out') # Tie machine power signal to the Parport Cape LED # Feel free to tie any other signal you like to the LED os.system('halcmd setp hm2_5i25.0.gpio.031.is_output true') hal.Pin('hm2_5i25.0.gpio.031.out').link('emcmot-0-enable') # link emcmot.xx.enable to stepper driver enable signals os.system('halcmd setp hm2_5i25.0.gpio.032.is_output true') os.system('halcmd setp hm2_5i25.0.gpio.032.invert_output true') hal.Pin('hm2_5i25.0.gpio.032.out').link('emcmot-0-enable')
def __init__(self, temp_hal, pwm_pin, on_pin, enable_sig, estop_reset_sig, config_name, comp_name, hal_name, motion_pin_number): self.temp_hal = temp_hal comp = hal.RemoteComponent(comp_name, timer=100) comp_limit_min_pin = comp.newpin('temp.limit.min', hal.HAL_FLOAT, hal.HAL_IN) comp_limit_max_pin = comp.newpin('temp.limit.max', hal.HAL_FLOAT, hal.HAL_IN) comp_standby_pin = comp.newpin('temp.standby', hal.HAL_FLOAT, hal.HAL_IN) comp_meas_pin = comp.newpin('temp.meas', hal.HAL_FLOAT, hal.HAL_IN) comp_set_pin = comp.newpin('temp.set', hal.HAL_FLOAT, hal.HAL_IO) comp_in_range_pin = comp.newpin('temp.in-range', hal.HAL_BIT, hal.HAL_IN) comp_active_pin = comp.newpin('active', hal.HAL_BIT, hal.HAL_IN) comp_error_pin = comp.newpin('error', hal.HAL_BIT, hal.HAL_IN) comp.ready() # -- General Signals -- meas_sig = hal.newsig('%s.meas' % hal_name, hal.HAL_FLOAT) meas_sig.link(temp_hal.pin('value')) meas_sig.link(comp_meas_pin) meas_sig.link('motion.analog-in-%02d' % motion_pin_number) set_sig = hal.newsig('%s.set' % hal_name, hal.HAL_FLOAT) set_sig.link(comp_set_pin) set_sig.link('motion.analog-out-io-%02d' % motion_pin_number) limit_min_sig = hal.newsig('%s.limit.min' % hal_name, hal.HAL_FLOAT) limit_min_sig.link(comp_limit_min_pin) limit_min_sig.set(config.find(config_name, 'TEMP_LIMIT_MIN', 0.0)) limit_max_sig = hal.newsig('%s.limit.max' % hal_name, hal.HAL_FLOAT) limit_max_sig.link(comp_limit_max_pin) limit_max_sig.set(config.find(config_name, 'TEMP_LIMIT_MAX', 30.0)) standby_sig = hal.newsig('%s.standby' % hal_name, hal.HAL_FLOAT) standby_sig.link(comp_standby_pin) standby_sig.set(config.find(config_name, 'TEMP_STANDBY', 15.0)) on_sig = hal.newsig('%s.on' % hal_name, hal.HAL_BIT) on_sig.link(on_pin) on_sig.link(comp_active_pin) error_sig = hal.newsig('%s.error' % hal_name, hal.HAL_BIT) self.error_sig = error_sig error_sig.link(comp_error_pin) self.temp_watchdog_sig = hal.newsig('%s.watchdog' % hal_name, hal.HAL_BIT) temp_hal.pin('watchdog').link(self.temp_watchdog_sig) # -- Measurement -- # In-Range Signal in_range_sig = hal.newsig('%s.in-range' % hal_name, hal.HAL_BIT) in_range_sig.link(comp_in_range_pin) in_range_sig.link('motion.digital-in-%02d' % motion_pin_number) range_lb_sum = rtapi.newinst('sum2', '%s.range.lb.sum2' % hal_name) hal.addf(range_lb_sum.name, SERVO_THREAD) range_ub_sum = rtapi.newinst('sum2', '%s.range.ub.sum2' % hal_name) hal.addf(range_ub_sum.name, SERVO_THREAD) range_lb_sig = hal.newsig('%s.range.lb' % hal_name, hal.HAL_FLOAT) range_ub_sig = hal.newsig('%s.range.ub' % hal_name, hal.HAL_FLOAT) range_lb_sum.pin('in0').link(set_sig) range_lb_sum.pin('in1').set(float(config.find(config_name, 'TEMP_RANGE_NEG_ERROR', -1.0))) range_lb_sum.pin('out').link(range_lb_sig) range_ub_sum.pin('in0').link(set_sig) range_ub_sum.pin('in1').set(float(config.find(config_name, 'TEMP_RANGE_POS_ERROR', 1.0))) range_ub_sum.pin('out').link(range_ub_sig) range_wcomp = rtapi.newinst('wcomp', '%s.range.wcomp' % hal_name) hal.addf(range_wcomp.name, SERVO_THREAD) range_wcomp.pin('min').link(range_lb_sig) range_wcomp.pin('max').link(range_ub_sig) range_wcomp.pin('in').link(meas_sig) range_wcomp.pin('out').link(in_range_sig) # -- Output -- pwm_raw_sig = hal.newsig('%s.pwm_raw' % hal_name, hal.HAL_FLOAT) pwm_sig = hal.newsig('%s.pwm' % hal_name, hal.HAL_FLOAT) pwm_max = float(config.find(config_name, 'PWM_MAX', 1.0)) # PID pid = rtapi.newinst('at_pid', '%s.pid' % hal_name) hal.addf(pid.name + '.do-pid-calcs', SERVO_THREAD) pid.pin('enable').link(enable_sig) pid.pin('feedback').link(meas_sig) pid.pin('command').link(set_sig) pid.pin('output').link(pwm_raw_sig) pid.pin('maxoutput').set(pwm_max) pid.pin('Pgain').set(float(config.find(config_name, 'PID_PGAIN', 0))) pid.pin('Igain').set(float(config.find(config_name, 'PID_IGAIN', 0))) pid.pin('Dgain').set(float(config.find(config_name, 'PID_DGAIN', 0))) pid.pin('maxerrorI').set(float(config.find(config_name, 'PID_MAXERRORI', 1.0))) pid.pin('bias').set(float(config.find(config_name, 'PID_BIAS', 0.0))) # PWM Limit (PID can output negative values) pwm_limit = rtapi.newinst('limit1', '%s.limit1.pwm' % hal_name) hal.addf(pwm_limit.name, SERVO_THREAD) pwm_limit.pin('min').set(0.0) pwm_limit.pin('max').set(pwm_max) pwm_limit.pin('in').link(pwm_raw_sig) pwm_limit.pin('out').link(pwm_sig) pwm_pin.link(pwm_sig) # -- Safety Check -- check_limit_ok_sig = hal.newsig('%s.check.limit-ok' % hal_name, hal.HAL_BIT) limit_wcomp = rtapi.newinst('wcomp', '%s.check.limit.wcomp' % hal_name) hal.addf(limit_wcomp.name, SERVO_THREAD) limit_wcomp.pin('min').link(limit_min_sig) limit_wcomp.pin('max').link(limit_max_sig) limit_wcomp.pin('in').link(meas_sig) limit_wcomp.pin('out').link(check_limit_ok_sig) out_range_sig = hal.newsig('%s.out-range' % hal_name, hal.HAL_BIT) out_range_not = rtapi.newinst('not', '%s.out-range.not' % hal_name) hal.addf(out_range_not.name, SERVO_THREAD) out_range_not.pin('in').link(in_range_sig) out_range_not.pin('out').link(out_range_sig) thermistor_check_enable_sig = hal.newsig('%s.check.therm.enable' % hal_name, hal.HAL_BIT) thermistor_check_enable_and = rtapi.newinst('and2', '%s.check.therm.enable.and2' % hal_name) hal.addf(thermistor_check_enable_and.name, SERVO_THREAD) thermistor_check_enable_and.pin('in0').link(enable_sig) thermistor_check_enable_and.pin('in1').link(out_range_sig) thermistor_check_enable_and.pin('out').link(thermistor_check_enable_sig) check_thermistor_ok_sig = hal.newsig('%s.check.therm-ok' % hal_name, hal.HAL_BIT) thermistor_check = rtapi.newinst('thermistor_check', '%s.check.therm-check' % hal_name) hal.addf(thermistor_check.name, SERVO_THREAD) thermistor_check.pin('enable').link(thermistor_check_enable_sig) thermistor_check.pin('pid').link(pwm_sig) thermistor_check.pin('temp').link(meas_sig) thermistor_check.pin('min-pid').set(float(config.find(config_name, 'CHECK_MIN_PID', 0.25))) thermistor_check.pin('min-temp').set(float(config.find(config_name, 'CHECK_MIN_TEMP', 2.0))) thermistor_check.pin('wait').set(float(config.find(config_name, 'CHECK_WAIT', 30.0))) thermistor_check.pin('no-error').link(check_thermistor_ok_sig) check_all_ok_sig = hal.newsig('%s.check.all-ok' % hal_name, hal.HAL_BIT) check_all_ok = rtapi.newinst('and2', '%s.check.all.and2' % hal_name) hal.addf(check_all_ok.name, SERVO_THREAD) check_all_ok.pin('in0').link(check_limit_ok_sig) check_all_ok.pin('in1').link(check_thermistor_ok_sig) check_all_ok.pin('out').link(check_all_ok_sig) check_error_sig = hal.newsig('%s.check.error' % hal_name, hal.HAL_BIT) check_error = rtapi.newinst('not', '%s.check.error.not' % hal_name) hal.addf(check_error.name, SERVO_THREAD) check_error.pin('in').link(check_all_ok_sig) check_error.pin('out').link(check_error_sig) error_latch = rtapi.newinst('flipflop', '%s.check.error.flipflop' % hal_name) hal.addf(error_latch.name, SERVO_THREAD) error_latch.pin('set').link(check_error_sig) error_latch.pin('reset').link(estop_reset_sig) error_latch.pin('out').link(error_sig)
name='storage', file='storage.ini', autosave=True, wait_name='storage') def readStorage(): hal.Pin('storage.read-trigger').set(True) # trigger read rt.init_RTAPI() c.load_ini('hardware.ini') rt.loadrt('hal_bb_gpio', output_pins='915,917,838,840') rt.loadrt('hal_arm335xQEP', encoders='eQEP0,eQEP2') rt.loadrt(c.find('PRUCONF', 'DRIVER'), 'prucode=' + c.find('PRUCONF', 'PRUBIN'), pru=0, num_pwmgens=7, halname='hpg') # storage setupStorage() # pru pwmgens hal.Pin('hpg.pwmgen.00.pwm_period').set(500000) # motor left hal.Pin('hpg.pwmgen.00.out.00.pin').set(911) hal.Pin('hpg.pwmgen.00.out.01.pin').set(913) # motor right hal.Pin('hpg.pwmgen.00.out.02.pin').set(808)
# HAL file for BeagleBone + TCT paralell port cape with 5 steppers and 3D printer board import os from machinekit import rtapi as rt from machinekit import hal from machinekit import config as c from config import base from config import motion # initialize the RTAPI command client rt.init_RTAPI() # loads the ini file passed by linuxcnc c.load_ini(os.environ['INI_FILE_NAME']) motion.setup_motion(kinematics=c.find('KINS','KINEMATICS')) # reading functions hal.addf('motion-command-handler', 'servo-thread') # Axis-of-motion Specific Configs (not the GUI) # X [0] Axis base.setup_stepper(section='AXIS_0', axisIndex=0, stepgenIndex=0, stepgenType='sim') # Y [1] Axis base.setup_stepper(section='AXIS_1', axisIndex=1, stepgenIndex=1, stepgenType='sim') # Z [2] Axis base.setup_stepper(section='AXIS_2', axisIndex=2, stepgenIndex=2, stepgenType='sim') # Z [2] Axis base.setup_stepper(section='AXIS_3', axisIndex=3, stepgenIndex=3, stepgenType='sim') # Z [2] Axis base.setup_stepper(section='AXIS_4', axisIndex=4, stepgenIndex=4, stepgenType='sim')
# initialize the RTAPI command client rt.init_RTAPI() # loads the ini file passed by linuxcnc c.load_ini(os.environ['INI_FILE_NAME']) motion.setup_motion() hardware.init_hardware() storage.init_storage('storage.ini') # reading functions hardware.hardware_read() hal.addf('motion-command-handler', 'servo-thread') hal.addf('motion-controller', 'servo-thread') numFans = c.find('FDM', 'NUM_FANS') numExtruders = c.find('FDM', 'NUM_EXTRUDERS') numLights = c.find('FDM', 'NUM_LIGHTS') hasHbp = c.find('FDM', 'HAS_HBP') # Axis-of-motion Specific Configs (not the GUI) ve.velocity_extrusion(extruders=numExtruders, thread='servo-thread') # X [0] Axis base.setup_stepper(section='AXIS_0', axisIndex=0, stepgenIndex=0, thread='servo-thread') # Y [1] Axis base.setup_stepper(section='AXIS_1', axisIndex=1, stepgenIndex=1, thread='servo-thread') # Z [2] Axis base.setup_stepper(section='AXIS_2', axisIndex=2, stepgenIndex=2, thread='servo-thread') # Extruder, velocity controlled for i in range(0, numExtruders): base.setup_stepper(section='EXTRUDER_%i' % i, stepgenIndex=3,
def init_hardware(): config.load_ini(os.environ['INI_FILE_NAME']) check_version() # we need to make the gpio pins used by the pru visible to userspace (??) in /sys/class/gpio os.system('sudo ' + HARDWARE_PATH + 'set_pru_gpio.sh') rtapi.init_RTAPI() error_sigs = [] watchdog_sigs = [] global AXIS_TOTAL AXIS_TOTAL = int(config.find('TRAJ', 'AXES', '3')) if AXIS_TOTAL < 3: raise RuntimeError("AXES must be >= 3") global EXTRUDER_TOTAL EXTRUDER_TOTAL = int(config.find('FDM', 'EXTRUDERS', '1')) if EXTRUDER_TOTAL < 1: raise RuntimeError("EXTRUDERS must be >= 1") global NUM_FANS NUM_FANS = int(config.find('FDM','NUM_FANS', 4)) system_fan = int(config.find('FDM','SYSTEM_FAN', 0)) if (NUM_FANS < system_fan): raise RuntimeError("NUM_FANS must be >= 1 if SYSTEM_FAN > 0") if (NUM_FANS > 4) or (NUM_FANS < 0 ): raise RuntimeError("NUM_FANS must be > 0 and < 5") rtapi.loadrt('tp') if config.find('MACHINE','DELTA_R') is not None: kinematics = 'lineardeltakins' rtapi.loadrt(kinematics) hal.Pin('lineardeltakins.L').set(config.find('MACHINE', 'CF_ROD')) hal.Pin('lineardeltakins.R').set(config.find('MACHINE', 'DELTA_R')) else: kinematics = 'trivkins' rtapi.loadrt(kinematics) rtapi.loadrt(config.find('EMCMOT', 'EMCMOT'), servo_period_nsec=config.find('EMCMOT', 'SERVO_PERIOD'), num_joints=str(AXIS_TOTAL), num_aio=51, num_dio=21, kins = kinematics) hal.addf('motion-command-handler', SERVO_THREAD) hal.addf('motion-controller', SERVO_THREAD) estop_reset = hal.newsig('estop-reset', hal.HAL_BIT) (main_enable, main_enable_inv) = setup_enable_chain() if BOARD_REV == 'B3A': replicape = hardware.ReplicapeB3A() if BOARD_REV == 'A4A': replicape = hardware.ReplicapeA4A() watchdog_sigs.extend(replicape.get_watchdog_sigs()) replicape.link_enable(main_enable, main_enable_inv) (joint_commands, joint_feedbacks) = setup_joints() for i in xrange(AXIS_TOTAL): setup_axis(replicape, joint_commands[i], joint_feedbacks[i], i) setup_limit_switches(replicape) extruder_sel_sig = hal.newsig('extruder-sel', hal.HAL_S32) setup_extruders(replicape, extruder_sel_sig) for i in xrange(EXTRUDER_TOTAL): t = ExtruderTemperature(replicape, i, main_enable, estop_reset) error_sigs.append(t.get_error_sig()) watchdog_sigs.append(t.get_temp_watchdog_sig()) if config.find('HBP', 'THERMISTOR'): t = HbpTemperature(replicape, main_enable, estop_reset) error_sigs.append(t.get_error_sig()) watchdog_sigs.append(t.get_temp_watchdog_sig()) # setup_system_fan(replicape) setup_fans(replicape) setup_estop(error_sigs, watchdog_sigs, estop_reset, SERVO_THREAD) connect_tool_changer()
ENC_A = io_map[20] EN1 = io_map[21] EN2 = io_map[22] IN1 = io_map[23] IN2 = io_map[24] output_pins = [EN1, EN2] input_pins = [IS1, IS2] output_pins_joined = ','.join(str(x) for x in output_pins) input_pins_joined = ','.join(str(x) for x in input_pins) rt.loadrt('hal_bb_gpio', output_pins=output_pins_joined, input_pins=input_pins_joined) rt.loadrt(c.find('PRUCONF', 'DRIVER'), 'prucode={}/{}'.format(c.Config().EMC2_RTLIB_DIR, c.find('PRUCONF', 'PRUBIN')), pru=0, num_stepgens=0, num_pwmgens=2, num_encoders=1, halname='hpg') hpg = hal.Component('hpg') hpg.pin('pwmgen.00.out.00.pin').set(IN1) hpg.pin('pwmgen.00.out.01.pin').set(IN2) hpg.pin('encoder.00.chan.00.A-pin').set(pru0_input_pins[ENC_A]) hpg.pin('encoder.00.chan.00.B-pin').set(pru0_input_pins[ENC_B]) hpg.pin('encoder.00.chan.00.index-pin').set(17) # ignore
def create_temperature_control(name, section, thread, hardwareOkSignal=None, coolingFan=None, hotendFan=None): tempSet = hal.newsig('%s-temp-set' % name, hal.HAL_FLOAT) tempMeas = hal.newsig('%s-temp-meas' % name, hal.HAL_FLOAT) tempInRange = hal.newsig('%s-temp-in-range' % name, hal.HAL_BIT) tempPwm = hal.newsig('%s-temp-pwm' % name, hal.HAL_FLOAT) tempPwmMax = hal.newsig('%s-temp-pwm-max' % name, hal.HAL_FLOAT) tempLimitMin = hal.newsig('%s-temp-limit-min' % name, hal.HAL_FLOAT) tempLimitMax = hal.newsig('%s-temp-limit-max' % name, hal.HAL_FLOAT) tempStandby = hal.newsig('%s-temp-standby' % name, hal.HAL_FLOAT) tempInLimit = hal.newsig('%s-temp-in-limit' % name, hal.HAL_BIT) tempThermOk = hal.newsig('%s-temp-therm-ok' % name, hal.HAL_BIT) error = hal.newsig('%s-error' % name, hal.HAL_BIT) active = hal.newsig('%s-active' % name, hal.HAL_BIT) tempPidPgain = hal.newsig('%s-temp-pid-Pgain' % name, hal.HAL_FLOAT) tempPidIgain = hal.newsig('%s-temp-pid-Igain' % name, hal.HAL_FLOAT) tempPidDgain = hal.newsig('%s-temp-pid-Dgain' % name, hal.HAL_FLOAT) tempPidMaxerrorI = hal.newsig('%s-temp-pid-maxerrorI' % name, hal.HAL_FLOAT) tempPidOut = hal.newsig('%s-temp-pid-out' % name, hal.HAL_FLOAT) tempPidBias = hal.newsig('%s-temp-pid-bias' % name, hal.HAL_FLOAT) tempRangeMin = hal.newsig('%s-temp-range-min' % name, hal.HAL_FLOAT) tempRangeMax = hal.newsig('%s-temp-range-max' % name, hal.HAL_FLOAT) noErrorIn = hal.newsig('%s-no-error-in' % name, hal.HAL_BIT) errorIn = hal.newsig('%s-error-in' % name, hal.HAL_BIT) # reset set temperature when estop is cleared reset = rt.newinst('reset', 'reset.%s-temp-set' % name) hal.addf(reset.name, thread) reset.pin('reset-float').set(0.0) reset.pin('out-float').link(tempSet) reset.pin('rising').set(True) reset.pin('falling').set(False) reset.pin('trigger').link('estop-reset') tempPidBiasOut = tempPidBias # coolingFan compensation if coolingFan: tempPidFanBias = hal.newsig('%s-temp-pid-fan-bias' % name, hal.HAL_FLOAT) tempPidBiasOut = hal.newsig('%s-temp-pid-bias-out' % name, hal.HAL_FLOAT) scale = rt.newinst('scale', 'scale.%s-temp-pid-fan-bias' % name) hal.addf(scale.name, thread) scale.pin('in').link('%s.pwm' % coolingFan) scale.pin('out').link(tempPidFanBias) scale.pin('gain').set(c.find(section, 'FAN_BIAS')) sum2 = rt.newinst('sum2', 'sum2.%s-temp-pid-bias' % name) hal.addf(sum2.name, thread) sum2.pin('in0').link(tempPidBias) sum2.pin('in1').link(tempPidFanBias) sum2.pin('out').link(tempPidBiasOut) # PID pid = rt.newinst('pid', 'pid.%s' % name) hal.addf('%s.do-pid-calcs' % pid.name, thread) pid.pin('enable').link('emcmot-0-enable') # motor enable pid.pin('feedback').link(tempMeas) pid.pin('command').link(tempSet) pid.pin('output').link(tempPidOut) pid.pin('maxoutput').link(tempPwmMax) pid.pin('bias').link(tempPidBias) pid.pin('Pgain').link(tempPidPgain) pid.pin('Igain').link(tempPidIgain) pid.pin('Dgain').link(tempPidDgain) pid.pin('maxerrorI').link(tempPidMaxerrorI) # Limit heater PWM to positive values # PWM mimics hm2 implementation, which generates output for negative values limit1 = rt.newinst('limit1', 'limit.%s-temp-heaterl' % name) hal.addf(limit1.name, thread) limit1.pin('in').link(tempPidOut) limit1.pin('out').link(tempPwm) limit1.pin('min').set(0.0) limit1.pin('max').link(tempPwmMax) # Temperature checking sum2 = rt.newinst('sum2', 'sum2.%s-temp-range-pos' % name) hal.addf(sum2.name, thread) sum2.pin('in0').link(tempSet) sum2.pin('in1').set(c.find(section, 'TEMP_RANGE_POS_ERROR')) sum2.pin('out').link(tempRangeMax) sum2 = rt.newinst('sum2', 'sum2.%s-temp-range-neg' % name) hal.addf(sum2.name, thread) sum2.pin('in0').link(tempSet) sum2.pin('in1').set(c.find(section, 'TEMP_RANGE_NEG_ERROR')) sum2.pin('out').link(tempRangeMin) #the output of this component will say if measured temperature is in range of set value wcomp = rt.newinst('wcomp', 'wcomp.%s-temp-in-range' % name) hal.addf(wcomp.name, thread) wcomp.pin('min').link(tempRangeMin) wcomp.pin('max').link(tempRangeMax) wcomp.pin('in').link(tempMeas) wcomp.pin('out').link(tempInRange) # limit the output temperature to prevent damage when thermistor is broken/removed wcomp = rt.newinst('wcomp', 'wcomp.%s-temp-in-limit' % name) hal.addf(wcomp.name, thread) wcomp.pin('min').link(tempLimitMin) wcomp.pin('max').link(tempLimitMax) wcomp.pin('in').link(tempMeas) wcomp.pin('out').link(tempInLimit) # check the thermistor # net e0.temp.meas => thermistor-check.e0.temp # net e0.temp.in-range => not.e0-temp-range.in # net e0.temp.in-range_n <= not.e0-temp-range.out # net e0.temp.in-range_n => thermistor-check.e0.enable # net e0.heaterl => thermistor-check.e0.pid # net e0.therm-ok <= thermistor-check.e0.no-error # no error chain and3 = rt.newinst('andn', 'and3.%s-no-error-in' % name, pincount=3) hal.addf(and3.name, thread) and3.pin('in0').link(tempThermOk) and3.pin('in1').link(tempInLimit) if hardwareOkSignal: and3.pin('in2').link(hardwareOkSignal) else: and3.pin('in2').set(True) and3.pin('out').link(noErrorIn) tempThermOk.set(True) # thermistor checking for now disabled notComp = rt.newinst('not', 'not.%s-error-in' % name) hal.addf(notComp.name, thread) notComp.pin('in').link(noErrorIn) notComp.pin('out').link(errorIn) safetyLatch = rt.newinst('safety_latch', 'safety-latch.%s-error' % name) hal.addf(safetyLatch.name, thread) safetyLatch.pin('error-in').link(errorIn) safetyLatch.pin('error-out').link(error) safetyLatch.pin('reset').link('estop-reset') safetyLatch.pin('threshold').set(500) # 500ms error safetyLatch.pin('latching').set(True) # active chain comp = rt.newinst('comp', 'comp.%s-active' % name) hal.addf(comp.name, thread) comp.pin('in0').set(0.0001) comp.pin('hyst').set(0.0) comp.pin('in1').link(tempPwm) comp.pin('out').link(active) # Thermistor checking # setp thermistor-check.e0.wait 9.0 # setp thermistor-check.e0.min-pid 1.5 # disable0.25 # setp thermistor-check.e0.min-temp 1.5 # net e0.pid.bias => thermistor-check.e0.bias # Hotend fan if hotendFan: comp = rt.newinst('comp', 'comp.%s-pwm-enable' % hotendFan) hal.addf(comp.name, thread) comp.pin('in0').set(c.find(section, 'HOTEND_FAN_THRESHOLD', 50.0)) comp.pin('in1').link(tempMeas) comp.pin('hyst').set(c.find(section, 'HOTEND_FAN_HYST', 2.0)) comp.pin('out').link('%s-pwm-enable' % hotendFan) hal.Signal('%s-pwm' % hotendFan).set(1.0) rcomps.create_temperature_rcomp(name) motion.setup_temperature_io(name) # init parameter signals tempLimitMin.set(c.find(section, 'TEMP_LIMIT_MIN')) tempLimitMax.set(c.find(section, 'TEMP_LIMIT_MAX')) tempStandby.set(c.find(section, 'TEMP_STANDBY')) tempPwmMax.set(c.find(section, 'PWM_MAX')) tempPidPgain.set(c.find(section, 'PID_PGAIN')) tempPidIgain.set(c.find(section, 'PID_IGAIN')) tempPidDgain.set(c.find(section, 'PID_DGAIN')) tempPidMaxerrorI.set(c.find(section, 'PID_MAXERRORI')) tempPidBias.set(c.find(section, 'PID_BIAS'))
logging.debug("starting motion") motion.setup_motion() logging.debug("motion should be started") hardware.init_hardware() logging.debug("done init") storage.init_storage('storage.ini') # reading functions hw = True if hw: hardware.hardware_read() hal.addf('motion-command-handler', 'servo-thread') hal.addf('motion-controller', 'servo-thread') numFans = c.find('FDM', 'NUM_FANS') numExtruders = c.find('FDM', 'NUM_EXTRUDERS') numLights = c.find('FDM', 'NUM_LIGHTS') logging.debug("fans %i extruders %i lights %i" % (numFans, numExtruders, numLights)) #raw_input() # Axis-of-motion Specific Configs (not the GUI) ve.velocity_extrusion(extruders=numExtruders, thread='servo-thread') # X [0] Axis base.setup_stepper(section='AXIS_0', stepgenType='hps', axisIndex=0, velocitySignal=None, stepgenIndex=0, thread='servo-thread') # Y [1] Axis
def setup_joints(): """ Create joints commands and feedbacks signal for the system """ commands = [None] * AXIS_TOTAL feedbacks = [None] * AXIS_TOTAL for i in xrange(AXIS_TOTAL): commands[i] = hal.newsig('machine.joint.%d.command' % i, hal.HAL_FLOAT) feedbacks[i] = hal.newsig('machine.joint.%d.feedback' % i, hal.HAL_FLOAT) core_xy = config.find('FDM','CORE_XY') if core_xy is not None and int(core_xy) > 0: sum_cmd_a = rtapi.newinst('sum2', 'corexy.sum2.cmd.a') sum_fb_x = rtapi.newinst('sum2', 'corexy.sum2.fb.x') sum_cmd_b = rtapi.newinst('sum2', 'corexy.sum2.cmd.b') sum_fb_y = rtapi.newinst('sum2', 'corexy.sum2.fb.y') hal.addf(sum_cmd_a.name, SERVO_THREAD) hal.addf(sum_cmd_b.name, SERVO_THREAD) hal.addf(sum_fb_x.name, SERVO_THREAD) hal.addf(sum_fb_y.name, SERVO_THREAD) sum_cmd_a.pin('gain0').set(1) sum_cmd_a.pin('gain1').set(1) sum_cmd_b.pin('gain0').set(1) sum_cmd_b.pin('gain1').set(-1) sum_fb_x.pin('gain0').set(0.5) sum_fb_x.pin('gain1').set(0.5) sum_fb_y.pin('gain0').set(0.5) sum_fb_y.pin('gain1').set(-0.5) corex_cmd = hal.newsig('machine.joint.corex.command', hal.HAL_FLOAT) corey_cmd = hal.newsig('machine.joint.corey.command', hal.HAL_FLOAT) corex_cmd.link('axis.0.motor-pos-cmd') corey_cmd.link('axis.1.motor-pos-cmd') sum_cmd_a.pin('in0').link(corex_cmd) sum_cmd_a.pin('in1').link(corey_cmd) sum_cmd_b.pin('in0').link(corex_cmd) sum_cmd_b.pin('in1').link(corey_cmd) sum_cmd_a.pin('out').link(commands[0]) sum_cmd_b.pin('out').link(commands[1]) sum_fb_x.pin('in0').link(feedbacks[0]) sum_fb_x.pin('in1').link(feedbacks[1]) sum_fb_y.pin('in0').link(feedbacks[0]) sum_fb_y.pin('in1').link(feedbacks[1]) sum_fb_x.pin('out').link('axis.0.motor-pos-fb') sum_fb_y.pin('out').link('axis.1.motor-pos-fb') else: commands[0].link('axis.0.motor-pos-cmd') feedbacks[0].link('axis.0.motor-pos-fb') commands[1].link('axis.1.motor-pos-cmd') feedbacks[1].link('axis.1.motor-pos-fb') for i in xrange(AXIS_TOTAL): if i >= 2: commands[i].link('axis.%d.motor-pos-cmd' % i) feedbacks[i].link('axis.%d.motor-pos-fb' % i) return (commands, feedbacks)
def init_hardware(): check_version() rtapi.init_RTAPI() config.load_ini(os.environ['INI_FILE_NAME']) error_sigs = [] watchdog_sigs = [] global AXIS_TOTAL AXIS_TOTAL = int(config.find('TRAJ', 'AXES', '3')) if AXIS_TOTAL < 3: raise RuntimeError("AXES must be >= 3") global EXTRUDER_TOTAL EXTRUDER_TOTAL = int(config.find('FDM', 'EXTRUDERS', '1')) if EXTRUDER_TOTAL < 1: raise RuntimeError("EXTRUDERS must be >= 1") rtapi.loadrt('tp') rtapi.loadrt('trivkins') rtapi.loadrt(config.find('EMCMOT', 'EMCMOT'), servo_period_nsec=config.find('EMCMOT', 'SERVO_PERIOD'), num_joints=str(AXIS_TOTAL), num_aio=51, num_dio=21) hal.addf('motion-command-handler', SERVO_THREAD) hal.addf('motion-controller', SERVO_THREAD) estop_reset = hal.newsig('estop-reset', hal.HAL_BIT) (main_enable, main_enable_inv) = setup_enable_chain() if BOARD_REV == 'B3A': replicape = hardware.ReplicapeB3A() if BOARD_REV == 'A4A': replicape = hardware.ReplicapeA4A() watchdog_sigs.extend(replicape.get_watchdog_sigs()) replicape.link_enable(main_enable, main_enable_inv) (joint_commands, joint_feedbacks) = setup_joints() for i in xrange(AXIS_TOTAL): setup_axis(replicape, joint_commands[i], joint_feedbacks[i], i) setup_limit_switches(replicape) extruder_sel_sig = hal.newsig('extruder-sel', hal.HAL_S32) setup_extruders(replicape, extruder_sel_sig) for i in xrange(EXTRUDER_TOTAL): t = ExtruderTemperature(replicape, i, main_enable, estop_reset) error_sigs.append(t.get_error_sig()) watchdog_sigs.append(t.get_temp_watchdog_sig()) if config.find('HBP', 'THERMISTOR'): t = HbpTemperature(replicape, main_enable, estop_reset) error_sigs.append(t.get_error_sig()) watchdog_sigs.append(t.get_temp_watchdog_sig()) setup_system_fan(replicape) setup_estop(error_sigs, watchdog_sigs, estop_reset, SERVO_THREAD) connect_tool_changer()
# initialize the RTAPI command client rt.init_RTAPI() # loads the ini file passed by linuxcnc c.load_ini(os.environ['INI_FILE_NAME']) motion.setup_motion() hardware.init_hardware() storage.init_storage('storage.ini') # reading functions hardware.hardware_read() hal.addf('motion-command-handler', 'servo-thread') hal.addf('motion-controller', 'servo-thread') numFans = c.find('FDM', 'NUM_FANS') numExtruders = c.find('FDM', 'NUM_EXTRUDERS') numLights = c.find('FDM', 'NUM_LIGHTS') # Axis-of-motion Specific Configs (not the GUI) ve.velocity_extrusion(extruders=numExtruders, thread='servo-thread') # X [0] Axis base.setup_stepper(section='AXIS_0', axisIndex=0, stepgenIndex=0, thread='servo-thread') # Y [1] Axis base.setup_stepper(section='AXIS_1', axisIndex=1, stepgenIndex=1, thread='servo-thread') # Z [2] Axis base.setup_stepper(section='AXIS_2', axisIndex=2, stepgenIndex=2, thread='servo-thread') # Extruder, velocity controlled for i in range(0, numExtruders): base.setup_stepper(section='EXTRUDER_%i' % i, stepgenIndex=3, velocitySignal='ve-extrude-vel', thread='servo-thread')
def init_hardware(): watchList = [] # load low-level drivers rt.loadrt('hal_bb_gpio', output_pins='807,819,826,926', input_pins='941') prubin = '%s/%s' % (c.Config().EMC2_RTLIB_DIR, c.find('PRUCONF', 'PRUBIN')) rt.loadrt(c.find('PRUCONF', 'DRIVER'), pru=0, num_stepgens=5, num_pwmgens=0, prucode=prubin, halname='hpg') # Python user-mode HAL module to interface with an I2C gpio extender hal.loadusr('hal_gpio_mcp23017', name='i2c-gpio', bus_id=2, address=32, interval=0.05, delay=2.5, input_pins='A00,A01,A02,A03,A04,A05,A06,A07,B06,B07', output_pins='B00,B01,B02,B03,B04,B05', wait_name='i2c-gpio') watchList.append(['i2c-gpio', 0.1]) # Python user-mode HAL module to interface with an I2C PWM generator hal.loadusr('hal_pwm_pca9685', name='i2c-pwm', bus_id=2, address=67, interval=0.1, delay=2.6, wait_name='i2c-pwm') watchList.append(['i2c-pwm', 0.2]) # Python user-mode HAL module to interface with an I2C ADC and convert it to temperature defaultThermistor = 'semitec_103GT_2' hal.loadusr( 'hal_temp_ads7828', name='i2c-temp', bus_id=2, address=72, interval=0.05, delay=2.7, filter_size=1, channels='00:%s,01:%s,02:%s,03:%s,04:%s,05:none,06:none,07:none' % (c.find('HBP', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_0', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_1', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_2', 'THERMISTOR', defaultThermistor), c.find('EXTRUDER_3', 'THERMISTOR', defaultThermistor)), wait_name='i2c-temp') watchList.append(['i2c-temp', 0.1]) base.usrcomp_status('i2c-gpio', 'gpio-hw', thread='servo-thread') base.usrcomp_status('i2c-pwm', 'pwm-hw', thread='servo-thread') base.usrcomp_status('i2c-temp', 'temp-hw', thread='servo-thread') base.usrcomp_watchdog(watchList, 'estop-reset', thread='servo-thread', errorSignal='watchdog-error')
rt.init_RTAPI() c.load_ini(os.environ['INI_FILE_NAME']) motion.setup_motion() storage.init_storage('storage.ini') # Gantry component for Z Axis base.init_gantry(axisIndex=2) base.gantry_read(gantryAxis=2, thread='servo-thread') hal.addf('motion-command-handler', 'servo-thread') # setup axis feedback limits = [ [c.find('AXIS_0', 'MAX_LIMIT') - 0.2, c.find('AXIS_0', 'MAX_LIMIT')], [c.find('AXIS_1', 'MAX_LIMIT') - 0.2, c.find('AXIS_1', 'MAX_LIMIT')], [c.find('AXIS_2', 'MIN_LIMIT'), 0.0] ] for n in range(c.find('TRAJ', 'AXES')): axisPos = hal.newsig('axis-%i-pos' % n, hal.HAL_FLOAT) hal.Pin('axis.%i.motor-pos-cmd' % n).link(axisPos) hal.Pin('axis.%i.motor-pos-fb' % n).link(axisPos) # fake limits limitHome = hal.newsig('limit-%i-home' % n, hal.HAL_BIT) hal.Pin('axis.%i.home-sw-in' % n).link(limitHome) wcomp = rt.newinst('wcomp', 'wcomp.axis-%i-home' % n) hal.addf(wcomp.name, 'servo-thread') wcomp.pin('in').link(axisPos)
def setupStorage(): hal.loadusr('hal_storage', name='storage', file='storage.ini', autosave=True, wait_name='storage') def readStorage(): hal.Pin('storage.read-trigger').set(True) # trigger read rt.init_RTAPI() c.load_ini('hardware.ini') rt.loadrt('hal_bb_gpio', output_pins='915,917,838,840') rt.loadrt('hal_arm335xQEP', encoders='eQEP0,eQEP2') rt.loadrt(c.find('PRUCONF', 'DRIVER'), 'prucode=' + c.find('PRUCONF', 'PRUBIN'), pru=0, num_pwmgens=7, halname='hpg') # storage setupStorage() # pru pwmgens hal.Pin('hpg.pwmgen.00.pwm_period').set(500000) # motor left hal.Pin('hpg.pwmgen.00.out.00.pin').set(911) hal.Pin('hpg.pwmgen.00.out.01.pin').set(913) # motor right hal.Pin('hpg.pwmgen.00.out.02.pin').set(808) hal.Pin('hpg.pwmgen.00.out.03.pin').set(810) baseThread = 'base_thread' rt.newthread(baseThread, 1000000, fp=True)
# initialize the RTAPI command client rt.init_RTAPI() # loads the ini file passed by linuxcnc c.load_ini(os.environ['INI_FILE_NAME']) motion.setup_motion('lineardeltakins') hardware.init_hardware() storage.init_storage('storage.ini') # reading functions hardware.hardware_read() hal.addf('motion-command-handler', 'servo-thread') hal.addf('motion-controller', 'servo-thread') numFans = c.find('FDM', 'NUM_FANS') numExtruders = c.find('FDM', 'NUM_EXTRUDERS') numLights = c.find('FDM', 'NUM_LIGHTS') hasHbp = c.find('FDM', 'HAS_HBP') # Axis-of-motion Specific Configs (not the GUI) ve.velocity_extrusion(extruders=numExtruders, thread='servo-thread') # X [0] Axis base.setup_stepper(section='AXIS_0', axisIndex=0, stepgenIndex=0, thread='servo-thread') # Y [1] Axis base.setup_stepper(section='AXIS_1', axisIndex=1, stepgenIndex=1,
# loads the ini file passed by linuxcnc c.load_ini(os.environ['INI_FILE_NAME']) motion.setup_motion() hardware.init_hardware() storage.init_storage('storage.ini') # Gantry component for Z Axis base.init_gantry(axisIndex=2) # reading functions hardware.hardware_read() base.gantry_read(gantryAxis=2, thread='servo-thread') hal.addf('motion-command-handler', 'servo-thread') numFans = c.find('FDM', 'NUM_FANS') numExtruders = c.find('FDM', 'NUM_EXTRUDERS') numLights = c.find('FDM', 'NUM_LIGHTS') withAbp = c.find('FDM', 'ABP', False) # Axis-of-motion Specific Configs (not the GUI) ve.velocity_extrusion(extruders=numExtruders, thread='servo-thread') # X [0] Axis base.setup_stepper(section='AXIS_0', axisIndex=0, stepgenIndex=0) # Y [1] Axis base.setup_stepper(section='AXIS_1', axisIndex=1, stepgenIndex=1) # Z [2] Axis base.setup_stepper(section='AXIS_2', axisIndex=2, stepgenIndex=2, thread='servo-thread', gantry=True, gantryJoint=0) base.setup_stepper(section='AXIS_2', axisIndex=2, stepgenIndex=3, gantry=True, gantryJoint=1)
def setup_stepper(stepgenIndex, section, axisIndex=None, stepgenType='hpg.stepgen', gantry=False, gantryJoint=0, velocitySignal=None, thread=None): stepgen = '%s.%02i' % (stepgenType, stepgenIndex) if axisIndex is not None: axis = 'axis.%i' % axisIndex hasMotionAxis = (axisIndex is not None) and (not gantry or gantryJoint == 0) velocityControlled = velocitySignal is not None # axis enable chain enableIndex = axisIndex if axisIndex is None: enableIndex = 0 # use motor enable signal enable = hal.Signal('emcmot-%i-enable' % enableIndex, hal.HAL_BIT) if hasMotionAxis: enable.link('%s.amp-enable-out' % axis) enable.link('%s.enable' % stepgen) # expose timing parameters so we can multiplex them later sigBase = 'stepgen-%i' % stepgenIndex dirsetup = hal.newsig('%s-dirsetup' % sigBase, hal.HAL_U32) dirhold = hal.newsig('%s-dirhold' % sigBase, hal.HAL_U32) steplen = hal.newsig('%s-steplen' % sigBase, hal.HAL_U32) stepspace = hal.newsig('%s-stepspace' % sigBase, hal.HAL_U32) scale = hal.newsig('%s-scale' % sigBase, hal.HAL_FLOAT) maxVel = hal.newsig('%s-max-vel' % sigBase, hal.HAL_FLOAT) maxAcc = hal.newsig('%s-max-acc' % sigBase, hal.HAL_FLOAT) controlType = hal.newsig('%s-control-type' % sigBase, hal.HAL_BIT) hal.Pin('%s.dirsetup' % stepgen).link(dirsetup) hal.Pin('%s.dirhold' % stepgen).link(dirhold) dirsetup.set(c.find(section, 'DIRSETUP')) dirhold.set(c.find(section, 'DIRHOLD')) hal.Pin('%s.steplen' % stepgen).link(steplen) hal.Pin('%s.stepspace' % stepgen).link(stepspace) steplen.set(c.find(section, 'STEPLEN')) stepspace.set(c.find(section, 'STEPSPACE')) hal.Pin('%s.position-scale' % stepgen).link(scale) scale.set(c.find(section, 'SCALE')) hal.Pin('%s.maxvel' % stepgen).link(maxVel) hal.Pin('%s.maxaccel' % stepgen).link(maxAcc) maxVel.set(c.find(section, 'STEPGEN_MAX_VEL')) maxAcc.set(c.find(section, 'STEPGEN_MAX_ACC')) hal.Pin('%s.control-type' % stepgen).link(controlType) # position command and feedback if not velocityControlled: if hasMotionAxis: # per axis fb and cmd posCmd = hal.newsig('emcmot-%i-pos-cmd' % axisIndex, hal.HAL_FLOAT) posCmd.link('%s.motor-pos-cmd' % axis) if not gantry: posCmd.link('%s.position-cmd' % stepgen) else: posCmd.link('gantry.%i.position-cmd' % axisIndex) posFb = hal.newsig('emcmot-%i-pos-fb' % axisIndex, hal.HAL_FLOAT) posFb.link('%s.motor-pos-fb' % axis) if not gantry: posFb.link('%s.position-fb' % stepgen) else: posFb.link('gantry.%i.position-fb' % axisIndex) if gantry: # per joint fb and cmd posCmd = hal.newsig('emcmot-%i-%i-pos-cmd' % (axisIndex, gantryJoint), hal.HAL_FLOAT) posCmd.link('gantry.%i.joint.%02i.pos-cmd' % (axisIndex, gantryJoint)) posCmd.link('%s.position-cmd' % stepgen) posFb = hal.newsig('emcmot-%i-%i-pos-fb' % (axisIndex, gantryJoint), hal.HAL_FLOAT) posFb.link('%s.position-fb' % stepgen) posFb.link('gantry.%i.joint.%02i.pos-fb' % (axisIndex, gantryJoint)) else: # velocity control hal.net(velocitySignal, '%s.velocity-cmd' % stepgen) controlType.set(1) # enable velocity control # limits if hasMotionAxis: limitHome = hal.newsig('limit-%i-home' % axisIndex, hal.HAL_BIT) limitMin = hal.newsig('limit-%i-min' % axisIndex, hal.HAL_BIT) limitMax = hal.newsig('limit-%i-max' % axisIndex, hal.HAL_BIT) limitHome.link('%s.home-sw-in' % axis) limitMin.link('%s.neg-lim-sw-in' % axis) limitMax.link('%s.pos-lim-sw-in' % axis) if gantry: if gantryJoint == 0: axisHoming = hal.newsig('emcmot-%i-homing' % axisIndex, hal.HAL_BIT) axisHoming.link('%s.homing' % axis) hal.Pin('gantry.%i.search-vel' % axisIndex).set(c.find(section, 'HOME_SEARCH_VEL')) hal.Pin('gantry.%i.homing' % axisIndex).link(axisHoming) hal.Pin('gantry.%i.home' % axisIndex).link(limitHome) or2 = rt.newinst('or2', 'or2.limit-%i-min' % axisIndex) hal.addf(or2.name, thread) or2.pin('out').link(limitMin) or2 = rt.newinst('or2', 'or2.limit-%i-max' % axisIndex) hal.addf(or2.name, thread) or2.pin('out').link(limitMax) limitHome = hal.newsig('limit-%i-%i-home' % (axisIndex, gantryJoint), hal.HAL_BIT) limitMin = hal.newsig('limit-%i-%i-min' % (axisIndex, gantryJoint), hal.HAL_BIT) limitMax = hal.newsig('limit-%i-%i-max' % (axisIndex, gantryJoint), hal.HAL_BIT) homeOffset = hal.Signal('home-offset-%i-%i' % (axisIndex, gantryJoint), hal.HAL_FLOAT) limitHome.link('gantry.%i.joint.%02i.home' % (axisIndex, gantryJoint)) limitMin.link('or2.limit-%i-min.in%i' % (axisIndex, gantryJoint)) limitMax.link('or2.limit-%i-max.in%i' % (axisIndex, gantryJoint)) homeOffset.link('gantry.%i.joint.%02i.home-offset' % (axisIndex, gantryJoint)) storage.setup_gantry_storage(axisIndex, gantryJoint)