Exemplo n.º 1
0
    def read_config(cls):
        #read config parameters from config file
        c_lines = open(cls.conf_file_name).readlines()

        config = []
        for line in c_lines:
            line = line.strip()
            if not line or line.startswith('#'):
                continue

            config.append( line.split()[:2] )

        for c_param in config:
            if c_param[0] == 'SERVICE_URL':
                cls.BASE_SERIVICE_URL = c_param[1]
            elif c_param[0] == 'WINDOWS_ORDERING':
                cls.WINDOWS_ORDERING = c_param[1]
            elif c_param[0] == 'LANG_SID':
                cls.LANG_SID = c_param[1]
            elif c_param[0] == 'LOG_LEVEL':
                cls.LOG_LEVEL = int(c_param[1])
            elif c_param[0] == 'LAST_USER':
                cls.USER_NAME = c_param[1]
            else:
                raise Exception('Configuration parameter %s is not supported' % c_param[0])

        LogManager.init_log(cls.LOG_PATH, cls.LOG_LEVEL)
Exemplo n.º 2
0
 def load_menu(self):
     f = None
     try:
         f = open(self.__menu_cache_file, 'rb')
         self.__menu = pickle.load(f)
     except Exception,e:
         LogManager.info('Menu cache %s is not loaded. Details: %s' %(self.__menu_cache_file,e))
Exemplo n.º 3
0
    def setLogLevel(cls, log_level):
        if log_level not in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]:
            raise Exception ('Unsupported log level: %s'%log_level)

        cls.LOG_LEVEL = log_level
        LogManager.change_log_level(log_level)

        cls.ismod = True
Exemplo n.º 4
0
    def menuClick(self,  action ):
        name = action.objectName()
        for menu in self.__menu:
            if menu.menu_sid == name:
                LogManager.info('Opening form with sid %s' %menu.form_sid)
                FormManager.openForm(menu.form_sid)
                LogManager.info('Form with sid %s is opened' %menu.form_sid)

                break
Exemplo n.º 5
0
    def call(self, method_name, *in_parameters):
        '''
        Call SOAP method with some input parameters

        @method_name    - SOAP method name for calling
        @in_parameters  - comma-separated list of input parameters

        @return         - SOAP response object
        '''
        LogManager.debug('CALL %s method with input:\n%s' %(method_name, in_parameters))

        method = getattr(self.client.service, method_name)

        ret = method(in_parameters)

        LogManager.debug('CALL %s method results:\n%s' %(method_name, ret))

        return ret
Exemplo n.º 6
0
        menu_checksum = md5.hexdigest()

        iface = Client.get_interface('FABLIK_BASE')
        inputVar = iface.create_variable('RequestGetMainMenu')

        inputVar.session_id = Config.getSessionID()
        inputVar.checksum = menu_checksum
        inputVar.lang_sid = Config.getLangSid()

        result = iface.call('getMainMenu', inputVar)

        if result.ret_code != 0:
            raise Exception(result.ret_message)

        if len(result.menu_list) == 0:
            LogManager.info('Menu cache is valid. Use it')
            return

        self.__menu = []
        for item in result.menu_list[0]:
            menuitem = MenuItem(item.id, item.help, item.name, item.form_sid, 0, item.parent_id, item.shortcut)

            self.__menu.append(menuitem)

        self._save_cache()
        LogManager.info('Menu loaded and saved to local cache file (%s)'%self.__menu_cache_file)


    def create_menu(self, MainWindow):
        if len(self.__menu) == 0:
            self.load_menu()
Exemplo n.º 7
0
    def __init__(self):
        super(DriverWindow, self).__init__()
        #uic.loadUi('ui/driverGUI.ui', self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.tabWidget.setCurrentIndex(0)
        self.resetInfo()
        self.ui.labelTest = {"MS5611": self.ui.label_baroTest, "MPU6050": self.ui.label_MPUTest, "HMC5883L": self.ui.label_magTest}

        self.state = STATE.DISCONNECTED


        # ROS
        self.ros = ROSNode()



        # FLIE
        self.flie = FlieControl()
        self.ui.checkBox_pktHZ.toggled.connect(lambda on: self.flie.setPacketUpdateSpeed(self.ui.spinBox_pktHZ.value() if on else 0 ))
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.inKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.outKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.emit(self.ui.spinBox_pktHZ.value()) # force update
        self.ui.checkBox_kill.toggled.connect(self.flie.setKillswitch)
        self.flie.setKillswitch(self.ui.checkBox_kill.isChecked())
        self.ui.checkBox_xmode.toggled.connect(self.flie.crazyflie.commander.set_client_xmode)
        self.flie.crazyflie.commander.set_client_xmode( self.ui.checkBox_xmode.isChecked())


        # Set up ParamManager
        self.paramManager = ParamManager(self.flie.crazyflie, self)
        self.ui.tab_param.layout().addWidget(self.paramManager)

        # Set up LogManager
        self.logManager = LogManager(self.flie.crazyflie, self)
        self.ui.tab_log.layout().addWidget(self.logManager)
        self.ui.checkBox_logHZ.toggled.connect(self.logManager.setEstimateHzOn)
        self.ui.spinBox_logHZ.valueChanged.connect(self.logManager.setFreqMonitorFreq)
        self.logManager.sig_rosData.connect(self.ros.receiveCrazyflieLog)

        self.autoRetryTimer = QTimer()
        self.autoRetryTimer.setInterval(1500)
        self.autoRetryTimer.timeout.connect(lambda : self.connectPressed(self.ui.comboBox_connect.currentText(), auto=True))
        self.autoRetryTimer.setSingleShot(True)





        # init previous settings
        self.readSettings()



        # Updateing the GUI (if we didnt do this, every change would result in an update...)
        self.guiUpdateQueue = {}
        self.guiUpdateQueueSave = 0
        self.guiUpdateTimer = QTimer()
        self.guiUpdateTimer.setInterval(1000/self.ui.spinBox_guiHZ.value())
        self.ui.spinBox_guiHZ.valueChanged.connect(lambda x: self.guiUpdateTimer.setInterval(1000/x))
        self.guiUpdateTimer.timeout.connect(self.updateGui)
        self.guiUpdateTimer.start()

        # Defaults according to settings within GUI
        self.beepOn = self.ui.checkBox_beep.isChecked()
        self.killOn = self.ui.checkBox_kill.isChecked()
        self.autoReconnectOn = self.ui.checkBox_reconnect.isChecked()
        self.startupConnectOn = self.ui.checkBox_startupConnect.isChecked()
        self.ui.groupBox_input.toggled.connect(lambda x: self.ros.sig_joydata.connect(self.setInputJoy) if x else self.ros.sig_joydata.disconnect(self.setInputJoy))
        if self.ui.groupBox_input.isChecked():
            self.ros.sig_joydata.connect(self.setInputJoy)





        # Set up URI scanner
        self.scanner = ScannerThread()
        self.scanner.start()


        # Connections from GUI
        self.ui.pushButton_connect.clicked.connect(lambda : self.connectPressed(self.ui.comboBox_connect.currentText(), auto=False)) # Start button -> connect
        self.ui.comboBox_connect.currentIndexChanged.connect(self.uriSelected)

        self.ui.checkBox_beep.toggled.connect(self.setBeep)
        self.ui.checkBox_kill.toggled.connect(self.setKill)
        self.ui.checkBox_reconnect.toggled.connect(self.setAutoReconnect)
        self.ui.checkBox_startupConnect.toggled.connect(self.setStartupConnect)
        self.ui.pushButton_genRosMsg.clicked.connect(self.genRosMsg)


        # Connections to GUI
        self.flie.sig_packetSpeed.connect(self.updatePacketRate)
        self.flie.sig_flieLink.connect(self.ui.progressbar_link.setValue)
        self.paramManager.sig_baroFound.connect(lambda found: self.ui.label_baroFound.setText("Yes" if found else "No"))
        self.paramManager.sig_magFound.connect(lambda found: self.ui.label_magFound.setText("Yes" if found else "No"))
        self.paramManager.sig_test.connect(lambda name, p: self.ui.labelTest[str(name)].setText("Pass" if p else "FAIL"))
        self.paramManager.sig_firmware.connect(lambda fw, mod: self.ui.label_fw.setText(fw))
        self.paramManager.sig_firmware.connect(lambda fw, mod: self.ui.label_fwMod.setText(mod))
        self.logManager.sig_batteryUpdated.connect( lambda v : self.setToUpdate("vbat",self.ui.progressbar_bat.setValue, v))
        self.flie.inKBPS.sig_KBPS.connect(lambda hz: self.updatePacketRate(self.ui.progressBar_pktIn,hz))
        self.flie.outKBPS.sig_KBPS.connect(lambda hz: self.updatePacketRate(self.ui.progressBar_pktOut,hz))


        # Connections GUI to GUI


        # Connections Within
        self.scanner.sig_foundURI.connect(self.receiveScanURI)
        self.sig_requestScan.connect(self.scanner.scan)
        self.sig_requestConnect.connect(self.flie.requestConnect)
        self.sig_requestDisconnect.connect(self.flie.requestDisconnect)
        self.flie.sig_stateUpdate.connect(self.updateFlieState)
        self.flie.sig_console.connect(self.ui.console.insertPlainText)

        # Show window
        self.show()

        # Initiate an initial Scan
        init_drivers(enable_debug_driver=False)
        self.startScanURI()
Exemplo n.º 8
0
class DriverWindow(QtGui.QMainWindow ):
    """ Main window and application """

    sig_requestScan = pyqtSignal()
    sig_requestConnect = pyqtSignal(str)
    sig_requestDisconnect = pyqtSignal()

    def __init__(self):
        super(DriverWindow, self).__init__()
        #uic.loadUi('ui/driverGUI.ui', self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.tabWidget.setCurrentIndex(0)
        self.resetInfo()
        self.ui.labelTest = {"MS5611": self.ui.label_baroTest, "MPU6050": self.ui.label_MPUTest, "HMC5883L": self.ui.label_magTest}

        self.state = STATE.DISCONNECTED


        # ROS
        self.ros = ROSNode()



        # FLIE
        self.flie = FlieControl()
        self.ui.checkBox_pktHZ.toggled.connect(lambda on: self.flie.setPacketUpdateSpeed(self.ui.spinBox_pktHZ.value() if on else 0 ))
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.inKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.outKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.emit(self.ui.spinBox_pktHZ.value()) # force update
        self.ui.checkBox_kill.toggled.connect(self.flie.setKillswitch)
        self.flie.setKillswitch(self.ui.checkBox_kill.isChecked())
        self.ui.checkBox_xmode.toggled.connect(self.flie.crazyflie.commander.set_client_xmode)
        self.flie.crazyflie.commander.set_client_xmode( self.ui.checkBox_xmode.isChecked())


        # Set up ParamManager
        self.paramManager = ParamManager(self.flie.crazyflie, self)
        self.ui.tab_param.layout().addWidget(self.paramManager)

        # Set up LogManager
        self.logManager = LogManager(self.flie.crazyflie, self)
        self.ui.tab_log.layout().addWidget(self.logManager)
        self.ui.checkBox_logHZ.toggled.connect(self.logManager.setEstimateHzOn)
        self.ui.spinBox_logHZ.valueChanged.connect(self.logManager.setFreqMonitorFreq)
        self.logManager.sig_rosData.connect(self.ros.receiveCrazyflieLog)

        self.autoRetryTimer = QTimer()
        self.autoRetryTimer.setInterval(1500)
        self.autoRetryTimer.timeout.connect(lambda : self.connectPressed(self.ui.comboBox_connect.currentText(), auto=True))
        self.autoRetryTimer.setSingleShot(True)





        # init previous settings
        self.readSettings()



        # Updateing the GUI (if we didnt do this, every change would result in an update...)
        self.guiUpdateQueue = {}
        self.guiUpdateQueueSave = 0
        self.guiUpdateTimer = QTimer()
        self.guiUpdateTimer.setInterval(1000/self.ui.spinBox_guiHZ.value())
        self.ui.spinBox_guiHZ.valueChanged.connect(lambda x: self.guiUpdateTimer.setInterval(1000/x))
        self.guiUpdateTimer.timeout.connect(self.updateGui)
        self.guiUpdateTimer.start()

        # Defaults according to settings within GUI
        self.beepOn = self.ui.checkBox_beep.isChecked()
        self.killOn = self.ui.checkBox_kill.isChecked()
        self.autoReconnectOn = self.ui.checkBox_reconnect.isChecked()
        self.startupConnectOn = self.ui.checkBox_startupConnect.isChecked()
        self.ui.groupBox_input.toggled.connect(lambda x: self.ros.sig_joydata.connect(self.setInputJoy) if x else self.ros.sig_joydata.disconnect(self.setInputJoy))
        if self.ui.groupBox_input.isChecked():
            self.ros.sig_joydata.connect(self.setInputJoy)





        # Set up URI scanner
        self.scanner = ScannerThread()
        self.scanner.start()


        # Connections from GUI
        self.ui.pushButton_connect.clicked.connect(lambda : self.connectPressed(self.ui.comboBox_connect.currentText(), auto=False)) # Start button -> connect
        self.ui.comboBox_connect.currentIndexChanged.connect(self.uriSelected)

        self.ui.checkBox_beep.toggled.connect(self.setBeep)
        self.ui.checkBox_kill.toggled.connect(self.setKill)
        self.ui.checkBox_reconnect.toggled.connect(self.setAutoReconnect)
        self.ui.checkBox_startupConnect.toggled.connect(self.setStartupConnect)
        self.ui.pushButton_genRosMsg.clicked.connect(self.genRosMsg)


        # Connections to GUI
        self.flie.sig_packetSpeed.connect(self.updatePacketRate)
        self.flie.sig_flieLink.connect(self.ui.progressbar_link.setValue)
        self.paramManager.sig_baroFound.connect(lambda found: self.ui.label_baroFound.setText("Yes" if found else "No"))
        self.paramManager.sig_magFound.connect(lambda found: self.ui.label_magFound.setText("Yes" if found else "No"))
        self.paramManager.sig_test.connect(lambda name, p: self.ui.labelTest[str(name)].setText("Pass" if p else "FAIL"))
        self.paramManager.sig_firmware.connect(lambda fw, mod: self.ui.label_fw.setText(fw))
        self.paramManager.sig_firmware.connect(lambda fw, mod: self.ui.label_fwMod.setText(mod))
        self.logManager.sig_batteryUpdated.connect( lambda v : self.setToUpdate("vbat",self.ui.progressbar_bat.setValue, v))
        self.flie.inKBPS.sig_KBPS.connect(lambda hz: self.updatePacketRate(self.ui.progressBar_pktIn,hz))
        self.flie.outKBPS.sig_KBPS.connect(lambda hz: self.updatePacketRate(self.ui.progressBar_pktOut,hz))


        # Connections GUI to GUI


        # Connections Within
        self.scanner.sig_foundURI.connect(self.receiveScanURI)
        self.sig_requestScan.connect(self.scanner.scan)
        self.sig_requestConnect.connect(self.flie.requestConnect)
        self.sig_requestDisconnect.connect(self.flie.requestDisconnect)
        self.flie.sig_stateUpdate.connect(self.updateFlieState)
        self.flie.sig_console.connect(self.ui.console.insertPlainText)

        # Show window
        self.show()

        # Initiate an initial Scan
        init_drivers(enable_debug_driver=False)
        self.startScanURI()



    @pyqtSlot()
    def updateGui(self):
        """ Execute all funcs in the queue """
        #rospy.loginfo("Draw queue size: %d/%s", len(self.guiUpdateQueue), self.guiUpdateQueueSave)
        for f in self.guiUpdateQueue.values():
            f()
        self.guiUpdateQueue = {}
        self.guiUpdateQueueSave = 0

    def setToUpdate(self, name, func, *args):
        """ Add functions to call at gui update hz rate"""
        self.guiUpdateQueue[name] = partial(func, *args)
        self.guiUpdateQueueSave +=1

    @pyqtSlot(float, float, float, float, bool)
    def setInputJoy(self, r, p, y, t, h):
        #TODO: should only do this at a specific hz
        self.setToUpdate("joyR", self.ui.doubleSpinBox_r.setValue, r)
        self.setToUpdate("joyP", self.ui.doubleSpinBox_p.setValue, p)
        self.setToUpdate("joyY", self.ui.doubleSpinBox_y.setValue, y)
        self.setToUpdate("joyT", self.ui.doubleSpinBox_t.setValue, t)
        self.ui.label_hover.setText( "On" if h else "Off")

    @pyqtSlot()
    def genRosMsg(self):
        #TODO: should do this in its own thread, or even as a progress bar
        self.ui.pushButton_genRosMsg.setEnabled(False)
        self.ui.pushButton_genRosMsg.setText("Generating")
        generateRosMessages(self.flie.getLogToC())
        self.ui.pushButton_genRosMsg.setEnabled(True)
        self.ui.pushButton_genRosMsg.setText("Generate ROS msgs from ToC")


    def closeEvent(self, event):
        """ Intercept shutdowns to cleanly disconnect from the flie and cleanly shut ROS down too """
        rospy.loginfo("Close Event")
        #self.autoRetryTimer.stop()

        # Shut Down the Flie
        if self.state < STATE.GEN_DISCONNECTED:
            rospy.loginfo("Triggering flie disconnect for shutdown")
            self.ui.pushButton_connect.setText("Shutting Down...")
            self.flie.requestDisconnect()

        # Clean up ROS
        rospy.signal_shutdown("User closed window")

        # Save State
        self.writeSettings()

        # Commence shutdown
        event.accept()

    def readSettings(self):
        """ Load setrtings from previous session """
        rospy.logdebug("Loading previous session settings")
        settings = QSettings("omwdunkley", "flieROS")
        self.resize(settings.value("size", QVariant(QSize(300, 500))).toSize())
        self.move(settings.value("pos", QVariant(QPoint(200, 200))).toPoint())

        self.ui.checkBox_reconnect.setChecked(settings.value("autoReconnect", QVariant(self.ui.checkBox_reconnect.isChecked())).toBool())
        self.ui.checkBox_beep.setChecked(settings.value("beepOn", QVariant(self.ui.checkBox_beep.isChecked())).toBool())
        self.ui.checkBox_xmode.setChecked(settings.value("xmodeOn", QVariant(self.ui.checkBox_xmode.isChecked())).toBool())
        self.ui.checkBox_kill.setChecked(settings.value("killOn", QVariant(self.ui.checkBox_kill.isChecked())).toBool())
        self.ui.checkBox_startupConnect.setChecked(settings.value("startConnect", QVariant(self.ui.checkBox_startupConnect)).toBool())

        self.ui.checkBox_pktHZ.setChecked(settings.value("pktHzOn", QVariant(self.ui.checkBox_pktHZ.isChecked())).toBool())
        self.ui.checkBox_logHZ.setChecked(settings.value("logHzOn", QVariant(self.ui.checkBox_logHZ.isChecked())).toBool())
        self.ui.horizontalSlider_pktHZ.setValue(settings.value("pktHzVal", QVariant(self.ui.horizontalSlider_pktHZ.value())).toInt()[0])
        self.ui.horizontalSlider_logHZ.setValue(settings.value("logHzVal", QVariant(self.ui.horizontalSlider_logHZ.value())).toInt()[0])
        self.ui.horizontalSlider_guiHZ.setValue(settings.value("guiHzVal", QVariant(self.ui.horizontalSlider_guiHZ.value())).toInt()[0])

        self.logManager.header().restoreState(settings.value("logTreeH", self.logManager.header().saveState()).toByteArray())
        self.paramManager.header().restoreState(settings.value("paramTreeH", self.paramManager.header().saveState()).toByteArray())

    def writeSettings(self):
        """ Write settings to load at next start up """
        rospy.logdebug("Saving session settings")
        settings = QSettings("omwdunkley", "flieROS")
        settings.setValue("pos", QVariant(self.pos()))
        settings.setValue("size", QVariant(self.size()))

        settings.setValue("autoReconnect", QVariant(self.ui.checkBox_reconnect.isChecked()))
        settings.setValue("beepOn", QVariant(self.ui.checkBox_beep.isChecked()))
        settings.setValue("xmodeOn", QVariant(self.ui.checkBox_xmode.isChecked()))
        settings.setValue("killOn", QVariant(self.ui.checkBox_kill.isChecked()))
        settings.setValue("startConnect", QVariant(self.ui.checkBox_startupConnect.isChecked()))

        settings.setValue("pktHzOn", QVariant(self.ui.checkBox_pktHZ.isChecked()))
        settings.setValue("logHzOn", QVariant(self.ui.checkBox_logHZ.isChecked()))
        settings.setValue("pktHzVal", QVariant(self.ui.horizontalSlider_pktHZ.value()))
        settings.setValue("logHzVal", QVariant(self.ui.horizontalSlider_logHZ.value()))
        settings.setValue("guiHzVal", QVariant(self.ui.horizontalSlider_guiHZ.value()))

        settings.setValue("logTreeH",QVariant(self.logManager.header().saveState()))
        settings.setValue("paramTreeH",QVariant(self.paramManager.header().saveState()))





    @pyqtSlot(bool)
    def setBeep(self, on):
        self.beepOn = on
    @pyqtSlot(bool)
    def setKill(self, on):
        self.killOn = on
    @pyqtSlot(bool)
    def setAutoReconnect(self, on):
        self.autoReconnectOn = on
    @pyqtSlot(bool)
    def setStartupConnect(self, on):
        self.startupConnectOn = on

    def getCRTPStatus(self):
        interface_status =get_interfaces_status()
        self.ui.label_crv.setText(interface_status["radio"])

    def resetInfo(self):
        """ Resets the labels on the info tab """
        self.ui.label_baroFound.setText("")
        self.ui.label_magTest.setText("")
        self.ui.label_baroTest.setText("")
        self.ui.label_magFound.setText("")
        self.ui.label_MPUTest.setText("")
        self.ui.label_fw.setText("")
        self.ui.label_fwMod.setText("")
        self.ui.label_crv.setText("")
        self.ui.progressBar_pktIn.setValue(0)
        self.ui.progressBar_pktOut.setValue(0)
        self.ui.progressbar_bat.setValue(3000)
        self.ui.progressbar_link.setValue(0)

    @pyqtSlot(int,int)
    def updatePacketRate(self, pb, hz):
        """ Updates the number of pb with hz ensuring we adjust the maximum incase max<hz """
        if hz>pb.maximum():
            rospy.logwarn("Maximum Packets Changed from %d/s -> %d/s", pb.maximum(), hz)
            pb.setMaximum(hz)
        pb.setValue(hz)


    def startScanURI(self):
        """ User Clicked Scan
            Remove all previously found URIs from dropdown
            Disable rescanning
        """
        self.ui.comboBox_connect.clear()

        self.ui.pushButton_connect.setText('Scanning')
        self.ui.pushButton_connect.setDisabled(True)

        #self.scanner.sig_requestScan.emit()
        self.sig_requestScan.emit()




    def receiveScanURI(self, uri):
        """ Results from URI scan
            Add them to dropdown
        """

        # None Found, enable rescanning
        self.ui.pushButton_connect.setDisabled(False)
        if not uri:
            self.ui.pushButton_connect.setText('Scan')
            return

        self.ui.pushButton_connect.setText('Connect')
        for i in uri:
            if len(i[1]) > 0:
                self.ui.comboBox_connect.addItem("%s - %s" % (i[0], i[1]))
            else:
                self.ui.comboBox_connect.addItem(i[0])

        self.ui.comboBox_connect.addItem("Rescan")

        if self.startupConnectOn:
            rospy.loginfo("Auto connecting to first found flie [ConnectOnStartUp = TRUE]")
            self.ui.pushButton_connect.clicked.emit(False)


    def uriSelected(self, uri):
        """ The user clicked on a URI or a scan request
            If SCAN was selected, initiate a scan
        """
        if self.ui.comboBox_connect.currentText() == "Rescan":
            self.startScanURI()

    def connectPressed(self, uri, auto=False):
        """ The user pressed the connect button.
            Either rescan if there is no URI or
            Connect to the flie
        """


        print "------STATE %s ------ MODE %s ------ URI %s" % (self.state, "auto" if auto else "manual", uri)


        # No URI Found
        if uri=="":
            self.startScanURI()
            return


        if self.state == STATE.CONNECTED:
            self.requestFlieDisconnect()
        elif self.state == STATE.CONNECTION_RETRYWAIT and not auto:
            # User aborted auto retry
            self.autoRetryTimer.stop()
            self.state = STATE.DISCONNECTED
            self.ui.pushButton_connect.setText("Connect")
            self.ui.comboBox_connect.setEnabled(True)
            print "Aborted auto reconnect"
        else:
            self.requestFlieConnect(uri)

    def requestFlieConnect(self, uri):
        """ Request connection to the flie
        """
        self.ui.pushButton_connect.setText("Connecting...")
        self.ui.pushButton_connect.setEnabled(False)
        self.ui.comboBox_connect.setEnabled(False)
        self.sig_requestConnect.emit(uri)


    def requestFlieDisconnect(self):
        """ Request flie disconnect """

        self.ui.pushButton_connect.setText("Disconnecting...")
        self.sig_requestDisconnect.emit()
        #TODO: UI elements should be changed when the flie reports its disconnected, not when we press the button



    @pyqtSlot(int, str, str)
    def updateFlieState(self, state, uri, msg):
        """ Function that receives all the state updates from the flie.
        """

        if state == STATE.CONNECTION_REQUESTED:
            self.beepMsg(Message(msg="Connection to [%s] requested" % uri))

        elif state == STATE.LINK_ESTABLISHED:
            self.beepMsg(Message(msg="Link to [%s] established" % uri, freq=3300, length=25, repeat=1))
            self.ui.pushButton_connect.setText("Download TOC...")
            self.ros.sig_joydataRaw.connect(self.flie.sendCmd) # This needs to be after

        elif state == STATE.CONNECTED:
            self.beepMsg(Message(msg="Connected to [%s]" % uri, freq=3500, length=10, repeat=2))
            self.ui.pushButton_connect.setText("Disconnect")
            self.ui.pushButton_connect.setEnabled(True)
            self.getCRTPStatus()
            self.ui.pushButton_genRosMsg.setEnabled(True)

        elif state == STATE.DISCONNECTED:
            self.beepMsg(Message(msg="Disconnected from [%s]" % uri, freq=120, length=0))
            self.ui.pushButton_connect.setText("Connect")
            self.ui.pushButton_connect.setEnabled(True)
            self.ros.sig_joydataRaw.disconnect(self.flie.sendCmd) # This needs to be after

        elif state == STATE.CONNECTION_FAILED:
            self.beepMsg(Message(msgtype=MSGTYPE.WARN, msg="Connecting to [%s] failed: %s" % (uri, msg)))
            if self.autoReconnectOn:
                rospy.loginfo("Attempting to auto reconnect after failing to connect")

                #QTimer.singleShot(1000, lambda : self.connectPressed(self.ui.comboBox_connect.currentText(), auto=True))
                self.ui.pushButton_connect.setText("Auto Retrying...")
                self.state = STATE.CONNECTION_RETRYWAIT
                self.ui.pushButton_connect.setEnabled(False)
                self.autoRetryTimer.start()
            else:
                self.ui.pushButton_connect.setText("Connect")
                self.ui.comboBox_connect.setEnabled(True)
                self.ui.pushButton_connect.setEnabled(True)

        elif state == STATE.CONNECTION_LOST:
            self.beepMsg(Message(msgtype=MSGTYPE.WARN, msg="Connected lost from [%s]: %s" % (uri, msg), freq=1200, length=10, repeat=6))
            if self.autoReconnectOn:
                rospy.loginfo("Attempting to auto reconnect after losing connection")
                self.ui.pushButton_connect.setText("Auto Retrying...")
                self.state = STATE.CONNECTION_RETRYWAIT
                self.ui.pushButton_connect.setEnabled(False)
                self.autoRetryTimer.start()
            else:
                self.ui.pushButton_connect.setText("Connect")
                self.ui.comboBox_connect.setEnabled(True)
                self.ui.pushButton_connect.setEnabled(True)

        else:
            rospy.logerr("Unknown State")

        if state>STATE.GEN_DISCONNECTED:
            self.resetInfo()
            self.ui.pushButton_genRosMsg.setEnabled(False)

        self.state = state


    @pyqtSlot(object) # Message
    def beepMsg(self, msg):
        if self.beepOn and msg.beep:
            os.system("beep -f "+str(msg.f)+"-l "+str(msg.l)+" -r "+str(msg.r)+"&")
        if msg.msg != "":
            if msg.type == MSGTYPE.INFO:
                rospy.loginfo(msg.msg)
            elif msg.type == MSGTYPE.WARN:
                rospy.logwarn(msg.msg)
            elif msg.type == MSGTYPE.ERROR:
                rospy.logerr(msg.msg)
            elif msg.type == MSGTYPE.DEBUG:
                rospy.logdebug(msg.msg)
            else:
                rospy.logerr("UNKNOWN MESSAGE TYPE: %s", msg.msg)
            self.ui.statusbar.showMessage(msg.msg, 0)
            print msg.msg
Created on Wed Jul 15 22:42:22 2020

@author: Simon.Hermes
"""

import concurrent.futures
import time
import sys

import pandas as pd

from optimizationModel import OptSys
from datetime import datetime
from logManager import LogManager

logManager = LogManager()
logger_main = logManager.setup_logger()
logger_run = logManager.setup_logger(name='logger_run',
                                     log_file='log_run.txt',
                                     level=None)


def optimization_coordinator(n_parallel=1):
    start = datetime.now()
    max_workers = 20

    if n_parallel > max_workers:
        n_parallel = max_workers
        logger_main.info(
            'optimization_coordinator: reduce parallel processes to max_workers'
        )
Exemplo n.º 10
0
    def __init__(self, options):
        super(DriverWindow, self).__init__()
        #uic.loadUi('ui/driverGUI.ui', self)
        self.options = options
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.tabWidget.setCurrentIndex(0)
        self.resetInfo(initial=True)
        self.ui.labelTest = {
            "MS5611": self.ui.label_baroTest,
            "MPU6050": self.ui.label_MPUTest,
            "HMC5883L": self.ui.label_magTest
        }

        self.state = STATE.DISCONNECTED

        # ROS
        self.d = Dialog(options)
        self.ros = ROSNode(options, self)

        # FLIE
        self.flie = FlieControl(self)
        self.ui.checkBox_pktHZ.toggled.connect(
            lambda on: self.flie.setPacketUpdateSpeed(self.ui.spinBox_pktHZ.
                                                      value() if on else 0))
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.inKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.outKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.emit(
            self.ui.spinBox_pktHZ.value())  # force update
        self.ui.checkBox_kill.toggled.connect(self.flie.setKillswitch)
        self.flie.setKillswitch(self.ui.checkBox_kill.isChecked())
        self.ui.checkBox_xmode.toggled.connect(
            self.flie.crazyflie.commander.set_client_xmode)
        self.flie.crazyflie.commander.set_client_xmode(
            self.ui.checkBox_xmode.isChecked())

        # Set up ParamManager
        self.paramManager = ParamManager(self.flie.crazyflie, self)
        self.ui.tab_param.layout().addWidget(self.paramManager)

        # Set up LogManager
        self.logManager = LogManager(self.flie.crazyflie, self)
        self.ui.tab_log.layout().addWidget(self.logManager)
        self.ui.checkBox_logHZ.toggled.connect(self.logManager.setEstimateHzOn)
        self.ui.spinBox_logHZ.valueChanged.connect(
            self.logManager.setFreqMonitorFreq)
        self.logManager.sig_rosData.connect(self.ros.receiveCrazyflieLog)

        self.autoRetryTimer = QTimer()
        self.autoRetryTimer.setInterval(1500)
        self.autoRetryTimer.timeout.connect(lambda: self.connectPressed(
            self.ui.comboBox_connect.currentText(), auto=True))
        self.autoRetryTimer.setSingleShot(True)

        # Set up TrackManager
        self.trackManager = TrackManager(self.ros.sub_tf, self.ros.pub_tf,
                                         self)
        self.ui.tab_tracking.layout().addWidget(self.trackManager)

        # AI
        self.ai = AttitudeIndicator(self.ui.tab_hud)
        self.logManager.sig_rpy.connect(self.ai.setRollPitchYaw)
        self.ui.tab_hud.layout().addWidget(self.ai)
        self.ui.checkBox_AI.stateChanged.connect(self.ai.setUpdatesEnabled)
        self.ui.spinBox_AIHZ.valueChanged.connect(self.ai.setUpdateSpeed)
        self.logManager.sig_hoverTarget.connect(self.ai.setHover)
        self.logManager.sig_baroASL.connect(self.ai.setBaro)
        self.logManager.sig_accZ.connect(self.ai.setAccZ)
        self.logManager.sig_motors.connect(self.ai.setMotors)
        self.logManager.sig_batteryUpdated.connect(self.ai.setBattery)
        self.logManager.sig_batteryState.connect(self.ai.setPower)
        self.logManager.sig_temp.connect(self.ai.setTemp)
        self.logManager.sig_cpuUpdated.connect(self.ai.setCPU)
        self.logManager.sig_pressure.connect(self.ai.setPressure)
        self.logManager.sig_aslLong.connect(self.ai.setAslLong)
        self.paramManager.sig_gyroCalib.connect(self.ai.setCalib)
        self.flie.inKBPS.sig_KBPS.connect(self.ai.setPktsIn)
        self.flie.outKBPS.sig_KBPS.connect(self.ai.setPktsOut)
        self.flie.sig_flieLink.connect(self.ai.setLinkQuality)
        self.flie.sig_stateUpdate.connect(self.ai.setFlieState)
        self.ui.checkBox_reconnect.stateChanged.connect(
            self.ai.setAutoReconnect)
        self.logManager.sig_hzMeasure.connect(self.ai.updateHz)
        self.logManager.sig_logStatus.connect(self.ai.updateHzTarget)

        # Yaw offset
        self.ui.doubleSpinBox_yaw.valueChanged.connect(
            lambda yaw: self.ui.horizontalSlider_yaw.setValue(yaw * 10))
        self.ui.horizontalSlider_yaw.valueChanged.connect(
            lambda yaw: self.ui.doubleSpinBox_yaw.setValue(yaw / 10))
        self.ui.doubleSpinBox_yaw.valueChanged.connect(
            self.logManager.setYawOffset)
        self.ui.checkBox_yaw.stateChanged.connect(
            lambda x: self.logManager.setYawOffset(self.ui.doubleSpinBox_yaw.
                                                   value() if x else 0))
        self.ui.checkBox_yaw.stateChanged.emit(
            self.ui.checkBox_yaw.checkState())  # force update
        self.ui.pushButton_north.clicked.connect(
            lambda: self.ui.doubleSpinBox_yaw.setValue(self.logManager.getYaw(
            )))

        # ASL offset
        self.ui.doubleSpinBox_ground.valueChanged.connect(
            self.logManager.setGroundLevel)
        self.ui.checkBox_ground.stateChanged.connect(
            lambda x: self.logManager.setGroundLevel(
                self.ui.doubleSpinBox_ground.value() if x else 0))
        self.ui.checkBox_ground.stateChanged.emit(
            self.ui.checkBox_ground.checkState())
        self.ui.pushButton_ground.clicked.connect(
            lambda: self.ui.doubleSpinBox_ground.setValue(self.logManager.
                                                          getASL()))
        self.ros.sig_baro.connect(self.logManager.setAslOffset)

        # init previous settings
        self.readSettings()

        # Sync
        self.sync = Sync(self.flie.crazyflie)
        self.sync.sig_delayUp.connect(
            lambda x: self.ui.label_up.setText(str(round(x, 2)) + "ms"))
        self.sync.sig_delayDown.connect(
            lambda x: self.ui.label_down.setText(str(round(x, 2)) + "ms"))

        self.ui.groupBox_sync.toggled.connect(self.sync.enable)
        self.ui.spinBox_syncHz.valueChanged.connect(self.sync.setSyncRate)
        self.ui.spinBox_syncHz.valueChanged.emit(
            self.ui.spinBox_syncHz.value())
        self.ui.groupBox_sync.toggled.emit(self.ui.groupBox_sync.isChecked())
        self.sync.sig_cpuTime.connect(
            lambda x: self.ui.label_cputime.setText("%08.03fs" % x))
        self.sync.sig_flieTime.connect(
            lambda x: self.ui.label_flietime.setText("%08.03fs" % x))
        self.sync.sig_diffTime.connect(
            lambda x: self.ui.label_difftime.setText("%08.03fs" % x))

        self.ui.checkBox_rosLog.stateChanged.connect(
            self.logManager.setPubToRos)
        self.ui.groupBox_ros.clicked.connect(
            lambda x: self.logManager.setPubToRos(
                min(self.ui.groupBox_ros.isChecked(),
                    self.ui.checkBox_rosLog.checkState())))  #

        # Updating the GUI (if we didnt do this, every change would result in an update...)
        self.guiUpdateQueue = {}
        self.guiUpdateQueueSave = 0
        self.guiUpdateTimer = QTimer()
        self.guiUpdateTimer.setInterval(1000 / self.ui.spinBox_guiHZ.value())
        self.ui.spinBox_guiHZ.valueChanged.connect(
            lambda x: self.guiUpdateTimer.setInterval(1000 / x))
        self.guiUpdateTimer.timeout.connect(self.updateGui)
        self.guiUpdateTimer.start()

        # Defaults according to settings within GUI
        self.beepOn = self.ui.checkBox_beep.isChecked()
        self.killOn = self.ui.checkBox_kill.isChecked()
        self.autoReconnectOn = self.ui.checkBox_reconnect.isChecked()
        self.startupConnectOn = self.ui.checkBox_startupConnect.isChecked()
        self.ui.groupBox_input.toggled.connect(
            lambda x: self.ros.sig_joydata.connect(self.setInputJoy)
            if x else self.ros.sig_joydata.disconnect(self.setInputJoy))
        if self.ui.groupBox_input.isChecked():
            self.ros.sig_joydata.connect(self.setInputJoy)

        # Set up URI scanner
        self.scanner = ScannerThread(radio=options.radio)
        self.scanner.start()

        # Connections from GUI
        self.ui.pushButton_connect.clicked.connect(
            lambda: self.connectPressed(self.ui.comboBox_connect.currentText(),
                                        auto=False))  # Start button -> connect
        self.ui.comboBox_connect.currentIndexChanged.connect(self.uriSelected)

        self.ui.checkBox_beep.toggled.connect(self.setBeep)
        self.ui.checkBox_kill.toggled.connect(self.setKill)
        self.ui.checkBox_kill.toggled.connect(self.ai.setKillSwitch)
        self.ui.checkBox_kill.toggled.emit(
            self.ui.checkBox_kill.checkState())  # force update
        self.ui.checkBox_hover.toggled.connect(self.flie.setHoverDisabled)
        self.ui.checkBox_hover.toggled.emit(
            self.ui.checkBox_hover.checkState())  # force update

        self.ui.checkBox_reconnect.toggled.connect(self.setAutoReconnect)
        self.ui.checkBox_startupConnect.toggled.connect(self.setStartupConnect)
        self.ui.pushButton_genRosMsg.clicked.connect(self.genRosMsg)

        self.ui.pushButton_baro.clicked.connect(self.updateBaroTopics)

        self.ui.groupBox_baro.toggled.connect(
            lambda x: self.updateBaroTopics(not x))

        # Connections to GUI
        self.flie.sig_packetSpeed.connect(self.updatePacketRate)
        self.flie.sig_flieLink.connect(self.ui.progressbar_link.setValue)
        self.paramManager.sig_baroFound.connect(
            lambda found: self.ui.label_baroFound.setText("Yes"
                                                          if found else "No"))
        self.paramManager.sig_magFound.connect(
            lambda found: self.ui.label_magFound.setText("Yes"
                                                         if found else "No"))
        self.paramManager.sig_test.connect(lambda name, p: self.ui.labelTest[
            str(name)].setText("Pass" if p else "FAIL"))
        self.paramManager.sig_firmware.connect(
            lambda fw, mod: self.ui.label_fw.setText(fw))
        self.paramManager.sig_firmware.connect(
            lambda fw, mod: self.ui.label_fwMod.setText(mod))
        self.logManager.sig_batteryUpdated.connect(lambda v: self.setToUpdate(
            "vbat", self.ui.progressbar_bat.setValue, v))
        self.logManager.sig_cpuUpdated.connect(lambda v: self.setToUpdate(
            "cpu", self.ui.progressbar_cpu.setValue, v))
        self.flie.inKBPS.sig_KBPS.connect(
            lambda hz: self.updatePacketRate(self.ui.progressBar_pktIn, hz))
        self.flie.outKBPS.sig_KBPS.connect(
            lambda hz: self.updatePacketRate(self.ui.progressBar_pktOut, hz))

        # Connections GUI to GUI

        # Connections Within
        self.scanner.sig_foundURI.connect(self.receiveScanURI)
        self.sig_requestScan.connect(self.scanner.scan)
        self.sig_requestConnect.connect(self.flie.requestConnect)
        self.sig_requestDisconnect.connect(self.flie.requestDisconnect)
        self.flie.sig_stateUpdate.connect(self.updateFlieState)
        self.flie.sig_console.connect(self.ui.console.insertPlainText)

        # Show window
        self.show()

        # Initiate an initial Scan
        init_drivers(enable_debug_driver=False)
        self.startScanURI()
Exemplo n.º 11
0
 def init_measure_logging(self):
     self.measure_log_handle = LogManager("logbook")
Exemplo n.º 12
0
class gaugeControllerApplication(tk.Tk):
    def __init__(self, default_animation_interval=1000, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.animation_interval = default_animation_interval
        self.winfo_toplevel().title("Pressure gauge controllers manager")
        self.container = Frame(self)
        self.container.grid()
        self.init_measure_logging()
        self.init_interval_controls()
        self.init_gauge_handles()
        self.init_animations()

    def init_measure_logging(self):
        self.measure_log_handle = LogManager("logbook")

    def init_interval_controls(self):
        interval_controls_frame = Frame(self.container, padding=(10, 10))
        interval_controls_frame.grid(row=0, column=0, columnspan=len(GAUGES))
        interval_controls_label = Label(interval_controls_frame,
                                        text="REFRESH [ms]",
                                        padding=(10, 10))
        interval_controls_label.grid(row=0, column=0)
        self.interval_controls_input = Entry(interval_controls_frame)
        self.interval_controls_input.grid(row=0, column=1)
        self.interval_controls_input.insert(tk.END, self.animation_interval)
        interval_controls_save_button = Button(
            interval_controls_frame,
            text="SET",
            command=self.set_animation_interval)
        interval_controls_save_button.grid(row=0, column=2)

    def set_animation_interval(self):
        interval_value = float(self.interval_controls_input.get())
        if interval_value < 3000:
            interval_value = 3000
        self.animation_interval = interval_value
        self.interval_controls_input.delete(0, tk.END)
        self.interval_controls_input.insert(0, str(interval_value))
        self.update_animators(interval_value)

    def init_gauge_handles(self):
        col = 0
        self.gauge_handles = []
        for gauge_name, gauge_classes in GAUGES.items():
            self.container.grid_columnconfigure(col, weight=1)
            self.measure_log_handle.add_channel(gauge_classes[0].get_name())
            widget = gaugeWidget(self.container, self, gauge_name,
                                 self.measure_log_handle)
            self.gauge_handles.append(widget)
            col += 1
        for i in range(len(GAUGES)):
            self.gauge_handles[i].grid(row=1, column=i, sticky="W")
            self.gauge_handles[i].tkraise()

    def init_animations(self):
        for gauges, gauge_parameters in GAUGES.items():
            gauge_parameters[1].refresh_figure(1)
            ANIMATORS.append(
                animation.FuncAnimation(gauge_parameters[2],
                                        gauge_parameters[1].refresh_figure,
                                        interval=self.animation_interval))

    def update_animators(self, interval):
        for animator in ANIMATORS:
            animator.event_source.interval = interval
Exemplo n.º 13
0
    def __init__(self,options):
        super(DriverWindow, self).__init__()
        #uic.loadUi('ui/driverGUI.ui', self)
        self.options = options
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.tabWidget.setCurrentIndex(0)
        self.resetInfo(initial=True)
        self.ui.labelTest = {"MS5611": self.ui.label_baroTest, "MPU6050": self.ui.label_MPUTest, "HMC5883L": self.ui.label_magTest}

        self.state = STATE.DISCONNECTED


        # ROS
        self.d = Dialog(options)
        self.ros = ROSNode(options, self)


        # FLIE
        self.flie = FlieControl(self)
        self.ui.checkBox_pktHZ.toggled.connect(lambda on: self.flie.setPacketUpdateSpeed(self.ui.spinBox_pktHZ.value() if on else 0 ))
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.inKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.connect(self.flie.outKBPS.setHZ)
        self.ui.spinBox_pktHZ.valueChanged.emit(self.ui.spinBox_pktHZ.value()) # force update
        self.ui.checkBox_kill.toggled.connect(self.flie.setKillswitch)
        self.flie.setKillswitch(self.ui.checkBox_kill.isChecked())
        self.ui.checkBox_xmode.toggled.connect(self.flie.crazyflie.commander.set_client_xmode)
        self.flie.crazyflie.commander.set_client_xmode( self.ui.checkBox_xmode.isChecked())


        # Set up ParamManager
        self.paramManager = ParamManager(self.flie.crazyflie, self)
        self.ui.tab_param.layout().addWidget(self.paramManager)

        # Set up LogManager
        self.logManager = LogManager(self.flie.crazyflie, self)
        self.ui.tab_log.layout().addWidget(self.logManager)
        self.ui.checkBox_logHZ.toggled.connect(self.logManager.setEstimateHzOn)
        self.ui.spinBox_logHZ.valueChanged.connect(self.logManager.setFreqMonitorFreq)
        self.logManager.sig_rosData.connect(self.ros.receiveCrazyflieLog)

        self.autoRetryTimer = QTimer()
        self.autoRetryTimer.setInterval(1500)
        self.autoRetryTimer.timeout.connect(lambda : self.connectPressed(self.ui.comboBox_connect.currentText(), auto=True))
        self.autoRetryTimer.setSingleShot(True)

        # Set up TrackManager
        self.trackManager = TrackManager(self.ros.sub_tf, self.ros.pub_tf, self)
        self.ui.tab_tracking.layout().addWidget(self.trackManager)


        # AI
        self.ai = AttitudeIndicator(self.ui.tab_hud)
        self.logManager.sig_rpy.connect(self.ai.setRollPitchYaw)
        self.ui.tab_hud.layout().addWidget(self.ai)
        self.ui.checkBox_AI.stateChanged.connect(self.ai.setUpdatesEnabled)
        self.ui.spinBox_AIHZ.valueChanged.connect(self.ai.setUpdateSpeed)
        self.logManager.sig_hoverTarget.connect(self.ai.setHover)
        self.logManager.sig_baroASL.connect(self.ai.setBaro)
        self.logManager.sig_accZ.connect(self.ai.setAccZ)
        self.logManager.sig_motors.connect(self.ai.setMotors)
        self.logManager.sig_batteryUpdated.connect(self.ai.setBattery)
        self.logManager.sig_batteryState.connect(self.ai.setPower)
        self.logManager.sig_temp.connect(self.ai.setTemp)
        self.logManager.sig_cpuUpdated.connect(self.ai.setCPU)
        self.logManager.sig_pressure.connect(self.ai.setPressure)
        self.logManager.sig_aslLong.connect(self.ai.setAslLong)
        self.paramManager.sig_gyroCalib.connect(self.ai.setCalib)
        self.flie.inKBPS.sig_KBPS.connect(self.ai.setPktsIn)
        self.flie.outKBPS.sig_KBPS.connect(self.ai.setPktsOut)
        self.flie.sig_flieLink.connect(self.ai.setLinkQuality)
        self.flie.sig_stateUpdate.connect(self.ai.setFlieState)
        self.ui.checkBox_reconnect.stateChanged.connect(self.ai.setAutoReconnect)
        self.logManager.sig_hzMeasure.connect(self.ai.updateHz)
        self.logManager.sig_logStatus.connect(self.ai.updateHzTarget)


        # Yaw offset
        self.ui.doubleSpinBox_yaw.valueChanged.connect(lambda yaw: self.ui.horizontalSlider_yaw.setValue(yaw*10))
        self.ui.horizontalSlider_yaw.valueChanged.connect(lambda yaw: self.ui.doubleSpinBox_yaw.setValue(yaw/10))
        self.ui.doubleSpinBox_yaw.valueChanged.connect(self.logManager.setYawOffset)
        self.ui.checkBox_yaw.stateChanged.connect(lambda x: self.logManager.setYawOffset(self.ui.doubleSpinBox_yaw.value() if x else 0))
        self.ui.checkBox_yaw.stateChanged.emit(self.ui.checkBox_yaw.checkState()) # force update
        self.ui.pushButton_north.clicked.connect(lambda: self.ui.doubleSpinBox_yaw.setValue(self.logManager.getYaw()))

        # ASL offset
        self.ui.doubleSpinBox_ground.valueChanged.connect(self.logManager.setGroundLevel)
        self.ui.checkBox_ground.stateChanged.connect(lambda x: self.logManager.setGroundLevel(self.ui.doubleSpinBox_ground.value() if x else 0))
        self.ui.checkBox_ground.stateChanged.emit(self.ui.checkBox_ground.checkState())
        self.ui.pushButton_ground.clicked.connect(lambda: self.ui.doubleSpinBox_ground.setValue(self.logManager.getASL()))
        self.ros.sig_baro.connect(self.logManager.setAslOffset)




        # init previous settings
        self.readSettings()


        # Sync
        self.sync = Sync(self.flie.crazyflie)
        self.sync.sig_delayUp.connect(lambda  x: self.ui.label_up.setText(str(round(x,2))+"ms"))
        self.sync.sig_delayDown.connect(lambda  x: self.ui.label_down.setText(str(round(x,2))+"ms"))

        self.ui.groupBox_sync.toggled.connect(self.sync.enable)
        self.ui.spinBox_syncHz.valueChanged.connect(self.sync.setSyncRate)
        self.ui.spinBox_syncHz.valueChanged.emit(self.ui.spinBox_syncHz.value())
        self.ui.groupBox_sync.toggled.emit(self.ui.groupBox_sync.isChecked())
        self.sync.sig_cpuTime.connect(lambda  x: self.ui.label_cputime.setText("%08.03fs"%x))
        self.sync.sig_flieTime.connect(lambda  x: self.ui.label_flietime.setText("%08.03fs"%x))
        self.sync.sig_diffTime.connect(lambda  x: self.ui.label_difftime.setText("%08.03fs"%x))


        self.ui.checkBox_rosLog.stateChanged.connect(self.logManager.setPubToRos)
        self.ui.groupBox_ros.clicked.connect(lambda x: self.logManager.setPubToRos(min(self.ui.groupBox_ros.isChecked(), self.ui.checkBox_rosLog.checkState()))) #




        # Updating the GUI (if we didnt do this, every change would result in an update...)
        self.guiUpdateQueue = {}
        self.guiUpdateQueueSave = 0
        self.guiUpdateTimer = QTimer()
        self.guiUpdateTimer.setInterval(1000/self.ui.spinBox_guiHZ.value())
        self.ui.spinBox_guiHZ.valueChanged.connect(lambda x: self.guiUpdateTimer.setInterval(1000/x))
        self.guiUpdateTimer.timeout.connect(self.updateGui)
        self.guiUpdateTimer.start()

        # Defaults according to settings within GUI
        self.beepOn = self.ui.checkBox_beep.isChecked()
        self.killOn = self.ui.checkBox_kill.isChecked()
        self.autoReconnectOn = self.ui.checkBox_reconnect.isChecked()
        self.startupConnectOn = self.ui.checkBox_startupConnect.isChecked()
        self.ui.groupBox_input.toggled.connect(lambda x: self.ros.sig_joydata.connect(self.setInputJoy) if x else self.ros.sig_joydata.disconnect(self.setInputJoy))
        if self.ui.groupBox_input.isChecked():
            self.ros.sig_joydata.connect(self.setInputJoy)





        # Set up URI scanner
        self.scanner = ScannerThread(radio=options.radio)
        self.scanner.start()


        # Connections from GUI
        self.ui.pushButton_connect.clicked.connect(lambda : self.connectPressed(self.ui.comboBox_connect.currentText(), auto=False)) # Start button -> connect
        self.ui.comboBox_connect.currentIndexChanged.connect(self.uriSelected)

        self.ui.checkBox_beep.toggled.connect(self.setBeep)
        self.ui.checkBox_kill.toggled.connect(self.setKill)
        self.ui.checkBox_kill.toggled.connect(self.ai.setKillSwitch)
        self.ui.checkBox_kill.toggled.emit(self.ui.checkBox_kill.checkState()) # force update
        self.ui.checkBox_hover.toggled.connect(self.flie.setHoverDisabled)
        self.ui.checkBox_hover.toggled.emit(self.ui.checkBox_hover.checkState()) # force update



        self.ui.checkBox_reconnect.toggled.connect(self.setAutoReconnect)
        self.ui.checkBox_startupConnect.toggled.connect(self.setStartupConnect)
        self.ui.pushButton_genRosMsg.clicked.connect(self.genRosMsg)

        self.ui.pushButton_baro.clicked.connect(self.updateBaroTopics)

        self.ui.groupBox_baro.toggled.connect(lambda x: self.updateBaroTopics(not x))






        # Connections to GUI
        self.flie.sig_packetSpeed.connect(self.updatePacketRate)
        self.flie.sig_flieLink.connect(self.ui.progressbar_link.setValue)
        self.paramManager.sig_baroFound.connect(lambda found: self.ui.label_baroFound.setText("Yes" if found else "No"))
        self.paramManager.sig_magFound.connect(lambda found: self.ui.label_magFound.setText("Yes" if found else "No"))
        self.paramManager.sig_test.connect(lambda name, p: self.ui.labelTest[str(name)].setText("Pass" if p else "FAIL"))
        self.paramManager.sig_firmware.connect(lambda fw, mod: self.ui.label_fw.setText(fw))
        self.paramManager.sig_firmware.connect(lambda fw, mod: self.ui.label_fwMod.setText(mod))
        self.logManager.sig_batteryUpdated.connect( lambda v : self.setToUpdate("vbat",self.ui.progressbar_bat.setValue, v))
        self.logManager.sig_cpuUpdated.connect( lambda v : self.setToUpdate("cpu",self.ui.progressbar_cpu.setValue, v))
        self.flie.inKBPS.sig_KBPS.connect(lambda hz: self.updatePacketRate(self.ui.progressBar_pktIn,hz))
        self.flie.outKBPS.sig_KBPS.connect(lambda hz: self.updatePacketRate(self.ui.progressBar_pktOut,hz))


        # Connections GUI to GUI


        # Connections Within
        self.scanner.sig_foundURI.connect(self.receiveScanURI)
        self.sig_requestScan.connect(self.scanner.scan)
        self.sig_requestConnect.connect(self.flie.requestConnect)
        self.sig_requestDisconnect.connect(self.flie.requestDisconnect)
        self.flie.sig_stateUpdate.connect(self.updateFlieState)
        self.flie.sig_console.connect(self.ui.console.insertPlainText)


        # Show window
        self.show()

        # Initiate an initial Scan
        init_drivers(enable_debug_driver=False)
        self.startScanURI()