コード例 #1
0
def main():
	"""
	Program entry point. Setting up HAL pins and construct the Extruder instance.
	"""
	c = hal.component("rs-extruder")
	c.newpin("connection", hal.HAL_BIT, hal.HAL_OUT)
	c.newpin("online", hal.HAL_BIT, hal.HAL_OUT)
	c.newpin("estop", hal.HAL_BIT, hal.HAL_OUT)
	c.newpin("enable", hal.HAL_BIT, hal.HAL_IN)
	c.newpin("running", hal.HAL_BIT, hal.HAL_IN)

	c.newparam("steps_per_mm_cube", hal.HAL_FLOAT, hal.HAL_RW)
	c['steps_per_mm_cube'] = 4.0 # Some random default. Don't rely on this.

	c.newpin("fault.communication", hal.HAL_BIT, hal.HAL_OUT)

	c.newpin("heater1.pv", hal.HAL_FLOAT, hal.HAL_OUT)
	c.newpin("heater1.sv", hal.HAL_FLOAT, hal.HAL_OUT)
	c.newpin("heater1.set-sv", hal.HAL_S32, hal.HAL_IN)
	c.newpin("heater1.on", hal.HAL_BIT, hal.HAL_OUT)

	c.newpin("motor1.pv", hal.HAL_U32, hal.HAL_OUT)
	c.newpin("motor1.sv", hal.HAL_U32, hal.HAL_OUT)
	c.newpin("motor1.speed", hal.HAL_S32, hal.HAL_IN)
	c.newpin("motor1.speed.trigger", hal.HAL_BIT, hal.HAL_IN)
	
	c.newpin("motor1.spindle", hal.HAL_FLOAT, hal.HAL_IN)
	c.newpin("motor1.spindle.on", hal.HAL_BIT, hal.HAL_IN)

	c.newpin("mapp.mcode", hal.HAL_S32, hal.HAL_IN)
	c.newpin("mapp.p", hal.HAL_FLOAT, hal.HAL_IN)
	c.newpin("mapp.q", hal.HAL_FLOAT, hal.HAL_IN)
	c.newpin("mapp.seqid", hal.HAL_S32, hal.HAL_IN)
	c.newpin("mapp.done", hal.HAL_S32, hal.HAL_OUT)

	c.ready()

	extruder = Extruder(c)
	try:
		while True:
		    try:
		        extruder.execute()
		    except IOError:
		        pass
		    except OSError:
		        pass
		    except  serial.serialutil.SerialException:
		        pass
		    finally:
		        c['connection'] = 0
		        c['fault.communication'] = 1
		        c['estop'] = 1
		        c['online'] = 0
		        time.sleep(0.05)
		        c['estop'] = 0
		        c['mapp.done'] = c['mapp.seqid']
		        time.sleep(0.05)
		        
	except KeyboardInterrupt:
		raise SystemExit    
コード例 #2
0
	def run(self) :
		import hal, time
		
		h = hal.component("compensation")
		h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
		h.newpin("enable", hal.HAL_BIT, hal.HAL_IN)
		h.newpin("x-map", hal.HAL_FLOAT, hal.HAL_IN)
		h.newpin("y-map", hal.HAL_FLOAT, hal.HAL_IN)
		h.newpin("reset", hal.HAL_BIT, hal.HAL_IN)
		h.newpin("error", hal.HAL_BIT, hal.HAL_OUT)
		# ok, lets we are ready, lets go 
		h.ready()
		last_reset = h["reset"]
		try:
			while 1:
				try:
					time.sleep(work_thread)
					if h["enable"] :
						x=h['x-map']
						y=h['y-map']
						h["out"]=self.get_comp(x,y)
					else :	
						h["out"]=0
					if h["reset"]  and not last_reset:
							self.reset()
					last_reset = h["reset"]
				except KeyboardInterrupt :
					raise SystemExit	
				except : 
					h["error"] = False
				else :
					h["error"] = True	

		except KeyboardInterrupt:
	  	  raise SystemExit
コード例 #3
0
	def __init__(self, halName="cnccontrol"):
		CNCControl.__init__(self, verbose=True)

		self.tk = Timekeeping()

		self.h = hal.component(halName)
		self.__createHalPins()
		self.h.ready()

		self.foBalance = ValueBalance(self.h, self.tk,
				scalePin="feed-override.scale",
				incPin="feed-override.inc",
				decPin="feed-override.dec",
				feedbackPin="feed-override.value")

		self.incJogPlus = {}
		self.incJogMinus = {}
		for ax in ALL_AXES:
			self.incJogPlus[ax] = BitPoke(self.h, self.tk,
						      "jog.%s.inc-plus" % ax)
			self.incJogMinus[ax] = BitPoke(self.h, self.tk,
						       "jog.%s.inc-minus" % ax)

		self.programStop = BitPoke(self.h, self.tk,
					   "program.stop", cycleMsec=100)

		self.spindleStart = BitPoke(self.h, self.tk, "spindle.start")
		self.spindleStop = BitPoke(self.h, self.tk, "spindle.stop")
コード例 #4
0
    def __init__(self, iocard, component_name, injected_component=None):
        self.iocard = iocard
        self._handles = []

        if injected_component is None:
            self.component = hal.component(component_name)
        else:
            self.component = injected_component
コード例 #5
0
ファイル: userfuncs.py プロジェクト: LinuxCNC/linuxcnc
 def __init__(self):
     print "UserFuncs.__init__()"
     myhal = hal.component("myhal")
     myhal.newpin("bit", hal.HAL_BIT, hal.HAL_OUT)
     myhal.newpin("float", hal.HAL_FLOAT, hal.HAL_OUT)
     myhal.newpin("int", hal.HAL_S32, hal.HAL_OUT)
     myhal.ready()
     self.myhal = myhal #FIXME
     self.components["myhal"] = myhal
コード例 #6
0
def setup_pins():
    global H
    H = hal.component("hal_racktoolchange")
    H.newpin("toolnumber", hal.HAL_S32, hal.HAL_IN)
    H.newpin("change", hal.HAL_BIT, hal.HAL_IN)
    H.newpin("changed", hal.HAL_BIT, hal.HAL_OUT)
    H.newpin("spindle_stopped", hal.HAL_BIT, hal.HAL_IN)
    H.newpin("tool_secure", hal.HAL_BIT, hal.HAL_IN)
    H.newpin("tool_released", hal.HAL_BIT, hal.HAL_IN)
    H.newpin("drawbar", hal.HAL_BIT, hal.HAL_OUT)
    H.newpin("blow", hal.HAL_BIT, hal.HAL_OUT)
    return H
コード例 #7
0
ファイル: graph.py プロジェクト: willrat/ioMachine
  def __init__(self, number=0):

#     self.command = emc.command()
#     self.status = emc.stat()
    self.initGui()

    name = "graph"
    name += "-%s" % (number)

    self.h = hal.component(name)

    panel = gladevcp.makepins.GladePanel(self.h, "graph.glade", self.builder, None)
    self.h.ready()
コード例 #8
0
ファイル: koppi-cnc-info.py プロジェクト: AceXIE/mk
        def __init__(self) :
#                logging.info("koppi-cnc-info.py init")
                self.h = hal.component("koppi-cnc-info")
#                logging.info("koppi-cnc-info.py ok")

                for i in range(0,3):
                        self.h.newpin("motor-supply-%d" % (i), hal.HAL_FLOAT, hal.HAL_OUT)
                        self.h.newpin("max-current-%d"  % (i), hal.HAL_FLOAT, hal.HAL_OUT)
                        self.h.newpin("temp-%i" % (i), hal.HAL_S32, hal.HAL_OUT)
                self.h.newpin("fan1-rpm", hal.HAL_S32, hal.HAL_OUT)
                self.h.newpin("temp1",    hal.HAL_FLOAT, hal.HAL_OUT)
                self.h.newpin("link-up",  hal.HAL_BIT, hal.HAL_IN)
                self.h.ready()
コード例 #9
0
ファイル: extruderCtl.py プロジェクト: adam-urbanczyk/emcfab
def runHal():
    #set up hal component
    extruder_hal = hal.component("extruder");
    extruder_hal.newpin("temp_cmd",hal.HAL_FLOAT,hal.HAL_IN);
    extruder_hal.newpin("temp_current",hal.HAL_FLOAT,hal.HAL_OUT);
    extruder_hal.newpin("heater_duty_out",hal.HAL_FLOAT,hal.HAL_OUT);
    extruder_hal.newpin("motor_duty_out",hal.HAL_FLOAT,hal.HAL_OUT);
    extruder_hal.newpin("heater_ok",hal.HAL_BIT,hal.HAL_OUT);
    extruder_hal.newpin("heater_enable",hal.HAL_BIT,hal.HAL_IN);
    extruder_hal.newpin("motor_enable",hal.HAL_BIT,hal.HAL_IN);
    extruder_hal.ready();
    #extruder_hal.newpin("fault",hal.HAL_BIT,hal.HAL_OUT);

    #default values of gains stored in firmware are probably fine,
    #and can be set manually if required

    #ex.newpin("igain",hal.HAL_FLOAT,hal.HAL_IN);    
    #ex.newpin("pgain",hal.HAL_FLOAT,hal.HAL_IN);    
    #ex.newpin("dgain",hal.HAL_FLOAT,hal.HAL_IN);    
    #ex.newpin("ff0gain",hal.HAL_FLOAT,hal.HAL_IN);    
    #ex.newpin("ff1gain",hal.HAL_FLOAT,hal.HAL_IN); 

    #connect serial port
    extruder = Extruder();
 
    try:
            while 1:
                #copy extruder status via serial interface
                #extruder.
                newVals = {};
                extruder.open();
                newVals["ht"] = extruder_hal["temp_cmd"];
                newVals["hge"] = float(extruder_hal["heater_enable"]);
                newVals["mge"] = float(extruder_hal["motor_enable"]);
                extruder.save(newVals);
                r = extruder.read();

                extruder_hal["temp_current"] = r["hv"];
                extruder_hal["heater_duty_out"] = r["hout"];                
                extruder_hal["motor_duty_out"] = r["mout"];                
                if r["he"] > 0:
                  extruder_hal["heater_ok"] = True;
                else:
                  extruder_hal["heater_ok"] = False;
                extruder.close();    
                time.sleep(HAL_POLL_INTERVAL);
    except Exception:
            exception("Uh, i got an exception");
            raise SystemExit;
コード例 #10
0
ファイル: pendant-menu.py プロジェクト: ftkalcevic/CNCConfig
    def __init__(self):
        self.hal = hal.component("pendant-menu")
        self.hal.newpin("axis-select", hal.HAL_S32, hal.HAL_IN)
        self.hal.newpin("multiplier-select", hal.HAL_S32, hal.HAL_IN)
        self.hal.newpin("menu1", hal.HAL_BIT, hal.HAL_IN)
        self.hal.newpin("menu2", hal.HAL_BIT, hal.HAL_IN)
        self.hal.newpin("menu3", hal.HAL_BIT, hal.HAL_IN)
        self.hal.newpin("menu4", hal.HAL_BIT, hal.HAL_IN)
        self.hal.newpin("enable", hal.HAL_BIT, hal.HAL_IN)
        self.hal.newpin("spindle-speed", hal.HAL_FLOAT, hal.HAL_IN)
        self.hal.newpin("page", hal.HAL_U32, hal.HAL_OUT)
        self.hal.newpin("tool-change", hal.HAL_BIT, hal.HAL_IN)
        self.hal.newpin("tool-changed",hal.HAL_BIT, hal.HAL_OUT)
        self.hal.newpin("tool-prep-number", hal.HAL_S32, hal.HAL_IN)
        self.hal.newpin("jog-wheel", hal.HAL_S32, hal.HAL_IN)
        self.hal.ready()
	self.stat = emc.stat()
	self.cmd = emc.command()
	self.loadToolTable()
コード例 #11
0
ファイル: vcpparse.py プロジェクト: LinuxCNC/linuxcnc
def create_vcp(master, comp = None, compname="pyvcp"):
    """ 
        create a pyVCP panel 
            master = Tkinter root window or other master container
            comp = HAL component
            compname = name of HAL component which is created if comp=None
    """
    global pyvcp0, pycomp
    pyvcp0 = master
    if comp is None:
        try: 
            comp = hal.component(compname)
        except:
            print "Error: Multiple components with the same name."
            sys.exit(0)

    pycomp = comp
    read_file() 
    updater()
    return comp
コード例 #12
0
ファイル: storable.py プロジェクト: willrat/ioMachine
  def __init__(self):
    # create store for all programs on the 'hmi'
    self.programs = []
#
    # create 1 default program so there is never an empty list
   # self.programs.append(motionProgram())

    # plus other things we might need to keep
    # track here....
    self.currentIndex = 0
    self.language = ""

    self.halComp = hal.component("persistent")

    self.halComp.newpin("axis.0.gain", hal.HAL_FLOAT, hal.HAL_IO)
    self.halComp.newpin("axis.0.offset", hal.HAL_FLOAT, hal.HAL_IO)

    self.halComp.newpin("axis.1.gain", hal.HAL_FLOAT, hal.HAL_IO)
    self.halComp.newpin("axis.1.offset", hal.HAL_FLOAT, hal.HAL_IO)
    self.halComp.ready()
コード例 #13
0
ファイル: cutmat.py プロジェクト: cnc-club/bbox
	def __init__(self):

		self.builder = gtk.Builder()
		self.builder.add_from_file(glade_file)
		self.builder.connect_signals(self)
		self.connect_signals()
		self.halcomp = hal.component("cutmat")
		panel = gladevcp.makepins.GladePanel( self.halcomp, glade_file, self.builder, None)		
		self.window = self.builder.get_object("window1")
		self.linuxcnc_ini = linuxcnc.ini(LINUXCNC_INI)
		self.window.show()
		self.window.connect("key-press-event", self.on_key_down)		
		self.window.connect("delete-event", self.on_window_destroy)		
		# init cfg
		self.c = linuxcnc.command()
		self.err = linuxcnc.error_channel()	
		# post gui
		print "Cutmat: loading postgui hal file"
		postgui_halfile = self.linuxcnc_ini.find("HAL", "POSTGUI_HALFILE")	
		print 	postgui_halfile
		p = subprocess.Popen(['halcmd', '-i', LINUXCNC_INI, "-f", postgui_halfile], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		out, err = p.communicate()
		print out, err
コード例 #14
0
ファイル: qtvcp.py プロジェクト: zym1rm/linuxcnc
    def __init__(self):
        sys.excepthook = self.excepthook
        INIPATH = None
        INITITLE = INFO.TITLE
        INIICON = INFO.ICON
        usage = "usage: %prog [options] myfile.ui"
        parser = OptionParser(usage=usage)
        parser.disable_interspersed_args()
        parser.add_options(options)
        # remove [-ini filepath] that linuxcnc adds if being launched as a screen
        # keep a reference of that path
        for i in range(len(sys.argv)):
            if sys.argv[i] == '-ini':
                # delete -ini
                del sys.argv[i]
                # pop out the ini path
                INIPATH = sys.argv.pop(i)
                break
        (opts, args) = parser.parse_args()

        # so web engine can load local images
        sys.argv.append("--disable-web-security")

        # initialize QApp so we can pop up dialogs now.
        self.app = MyApplication(sys.argv)

        # we import here so that the QApp is initialized before
        # the Notify library is loaded because it uses DBusQtMainLoop
        # DBusQtMainLoop must be initialized after to work properly
        from qtvcp import qt_makepins, qt_makegui

        # ToDo: pass specific log levels as an argument, or use an INI setting
        if opts.debug:
            # Log level defaults to INFO, so set lower if in debug mode
            logger.setGlobalLevel(logger.DEBUG)
        if opts.verbose:
            # Log level defaults to INFO, so set lowest if in verbose mode
            logger.setGlobalLevel(logger.VERBOSE)
            LOG.verbose('VERBOSE DEBUGGING ON')

        # a specific path has been set to load from or...
        # no path set but -ini is present: default qtvcp screen...or
        # oops error
        if args:
            basepath = args[0]
        elif INIPATH:
            basepath = "qt_cnc"
        else:
            print(parser.print_help())
            sys.exit(0)
        # set paths using basename
        error = PATH.set_paths(basepath, bool(INIPATH))
        if error:
            sys.exit(0)

        # keep track of python version during this transition
        ver = 'Python 3'

        #################
        # Screen specific
        #################
        if INIPATH:
            LOG.info(
                'green<Building A Linuxcnc Main Screen with {}>'.format(ver))
            import linuxcnc
            # pull info from the INI file
            self.inifile = linuxcnc.ini(INIPATH)
            self.inipath = INIPATH

            # if no handler file specified, use stock test one
            if not opts.usermod:
                LOG.info('No handler file specified on command line')
                target = os.path.join(PATH.CONFIGPATH,
                                      '%s_handler.py' % PATH.BASENAME)
                source = os.path.join(PATH.SCREENDIR,
                                      'tester/tester_handler.py')
                if PATH.HANDLER is None:
                    message = ("""
Qtvcp encountered an error; No handler file was found.
Would you like to copy a basic handler file into your config folder?
This handler file will allow display of your screen and basic keyboard jogging.

The new handlerfile's path will be:
%s

Pressing cancel will close linuxcnc.""" % target)
                    rtn = QtWidgets.QMessageBox.critical(
                        None, "QTVCP Error", message, QtWidgets.QMessageBox.Ok
                        | QtWidgets.QMessageBox.Cancel)
                    if rtn == QtWidgets.QMessageBox.Ok:
                        try:
                            shutil.copy(source, target)
                        except IOError as e:
                            LOG.critical("Unable to copy handler file. %s" % e)
                            sys.exit(0)
                        except:
                            LOG.critical(
                                "Unexpected error copying handler file:",
                                sys.exc_info())
                            sys.exit(0)
                        opts.usermod = PATH.HANDLER = target
                    else:
                        LOG.critical(
                            'No handler file found or specified. User requested stopping'
                        )
                else:
                    opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                LOG.info(
                    'No HAL component base name specified on command line using: {}'
                    .format(PATH.BASENAME))
                opts.component = PATH.BASENAME

        #################
        # VCP specific
        #################
        else:
            LOG.info('green<Building A VCP Panel with {}>'.format(ver))
            # if no handler file specified, use stock test one
            if not opts.usermod:
                LOG.info('No handler file specified - using {}'.format(
                    PATH.HANDLER))
                opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                LOG.info(
                    'No HAL component base name specified - using: {}'.format(
                        PATH.BASENAME))
                opts.component = PATH.BASENAME

        ############################
        # International translation
        ############################
        if PATH.LOCALEDIR is not None:
            translator = QtCore.QTranslator()
            translator.load(PATH.LOCALEDIR)
            self.app.installTranslator(translator)
            #QtCore.QCoreApplication.installTranslator(translator)
            #print(self.app.translate("MainWindow", 'Machine Log'))

        ##############
        # Build ui
        ##############

        #if there was no component name specified use the xml file name
        if opts.component is None:
            opts.component = PATH.BASENAME

        # initialize HAL
        try:
            self.halcomp = hal.component(opts.component)
            self.hal = Qhal(self.halcomp, hal)
        except:
            LOG.critical(
                "Asking for a HAL component using a name that already exists?")
            raise Exception(
                '"Asking for a HAL component using a name that already exists?'
            )

        # initialize the window
        window = qt_makegui.VCPWindow(self.hal, PATH)

        # give reference to user command line options
        if opts.useropts:
            window.USEROPTIONS_ = opts.useropts
        else:
            window.USEROPTIONS_ = None

        # load optional user handler file
        if opts.usermod:
            LOG.debug('Loading the handler file')
            window.load_extension(opts.usermod)
            try:
                window.web_view = QWebView()
            except:
                window.web_view = None
            # do any class patching now
            if "class_patch__" in dir(window.handler_instance):
                window.handler_instance.class_patch__()
            # add filter to catch keyboard events
            LOG.debug('Adding the key events filter')
            myFilter = qt_makegui.MyEventFilter(window)
            self.app.installEventFilter(myFilter)

        # actually build the widgets
        window.instance()

        # title
        if INIPATH:
            if (INITITLE == ""):
                INITITLE = 'QTvcp-Screen-%s' % opts.component
            title = INITITLE
        else:
            title = 'QTvcp-Panel-%s' % opts.component
        window.setWindowTitle(title)

        # make QT widget HAL pins
        self.panel = qt_makepins.QTPanel(self.hal, PATH, window, opts.debug)

        # call handler file's initialized function
        if opts.usermod:
            if "initialized__" in dir(window.handler_instance):
                LOG.debug(
                    '''Calling the handler file's initialized__ function''')
                window.handler_instance.initialized__()
            # add any external handler override user commands
            if INFO.USER_COMMAND_FILE is None:
                INFO.USER_COMMAND_FILE = os.path.join(
                    PATH.CONFIGPATH, '.{}rc'.format(PATH.BASEPATH))
            INFO.USER_COMMAND_FILE = INFO.USER_COMMAND_FILE.replace(
                'CONFIGFOLDER', PATH.CONFIGPATH)
            INFO.USER_COMMAND_FILE = INFO.USER_COMMAND_FILE.replace(
                'WORKINGFOLDER', PATH.WORKINGDIR)

            window.handler_instance.call_user_command_(window.handler_instance,
                                                       INFO.USER_COMMAND_FILE)

        # All Widgets should be added now - synch them to linuxcnc
        STATUS.forced_update()

        # call a HAL file after widgets built
        if opts.halfile:
            if opts.halfile[-4:] == ".tcl":
                cmd = ["haltcl", opts.halfile]
            else:
                cmd = ["halcmd", "-f", opts.halfile]
            res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr)
            if res:
                print >> sys.stderr, "'%s' exited with %d" % (' '.join(cmd),
                                                              res)
                self.shutdown()

        # User components are set up so report that we are ready
        LOG.debug('Set HAL ready')
        self.halcomp.ready()

        # embed us into an X11 window (such as AXIS)
        if opts.parent:
            window = xembed.reparent_qt_to_x11(window, opts.parent)
            forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None)
            LOG.critical('Forwarding events to AXIS is not well tested yet')
            if forward:
                xembed.XEmbedFowarding(window, forward)

        # push the window id for embedment into an external program
        if opts.push_XID:
            wid = int(window.winId())
            print(wid, file=sys.stdout)
            sys.stdout.flush()

        # for window resize and or position options
        if "+" in opts.geometry:
            LOG.debug('-g option: moving window')
            try:
                j = opts.geometry.partition("+")
                pos = j[2].partition("+")
                window.move(int(pos[0]), int(pos[2]))
            except Exception as e:
                LOG.critical("With -g window position data:\n {}".format(e))
                parser.print_help()
                self.shutdown()
        if "x" in opts.geometry:
            LOG.debug('-g option: resizing')
            try:
                if "+" in opts.geometry:
                    j = opts.geometry.partition("+")
                    t = j[0].partition("x")
                else:
                    t = opts.geometry.partition("x")
                window.resize(int(t[0]), int(t[2]))
            except Exception as e:
                LOG.critical("With -g window resize data:\n {}".format(e))
                parser.print_help()
                self.shutdown()

        # always on top
        if opts.always_top:
            window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

        # theme (styles in QT speak) specify a qss file
        if opts.theme:
            window.apply_styles(opts.theme)
        # apply qss file or default theme
        else:
            window.apply_styles()

        LOG.debug('Show window')
        # maximize
        if opts.maximum:
            window.showMaximized()
        # fullscreen
        elif opts.fullscreen:
            window.showFullScreen()
        else:
            self.panel.set_preference_geometry()

        window.show()
        if INIPATH:
            self.postgui()
            self.postgui_cmd()
            if (INIICON == ""):
                window.setWindowIcon(
                    QtGui.QIcon(os.path.join(PATH.IMAGEDIR,
                                             'linuxcncicon.png')))
            else:
                window.setWindowIcon(
                    QtGui.QIcon(os.path.join(PATH.CONFIGPATH, INIICON)))
        else:
            window.setWindowIcon(
                QtGui.QIcon(os.path.join(PATH.IMAGEDIR,
                                         'linuxcnc-wizard.gif')))

        # catch control c and terminate signals
        signal.signal(signal.SIGTERM, self.shutdown)
        signal.signal(signal.SIGINT, self.shutdown)

        if opts.usermod and "before_loop__" in dir(window.handler_instance):
            LOG.debug('''Calling the handler file's before_loop__ function''')
            window.handler_instance.before_loop__()

        LOG.info('Preference path: {}'.format(PATH.PREFS_FILENAME))
        # start loop
        self.app.exec_()

        # now shut it all down
        self.shutdown()
コード例 #15
0
ファイル: hal_interface.py プロジェクト: CNCBASHER/linuxcnc
    def __init__(self, gui, emc_control, mdi_control, emc):
        self.gui = gui
        self.emc_control = emc_control
        self.emc = emc
        self.emc_stat = self.emc.stat()
        self.mdi_control = mdi_control
        self.c = hal.component("touchy")
        self.c.newpin("status-indicator", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.active", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.x", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.y", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.z", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.a", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.b", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.c", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.u", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.v", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.w", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.increment", hal.HAL_FLOAT, hal.HAL_OUT)

        self.c.newpin("jog.continuous.x.positive", hal.HAL_BIT, hal.HAL_IN)
        self.xp = 0
        self.c.newpin("jog.continuous.x.negative", hal.HAL_BIT, hal.HAL_IN)
        self.xn = 0
        self.c.newpin("jog.continuous.y.positive", hal.HAL_BIT, hal.HAL_IN)
        self.yp = 0
        self.c.newpin("jog.continuous.y.negative", hal.HAL_BIT, hal.HAL_IN)
        self.yn = 0
        self.c.newpin("jog.continuous.z.positive", hal.HAL_BIT, hal.HAL_IN)
        self.zp = 0
        self.c.newpin("jog.continuous.z.negative", hal.HAL_BIT, hal.HAL_IN)
        self.zn = 0

        self.c.newpin("jog.continuous.a.positive", hal.HAL_BIT, hal.HAL_IN)
        self.ap = 0
        self.c.newpin("jog.continuous.a.negative", hal.HAL_BIT, hal.HAL_IN)
        self.an = 0
        self.c.newpin("jog.continuous.b.positive", hal.HAL_BIT, hal.HAL_IN)
        self.bp = 0
        self.c.newpin("jog.continuous.b.negative", hal.HAL_BIT, hal.HAL_IN)
        self.bn = 0
        self.c.newpin("jog.continuous.c.positive", hal.HAL_BIT, hal.HAL_IN)
        self.cp = 0
        self.c.newpin("jog.continuous.c.negative", hal.HAL_BIT, hal.HAL_IN)
        self.cn = 0

        self.c.newpin("jog.continuous.u.positive", hal.HAL_BIT, hal.HAL_IN)
        self.up = 0
        self.c.newpin("jog.continuous.u.negative", hal.HAL_BIT, hal.HAL_IN)
        self.un = 0
        self.c.newpin("jog.continuous.v.positive", hal.HAL_BIT, hal.HAL_IN)
        self.vp = 0
        self.c.newpin("jog.continuous.v.negative", hal.HAL_BIT, hal.HAL_IN)
        self.vn = 0
        self.c.newpin("jog.continuous.w.positive", hal.HAL_BIT, hal.HAL_IN)
        self.wp = 0
        self.c.newpin("jog.continuous.w.negative", hal.HAL_BIT, hal.HAL_IN)
        self.wn = 0

        self.xp_sw = 0
        self.xn_sw = 0
        self.yp_sw = 0
        self.yn_sw = 0
        self.zp_sw = 0
        self.zn_sw = 0
        self.ap_sw = 0
        self.an_sw = 0
        self.bp_sw = 0
        self.bn_sw = 0
        self.cp_sw = 0
        self.cn_sw = 0
        self.up_sw = 0
        self.un_sw = 0
        self.vp_sw = 0
        self.vn_sw = 0
        self.wp_sw = 0
        self.wn_sw = 0
        self.sw_button_presented = 0

        self.c.newpin("joint-for-x", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-y", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-z", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-a", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-b", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-c", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-u", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-v", hal.HAL_U32, hal.HAL_IN)
        self.c.newpin("joint-for-w", hal.HAL_U32, hal.HAL_IN)
        
        self.c.newpin("quill-up", hal.HAL_BIT, hal.HAL_IN)
        self.quillup = 0
        self.c.newpin("cycle-start", hal.HAL_BIT, hal.HAL_IN)
        self.cyclestart = 0
        self.c.newpin("abort", hal.HAL_BIT, hal.HAL_IN)
        self.abort = 0
        self.c.newpin("single-block", hal.HAL_BIT, hal.HAL_IN)
        self.singleblock = 0
        self.c.newpin("wheel-counts", hal.HAL_S32, hal.HAL_IN)
        self.counts = 0
        self.jog_velocity = 1
        if self.gui.injector == 1:
          # let injector call hal ready
          pass
        else:
          self.c.ready()
        self.active = 0
        self.jogaxis(0)
コード例 #16
0
#!/usr/bin/python

import hal
import time
import logging
import logging.config
import uuid
import os

h = hal.component("spindle_logging")
h.newpin("speed_in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("speed_measured", hal.HAL_FLOAT, hal.HAL_IN)
h.ready()


def ConfigureLogger(name, file):
    logger = logging.getLogger(name)
    formatter = logging.Formatter("%(message)s")
    fileHandler = logging.FileHandler(file, mode='a')
    fileHandler.setFormatter(formatter)
    streamFormatter = logging.Formatter("%(name)s %(message)s")
    streamHandler = logging.StreamHandler()
    streamHandler.setFormatter(streamFormatter)
    logger.setLevel(logging.INFO)
    logger.addHandler(fileHandler)
    logger.addHandler(streamHandler)


commandedName = "CommandedSpindle"
measuredName = "MeasuredSpindle"
uid = uuid.uuid4()
コード例 #17
0
        if (len(pinRaw) != 2):
            print(("wrong input"))
            sys.exit(1)
        pin = Pin()
        pin.pin = int(pinRaw[0])
        if ((pin.pin > 5) or (pin.pin < 0)):
            print(("Pin not available"))
            sys.exit(1)
        checkAdcInput(pin)
        if (pinRaw[1] != "none"):
            pin.r2temp = R2Temp(pinRaw[1])
        pin.filterSize = filterSize
        pins.append(pin)

# Initialize HAL
h = hal.component(args.name)
for pin in pins:
    pin.halRawPin = h.newpin(
        getHalName(pin) + ".raw", hal.HAL_FLOAT, hal.HAL_OUT)
    if (pin.r2temp is not None):
        pin.halValuePin = h.newpin(
            getHalName(pin) + ".value", hal.HAL_FLOAT, hal.HAL_OUT)
halErrorPin = h.newpin("error", hal.HAL_BIT, hal.HAL_OUT)
halNoErrorPin = h.newpin("no-error", hal.HAL_BIT, hal.HAL_OUT)
halWatchdogPin = h.newpin("watchdog", hal.HAL_BIT, hal.HAL_OUT)
h.ready()

halErrorPin.value = error
halNoErrorPin.value = not error
halWatchdogPin.value = watchdog
コード例 #18
0
ファイル: test-ui.py プロジェクト: LinuxCNC/linuxcnc
import time
import sys
import os


# this is how long we wait for linuxcnc to do our bidding
timeout = 1.0


#
# set up pins
# shell out to halcmd to net our pins to where they need to go
#

h = hal.component("python-ui")
h.ready()


#
# connect to LinuxCNC
#

c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel()

l = linuxcnc_util.LinuxCNC(command=c, status=s, error=e)

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
コード例 #19
0
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

from vismach import *
import hal

c = hal.component("pumagui")
c.newpin("joint1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint4", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint5", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint6", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("grip", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()

###################
# this stuff is the actual definition of the machine
# ideally it would be in a separate file from the code above
#

# gripper fingers
コード例 #20
0
#!/usr/bin/python
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.register_read_message import ReadInputRegistersResponse
from pprint import pprint
import time
import linuxcnc, hal

updateRate = 0.050  ##Second

plc = hal.component("plc01")
plc.newpin("in.x0", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x1", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x2", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x3", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x4", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x5", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x6", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x7", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x10", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x11", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x12", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x13", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x14", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x15", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x16", hal.HAL_BIT, hal.HAL_OUT)
plc.newpin("in.x17", hal.HAL_BIT, hal.HAL_OUT)

plc.newpin("out.y0", hal.HAL_BIT, hal.HAL_IN)
plc.newpin("out.y1", hal.HAL_BIT, hal.HAL_IN)
plc.newpin("out.y2", hal.HAL_BIT, hal.HAL_IN)
plc.newpin("out.y3", hal.HAL_BIT, hal.HAL_IN)
コード例 #21
0
ファイル: gladevcp.py プロジェクト: LinuxCNC/linuxcnc
        try:
            # try loading as a gtk.builder project
            dbg("**** GLADE VCP INFO:    Not a builder project, trying to load as a lib glade project")
            builder = gtk.glade.XML(xmlname)
            builder = GladeBuilder(builder)

        except Exception,e:
            print >> sys.stderr, "**** GLADE VCP ERROR:    With xml file: %s : %s" % (xmlname,e)
            sys.exit(0)

    window = builder.get_object("window1")

    window.set_title(opts.component)

    try:
        halcomp = hal.component(opts.component)
    except:
        print >> sys.stderr, "*** GLADE VCP ERROR:    Asking for a HAL component using a name that already exists."
        sys.exit(0)

    panel = gladevcp.makepins.GladePanel( halcomp, xmlname, builder, None)

    # at this point, any glade HL widgets and their pins are set up.
    handlers = load_handlers(opts.usermod,halcomp,builder,opts.useropts)

    builder.connect_signals(handlers)

    # This option puts the gladevcp panel into a plug and pushed the plug's
    # X window id number to standard output - so it can be reparented exterally
    # it also forwards events to qtvcp
    if opts.push_XID:
コード例 #22
0
#!/usr/bin/python
import serial
import hal
import sys
import time

PORT = "/dev/ttyACM0"
ser = serial.Serial(PORT, 115200, timeout=0)

#Now we create the HAL component and its pins
## HAL_IN  arduino can read from linuxCNC
## HAL_OUT arduino can write to linuxCNC
#
c = hal.component("arduino")
c.newpin("spindle_rev", hal.HAL_BIT, hal.HAL_IN)
c.newpin("vacuum_pump", hal.HAL_BIT, hal.HAL_IN)
c.newpin("servo_tool", hal.HAL_BIT, hal.HAL_IN)
c.newpin("probe_3d", hal.HAL_BIT, hal.HAL_IN)
#c.newpin("temperature",hal.HAL_FLOAT,hal.HAL_OUT)

time.sleep(1)
c.ready()

spindle_rev = c['spindle_rev']
vacuum_pump = c['vacuum_pump']
servo_tool = c['servo_tool']
probe_3d = c['probe_3d']

spindle_rev_old = 'False'
vacuum_pump_old = 'False'
servo_tool_old = 'False'
コード例 #23
0
ファイル: max5gui.py プロジェクト: zym1rm/linuxcnc
from vismach import *
import hal
import math
import sys

# give endpoint Z values and radii
# resulting cylinder is on the Z axis
class HalToolCylinder(CylinderZ):
    def __init__(self, comp, *args):
        CylinderZ.__init__(self, *args)
        self.comp = comp

    def coords(self):
        return (45, self.comp["tool-radius"], -self.comp["tool-length"], self.comp["tool-radius"])

c = hal.component("max5gui")
# table
c.newpin("table", hal.HAL_FLOAT, hal.HAL_IN)
# saddle
c.newpin("saddle", hal.HAL_FLOAT, hal.HAL_IN)
# head vertical slide
c.newpin("head", hal.HAL_FLOAT, hal.HAL_IN)
# head tilt
c.newpin("tilt", hal.HAL_FLOAT, hal.HAL_IN)
# rotary table
c.newpin("rotate", hal.HAL_FLOAT, hal.HAL_IN)

c.newpin("tool-length", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("tool-radius", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()
コード例 #24
0
    else:
        message = _("Remove the tool and click continue when ready")
    app.wm_withdraw()
    app.update()
    poll_hal_in_background()
    try:
        r = app.tk.call("nf_dialog", ".tool_change",
            _("Tool change"), message, "info", 0, _("Continue"))
    finally:
        stop_polling_hal_in_background()
    if isinstance(r, str): r = int(r)
    if r == 0:
        h.changed = True
    app.update()

h = hal.component("hal_manualtoolchange")
h.newpin("number", hal.HAL_S32, hal.HAL_IN)
h.newpin("change", hal.HAL_BIT, hal.HAL_IN)
h.newpin("changed", hal.HAL_BIT, hal.HAL_OUT)
h.ready()

import Tkinter, nf, rs274.options

app = Tkinter.Tk(className="AxisToolChanger")
app.wm_geometry("-60-60")
app.wm_title(_("AXIS Manual Toolchanger"))
rs274.options.install(app)
nf.start(app); nf.makecommand(app, "_", _)
app.wm_protocol("WM_DELETE_WINDOW", app.wm_withdraw)
lab = Tkinter.Message(app, aspect=500, text = _("\
This window is part of the AXIS manual toolchanger.  It is safe to close \
コード例 #25
0
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# graphic model of a Unimate Puma 560
# according to the dimensions from: http://www.juve.ro/blog/puma/
# the obj files can be downloaded there, and may be included in emc2 later

# link description
# link1 - stationary base
# link2 .. link7 - the 6 moving parts of the robot, numbered form base to end effector

from vismach import *
import hal

c = hal.component("puma560gui")
c.newpin("joint1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint4", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint5", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint6", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("grip", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()

# add a XYZ cross for debug
#floor = Collection([
#	Box(-100,-100,-0.1,100,100,0),
#	Box(-10,-0.1,-10,10,0,10),
#	Box(-0.1,-10,-10,0,10,10),
##	Color([0,1,0,1],[Box(-10,-10,9.9,10,10,10)]),
コード例 #26
0
import sys


# give endpoint Z values and radii
# resulting cylinder is on the Z axis
class HalToolCylinder(CylinderZ):
    def __init__(self, comp, *args):
        CylinderZ.__init__(self, *args)
        self.comp = comp

    def coords(self):
        return (0, self.comp["tool-radius"], self.comp["tool-length"],
                self.comp["tool-radius"])


c = hal.component("mahogui")
# table
c.newpin("table", hal.HAL_FLOAT, hal.HAL_IN)
# full width ways that table rides one
# this assembly moves up and down for Y
c.newpin("tableway", hal.HAL_FLOAT, hal.HAL_IN)
# head vertical slide
c.newpin("head", hal.HAL_FLOAT, hal.HAL_IN)
# head tilt
c.newpin("arotate", hal.HAL_FLOAT, hal.HAL_IN)
# rotary table
c.newpin("brotate", hal.HAL_FLOAT, hal.HAL_IN)

c.newpin("tool-length", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("tool-radius", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()
コード例 #27
0
ファイル: customtask.py プロジェクト: liuzq71/x1Mill_branch
    def __init__(self):
        signal.signal(signal.SIGINT, handler)
        signal.signal(signal.SIGTERM, handler)
        try:
            if debug(): print "py:  CustomTask()"
            emctask.Task.__init__(self)
            self.inifile = emc.ini(emctask.ini_filename())
            self.tcpins = int(self.inifile.find("TOOL", "TASK_TOOLCHANGE_PINS") or 0)
            self.startchange_pins = int(self.inifile.find("TOOL", "TASK_START_CHANGE_PINS") or 0)
            self.fault_pins = int(self.inifile.find("TOOL", "TASK_TOOLCHANGE_FAULT_PINS") or 0)

            h = hal.component("iocontrol.0")
            h.newpin("coolant-flood", hal.HAL_BIT, hal.HAL_OUT)
            h.newpin("coolant-mist", hal.HAL_BIT, hal.HAL_OUT)

            h.newpin("lube-level", hal.HAL_BIT, hal.HAL_OUT)
            h.newpin("lube", hal.HAL_BIT, hal.HAL_OUT)

            h.newpin("emc-enable-in", hal.HAL_BIT, hal.HAL_IN)
            h.newpin("user-enable-out", hal.HAL_BIT, hal.HAL_OUT)
            h.newpin("user-request-enable", hal.HAL_BIT, hal.HAL_OUT)

            if self.tcpins:
                h.newpin("tool-change", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("tool-changed", hal.HAL_BIT, hal.HAL_IN)
                h.newpin("tool-number", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("tool-prep-number", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("tool-prep-pocket", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("tool-prepare", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("tool-prepared", hal.HAL_BIT, hal.HAL_IN)
            if self.startchange_pins:
                h.newpin("start-change", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("start-change-ack", hal.HAL_BIT, hal.HAL_IN)
            if self.fault_pins:
                h.newpin("emc-abort", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("emc-abort-ack", hal.HAL_BIT, hal.HAL_IN)
                h.newpin("emc-reason", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("toolchanger-fault", hal.HAL_BIT, hal.HAL_IN)
                h.newpin("toolchanger-fault-ack", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("toolchanger-reason", hal.HAL_S32, hal.HAL_IN)
                h.newpin("toolchanger-faulted", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("toolchanger-clear-fault", hal.HAL_BIT, hal.HAL_IN)

            h.ready()
            self.components = dict()
            self.components["iocontrol.0"] = h
            self.hal = h
            self.hal_init_pins()
            self.io = emctask.emcstat.io
            self.io.aux.estop = 1
            self._callback = None
            self._check = None
            tt = self.io.tool.toolTable
            for p in range(0,len(tt)):
                tt[p].zero()
            UserFuncs.__init__(self)
            self.enqueue = EnqueueCall(self)
        except Exception,e:
            print "__init__"
            print_exc_plus()
            self.io.status  = emctask.RCS_STATUS.RCS_ERROR
コード例 #28
0
ファイル: dargon-gui2.py プロジェクト: KangFu45/linuxcnc
#!/usr/bin/env python

from vismach import *
import hal

c = hal.component("dargon-gui2")
c.newpin("joint-x", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint-y", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint-z", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()

###################

tooltip = Capture()

tool = Collection([
    tooltip,
    #Color([0.5,0.5,0.5,0],
    CylinderZ(0, 0.3, 10, 5),
    CylinderZ(10, 5, 30, 5)
])
#tool = Translate([tool],0,0,-15)

zzz = Collection([tool, Color([0, 1, 0, 0], [Box(15, -5, 20, -15, -25, 520)])])

zzz = Translate([zzz], 0, 0, 400)
zzz = HalTranslate([zzz], c, "joint-z", 0, 0, -1)
zzz = HalTranslate([zzz], c, "joint-x", 1, 0, 0)

xxx = Collection(
    [zzz, Color([0, 0, 1, 0], [Box(555, -25, 420, -45, -40, 440)])])
コード例 #29
0
if (args.output_pins != ""):
    outputPinsRaw = args.output_pins.split(',')
    for pinRaw in outputPinsRaw:
        pins.append(parseInputPin(pinRaw, MCP23017.DIR_OUT))
if (args.input_pins != ""):
    inputPinsRaw = args.input_pins.split(',')
    for pinRaw in inputPinsRaw:
        pins.append(parseInputPin(pinRaw, MCP23017.DIR_IN))

if (len(pins) == 0):
    print(("No pins specified"))
    sys.exit(1)

# Initialize HAL
h = hal.component(args.name)
for pin in pins:
    if (pin.direction == MCP23017.DIR_IN):
        pin.halPin = h.newpin(getHalName(pin), hal.HAL_BIT, hal.HAL_OUT)
    else:
        pin.halPin = h.newpin(getHalName(pin), hal.HAL_BIT, hal.HAL_IN)
    pin.halPullupPin = h.newpin(getHalName(pin) + ".pullup", hal.HAL_BIT, hal.HAL_IN)
    pin.halInvertedPin = h.newpin(getHalName(pin) + ".invert", hal.HAL_BIT, hal.HAL_IN)
halErrorPin = h.newpin("error", hal.HAL_BIT, hal.HAL_OUT)
halNoErrorPin = h.newpin("no-error", hal.HAL_BIT, hal.HAL_OUT)
halWatchdogPin = h.newpin("watchdog", hal.HAL_BIT, hal.HAL_OUT)
h.ready()

halErrorPin.value = error
halNoErrorPin.value = not error
halWatchdogPin.value = watchdog
コード例 #30
0
ファイル: 5axisgui.py プロジェクト: zym1rm/linuxcnc
    print(setting)
    exec(setting)

# give endpoint Z values and radii
# resulting cylinder is on the Z axis
class HalToolCylinder(CylinderZ):
    def __init__(self, comp, *args):
        CylinderZ.__init__(self, *args)
        self.comp = comp

    def coords(self):
        r = 20 # default if hal pin not set
        if (c.tool_diam > 0): r=c.tool_diam/2
        return -self.comp.tool_length, r, 0, r

c = hal.component("5axisgui")
c.newpin("jx", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("jy", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("jz", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("jb", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("jc", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("tool_length", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("tool_diam", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("pivot_len", hal.HAL_FLOAT, hal.HAL_OUT)
c["pivot_len"] = pivot_len
c.ready()

tooltip = Capture()
tool = Collection([HalTranslate([tooltip], c, "tool_length", 0,0,-1),
                   HalToolCylinder(c),
                   CylinderZ(pivot_len-(zb+za), 100, 0.0, 50),
コード例 #31
0
ファイル: hal.py プロジェクト: paulhart/graster
#!/usr/bin/env python

import hal

h = hal.component("circle")
h.newpin("center", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("radius", hal.HAL_FLOAT, hal.HAL_IN)
h.ready()
コード例 #32
0
ファイル: rostock.py プロジェクト: trigrass2/machinekit-2
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
from vismach import *
import hal
import lineardeltakins
import sys

EFFECTOR_OFFSET = CARRIAGE_OFFSET = 30
MIN_JOINT = -236
MAX_JOINT = 300

for setting in sys.argv[1:]:
    exec setting

c = hal.component("rostock")
c.newpin("joint0", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("R", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("L", hal.HAL_FLOAT, hal.HAL_IN)
c['R'], c['L'] = lineardeltakins.get_geometry()
c.ready()


class DeltaTranslate(Collection):
    def __init__(self, parts, comp):
        self.comp = comp
        self.parts = parts
        self.x = self.y = self.z = 0
コード例 #33
0
    else:
        message = _("Remove the tool and click continue when ready")
    app.wm_withdraw()
    app.update()
    poll_hal_in_background()
    try:
        r = app.tk.call("nf_dialog", ".tool_change",
            _("Tool change"), message, "info", 0, _("Continue"))
    finally:
        stop_polling_hal_in_background()
    if isinstance(r, str): r = int(r)
    if r == 0:
        h.changed = True
    app.update()

h = hal.component("hal_manualtoolchange")
h.newpin("number", hal.HAL_S32, hal.HAL_IN)
h.newpin("change", hal.HAL_BIT, hal.HAL_IN)
h.newpin("change_button", hal.HAL_BIT, hal.HAL_IN)
h.newpin("changed", hal.HAL_BIT, hal.HAL_OUT)
h.ready()

import Tkinter, nf, rs274.options

app = Tkinter.Tk(className="AxisToolChanger")
app.wm_geometry("-60-60")
app.wm_title(_("AXIS Manual Toolchanger"))
rs274.options.install(app)
nf.start(app); nf.makecommand(app, "_", _)
app.wm_protocol("WM_DELETE_WINDOW", app.wm_withdraw)
lab = Tkinter.Message(app, aspect=500, text = _("\
コード例 #34
0
ファイル: hallink.py プロジェクト: bhushan00/linuxcnc-plasmac
#!/usr/bin/env python

import subprocess
import hal

def cmd(arg):
    subprocess.call(arg, shell=True)

h = hal.component("linktest")
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("inout", hal.HAL_FLOAT, hal.HAL_IO)
h.ready()

# set pin values before linking
h['in'] = 42
h['inout'] = 43
assert h['in'] == 42
assert h['inout'] == 43

# make sure halcmd setp works as expected
cmd("halcmd setp linktest.in    4712")
cmd("halcmd setp linktest.inout 4713")
assert h['in'] == 4712
assert h['inout'] == 4713

# create virgin signals
cmd("halcmd newsig insig float")
cmd("halcmd newsig inoutsig float")

# link to them
cmd("halcmd net insig    linktest.in")
コード例 #35
0
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#**************************************************************************

#--------------------------------------------------------------------------
# Visualization model of the Hermle mill, as modified to 5-axis
# with rotary axes B and C added, with moving spindle head
# and rotary axis offsets
#--------------------------------------------------------------------------

from vismach import *
import hal
import math
import sys

c = hal.component("xyzbc-trt-gui")
# table-x
c.newpin("table-x", hal.HAL_FLOAT, hal.HAL_IN)
# saddle-y
c.newpin("saddle-y", hal.HAL_FLOAT, hal.HAL_IN)
# head vertical slide
c.newpin("spindle-z", hal.HAL_FLOAT, hal.HAL_IN)
# table-x tilt-b
c.newpin("tilt-b", hal.HAL_FLOAT, hal.HAL_IN)
# rotary table-x
c.newpin("rotate-c", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("z-offset", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("x-offset", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("tool-offset", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()
コード例 #36
0
ファイル: heater.py プロジェクト: ftkalcevic/CNCRouterConfig
print "heater: Starting Heater port=", port, " name=", component_name

# open the serial port to the platform
ser = serial.Serial()
ser.port = port
ser.baudrate = 19200
ser.timeout = 0
ser.xonxoff = False
print "heater: Opening port"
ser.open()
if not ser.isOpen():
    print "heater: Failed to open serial port"
    sys.exit()

# create hal pins
c = hal.component(component_name)
c.newpin("run", hal.HAL_BIT, hal.HAL_IN)
c.newpin("running", hal.HAL_BIT, hal.HAL_OUT)
c.newpin("ready", hal.HAL_BIT, hal.HAL_OUT)
c.newpin("set-temp", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("temp", hal.HAL_FLOAT, hal.HAL_OUT)
c.newpin("actual-set-temp", hal.HAL_FLOAT, hal.HAL_OUT)

# last values of the input or input/output pins
last_run = 0
last_set_temp = 0
last_poll_time = 0

WAIT_FOR_STX = 1
WAIT_FOR_MSG = 2
WAIT_FOR_CHKSUM = 3
コード例 #37
0
ファイル: art_scaragui.py プロジェクト: yisea123/linuxcnc-2
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

from vismach import *
import hal
import math
import sys
import time

c = hal.component("art_scaragui")
c.newpin("joint0", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint4", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint5", hal.HAL_FLOAT, hal.HAL_IN)

c.newpin("D1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("D2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("D3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("D4", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("D5", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("D6", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("J3MIN", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("J3MAX", hal.HAL_FLOAT, hal.HAL_IN)
コード例 #38
0
ファイル: tracking-test.py プロジェクト: zym1rm/linuxcnc
# Copyright 2007 Ben Lipkowitz
# You may distribute this software under the GNU GPL v2 or later
#
# see configs/tracking-test.hal

from vismach import *
import hal
import sys

for setting in sys.argv[1:]:
    exec(setting)

#compname must be the same as given in 'loadusr -W' or the comp
#will never be ready
compname = "tracking-test"
c = hal.component(compname)
#declare hal pins here
c.newpin("joint0", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint4", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint5", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("axis0", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("axis1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("axis2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("axis3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("axis4", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("axis5", hal.HAL_FLOAT, hal.HAL_IN)

c.ready()
コード例 #39
0
    def __init__(self,
                 vfd_names=[['mitsub_vfd', '00']],
                 baudrate=9600,
                 port='/dev/ttyUSB0'):
        try:
            self.ser = serial.Serial(port,
                                     baudrate,
                                     parity=serial.PARITY_NONE,
                                     stopbits=serial.STOPBITS_TWO,
                                     bytesize=serial.EIGHTBITS)
            self.ser.open()
            self.ser.isOpen()
        except Exception as e:
            try:
                self.ser.close()
                self.ser.open()
            except:
                print(
                    "ERROR : mitsub_vfd - No serial interface found at %s\nError: %s"
                    % (port, e))
                pass
            #raise SystemExit
        print("Mitsubishi VFD serial computer link has loaded")
        print(
            "Port: %s,\nbaudrate: %d\n8 data bits, no parity, 2 stop bits\n" %
            (port, baudrate))

        self.h = []
        self.comp_names = vfd_names
        for index, name in enumerate(self.comp_names):
            #print index,' NAME:',name[0],' SLAVE:',name[1]
            c = hal.component(name[0])
            c.newpin("fwd", hal.HAL_BIT, hal.HAL_IN)
            c.newpin("run", hal.HAL_BIT, hal.HAL_IN)
            c.newpin("up-to-speed", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("alarm", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("debug", hal.HAL_BIT, hal.HAL_IN)
            c.newpin("monitor", hal.HAL_BIT, hal.HAL_IN)
            c.newpin("motor-cmd", hal.HAL_FLOAT, hal.HAL_IN)
            c.newpin("motor-fb", hal.HAL_FLOAT, hal.HAL_OUT)
            c.newpin("motor-amps", hal.HAL_FLOAT, hal.HAL_OUT)
            c.newpin("motor-volts", hal.HAL_FLOAT, hal.HAL_OUT)
            c.newpin("motor-power", hal.HAL_FLOAT, hal.HAL_OUT)
            c.newpin("motor-user", hal.HAL_FLOAT, hal.HAL_OUT)
            c.newpin("scale-cmd", hal.HAL_FLOAT, hal.HAL_IN)
            c.newpin("scale-fb", hal.HAL_FLOAT, hal.HAL_IN)
            c.newpin("scale-amps", hal.HAL_FLOAT, hal.HAL_IN)
            c.newpin("scale-volts", hal.HAL_FLOAT, hal.HAL_IN)
            c.newpin("scale-power", hal.HAL_FLOAT, hal.HAL_IN)
            c.newpin("scale-user", hal.HAL_FLOAT, hal.HAL_IN)
            c.newpin("estop", hal.HAL_BIT, hal.HAL_IN)
            c.newpin("stat-bit-0", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("stat-bit-1", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("stat-bit-2", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("stat-bit-3", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("stat-bit-4", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("stat-bit-5", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("stat-bit-6", hal.HAL_BIT, hal.HAL_OUT)
            c.newpin("stat-bit-7", hal.HAL_BIT, hal.HAL_OUT)
            # set reasonable defaults
            c['scale-cmd'] = 1
            c['scale-fb'] = 1
            c['scale-amps'] = 1
            c['scale-volts'] = 1
            c['scale-power'] = 1
            c['scale-user'] = 1
            c['fwd'] = 1
            # flags for each device
            self['last_run%d' % index] = c['run']
            self['last_fwd%d' % index] = c['fwd']
            self['last_cmd%d' % index] = c['motor-cmd']
            self['last_monitor%d' % index] = c['monitor']
            self['last_estop%d' % index] = c['estop']
            #add device to component reference variable
            self.h.append(c)
            print("Mitsubishi %s VFD: slave# %s added\n" % (name[0], name[1]))

        # only issue ready when all the components are ready
        for i in self.h:
            i.ready()
        self.set_special_monitor()
コード例 #40
0
# G91 G1 F50 Z0.01
# repeat at a slower speed to get a more accurate reading
# G90 G38.2 Z2.240 F1

# Now back off so that operator can remove the probe
# G0 Z0.5 G91
# TODO does this leave us in incremental mode? That would be bad.

# For all of these commands, we know to execute the next one once machine.in-position is true

# Inputs: start, in-position
# Outputs: 5 unique mdi commands

import hal, time

h = hal.component("probe-touchoff")
h.newpin("start", hal.HAL_BIT, hal.HAL_IN)
h.newpin("in-position", hal.HAL_BIT, hal.HAL_IN)
h.newpin("mdi-g54z0", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("mdi-g38fast", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("mdi-backoff-tiny", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("mdi-g38slow", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("mdi-backoff-final", hal.HAL_BIT, hal.HAL_OUT)
h.ready()

# MDI_DURATION=1
MDI_DURATION=0.1
SHORT_SLEEP=0.1

# Periodically, usually in response to a timer, all HAL_OUT pins should be "driven" by assigning
# them a new value. This should be done whether or not the value is different than the last one
コード例 #41
0
ファイル: customtask.py プロジェクト: 13788593535/machinekit
    def __init__(self):
        signal.signal(signal.SIGINT, handler)
        signal.signal(signal.SIGTERM, handler)
        try:
            if debug(): print "py:  CustomTask()"
            emctask.Task.__init__(self)
            self.inifile = emc.ini(emctask.ini_filename())
            self.tcpins = int(self.inifile.find("TOOL", "TASK_TOOLCHANGE_PINS") or 0)
            self.startchange_pins = int(self.inifile.find("TOOL", "TASK_START_CHANGE_PINS") or 0)
            self.fault_pins = int(self.inifile.find("TOOL", "TASK_TOOLCHANGE_FAULT_PINS") or 0)

            h = hal.component("iocontrol.0")
            h.newpin("coolant-flood", hal.HAL_BIT, hal.HAL_OUT)
            h.newpin("coolant-mist", hal.HAL_BIT, hal.HAL_OUT)

            h.newpin("lube-level", hal.HAL_BIT, hal.HAL_OUT)
            h.newpin("lube", hal.HAL_BIT, hal.HAL_OUT)

            h.newpin("emc-enable-in", hal.HAL_BIT, hal.HAL_IN)
            h.newpin("user-enable-out", hal.HAL_BIT, hal.HAL_OUT)
            h.newpin("user-request-enable", hal.HAL_BIT, hal.HAL_OUT)

            if self.tcpins:
                h.newpin("tool-change", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("tool-changed", hal.HAL_BIT, hal.HAL_IN)
                h.newpin("tool-number", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("tool-prep-number", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("tool-prep-pocket", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("tool-prepare", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("tool-prepared", hal.HAL_BIT, hal.HAL_IN)
            if self.startchange_pins:
                h.newpin("start-change", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("start-change-ack", hal.HAL_BIT, hal.HAL_IN)
            if self.fault_pins:
                h.newpin("emc-abort", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("emc-abort-ack", hal.HAL_BIT, hal.HAL_IN)
                h.newpin("emc-reason", hal.HAL_S32, hal.HAL_OUT)
                h.newpin("toolchanger-fault", hal.HAL_BIT, hal.HAL_IN)
                h.newpin("toolchanger-fault-ack", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("toolchanger-reason", hal.HAL_S32, hal.HAL_IN)
                h.newpin("toolchanger-faulted", hal.HAL_BIT, hal.HAL_OUT)
                h.newpin("toolchanger-clear-fault", hal.HAL_BIT, hal.HAL_IN)

            h.ready()
            self.components = dict()
            self.components["iocontrol.0"] = h
            self.hal = h
            self.hal_init_pins()
            self.io = emctask.emcstat.io
            self.io.aux.estop = 1
            self._callback = None
            self._check = None
            tt = self.io.tool.toolTable
            for p in range(0,len(tt)):
                tt[p].zero()
            UserFuncs.__init__(self)
            self.enqueue = EnqueueCall(self)
        except Exception,e:
            print "__init__"
            print_exc_plus()
            self.io.status  = emctask.RCS_STATUS.RCS_ERROR
コード例 #42
0
ファイル: ctrlpanel.py プロジェクト: pvd/cncmill
#!/usr/bin/python

import serial
import time
import struct
import hal

comm = serial.Serial()
comm.port = "/dev/ttyACM0"
comm.baudrate = 115200
comm.timeout = 1
comm.dtr = True
comm.open()

h = hal.component("ctrlpanel")
h.newpin("mpgXcount", hal.HAL_S32, hal.HAL_OUT)
h.newpin("mpgYcount", hal.HAL_S32, hal.HAL_OUT)
h.newpin("mpgZcount", hal.HAL_S32, hal.HAL_OUT)

# buttons
h.newpin("power", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("home", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("zeroAll", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("zeroX", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("zeroY", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("zeroZ", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("start", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("stop", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("laser", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("feedPlus", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("feedMin", hal.HAL_BIT, hal.HAL_OUT)
コード例 #43
0
ファイル: gladevcp.py プロジェクト: kinsamanka/machinekit-NG
    if opts.instance != -1:
        print >> sys.stderr, "*** GLADE VCP ERROR: the -I option is deprecated, either use:"
        print >> sys.stderr, "-s <uuid> for zeroconf lookup, or"
        print >> sys.stderr, "-C <halrcmd_uri> -M <halrcomp_uri> for explicit URI's "
        sys.exit(0)

    if opts.svc_uuid and (opts.halrcmd_uri or opts.halrcomp_uri):
        print >> sys.stderr, "*** GLADE VCP ERROR: use either -s<uuid> or -C/-M, but not both"
        sys.exit(0)

    if not (opts.svc_uuid or opts.use_mki or opts.halrcmd_uri
            or opts.halrcomp_uri):  # local
        try:
            import hal
            halcomp = hal.component(opts.component)
        except:
            print >> sys.stderr, "*** GLADE VCP ERROR:    Asking for a HAL component using a name that already exists."
            sys.exit(0)

        panel = gladevcp.makepins.GladePanel(halcomp, xmlname, builder, None)
    else:
        if opts.rcdebug:
            print "remote uuid=%s halrcmd=%s halrcomp=%s" % (
                opts.svc_uuid, opts.halrcmd_uri, opts.halrcomp_uri)
        if opts.use_mki:
            mki = ConfigParser.ConfigParser()
            mki.read(os.getenv("MACHINEKIT_INI"))
            uuid = mki.get("MACHINEKIT", "MKUUID")
        else:
            uuid = opts.svc_uuid
コード例 #44
0
#!/usr/bin/env python3
import hal
import time
c = hal.component("stream_writer")
writer = hal.stream(c, hal.streamer_base, 10, "bfsu")

for i in range(9):
    assert writer.writable
    writer.write((i % 2, i, i, i))
assert not writer.writable
assert writer.num_overruns == 0
try:
    writer.write((1,1,1,1))
except:
    pass
else:
    assert False, "failed to get exception on full stream"
assert writer.num_overruns == 1
c.ready()

try:
    while 1: time.sleep(1)
except KeyboardInterrupt: pass
コード例 #45
0
ファイル: test-ui.py プロジェクト: LinuxCNC/linuxcnc
            return
        time.sleep(0.1)
    raise RuntimeError("hal pin %s didn't get to %s after %.3f seconds" % (name, value, timeout))


# After doing something that should change the stat buffer, wait this
# long before polling to let the change propagate through.
# FIXME: this is bogus
stat_poll_wait = 0.100


c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel()

h = hal.component("test-ui")

h.newpin("tool-change", hal.HAL_BIT, hal.HAL_IN)
h.newpin("tool-changed", hal.HAL_BIT, hal.HAL_OUT)
h["tool-changed"] = False

h.newpin("tool-prepare", hal.HAL_BIT, hal.HAL_IN)
h.newpin("tool-prepared", hal.HAL_BIT, hal.HAL_OUT)
h["tool-prepared"] = False

h.newpin("tool-number", hal.HAL_S32, hal.HAL_IN)
h.newpin("tool-prep-number", hal.HAL_S32, hal.HAL_IN)
h.newpin("tool-prep-pocket", hal.HAL_S32, hal.HAL_IN)

h.ready()
コード例 #46
0
ファイル: qtvcp.py プロジェクト: seamanking/linuxcnc
    def __init__(self):
        sys.excepthook = self.excepthook
        INIPATH = None
        usage = "usage: %prog [options] myfile.ui"
        parser = OptionParser(usage=usage)
        parser.disable_interspersed_args()
        parser.add_options(options)
        # remove [-ini filepath] that linuxcnc adds if being launched as a screen
        # keep a reference of that path
        for i in range(len(sys.argv)):
            if sys.argv[i] =='-ini':
                # delete -ini
                del sys.argv[i]
                # pop out the ini path
                INIPATH = sys.argv.pop(i)
                break

        (opts, args) = parser.parse_args()

        # initialize QApp so we can pop up dialogs now. 
        self.app = QtWidgets.QApplication(sys.argv)

        # we import here so that the QApp is initialized before
        # the Notify library is loaded because it uses DBusQtMainLoop
        # DBusQtMainLoop must be initialized after to work properly
        from qtvcp import qt_makepins, qt_makegui

        # ToDo: pass specific log levels as an argument, or use an INI setting
        if not opts.debug:
            # Log level defaults to DEBUG, so set higher if not debug
            logger.setGlobalLevel(logger.ERROR)

        # a specific path has been set to load from or...
        # no path set but -ini is present: default qtvcp screen...or
        # oops error
        if args:
            basepath=args[0]
        elif INIPATH:
            basepath = "qt_cnc"
        else:
            log.error('Error in path')
            sys.exit()

        # set paths using basename
        PATH = Paths(basepath, bool(INIPATH))

        #################
        # Screen specific
        #################
        if INIPATH:
            log.debug('Building A Linuxcnc Main Screen')
            import linuxcnc
            # internationalization and localization
            import locale, gettext
            # pull info from the INI file
            self.inifile = linuxcnc.ini(INIPATH)
            self.inipath = INIPATH
            # screens require more path info
            PATH.add_screen_paths()

            # International translation
            locale.setlocale(locale.LC_ALL, '')
            locale.bindtextdomain(PATH.DOMAIN, PATH.LOCALEDIR)
            gettext.install(PATH.DOMAIN, localedir=PATH.LOCALEDIR, unicode=True)
            gettext.bindtextdomain(PATH.DOMAIN, PATH.LOCALEDIR)

            # if no handler file specified, use stock test one
            if not opts.usermod:
                log.info('No handler file specified on command line')
                target =  os.path.join(PATH.CONFIGPATH, '%s_handler.py' % PATH.BASENAME)
                source =  os.path.join(PATH.SCREENDIR, 'tester/tester_handler.py')
                if PATH.HANDLER is None:
                    message = ("""
Qtvcp encountered an error; No handler file was found.
Would you like to copy a basic handler file into your config folder?
This handker file will allow display of your screen and basic keyboard jogging.

The new handlerfile's path will be:
%s

Pressing cancel will close linuxcnc.""" % target)
                    rtn = QtWidgets.QMessageBox.critical(None, "QTVCP Error", message,QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
                    if rtn == QtWidgets.QMessageBox.Ok:
                        try:
                            shutil.copy(source, target)
                        except IOError as e:
                            log.critical("Unable to copy handler file. %s" % e)
                            sys.exit(0)
                        except:
                            log.critical("Unexpected error copying handler file:", sys.exc_info())
                            sys.exit(0)
                        opts.usermod = PATH.HANDLER = target
                    else:
                        log.critical('No handler file found or specified. User requested stopping')
                else:
                    opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                log.info('No HAL component base name specified on command line using: {}'.format(PATH.BASENAME))
                opts.component = PATH.BASENAME

        #################
        # VCP specific
        #################
        else:
            log.debug('Building A VCP Panel')
            # if no handler file specified, use stock test one
            if not opts.usermod:
                log.info('No handler file specified - using {}'.format(PATH.HANDLER))
                opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                log.info('No HAL component base name specified - using: {}'.format(PATH.BASENAME))
                opts.component = PATH.BASENAME

        ##############
        # Build ui
        ##############

        #if there was no component name specified use the xml file name
        if opts.component is None:
            opts.component = PATH.BASENAME

        # initialize HAL
        try:
            self.halcomp = hal.component(opts.component)
            self.hal = QComponent(self.halcomp)
        except:
            log.critical("Asking for a HAL component using a name that already exists?")
            sys.exit(0)

        # initialize the window
        window = qt_makegui.MyWindow(self.hal, PATH)
 
        # load optional user handler file
        if opts.usermod:
            log.debug('Loading the handler file')
            window.load_extension(opts.usermod)
            # do any class patching now
            if "class_patch__" in dir(window.handler_instance):
                window.handler_instance.class_patch__()
            # add filter to catch keyboard events
            log.debug('Adding the key events filter')
            myFilter = qt_makegui.MyEventFilter(window)
            self.app.installEventFilter(myFilter)

        # actually build the widgets
        window.instance()

        # make QT widget HAL pins
        self.panel = qt_makepins.QTPanel(self.hal, PATH, window, opts.debug)

        # call handler file's initialized function
        if opts.usermod:
            if "initialized__" in dir(window.handler_instance):
                log.debug('''Calling the handler file's initialized__ function''')
                window.handler_instance.initialized__()
        # All Widgets should be added now - synch them to linuxcnc
        STATUS.forced_update()

        # User components are set up so report that we are ready
        log.debug('Set HAL ready')
        self.halcomp.ready()

        # embed us into an X11 window (such as AXIS)
        if opts.parent:
            window = xembed.reparent_qt_to_x11(window, opts.parent)
            forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None)
            log.critical('Forwarding events to AXIS is not well tested yet')
            if forward:
                xembed.XEmbedFowarding(window, forward)

        # push the window id for embedment into an external program
        if opts.push_XID:
            wid = int(window.winId())
            print >> sys.stdout,wid
            sys.stdout.flush()

        # for window resize and or position options
        if "+" in opts.geometry:
            log.debug('-g option: moving window')
            try:
                j =  opts.geometry.partition("+")
                pos = j[2].partition("+")
                window.move( int(pos[0]), int(pos[2]) )
            except:
                log.critical("With window position data")
                parser.print_usage()
                sys.exit(1)
        if "x" in opts.geometry:
            log.debug('-g option: resizing')
            try:
                if "+" in opts.geometry:
                    j =  opts.geometry.partition("+")
                    t = j[0].partition("x")
                else:
                    t = window_geometry.partition("x")
                window.resize( int(t[0]), int(t[2]) )
            except:
                log.critical("With window resize data")
                parser.print_usage()
                sys.exit(1)

        # always on top
        if opts.always_top:
            window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

        # theme (styles in QT speak) specify a qss file
        if opts.theme:
            window.apply_styles(opts.theme)
        # appy qss file or default theme
        else:
            window.apply_styles()

        # title
        if INIPATH:
            title = 'QTvcp-Screen-%s'% opts.component
        else:
            title = 'QTvcp-Panel-%s'% opts.component
        window.setWindowTitle(title)

        log.debug('Show window')
        # maximize
        if opts.maximum:
            window.showMaximized()
        # fullscreen
        elif opts.fullscreen:
            window.showFullScreen()
        else:
            self.panel.set_preference_geometry()
        window.show()
        if INIPATH:
            self.postgui()

        # catch control c and terminate signals
        signal.signal(signal.SIGTERM, self.shutdown)
        signal.signal(signal.SIGINT, self.shutdown)

        if opts.usermod and "before_loop__" in dir(window.handler_instance):
            log.debug('''Calling the handler file's before_loop__ function''')
            window.handler_instance.before_loop__()
        # start loop
        self.app.exec_()

        # now shut it all down
        self.shutdown()
コード例 #47
0
ファイル: t.py プロジェクト: ftkalcevic/CNCConfig
#!/usr/bin/python
import hal, time
h = hal.component("passthrough")
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT) 
h.ready()
try:    
	while 0:        
      		time.sleep(1)        
		h['out'] = h['in']
except KeyboardInterrupt:    
	raise SystemExit

コード例 #48
0
ファイル: alsa-fft.py プロジェクト: AceXIE/mk
def calculate_levels(data, chunk,sample_rate):
#   data    = unpack("%dh" % (len(data)), data)
   data    = np.fromstring(data, dtype='int16')
#   data    = np.array(data, dtype='h')
   fourier = np.fft.rfft(data)
   fourier = np.delete(fourier, len(fourier)-1)
   power   = np.log10(np.abs(fourier)+0.000001)**2
#   print (power)
   power   = np.reshape(power, (rows, chunk/rows/2))
   matrix  = np.average(power, axis=1)/4
   return matrix

logging.debug("init")

h = hal.component("alsa-fft")
h.newpin("min", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("max", hal.HAL_FLOAT, hal.HAL_OUT)
for i in range(0, rows):
   h.newpin("fft-%d" % (i), hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
logging.debug("ready")

sample_rate = 44100
chunk       = 1024 # Use a multiple of [rows]

logging.debug("aa.PCM begin")
audio = aa.PCM(type=aa.PCM_CAPTURE, mode=aa.PCM_NORMAL)
audio.setchannels(1)
audio.setrate(sample_rate)
audio.setformat(aa.PCM_FORMAT_S16_LE)
コード例 #49
0
ファイル: hal_interface.py プロジェクト: EqAfrica/machinekit
    def __init__(self, gui, emc_control, mdi_control, emc):
        self.gui = gui
        self.emc_control = emc_control
        self.emc = emc
        self.emc_stat = self.emc.stat()
        self.mdi_control = mdi_control
        self.c = hal.component("touchy")
        self.c.newpin("status-indicator", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.active", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.x", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.y", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.z", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.a", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.b", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.c", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.u", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.v", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.w", hal.HAL_BIT, hal.HAL_OUT)
        self.c.newpin("jog.wheel.increment", hal.HAL_FLOAT, hal.HAL_OUT)

        self.c.newpin("jog.continuous.x.positive", hal.HAL_BIT, hal.HAL_IN)
        self.xp = 0
        self.c.newpin("jog.continuous.x.negative", hal.HAL_BIT, hal.HAL_IN)
        self.xn = 0
        self.c.newpin("jog.continuous.y.positive", hal.HAL_BIT, hal.HAL_IN)
        self.yp = 0
        self.c.newpin("jog.continuous.y.negative", hal.HAL_BIT, hal.HAL_IN)
        self.yn = 0
        self.c.newpin("jog.continuous.z.positive", hal.HAL_BIT, hal.HAL_IN)
        self.zp = 0
        self.c.newpin("jog.continuous.z.negative", hal.HAL_BIT, hal.HAL_IN)
        self.zn = 0

        self.c.newpin("jog.continuous.a.positive", hal.HAL_BIT, hal.HAL_IN)
        self.ap = 0
        self.c.newpin("jog.continuous.a.negative", hal.HAL_BIT, hal.HAL_IN)
        self.an = 0
        self.c.newpin("jog.continuous.b.positive", hal.HAL_BIT, hal.HAL_IN)
        self.bp = 0
        self.c.newpin("jog.continuous.b.negative", hal.HAL_BIT, hal.HAL_IN)
        self.bn = 0
        self.c.newpin("jog.continuous.c.positive", hal.HAL_BIT, hal.HAL_IN)
        self.cp = 0
        self.c.newpin("jog.continuous.c.negative", hal.HAL_BIT, hal.HAL_IN)
        self.cn = 0

        self.c.newpin("jog.continuous.u.positive", hal.HAL_BIT, hal.HAL_IN)
        self.up = 0
        self.c.newpin("jog.continuous.u.negative", hal.HAL_BIT, hal.HAL_IN)
        self.un = 0
        self.c.newpin("jog.continuous.v.positive", hal.HAL_BIT, hal.HAL_IN)
        self.vp = 0
        self.c.newpin("jog.continuous.v.negative", hal.HAL_BIT, hal.HAL_IN)
        self.vn = 0
        self.c.newpin("jog.continuous.w.positive", hal.HAL_BIT, hal.HAL_IN)
        self.wp = 0
        self.c.newpin("jog.continuous.w.negative", hal.HAL_BIT, hal.HAL_IN)
        self.wn = 0

        self.c.newpin("quill-up", hal.HAL_BIT, hal.HAL_IN)
        self.quillup = 0
        self.c.newpin("cycle-start", hal.HAL_BIT, hal.HAL_IN)
        self.cyclestart = 0
        self.c.newpin("abort", hal.HAL_BIT, hal.HAL_IN)
        self.abort = 0
        self.c.newpin("single-block", hal.HAL_BIT, hal.HAL_IN)
        self.singleblock = 0
        self.c.newpin("wheel-counts", hal.HAL_S32, hal.HAL_IN)
        self.counts = 0
        self.jog_velocity = 1
        self.c.ready()
        self.active = 0
        self.jogaxis(0)
コード例 #50
0
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


from vismach import *
import hal
import math
import sys

c = hal.component("scaragui")
c.newpin("joint0", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint1", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint2", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint3", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint4", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("joint5", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()

# parameters that define the geometry see scarakins.c for definitions these
# numbers match the defaults there, and will need to be changed or specified on
# the commandline if you are not using the defaults.

d1 =  490.0
d2 =  340.0
d3 =   50.0
コード例 #51
0
#!/usr/bin/env python

from PowermaxSerialFuncs import *
import hal
import sys


try:
	h = hal.component("powermax")
	h.newpin("minCurr", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("maxCurr", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("minPres", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("maxPres", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("runTime", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("fltCode", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("presFB", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("currFB", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("presSP", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("currSP", hal.HAL_FLOAT, hal.HAL_IN)
	h.newpin("machON", hal.HAL_BIT, hal.HAL_IN)
	h.newpin("modeNorSP", hal.HAL_BIT, hal.HAL_IN)	
	h.newpin("modeCpaSP", hal.HAL_BIT, hal.HAL_IN)	
	h.newpin("modeGouSP", hal.HAL_BIT, hal.HAL_IN)	
	h.newpin("modeNorFB", hal.HAL_BIT, hal.HAL_OUT)	
	h.newpin("modeCpaFB", hal.HAL_BIT, hal.HAL_OUT)	
	h.newpin("modeGouFB", hal.HAL_BIT, hal.HAL_OUT)	
	h.ready()
	#print "PYTHON SERIAL: Finished creating HAL pins"
except:
	raise
	
コード例 #52
0
	def run(self) :
		import hal, time
		
		self.h = hal.component("compensation")
		self.h.newpin("enable-in", hal.HAL_BIT, hal.HAL_IN)
		self.h.newpin("enable-out", hal.HAL_BIT, hal.HAL_OUT)
		self.h.newpin("scale", hal.HAL_FLOAT, hal.HAL_IN)
		self.h.newpin("counts", hal.HAL_S32, hal.HAL_OUT)
		self.h.newpin("clear", hal.HAL_BIT, hal.HAL_IN)
		self.h.newpin("x-pos", hal.HAL_FLOAT, hal.HAL_IN)
		self.h.newpin("y-pos", hal.HAL_FLOAT, hal.HAL_IN)
		self.h.newpin("z-pos", hal.HAL_FLOAT, hal.HAL_IN)
		self.h.newpin("fade-height", hal.HAL_FLOAT, hal.HAL_IN)
		self.h.ready()
		
		s = linuxcnc.stat()
		
		currentState = States.START
		prevState = States.STOP

		try:
			while True:
				time.sleep(update)
				
				# get linuxcnc task_state status for machine on / off transitions
				s.poll()
				
				if currentState == States.START :
					if currentState != prevState :
						print("\nCompensation entering START state")
						prevState = currentState
						
					# do start-up tasks
					print(" %s last modified: %s" % (self.filename, time.ctime(os.path.getmtime(self.filename))))
					
					prevMapTime = 0
					
					self.h["counts"] = 0
					
					# transition to IDLE state
					currentState = States.IDLE
				
				elif currentState == States.IDLE :
					if currentState != prevState :
						print("\nCompensation entering IDLE state")
						prevState = currentState
						
					# stay in IDLE state until compensation is enabled
					if self.h["enable-in"] :
						currentState = States.LOADMAP
			
				elif currentState == States.LOADMAP :
					if currentState != prevState :
						print("\nCompensation entering LOADMAP state")
						prevState = currentState
			
					mapTime = os.path.getmtime(self.filename)
			
					if mapTime != prevMapTime:
						self.loadMap()
						print("	Compensation map loaded")
						prevMapTime = mapTime
					
					# transition to RUNNING state
					currentState = States.RUNNING
				
				elif currentState == States.RUNNING :
					if currentState != prevState :
						print("\nCompensation entering RUNNING state")
						prevState = currentState
			
					if self.h["enable-in"] :
						# enable external offsets
						self.h["enable-out"] = 1
						
						fadeHeight = self.h["fade-height"]
						zPos = self.h["z-pos"]
						
						if fadeHeight == 0 :
							compScale = 1
						elif zPos < fadeHeight:
							compScale = (fadeHeight - zPos)/fadeHeight
							if compScale > 1 :
								compScale = 1
						else :
							compScale = 0
							
						if s.task_state == linuxcnc.STATE_ON :
							# get the compensation if machine power is on, else set to 0
							# otherwise we loose compensation eoffset if machine power is cycled 
							# when copensation is enable
							compensation = self.compensate()
							self.h["counts"] = compensation * compScale
							self.h["scale"] = self.scale
						else :
							self.h["counts"] = 0
						
					else :
						# transition to RESET state
						currentState = States.RESET
						
				elif currentState == States.RESET :
					if currentState != prevState :
						print("\nCompensation entering RESET state")
						prevState = currentState

					# reset the eoffsets counts register so we don't accumulate
					self.h["counts"] = 0

					# toggle the clear output
					self.h["clear"] = 1;
					time.sleep(0.1)
					self.h["clear"] = 0;

					# disable external offsets
					self.h["enable-out"] = 0
					
					# transition to IDLE state
					currentState = States.IDLE

		except KeyboardInterrupt:
	  	  raise SystemExit
コード例 #53
0
ファイル: Pin.py プロジェクト: gorilux/LinuxCNC-QML
 def name(self, name):
     self._name = name
     self.h = hal.component(name)
コード例 #54
0
ファイル: test-ui.py プロジェクト: yisea123/linuxcnc2.7.14
    while ((time.time() - start) < timeout):
        if h[pin_name]:
            print "halui reports mode", pin_name
            return
        time.sleep(0.1)
    print "timeout waiting for halui to report mode", pin_name
    sys.exit(1)


#
# set up pins
# shell out to halcmd to make nets to halui and motion
#

h = hal.component("python-ui")

h.newpin("mdi-0", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("mdi-1", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("mdi-2", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("mdi-3", hal.HAL_BIT, hal.HAL_OUT)

h.newpin("joint-0-position", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("joint-1-position", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("joint-2-position", hal.HAL_FLOAT, hal.HAL_IN)

h.newpin("is-manual", hal.HAL_BIT, hal.HAL_IN)
h.newpin("is-auto", hal.HAL_BIT, hal.HAL_IN)
h.newpin("is-mdi", hal.HAL_BIT, hal.HAL_IN)

h.ready()  # mark the component as 'ready'
コード例 #55
0
ファイル: hbmgui.py プロジェクト: 13788593535/machinekit
# distance from spindle nose to tool-length = 0 point
tool_length_offset = 4.0

# give endpoint Z values and radii
# resulting cylinder is on the Z axis
class HalToolCylinder(CylinderZ):
    def __init__(self, comp, *args):
	CylinderZ.__init__(self, *args)
	self.comp = comp

    def coords(self):
        return (0, self.comp["tool-radius"],
        -tool_length_offset-self.comp["tool-length"], self.comp["tool-radius"])


c = hal.component("hbmgui")
# HAL pins
c.newpin("table", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("saddle", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("head", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("quill", hal.HAL_FLOAT, hal.HAL_IN)

c.newpin("tool-length", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("tool-radius", hal.HAL_FLOAT, hal.HAL_IN)
c.ready()

tool_radius=0.5

for setting in sys.argv[1:]: exec setting

# the approach here is a little different than in previous vismach models
コード例 #56
0
TIME_INCR = 0.1
TIMEOUT = 10.0

#
# connect to LinuxCNC
#

c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel()
l = linuxcnc_util.LinuxCNC(command=c, status=s, error=e)

#
# Create and connect test feedback comp
#
h = hal.component("test-ui")
h.newpin("Xpos", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("Ypos", hal.HAL_FLOAT, hal.HAL_IN)
h.ready()
os.system("halcmd source ./postgui.hal")

#
# Come out of E-stop, turn the machine on, home
#

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(0)
c.home(1)
c.home(2)
l.wait_for_home([1, 1, 1, 0, 0, 0, 0, 0, 0])
コード例 #57
0
 def __init__(self):
     self.lcnc = linuxCNC()
     gtk.settings_get_default().set_property(
         'gtk-theme-name', self.lcnc.iniFile.find('PLASMAC', 'THEME'))
     self.gui = "./test/plasmac_test.glade"
     self.B = gtk.Builder()
     self.B.add_from_file(self.gui)
     self.B.connect_signals(self)
     self.W = self.B.get_object("window1")
     self.halcomp = hal.component('plasmactest')
     self.panel = gladevcp.makepins.GladePanel(self.halcomp, self.gui,
                                               self.B, None)
     self.halcomp.ready()
     if not hal.pin_has_writer('plasmac.arc-ok-in'):
         sp.Popen([
             'halcmd net p_test:arc-ok-in plasmactest.arcOk plasmac.arc-ok-in'
         ],
                  shell=True)
     if not hal.pin_has_writer('plasmac.arc-voltage-in'):
         sp.Popen([
             'halcmd net p_test:arc-voltage-in plasmactest.arcVoltage plasmac.arc-voltage-in'
         ],
                  shell=True)
     if not hal.pin_has_writer('debounce.0.0.in'):
         sp.Popen([
             'halcmd net p_test:float-switch plasmactest.floatSwitch debounce.0.0.in'
         ],
                  shell=True)
     if not hal.pin_has_writer('debounce.0.1.in'):
         sp.Popen([
             'halcmd net p_test:breakaway-switch plasmactest.breakawaySwitch debounce.0.1.in'
         ],
                  shell=True)
     if not hal.pin_has_writer('debounce.0.2.in'):
         sp.Popen([
             'halcmd net p_test:ohmic-probe plasmactest.ohmicProbe debounce.0.2.in'
         ],
                  shell=True)
     if not hal.pin_has_writer('plasmac.move-down'):
         sp.Popen([
             'halcmd net p_test:move-down plasmactest.moveDown plasmac.move-down'
         ],
                  shell=True)
     if not hal.pin_has_writer('plasmac.move-up'):
         sp.Popen([
             'halcmd net p_test:move-up plasmactest.moveUp plasmac.move-up'
         ],
                  shell=True)
     self.W.connect('delete_event', self.ignore)
     self.W.set_type_hint(gdk.WINDOW_TYPE_HINT_MENU)
     self.W.set_keep_above(True)
     self.W.show_all()
     mode = self.lcnc.iniFile.find('PLASMAC', 'MODE') or '0'
     if mode not in '012':
         mode = 0
     self.B.get_object('mode' + mode).set_active(1)
     functions = {
         '0': self.on_mode0_toggled(0),
         '1': self.on_mode1_toggled(0),
         '2': self.on_mode2_toggled(0),
     }
     if mode in functions:
         functions[mode]
コード例 #58
0
ファイル: stream_reader.py プロジェクト: mark-v-d/linuxcnc-1
#!/usr/bin/env linuxcnc-python
import hal
import time
c = hal.component("stream_reader")
reader = hal.stream(c, hal.streamer_base, "bfsu")
for i in range(9):
    assert reader.readable
    assert reader.read() == ((i % 2, i, i, i))
    assert reader.num_underruns == 0
    assert reader.sampleno == i+1
assert reader.read() is None
assert reader.num_underruns == 1
c.ready()
print("pass")

try:
    while 1: time.sleep(1)
except KeyboardInterrupt: pass
コード例 #59
0
ファイル: stream_reader.py プロジェクト: CUGLSF/linuxcnc
#!/usr/bin/python
import hal
import time
c = hal.component("stream_reader")
reader = hal.stream(c, hal.streamer_base, "bfsu")
for i in range(9):
    assert reader.readable
    assert reader.read() == ((i % 2, i, i, i))
    assert reader.num_underruns == 0
    assert reader.sampleno == i+1
assert reader.read() is None
assert reader.num_underruns == 1
c.ready()
print "pass"

try:
    while 1: time.sleep(1)
except KeyboardInterrupt: pass
コード例 #60
0
#!/usr/bin/python

from Adafruit_I2C import Adafruit_I2C
import hal
import time

i2c = Adafruit_I2C(0x60)

h = hal.component("spindle_voltage")
h.newpin("speed_in", hal.HAL_FLOAT, hal.HAL_IN)
h.ready()

x0 = 200.0
y0 = 764.15

x1 = 2080.0
y1 = 10000.0

lastSpeed = 0

try:
    while True:
        if h['speed_in'] != lastSpeed:
            speed = h['speed_in']
            value = x0 + (x1 - x0) * (speed - y0) / (y1 - y0)

            i = int(min(max(value, 0), 4095))

            lo = i & 15 << 4
            hi = i >> 4