def load_hal_file(filename, ini=None): sys.stdout.write("loading " + filename + '... ') sys.stdout.flush() _, ext = os.path.splitext(filename) if ext == '.py': from machinekit import rtapi if not rtapi.__rtapicmd: rtapi.init_RTAPI() if ini is not None: from machinekit import config config.load_ini(ini) globals_ = {} with open(filename, 'r') as f: data = compile(f.read(), filename, 'exec') exec(data, globals_) else: command = 'halcmd' if ini is not None: command += ' -i ' + ini command += ' -f ' + filename subprocess.check_call(command, shell=True) sys.stdout.write('done\n')
def main(): c.load_ini('hardware.ini') init_hardware() configure_stepgen() create_rcomp() setup_functions() # ready to start the threads hal.start_threads() # start haltalk server after everything is initialized # else binding the remote components on the UI might fail hal.loadusr('haltalk', wait=True)
def load_hal_file(filename, ini=None): sys.stdout.write("loading " + filename + '... ') sys.stdout.flush() _, ext = os.path.splitext(filename) if ext == '.py': from machinekit import rtapi if not rtapi.__rtapicmd: rtapi.init_RTAPI() if ini is not None: from machinekit import config config.load_ini(ini) execfile(filename) else: command = 'halcmd' if ini is not None: command += ' -i ' + ini command += ' -f ' + filename subprocess.check_call(command, shell=True) sys.stdout.write('done\n')
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)
import os from machinekit import rtapi as rt from machinekit import hal from machinekit import config as c from fdm.config import velocity_extrusion as ve from fdm.config import base from fdm.config import storage from fdm.config import motion import cramps as hardware # 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')
import attr from aenum import Enum from machinekit import hal from machinekit import rtapi as rt from machinekit import config as c from pinconfig import io_map, pru0_input_pins from servo import setup_servo c.load_ini('hardware.ini') PinDirection = Enum('PinDirection', 'IN OUT LOW HIGH') @attr.s class IOPin(object): number = attr.ib(default='') direction = attr.ib(default=PinDirection.IN) def get_io_pin(id_, direction=PinDirection.IN): port, pin = str(id_)[0], str(id_)[1:] dir_ = 'in' if direction is PinDirection.IN else 'out' return hal.pins['bb_gpio.p{}.{}-{}'.format(port, dir_, pin)] def setup_storage(): hal.loadusr('hal_storage', name='storage', file='storage.ini',
# HAL file for Trinamic SPI configuration import os from machinekit import hal from machinekit import rtapi as rt from machinekit import config as c #from fdm.config import motion from fdm_local.config import motion from fdm.config import base import cramps as hardware hal.epsilon[1] = 0.1 # 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() # reading functions hardware.hardware_read() 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='hm2_5i25.0.stepgen')
kalman.pin('dt').link(sigDt) kalman.pin('new-angle').link(sigNewAngle) kalman.pin('new-rate').link(sigNewRate) 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)
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()
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()
# 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