def main(): parser = argparse.ArgumentParser( description='Videoserver provides a webcam interface for Machinetalk') parser.add_argument('-i', '--ini', help='INI file', default='video.ini') parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true') parser.add_argument('webcams', help='List of webcams to stream', nargs='+') args = parser.parse_args() debug = args.debug mkconfig = config.Config() mkini = os.getenv("MACHINEKIT_INI") if mkini is None: mkini = mkconfig.MACHINEKIT_INI if not os.path.isfile(mkini): sys.stderr.write("MACHINEKIT_INI " + mkini + " does not exist\n") sys.exit(1) mki = ConfigParser.ConfigParser() mki.read(mkini) mkUuid = mki.get("MACHINEKIT", "MKUUID") remote = mki.getint("MACHINEKIT", "REMOTE") if remote == 0: print( "Remote communication is deactivated, videoserver will use the loopback interfaces" ) print(("set REMOTE in " + mkini + " to 1 to enable remote communication")) if debug: print("announcing videoserver") hostname = '%(fqdn)s' # replaced by service announcement video = VideoServer(args.ini, svc_uuid=mkUuid, host=hostname, loopback=(not remote), debug=debug) video.setDaemon(True) video.start() for webcam in args.webcams: video.startVideo(webcam) while True: time.sleep(1)
def init_hardware(): # load low-level drivers rt.loadrt('hal_bb_gpio', output_pins='807,808,810,819,828,841', input_pins='809,831,832,833,835,837,838') prubin = '%s/%s' % (c.Config().EMC2_RTLIB_DIR, c.find('PRUCONF', 'PRUBIN')) rt.loadrt(c.find('PRUCONF', 'DRIVER'), pru=0, num_stepgens=4, num_pwmgens=4, pru_period=2500, prucode=prubin, halname='hpg')
def main(): debug = int(os.environ.get("DEBUG", 0)) launcher.set_debug_level(debug) if "MACHINEKIT_INI" not in os.environ: # export for package installs mkconfig = config.Config() os.environ["MACHINEKIT_INI"] = mkconfig.MACHINEKIT_INI hal_mgr = HalMgr() try: hal_mgr.start() hal_mgr.loop() except subprocess.CalledProcessError as e: hal_mgr.shutdown("Process error: %s" % e, 1) except rospy.ROSInterruptException as e: hal_mgr.shutdown("Interrupt: %s" % e, 0) else: hal_mgr.shutdown("Shutting down", 0)
def init_hardware(): watchList = [] #rt=rtapi.RTAPIcommand() rt.newinst('pp_gpio', 'hpg', 'pincount=6') rt.newinst('pp_stepgen', 'hps', 'pincount=5') #print(c.find('HBP', 'THERMISTOR', defaultThermistor)) #raw_input() # load low-level drivers if False: 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.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__(self): self.pru = rtapi.loadrt('hal_pru_generic', pru=0, num_stepgens=5, num_pwmgens=0, halname='hpg', prucode='%s/xenomai/pru_generic.bin' % (config.Config().EMC2_RTLIB_DIR)) 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) 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)) self.get_pru_pin('stepgen.%02i.maxvel' % i).set(0) self.get_pru_pin('stepgen.%02i.maxaccel' % i).set(0) 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 loadTable(self, name): c = config.Config() localInputFile = os.path.join(os.getcwd(), 'thermistor_tables', name + '.txt') systemInputFile = os.path.join(c.datadir, 'fdm', 'thermistor_tables', name + '.txt') if os.path.exists(name): inputFile = name elif os.path.exists(localInputFile): inputFile = localInputFile elif os.path.exists(systemInputFile): inputFile = systemInputFile else: raise RuntimeError('Thermistor table was not found') with open(inputFile, "r") as f: self.thermistor_table_raw = [] content = f.readlines() for line in content: line = ' '.join(line.split()) if ((len(line) == 0) or (line[0] == '#')): continue datas = line.split(' ') tableEntry = [] for data in datas: tableEntry.append(float(data)) self.thermistor_table_raw.append(tableEntry) if len(self.thermistor_table_raw) == 0: return # Temperature table needs resistance to be ordered low [0] to high [n] if (self.thermistor_table_raw[0][0] < self.thermistor_table_raw[-1][0]): self.thermistor_table_raw.reverse()
import os import ConfigParser from machinekit import rtapi, hal, config # retrieve the machinekit UUID cfg = ConfigParser.ConfigParser() mkini = os.getenv("MACHINEKIT_INI") if mkini is None: mkini = config.Config().MACHINEKIT_INI cfg.read(mkini) uuid = cfg.get("MACHINEKIT", "MKUUID") # open a command channel to rtapi_app rt = rtapi.RTAPIcommand(uuid=uuid)
from machinekit import launcher from machinekit import config #launcher.set_debug_level(5) def check_mklaucher(): try: subprocess.check_output(['pgrep', 'mklauncher']) return True except subprocess.CalledProcessError: return False os.chdir(os.path.dirname(os.path.realpath(__file__))) c = config.Config() os.environ["MACHINEKIT_INI"] = c.MACHINEKIT_INI parser = argparse.ArgumentParser( description='This is the Prusa-i3-soc run script ' 'it demonstrates how a run script could look like ' 'and of course starts the Prusa-i3 config') parser.add_argument('-v', '--video', help='Starts the video server', action='store_true') args = parser.parse_args() try:
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 hpg.pin('encoder.00.chan.00.counter-mode').set(0) # Quadrature Mode
'it starts the xyz configuration and UI') parser.add_argument('-nc', '--no_config', help='Disables the config server', action='store_true') parser.add_argument('-l', '--local', help='Enable local mode only', action='store_true') parser.add_argument('-s', '--halscope', help='Starts the halscope', action='store_true') parser.add_argument('-m', '--halmeter', help='Starts the halmeter', action='store_true') parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true') parser.add_argument('-hw', '--hardware', help='Hardware setup', action='store') parser.add_argument('-t', '--test', help='Connect test motor to siggen', action='store_true') args = parser.parse_args() if args.debug: launcher.set_debug_level(5) if 'MACHINEKIT_INI' not in os.environ: # export for package installs mkconfig = config.Config() os.environ['MACHINEKIT_INI'] = mkconfig.MACHINEKIT_INI def check_mklaucher(): try: subprocess.check_output(['pgrep', 'mklauncher']) return True except subprocess.CalledProcessError: return False try: launcher.check_installation() launcher.cleanup_session() launcher.start_realtime() # setup the configuration
def main(): parser = argparse.ArgumentParser( description= 'Configserver is the entry point for Machinetalk based user interfaces' ) parser.add_argument('-n', '--name', help='Name of the machine', default="Machinekit") parser.add_argument( '-s', '--suppress_ip', help='Do not show ip of machine in service name', action='store_false', ) parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true') parser.add_argument( 'dirs', nargs='*', help="List of directories to scan for user interface configurations", ) args = parser.parse_args() debug = args.debug mkconfig = config.Config() mkini = os.getenv("MACHINEKIT_INI") if mkini is None: mkini = mkconfig.MACHINEKIT_INI if not os.path.isfile(mkini): sys.stderr.write("MACHINEKIT_INI " + mkini + " does not exist\n") sys.exit(1) mki = configparser.ConfigParser() mki.read(mkini) uuid = mki.get("MACHINEKIT", "MKUUID") remote = mki.getint("MACHINEKIT", "REMOTE") if remote == 0: print( "Remote communication is deactivated, configserver will use the loopback interfaces" ) print("set REMOTE in " + mkini + " to 1 to enable remote communication") if debug: print("announcing configserver") context = zmq.Context() context.linger = 0 register_exit_handler() config_service = None try: hostname = '%(fqdn)s' # replaced by service announcement config_service = ConfigServer( context, svc_uuid=uuid, topdir=".", host=hostname, app_dirs=args.dirs, name=args.name, host_in_name=bool(args.suppress_ip), loopback=(not remote), debug=debug, ) while config_service.running and not check_exit(): time.sleep(1) except Exception as e: print("exception") print(e) if debug: print("stopping threads") if config_service is not None: config_service.stop() # wait for all threads to terminate while threading.active_count() > 1: time.sleep(0.1) if debug: print("threads stopped") sys.exit(0)
card = hardwarelist[hardware][1] #load mesa card with firmware if hardware == 'mesa-5i20': rt.loadrt('hostmot2') rt.loadrt('hm2_pci', config="firmware=hm2/5i20/SVST8_4.BIT \ num_pwmgens=3 \ num_stepgens=4") if hardware == 'bbb-cramps': os.system('./setup.sh') 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, 'xenomai/pru_generic.bin') rt.loadrt('hal_pru_generic', pru=0, num_stepgens=5, num_pwmgens=0, prucode=prubin, halname=card) if hardware == 'bbb-bebopr++': os.system('./setup.bridge.sh') rt.loadrt('hal_bb_gpio', output_pins='807,924,926', input_pins='808,809,810,814,817,818') prubin = '%s/%s' % (c.Config().EMC2_RTLIB_DIR, 'xenomai/pru_generic.bin') rt.loadrt('hal_pru_generic', pru=0,
def get_pin(name): if name in hal.pins: return hal.pins[name] else: return None c.load_ini('hardware.ini') rt.loadrt('hal_bb_gpio', output_pins='826,827,923,926,930', input_pins='807,810,814,817,818,819,912,914,915,916,917,918,924,941') rt.loadrt(c.find('PRUCONF', 'DRIVER'), 'prucode=%s/%s' % (c.Config().EMC2_RTLIB_DIR, c.find('PRUCONF', 'PRUBIN')), pru=1, num_stepgens=6, num_pwmgens=1, halname='hpg') # axis_enable_signal = hal.Signal('emcmot.00.enable', hal.HAL_BIT) # hal.Pin('hpg.stepgen.00.enable').link(axis_enable_signal) # axis_enable_signal.set(True) # pos_cmd_signal = hal.Signal('emcmot.00.pos-cmd', hal.HAL_FLOAT) # hal.Pin('hpg.stepgen.00.position-cmd').link(pos_cmd_signal) # pos_fb_signal = hal.Signal('emcmot.00.pos-fb', hal.HAL_FLOAT) # hal.Pin('hpg.stepgen.00.position-fb').link(pos_fb_signal) hal.Pin('hpg.stepgen.00.dirsetup').set(c.find('AXIS_0', 'DIRSETUP')) hal.Pin('hpg.stepgen.00.dirhold').set(c.find('AXIS_0', 'DIRHOLD'))
def main(): parser = argparse.ArgumentParser( description= 'Configserver is the entry point for Machinetalk based user interfaces' ) parser.add_argument('-n', '--name', help='Name of the machine', default="Machinekit") parser.add_argument('-s', '--suppress_ip', help='Do not show ip of machine in service name', action='store_false') parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true') parser.add_argument( 'dirs', nargs='*', help="List of directories to scan for user interface configurations") args = parser.parse_args() debug = args.debug mkconfig = config.Config() mkini = os.getenv("MACHINEKIT_INI") if mkini is None: mkini = mkconfig.MACHINEKIT_INI if not os.path.isfile(mkini): sys.stderr.write("MACHINEKIT_INI " + mkini + " does not exist\n") sys.exit(1) mki = ConfigParser.ConfigParser() mki.read(mkini) uuid = mki.get("MACHINEKIT", "MKUUID") remote = mki.getint("MACHINEKIT", "REMOTE") prefs = mki.get("MACHINEKIT", "INTERFACES").split() if remote == 0: print( "Remote communication is deactivated, configserver will use the loopback interfaces" ) print(("set REMOTE in " + mkini + " to 1 to enable remote communication")) iface = ['lo', '127.0.0.1'] else: iface = choose_ip(prefs) if not iface: sys.stderr.write( "failed to determine preferred interface (preference = %s)\n" % prefs) sys.exit(1) if debug: print(("announcing configserver on " + str(iface))) context = zmq.Context() context.linger = 0 register_exit_handler() configService = None try: configService = ConfigServer(context, svcUuid=uuid, topdir=".", ip=iface[1], appDirs=args.dirs, name=args.name, ipInName=bool(args.suppress_ip), debug=debug) while configService.running and not check_exit(): time.sleep(1) except Exception as e: print("exception") print(e) except: print("other exception") if debug: print("stopping threads") if configService is not None: configService.stop() # wait for all threads to terminate while threading.active_count() > 1: time.sleep(0.1) if debug: print("threads stopped") sys.exit(0)
def main(): parser = argparse.ArgumentParser( description= 'mklauncher is Machinetalk based session/configuration launcher for Machinekit' ) parser.add_argument('-n', '--name', help='Name of the machine', default="Machinekit Launcher") parser.add_argument('-s', '--suppress_ip', help='Do not show ip of machine in service name', action='store_false') parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true') parser.add_argument( 'dirs', nargs='*', help="List of directories to scan for launcher configurations") args = parser.parse_args() debug = args.debug logging.basicConfig() if debug: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) mkconfig = config.Config() mkini = os.getenv("MACHINEKIT_INI") if mkini is None: mkini = mkconfig.MACHINEKIT_INI if not os.path.isfile(mkini): sys.stderr.write("MACHINEKIT_INI " + mkini + " does not exist\n") sys.exit(1) mki = configparser.ConfigParser() mki.read(mkini) uuid = mki.get("MACHINEKIT", "MKUUID") remote = mki.getint("MACHINEKIT", "REMOTE") if remote == 0: logger.info( "Remote communication is deactivated, configserver will use the loopback interfaces" ) logger.info(("set REMOTE in " + mkini + " to 1 to enable remote communication")) logger.debug("announcing mklauncher") context = zmq.Context() context.linger = 0 register_exit_handler() hostname = '%(fqdn)s' # replaced by service announcement mklauncher = Mklauncher(context, svc_uuid=uuid, host=hostname, launcher_dirs=args.dirs, name=args.name, host_in_name=bool(args.suppress_ip), loopback=(not remote), debug=debug) mklauncher.start() while mklauncher.running and not check_exit(): time.sleep(1) logger.debug('stopping threads') mklauncher.stop() # wait for all threads to terminate while threading.active_count() > 1: time.sleep(0.1) logger.debug('threads stopped') sys.exit(0)
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')