예제 #1
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.setObjectName('controlLoop')
        self.setTitle('Control Loop Mode')

        self.controlLoopHorizontalLayout = QtWidgets.QHBoxLayout(self)
        self.controlLoopHorizontalLayout.setObjectName(
            'controlLoopHorizontalLayout')

        self.selectorControlLoop = QtWidgets.QComboBox(self)
        self.selectorControlLoop.setObjectName('selectorControlLoop')
        self.selectorControlLoop.addItems([
            'Torque', 'Velocity', 'Angle', 'Velocity openloop',
            'Angle openloop'
        ])
        self.selectorControlLoop.currentIndexChanged.connect(
            self.changeControlLoop)
        self.controlLoopHorizontalLayout.addWidget(self.selectorControlLoop)

        self.setControlLopMode(self.device.controlType)

        self.disableUI()
        self.device.addConnectionStateListener(self)
        self.device.commProvider.commandDataReceived.connect(
            self.commandResponseReceived)

        self.connectionStateChanged(self.device.isConnected)
예제 #2
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.setTitle('Simple FOC Digital Read Out')
        self.setObjectName('digitalReadOut')

        self.droHorizontalLayout = QtWidgets.QHBoxLayout(self)
        self.droHorizontalLayout.setObjectName('droHorizontalLayout')

        self.signal0Label = QtWidgets.QLabel(self)
        self.signal0Label.setObjectName('angleLabel')
        self.signal0Label.setText('Angle')
        self.droHorizontalLayout.addWidget(self.signal0Label)

        self.signal0LCDNumber = QtWidgets.QLCDNumber(self)
        self.putStyleToLCDNumber(self.signal0LCDNumber)
        self.signal0LCDNumber.setObjectName('signal0LCDNumber')
        self.droHorizontalLayout.addWidget(self.signal0LCDNumber)

        self.signal1Label = QtWidgets.QLabel(self)
        self.signal1Label.setObjectName('velLabel')
        self.signal1Label.setText('Velocity')
        self.droHorizontalLayout.addWidget(self.signal1Label)

        self.signal1LCDNumber = QtWidgets.QLCDNumber(self)
        self.putStyleToLCDNumber(self.signal1LCDNumber)
        self.signal1LCDNumber.setObjectName('signal1LCDNumber')
        self.droHorizontalLayout.addWidget(self.signal1LCDNumber)

        self.signal2Label = QtWidgets.QLabel(self)
        self.signal2Label.setObjectName('torqueLabel')
        self.signal2Label.setText('Target')
        self.droHorizontalLayout.addWidget(self.signal2Label)

        self.signal2LCDNumber = QtWidgets.QLCDNumber(self)
        self.putStyleToLCDNumber(self.signal2LCDNumber)
        self.signal2LCDNumber.setObjectName('signal2LCDNumber')
        self.droHorizontalLayout.addWidget(self.signal2LCDNumber)

        self.signal3Label = QtWidgets.QLabel(self)
        self.signal3Label.setObjectName('targetLabel')
        self.signal3Label.setText('Target')
        self.droHorizontalLayout.addWidget(self.signal3Label)

        self.signal3LCDNumber = QtWidgets.QLCDNumber(self)
        self.putStyleToLCDNumber(self.signal3LCDNumber)
        self.signal3LCDNumber.setObjectName('signal3LCDNumber')
        self.droHorizontalLayout.addWidget(self.signal3LCDNumber)

        self.commandResponseReceived('init')

        self.initDiplay()
        self.disableUI()

        self.device.addConnectionStateListener(self)
        self.device.commProvider.stateMonitorReceived.connect(self.commandResponseReceived)

        self.connectionStateChanged(self.device.isConnected)
    def openDevice(self):
        if self.configDeviceTool is None:
            dlg = QtWidgets.QFileDialog()
            dlg.setFileMode(QtWidgets.QFileDialog.AnyFile)
            filenames = None
            if dlg.exec_():
                filenames = dlg.selectedFiles()
                try:
                    with open(filenames[0]) as json_file:
                        configurationInfo = json.load(json_file)
                        sfd = SimpleFOCDevice.getInstance()
                        sfd.configureDevice(configurationInfo)
                        self.configDeviceTool = TreeViewConfigTool()
                        sfd.openedFile = filenames
                        self.activeToolsList.append(self.configDeviceTool)
                        tabName = self.configDeviceTool.getTabName()
                        if tabName == '':
                            tabName = 'Device'
                        self.addTab(self.configDeviceTool,
                                    self.configDeviceTool.getTabIcon(),
                                    tabName)
                        self.setCurrentIndex(self.currentIndex() + 1)

                except Exception as exception:
                    msgBox = QtWidgets.QMessageBox()
                    msgBox.setIcon(QtWidgets.QMessageBox.Warning)
                    msgBox.setText('Error while opening selected file')
                    msgBox.setWindowTitle('SimpleFOC configDeviceTool')
                    msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
                    msgBox.exec()
예제 #4
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.setObjectName('torqueMode')
        self.setTitle('Torque Mode')

        self.torqueTypeHorizontalLayout = QtWidgets.QHBoxLayout(self)
        self.torqueTypeHorizontalLayout.setObjectName('torqueHorizontalLayout')

        self.selectorTorque = QtWidgets.QComboBox(self)
        self.selectorTorque.setObjectName('selectorControlLoop')
        self.selectorTorque.addItems(['Voltage', 'DC Current', 'FOC Current'])
        self.selectorTorque.currentIndexChanged.connect(self.changeTorque)
        self.torqueTypeHorizontalLayout.addWidget(self.selectorTorque)

        self.setTorqueMode(self.device.torqueType)

        self.disableUI()
        self.device.addConnectionStateListener(self)
        self.device.commProvider.commandDataReceived.connect(
            self.commandResponseReceived)

        self.connectionStateChanged(self.device.isConnected)
예제 #5
0
    def __init__(self, parent=None ):
        super().__init__(parent)
        
        self.device = SimpleFOCDevice.getInstance()
        dlg = GenerateCodeDialog()  # If you pass self, the dialog will be centered over the main window as before.
        if dlg.exec_():
            toGenerate=[
                dlg.checkBoxMotionControl.isChecked(),
                dlg.checkBoxPidVel.isChecked(),
                dlg.checkBoxPidAngle.isChecked(),
                dlg.checkBoxPidCq.isChecked(),
                dlg.checkBoxPidCd.isChecked(),
                dlg.checkBoxLimits.isChecked(),
                dlg.sensorOffset.isChecked(),
                dlg.sensorElOffset.isChecked(),
                dlg.checkBoxPhaseRes.isChecked(),
                dlg.checkBoxModulation.isChecked(),
            ]
            code = self.device.toArduinoCode(toGenerate)

        self.layout = QVBoxLayout(self)

        text = "<h1>Generated Arduino Code</h1>"
        text += "This generated code you can just copy/paste into your <code>setup()</code> function, it is important that you place it before calling the <code>motor.init()</code><br>"

        message1 = QtWidgets.QLabel(text)
        self.layout.addWidget(message1)

        self.codeDisplayBefore = QtWidgets.QLabel(self)
        self.layout.addWidget(self.codeDisplayBefore)
        code0 = '<font color="#5e6d03">#include</font> <font color="#434f54">&lt;</font><b><font color="#d35400">SimpleFOC</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">&gt;</font>'
        code0 +="<br>...<br>"
        code0 += '<font color="#00979c">void</font> <font color="#5e6d03">setup</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#000000">{</font><br>'
        code0 += "  ...."
        self.codeDisplayBefore.setText(code0)
        self.codeDisplayBefore.setTextFormat(Qt.TextFormat.RichText)

        self.codeDisplay = QtWidgets.QTextEdit(self)
        self.codeDisplay.setObjectName('codeDisplay')
        self.codeDisplay.setText(code)

        highlighter = MyHighlighter( self.codeDisplay, "Classic" )
        self.layout.addWidget(self.codeDisplay)
        


        self.codeDisplayAfter = QtWidgets.QLabel(self)
        self.layout.addWidget(self.codeDisplayAfter)
        code1 = '<font color="#434f54">&#47;&#47; initialize motor</font><br>'
        code1 += '<font color="#d35400">motor</font><font color="#434f54">.</font><font color="#d35400">init</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font><br>'
        code1 += '<font color="#434f54">&#47;&#47; align sensor and start FOC</font><br>'
        code1 += '<font color="#d35400">motor</font><font color="#434f54">.</font><font color="#d35400">initFOC</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font><br> ...<br> }'
        code1 += '<br><font color="#00979c">void</font> <font color="#5e6d03">loop</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#000000">{</font><br>....<br>}'
        # MyHighlighter( self.codeDisplayAfter, "Classic" )
        self.codeDisplayAfter.setText(code1)
        self.codeDisplayAfter.setTextFormat(Qt.TextFormat.RichText)

        self.setLayout(self.layout)
예제 #6
0
    def __init__(self, parent=None):

        super().__init__(parent)

        self.setObjectName('plotWidget')
        self.setTitle('Real time motor variables: ')
        self.horizontalLayout = QtWidgets.QVBoxLayout(self)
        self.device = SimpleFOCDevice.getInstance()

        self.numberOfSamples = 300

        pg.setConfigOptions(antialias=True)
        self.plotWidget = pg.PlotWidget()
        self.plotWidget.showGrid(x=True, y=True, alpha=0.5)
        self.plotWidget.addLegend()

        # self.legend = pg.LegendItem()
        # self.legend.setParentItem(self.plotWidget)

        self.timeArray = np.arange(-self.numberOfSamples, 0, 1)

        self.controlPlotWidget = ControlPlotPanel(controllerPlotWidget=self)

        self.signalDataArrays = []
        self.signalPlots = []
        self.signalPlotFlags = []
        for (sig, sigColor, checkBox,
             tooltip) in zip(self.signals, self.signalColors,
                             self.controlPlotWidget.signalCheckBox,
                             self.signal_tooltip):
            # define signal plot data array
            self.signalDataArrays.append(np.zeros(self.numberOfSamples))
            # configure signal plot parameters
            signalPen = pg.mkPen(color=sigColor, width=1.5)
            self.signalPlots.append(
                pg.PlotDataItem(self.timeArray,
                                self.signalDataArrays[-1],
                                pen=signalPen,
                                name=tooltip))
            self.plotWidget.addItem(self.signalPlots[-1])

            # is plotted flag
            self.signalPlotFlags.append(True)
            # add callback
            checkBox.stateChanged.connect(self.signalPlotFlagUpdate)

        self.horizontalLayout.addWidget(self.plotWidget)
        self.horizontalLayout.addWidget(self.controlPlotWidget)

        self.device.commProvider.monitoringDataReceived.connect(
            self.upDateGraphic)

        self.currentStatus = self.disconnectedState
        self.controlPlotWidget.pauseContinueButton.setDisabled(True)

        self.device.addConnectionStateListener(self)

        self.connectionStateChanged(self.device.isConnected)
예제 #7
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.device = SimpleFOCDevice.getInstance()

        self.setObjectName('joggingControl')
        self.setTitle('Jogging control')

        self.horizontalLayout = QtWidgets.QHBoxLayout(self)
        self.horizontalLayout.setObjectName('generalControlHL')

        self.fastFordwardButton = QtWidgets.QPushButton()
        self.fastFordwardButton.setObjectName('fastbackward')
        self.fastFordwardButton.setIcon(
            GUIToolKit.getIconByName('fastbackward'))
        self.fastFordwardButton.clicked.connect(self.joggingFastBackward)
        self.horizontalLayout.addWidget(self.fastFordwardButton)

        self.backwardButton = QtWidgets.QPushButton()
        self.backwardButton.setObjectName('backward')
        self.backwardButton.setIcon(GUIToolKit.getIconByName('backward'))
        self.backwardButton.clicked.connect(self.joggingBackward)
        self.horizontalLayout.addWidget(self.backwardButton)

        self.stopButton = QtWidgets.QPushButton()
        self.stopButton.setObjectName('stopbutton')
        self.stopButton.setIcon(GUIToolKit.getIconByName('stopjogging'))
        self.stopButton.clicked.connect(self.joggingStop)
        self.horizontalLayout.addWidget(self.stopButton)

        self.fordwardButton = QtWidgets.QPushButton()
        self.fordwardButton.setObjectName('fordward')
        self.fordwardButton.setIcon(GUIToolKit.getIconByName('fordward'))
        self.fordwardButton.clicked.connect(self.joggingFordward)
        self.horizontalLayout.addWidget(self.fordwardButton)

        self.fastBackwardButton = QtWidgets.QPushButton()
        self.fastBackwardButton.setObjectName('fastfordward')
        self.fastBackwardButton.setIcon(
            GUIToolKit.getIconByName('fastfordward'))
        self.fastBackwardButton.clicked.connect(self.joggingfastFordward)
        self.horizontalLayout.addWidget(self.fastBackwardButton)

        self.incrementLabel = QtWidgets.QLabel("Increment:")
        self.horizontalLayout.addWidget(self.incrementLabel)

        onlyFloat = QtGui.QRegExpValidator(
            QtCore.QRegExp("[+-]?([0-9]*[.])?[0-9]+"))
        self.incrementEdit = QtWidgets.QLineEdit()
        self.incrementEdit.setValidator(onlyFloat)
        self.incrementEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.incrementEdit.setText('1.0')
        self.incrementEdit.setObjectName('incrementEdit')
        self.horizontalLayout.addWidget(self.incrementEdit)

        self.disableUI()
        self.device.addConnectionStateListener(self)
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.setObjectName('groupBox')
        self.setTitle('Command Line interface')

        self.cmlVerticalLayout = QtWidgets.QVBoxLayout(self)
        self.cmlVerticalLayout.setObjectName('cmlVerticalLayout')

        self.commandLineDisplay = QtWidgets.QTextEdit(self)
        self.commandLineDisplay.setObjectName('commandLineDisplay')
        self.cmlVerticalLayout.addWidget(self.commandLineDisplay)

        self.commandLineDisplay.setReadOnly(True)
        self.commandLineDisplay.setTextColor(QtGui.QColor(68, 117, 68, 255))

        self.cmlWidget = QtWidgets.QWidget(self)
        self.cmlWidget.setObjectName('cmlWidget')
        self.cmlHorizontalLayout = QtWidgets.QHBoxLayout(self.cmlWidget)
        self.cmlHorizontalLayout.setObjectName('cmlHorizontalLayout')

        self.commandLineEdit = QtWidgets.QLineEdit(self.cmlWidget)
        self.commandLineEdit.setObjectName('commandLineEdit')
        self.cmlHorizontalLayout.addWidget(self.commandLineEdit)

        self.commandLineEdit.returnPressed.connect(self.sendAction)

        self.sendButton = QtWidgets.QPushButton(self.cmlWidget)
        self.sendButton.setObjectName('sendButton')
        self.sendButton.setText('Send')
        self.sendButton.setIcon(GUIToolKit.getIconByName('send'))
        self.sendButton.clicked.connect(self.sendAction)

        self.cmlHorizontalLayout.addWidget(self.sendButton)

        self.clearButton = QtWidgets.QPushButton(self.cmlWidget)
        self.clearButton.setObjectName('clearButton')
        self.cmlHorizontalLayout.addWidget(self.clearButton)
        self.clearButton.setIcon(GUIToolKit.getIconByName('delete'))
        self.clearButton.clicked.connect(self.clearAction)
        self.clearButton.setText('Clear')

        self.listDevices = QtWidgets.QPushButton(self.cmlWidget)
        self.listDevices.setObjectName('listDevices')
        self.cmlHorizontalLayout.addWidget(self.listDevices)
        self.listDevices.setIcon(GUIToolKit.getIconByName('list'))
        self.listDevices.clicked.connect(self.sendListDevices)
        self.listDevices.setText('List Devices')

        self.cmlVerticalLayout.addWidget(self.cmlWidget)
        self.device.addConnectionStateListener(self)
        self.setEnabled(False)
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.setObjectName('DeviceConfigurationTool')

        self.verticalLayout = QtWidgets.QVBoxLayout(self)
        self.verticalLayout.setObjectName('verticalLayout')

        self.counterWidget = QtWidgets.QWidget(self)
        self.counterWidget.setObjectName('counterWidget')
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.counterWidget)
        self.horizontalLayout.setObjectName('horizontalLayout')
        self.digitalReadOut = DROGroupBox(self.counterWidget)
        self.horizontalLayout.addWidget(self.digitalReadOut)

        self.controlLoop = ControlLoopGroupBox(self.counterWidget)
        self.horizontalLayout.addWidget(self.controlLoop)

        self.torqueConfig = TorqueGroupBox(self.counterWidget)
        self.horizontalLayout.addWidget(self.torqueConfig)

        self.connectionControl = ConnectionControlGroupBox(self.counterWidget)
        self.horizontalLayout.addWidget(self.connectionControl)
        self.verticalLayout.addWidget(self.counterWidget)

        self.graphicWidget = SimpleFOCGraphicWidget()
        self.verticalLayout.addWidget(self.graphicWidget)

        self.bottomWidget = QtWidgets.QWidget(self)
        self.bottomWidget.setObjectName('bottomWidget')

        self.bottomHorizontalLayout = QtWidgets.QHBoxLayout(self.bottomWidget)
        self.bottomHorizontalLayout.setObjectName('configureHorizontalLayout')

        self.pidConfigurator = PidGroupBox(self.bottomWidget)
        self.bottomHorizontalLayout.addWidget(self.pidConfigurator)

        self.generalLayout = QtWidgets.QVBoxLayout()
        self.generalDeviceSettings = GeneralSettingsGroupBox(self.bottomWidget)
        self.generalControls = GeneralControls(self.bottomWidget)
        self.generalLayout.addWidget(self.generalControls)
        self.generalLayout.addWidget(self.generalDeviceSettings)
        self.bottomHorizontalLayout.addLayout(self.generalLayout)

        self.commandLine = CommandLineWidget(self)
        self.bottomHorizontalLayout.addWidget(self.commandLine)
        self.verticalLayout.addWidget(self.bottomWidget)

        self.device.commProvider.commandDataReceived.connect(
            self.commandLine.publishCommandResponseData)
예제 #10
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.verticalLayout = QtWidgets.QVBoxLayout(self)
        self.verticalLayout.setObjectName('verticalLayout')

        self.configureConnection = ConfigureConnection()
        self.verticalLayout.addWidget(self.configureConnection)

        self.commandLineInterface = CommandLineWidget()
        self.verticalLayout.addWidget(self.commandLineInterface)

        self.device.commProvider.rawDataReceived.connect(self.commandLineInterface.publishCommandResponseData)
    def __init__(self, parent=None):
        super().__init__(parent)
        self.device = SimpleFOCDevice.getInstance()

        self.layout = QVBoxLayout(self)

        self.treeViewWidget = DevicesInspectorTree(self)
        self.leftWidget = DeviceInteractionFrame(self)

        self.verticalSplitter = QSplitter(Qt.Horizontal)
        self.verticalSplitter.addWidget(self.treeViewWidget)
        self.verticalSplitter.addWidget(self.leftWidget)

        self.layout.addWidget(self.verticalSplitter)

        self.setLayout(self.layout)
예제 #12
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.setObjectName('connectionControl')
        self.setTitle('Connection control')

        self.horizontalLayout = QtWidgets.QHBoxLayout(self)
        self.horizontalLayout.setObjectName('generalControlHL')

        self.devCommandIDLabel = QtWidgets.QLabel("Command:")
        self.horizontalLayout.addWidget(self.devCommandIDLabel)
        self.devCommandIDLetter = QtWidgets.QLineEdit()
        self.devCommandIDLetter.setObjectName('devCommandIDLetter')
        self.devCommandIDLetter.editingFinished.connect(
            self.changeDevicedevCommandID)
        self.horizontalLayout.addWidget(self.devCommandIDLetter)

        self.pullConfig = QtWidgets.QPushButton()
        self.pullConfig.setObjectName('pullConfig')
        self.pullConfig.setIcon(GUIToolKit.getIconByName('pull'))
        self.pullConfig.setText(' Pull Params')
        self.pullConfig.clicked.connect(self.device.pullConfiguration)

        self.horizontalLayout.addWidget(self.pullConfig)

        self.connectDisconnectButton = QtWidgets.QPushButton(self)
        self.connectDisconnectButton.setIcon(
            GUIToolKit.getIconByName('connect'))
        self.connectDisconnectButton.setObjectName('connectDeviceButton')
        self.connectDisconnectButton.setText('Connect')
        self.connectDisconnectButton.clicked.connect(
            self.connectDisconnectDeviceAction)

        self.horizontalLayout.addWidget(self.connectDisconnectButton)

        self.configureDeviceButton = QtWidgets.QPushButton(self)
        self.configureDeviceButton.setIcon(
            GUIToolKit.getIconByName('configure'))
        self.configureDeviceButton.setObjectName('configureDeviceButton')
        self.configureDeviceButton.setText('Configure')
        self.configureDeviceButton.clicked.connect(self.configureDeviceAction)
        self.horizontalLayout.addWidget(self.configureDeviceButton)

        self.device.addConnectionStateListener(self)
        self.connectionStateChanged(self.device.isConnected)
예제 #13
0
    def __init__(self, parent=None):

        super().__init__(parent)

        # self.setMaximumWidth(300)

        onlyFloat = QtGui.QRegExpValidator(
            QtCore.QRegExp("[+-]?([0-9]*[.])?[0-9]+"))

        self.device = SimpleFOCDevice.getInstance()

        self.setTitle('General Controls')

        self.setObjectName('generalControls')

        self.gcGridLayout = QtWidgets.QGridLayout(self)
        self.gcGridLayout.setObjectName('gcGridLayout')

        self.enableDeviceButton = QtWidgets.QPushButton(self)
        self.enableDeviceButton.setObjectName('enButton')
        self.enableDeviceButton.setText('Enable Device')
        self.enableDeviceButton.setIcon(GUIToolKit.getIconByName('greendot'))
        self.enableDeviceButton.clicked.connect(self.toggleEnable)
        self.gcGridLayout.addWidget(self.enableDeviceButton, 1, 0, 1, 1)

        self.sensorZeroButton = QtWidgets.QPushButton(self)
        self.sensorZeroButton.setObjectName('homeButton')
        self.sensorZeroButton.setText('Sensor Zero')
        self.sensorZeroButton.setIcon(GUIToolKit.getIconByName('home'))
        self.sensorZeroButton.clicked.connect(self.setSensorZero)
        self.gcGridLayout.addWidget(self.sensorZeroButton, 1, 1, 1, 1)

        self.setZeroTarget = QtWidgets.QPushButton(self)
        self.setZeroTarget.setObjectName('zeroButton')
        self.setZeroTarget.setText('Zero Target')
        self.setZeroTarget.setIcon(GUIToolKit.getIconByName('stop'))
        self.setZeroTarget.clicked.connect(self.setTargetZero)
        self.gcGridLayout.addWidget(self.setZeroTarget, 1, 2, 1, 1)
        self.reloadValues()

        self.device.addConnectionStateListener(self)
        self.device.commProvider.commandDataReceived.connect(
            self.commandResponseReceived)

        self.connectionStateChanged(self.device.isConnected)
예제 #14
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setTabsClosable(True)
        self.setMovable(True)
        self.setObjectName('devicesTabWidget')

        self.device = SimpleFOCDevice.getInstance()

        self.cmdLineTool = None
        self.configDeviceTool = None
        self.generatedCodeTab = None
        self.activeToolsList = []

        self.tabCloseRequested.connect(self.removeTabHandler)

        self.setStyleSheet(
            'QTabBar::close - button { image: url(close.png) subcontrol - position: left; }'
        )
        self.setStyleSheet('QTabBar::tab { height: 30px; width: 150px;}')
예제 #15
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.device = SimpleFOCDevice.getInstance()

        self.layout = QVBoxLayout(self)
        self.setLayout(self.layout)

        self.droWidget = DROGroupBox(self)
        self.layout.addWidget(self.droWidget)

        self.generalControls = GeneralControls(self)
        self.layout.addWidget(self.generalControls)

        self.treeView = DeviceTreeView(self)
        self.layout.addWidget(self.treeView)

        self.connectionControl = ConnectionControlGroupBox(self)
        self.layout.addWidget(self.connectionControl)

        self.setMaximumWidth(500)
    def __init__(self, parent=None):
        super().__init__(parent)

        self.layout = QVBoxLayout(self)
        self.setLayout(self.layout)
        self.device = SimpleFOCDevice.getInstance()

        self.graphicWidget = SimpleFOCGraphicWidget(self)
        self.cmdLineTollWidget = CommandLineWidget(self)

        self.cmdLineTollWidget.setMaximumHeight(150)

        self.verticalSplitter = QSplitter(Qt.Vertical)
        self.verticalSplitter.addWidget(self.graphicWidget)
        self.verticalSplitter.addWidget(self.cmdLineTollWidget)
        self.device.commProvider.commandDataReceived.connect(
            self.cmdLineTollWidget.publishCommandResponseData)
        self.layout.addWidget(self.verticalSplitter)

        self.setLayout(self.layout)
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()
        dlg = MinimalCodeDialog(
        )  # If you pass self, the dialog will be centered over the main window as before.
        if not dlg.exec_():
            return

        # get the version of the library from te github
        try:
            repo = Repo('lib_src')
            QMessageBox.about(
                self, "INFO",
                "Using already cloned <i>Simple<b>FOC</b>library</i> files from <i>lib_src</i> folder!"
            )
        except git.exc.NoSuchPathError:
            QMessageBox.about(
                self, "INFO",
                "Cloning the <i>Siimple<b>FOC</b>library</i> files to th <i>lib_src</i> folder!<br> This could take few mmoments."
            )
            repo = Repo.clone_from(
                "https://github.com/simplefoc/Arduino-FOC.git",
                "lib_src",
                single_branch=True,
                branch='v2.2')
            QMessageBox.about(self, "INFO", "Cloning done.")

        folder_path = os.path.join(dlg.folderPath.box.text(),
                                   dlg.projectNameEdit.text())
        project_name = dlg.projectNameEdit.text()
        # checking whether folder exists or not
        if os.path.exists(folder_path):
            # checking whether the folder is empty or not
            if len(os.listdir(folder_path)) != 0:
                # messaging saying folder not empty
                QMessageBox.about(
                    self, "ERROR",
                    "Folder is not empty. Project may already exist! <br><br>Rewritig the project files not supported, please choose different project name."
                )
                return
        else:
            # file not found message
            os.mkdir(folder_path)
        """
        create the ino file
        """
        start_comment = "/* \n* SimpleFOCStudio generated example \n"+ \
                "* at "+datetime.now().strftime("%d/%m/%Y %H:%M:%S"+"\n")+ \
                "*\n*\n"+ \
                "* Chosen components:\n" \

        ino_includes = ""
        start_inc = '#include "src/'
        end_inc = "\" \n"
        """
        building the minimal example structure
        """
        # add the source folder
        os.mkdir(os.path.join(folder_path, 'src'))

        # common files
        shutil.copytree(os.path.join("lib_src", "src/common"),
                        os.path.join(folder_path, "src/common"))
        """ 
        motors
        """
        if dlg.checkBoxBLDCMotor.isChecked():
            shutil.copy(os.path.join('lib_src', 'src/BLDCMotor.cpp'),
                        os.path.join(folder_path, 'src/'))
            shutil.copy(os.path.join('lib_src', 'src/BLDCMotor.h'),
                        os.path.join(folder_path, 'src/'))
            start_comment += "*\t - BLDCMotor\n"
            ino_includes += start_inc + "BLDCMotor.h" + end_inc

        if dlg.checkBoxStepperMotor.isChecked():
            shutil.copy(os.path.join('lib_src', 'src/StepperMotor.cpp'),
                        os.path.join(folder_path, 'src/'))
            shutil.copy(os.path.join('lib_src', 'src/StepperMotor.h'),
                        os.path.join(folder_path, 'src/'))
            start_comment += "*\t - StepperMotor\n"
            ino_includes += start_inc + "StepperMotor.h" + end_inc
        """ 
        drivers
        """
        src_drivers = os.path.join('lib_src', 'src/drivers')
        target_drivers = os.path.join(folder_path, 'src/drivers')

        if dlg.checkBoxBLDCDriver3PWM.isChecked(
        ) or dlg.checkBoxBLDCDriver6PWM.isChecked(
        ) or dlg.checkBoxStepperDriver2PWM.isChecked(
        ) or dlg.checkBoxStepperDriver4PWM.isChecked():
            os.mkdir(os.path.join(folder_path, 'src/drivers'))
            shutil.copy(os.path.join(src_drivers, 'hardware_api.h'),
                        target_drivers)
            # add hardware specific stuff
            target_hardware_specific = os.path.join(target_drivers,
                                                    'hardware_specific')
            src_hardware_specific = os.path.join(src_drivers,
                                                 'hardware_specific')

            # create hardware specific folder
            os.mkdir(target_hardware_specific)
            # for now coppy the generic as well - this might change in future
            shutil.copy(os.path.join(src_hardware_specific, 'generic_mcu.cpp'),
                        target_hardware_specific)

            # find selected mcu
            mcu = dlg.dropDownMCU.currentData()
            # coppy necessary files
            for file_name in driverMCUFiles[mcu]:
                shutil.copy(os.path.join(src_hardware_specific, file_name),
                            target_hardware_specific)

        if dlg.checkBoxBLDCDriver3PWM.isChecked():
            shutil.copy(os.path.join(src_drivers, 'BLDCDriver3PWM.cpp'),
                        target_drivers)
            shutil.copy(os.path.join(src_drivers, 'BLDCDriver3PWM.h'),
                        target_drivers)
            start_comment += "*\t - BLDCDriver3PWM\n"
            ino_includes += start_inc + "drivers/BLDCDriver3PWM.h" + end_inc

        if dlg.checkBoxBLDCDriver6PWM.isChecked():
            shutil.copy(os.path.join(src_drivers, 'BLDCDriver6PWM.cpp'),
                        target_drivers)
            shutil.copy(os.path.join(src_drivers, 'BLDCDriver6PWM.h'),
                        target_drivers)
            start_comment += "*\t - BLDCDriver6PWM\n"
            ino_includes += start_inc + "drivers/BLDCDriver6PWM.h" + end_inc

        if dlg.checkBoxStepperDriver2PWM.isChecked():
            shutil.copy(os.path.join(src_drivers, 'StepperDriver2PWM.cpp'),
                        target_drivers)
            shutil.copy(os.path.join(src_drivers, 'StepperDriver2PWM.h'),
                        target_drivers)
            start_comment += "*\t - StepperDriver2PWM\n"
            ino_includes += start_inc + "drivers/StepperDriver2PWM.h" + end_inc

        if dlg.checkBoxStepperDriver4PWM.isChecked():
            shutil.copy(os.path.join(src_drivers, 'StepperDriver4PWM.cpp'),
                        target_drivers)
            shutil.copy(os.path.join(src_drivers, 'StepperDriver4PWM.h'),
                        target_drivers)
            start_comment += "*\t - StepperDriver4PWM\n"
            ino_includes += start_inc + "drivers/StepperDriver4PWM.h" + end_inc

        # driver mcu specific
        """ 
        sensors
        """
        src_sensors = os.path.join('lib_src', 'src/sensors')
        target_sensors = os.path.join(folder_path, 'src/sensors')

        if dlg.checkBoxEncoder.isChecked() or dlg.checkBoxHallSensor.isChecked(
        ) or dlg.checkBoxMagneticAnalog.isChecked(
        ) or dlg.checkBoxMagneticSPI.isChecked(
        ) or dlg.checkBoxMagneticI2C.isChecked(
        ) or dlg.checkBoxMagneticPWM.isChecked():
            os.mkdir(os.path.join(folder_path, 'src/sensors'))

        if dlg.checkBoxEncoder.isChecked():
            shutil.copy(os.path.join(src_sensors, 'Encoder.cpp'),
                        target_sensors)
            shutil.copy(os.path.join(src_sensors, 'Encoder.h'), target_sensors)
            start_comment += "*\t - Encoder\n"
            ino_includes += start_inc + "sensors/Encoder.h" + end_inc

        if dlg.checkBoxHallSensor.isChecked():
            shutil.copy(os.path.join(src_sensors, 'HallSensor.cpp'),
                        target_sensors)
            shutil.copy(os.path.join(src_sensors, 'HallSensor.h'),
                        target_sensors)
            start_comment += "*\t - HallSensor\n"
            ino_includes += start_inc + "sensors/HallSensor.h" + end_inc

        if dlg.checkBoxMagneticSPI.isChecked():
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorSPI.cpp'),
                        target_sensors)
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorSPI.h'),
                        target_sensors)
            start_comment += "*\t - MagneticSensorSPI\n"
            ino_includes += start_inc + "sensors/MagneticSensorSPI.h" + end_inc

        if dlg.checkBoxMagneticI2C.isChecked():
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorI2C.cpp'),
                        target_sensors)
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorI2C.h'),
                        target_sensors)
            start_comment += "*\t - MagneticSensorI2C\n"
            ino_includes += start_inc + "sensors/MagneticSensorSPI.h" + end_inc

        if dlg.checkBoxMagneticPWM.isChecked():
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorPWM.cpp'),
                        target_sensors)
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorPWM.h'),
                        target_sensors)
            start_comment += "*\t - MagneticSensorPWM\n"
            ino_includes += start_inc + "sensors/MagneticSensorPWM.h" + end_inc

        if dlg.checkBoxMagneticAnalog.isChecked():
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorAnalog.cpp'),
                        target_sensors)
            shutil.copy(os.path.join(src_sensors, 'MagneticSensorAnalog.h'),
                        target_sensors)
            start_comment += "*\t - MagneticSensorAnalog\n"
            ino_includes += start_inc + "sensors/MagneticSensorAnalog.h" + end_inc
        """
        current sense 
        """
        src_currentsense = os.path.join('lib_src', 'src/current_sense')
        target_currentsense = os.path.join(folder_path, 'src/current_sense')

        if dlg.checkBoxCSInline.isChecked() or dlg.checkBoxCSLowside.isChecked(
        ):
            os.mkdir(target_currentsense)
            shutil.copy(os.path.join(src_currentsense, 'hardware_api.h'),
                        target_currentsense)

            # add hardware specific stuff
            target_hardware_specific = os.path.join(target_currentsense,
                                                    'hardware_specific')
            src_hardware_specific = os.path.join(src_currentsense,
                                                 'hardware_specific')

            # create hardware specific folder
            os.mkdir(target_hardware_specific)
            # for now coppy the generic as well - this might change in future
            shutil.copy(os.path.join(src_hardware_specific, 'generic_mcu.cpp'),
                        target_hardware_specific)

            # find selected mcu
            mcu = dlg.dropDownMCU.currentData()
            # coppy necessary files
            for file_name in currentsenseMCUFiles[mcu]:
                shutil.copy(os.path.join(src_hardware_specific, file_name),
                            target_hardware_specific)

        if dlg.checkBoxCSInline.isChecked():
            shutil.copy(
                os.path.join(src_currentsense, 'InlineCurrentSense.cpp'),
                target_currentsense)
            shutil.copy(os.path.join(src_currentsense, 'InlineCurrentSense.h'),
                        target_currentsense)
            start_comment += "*\t - InlineCurrentSense\n"
            ino_includes += start_inc + "current_sense/InlineCurrentSense.h" + end_inc

        if dlg.checkBoxCSLowside.isChecked():
            shutil.copy(
                os.path.join(src_currentsense, 'LowsideCurrentSense.cpp'),
                target_currentsense)
            shutil.copy(
                os.path.join(src_currentsense, 'LowsideCurrentSense.h'),
                target_currentsense)
            start_comment += "*\t - LowsideCurrentSense\n"
            ino_includes += start_inc + "current_sense/LowsideCurrentSense.h" + end_inc
        # current sense specific
        """
        communication
        """
        src_communication = os.path.join('lib_src', 'src/communication')
        target_communication = os.path.join(folder_path, 'src/communication')

        if dlg.checkBoxCommander.isChecked(
        ) or dlg.checkBoxCommStepDir.isChecked():
            os.mkdir(os.path.join(folder_path, 'src/communication'))

        if dlg.checkBoxCommander.isChecked():
            shutil.copy(os.path.join(src_communication, 'Commander.cpp'),
                        target_communication)
            shutil.copy(os.path.join(src_communication, 'Commander.h'),
                        target_communication)
            shutil.copy(os.path.join(src_communication, 'commands.h'),
                        target_communication)
            start_comment += "*\t - Commander\n"
            ino_includes += start_inc + "communication/Commander.h" + end_inc

        if dlg.checkBoxCommStepDir.isChecked():
            shutil.copy(os.path.join(src_communication, 'StepDirListener.cpp'),
                        target_communication)
            shutil.copy(os.path.join(src_communication, 'StepDirListener.h'),
                        target_communication)
            start_comment += "*\t - StepDirListener\n"
            ino_includes += start_inc + "communication/StepDirListener.h" + end_inc

        # include file ( maybe )

        # finish the ino file
        f = open(os.path.join(folder_path, project_name + '.ino'), "w")
        start_comment += "*\n* Microcontroller type:\n"
        start_comment += "*\t -" + dlg.dropDownMCU.currentText() + "\n*\n"
        start_comment += "*/\n\n"
        ino_includes += "\n\n"
        f.write(start_comment)
        f.write(ino_includes)
        f.writelines([
            "void setup(){\n\t\n\t\n",
            "}\n\n",
            "void loop(){\n\t\n\t\n",
            "}\n\n",
        ])
        f.close()

        QMessageBox.about(self, "INFO", "Project generated successfully!")

        self.layout = QVBoxLayout()

        text = "<h1>Arduino Minimal Project Code Generation</h1>"
        text += "Generated minimal stand alone arduino project using the <i>Simple<b>FOC</b>Studio</i>, based on the <i>Simple<b>FOC</b>library</i> <small>v2.2</small> <br><br>"
        text += "In this window you can simply navigate and familiarise yourself with the code structure.<br>"
        text += "Your project is saved on the disk at the desired path: <b>" + folder_path + "</b><br>"
        text += "<br>"

        message = QtWidgets.QLabel(text)
        self.layout.addWidget(message)
        self.layout.addWidget(QLabel("<h2>Generated project structure:</h2>"))

        self.model = QFileSystemModel()
        self.model.setIconProvider(FileIconProvider())
        self.model.setRootPath(folder_path)
        self.tree = QTreeView()
        self.tree.setModel(self.model)
        self.tree.setRootIndex(self.model.index(folder_path))

        self.tree.setAnimated(False)
        self.tree.setIndentation(20)
        self.tree.setSortingEnabled(True)

        self.tree.setWindowTitle("Project View")

        self.codeDisplay = QtWidgets.QTextEdit()
        self.codeDisplay.setObjectName('codeDisplay')
        self.codeDisplay.setText("")
        self.codeDisplay.setReadOnly(True)

        h = Highlighter(self.codeDisplay)
        self.separatedView = QHBoxLayout()
        self.separatedView.addWidget(self.tree)
        self.separatedView.addWidget(self.codeDisplay)

        self.layout.addLayout(self.separatedView)
        self.setLayout(self.layout)

        self.tree.clicked.connect(self.on_treeView_clicked)
        # display ino file on startup
        self.tree.setCurrentIndex(
            self.model.index(os.path.join(folder_path, project_name + '.ino')))
        self.on_treeView_clicked(
            self.model.index(os.path.join(folder_path, project_name + '.ino')))
예제 #18
0
    def __init__(self, parent=None, controllerPlotWidget=None):
        '''Constructor for ToolsWidget'''
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()
        self.controlledPlot = controllerPlotWidget

        self.verticalLayout = QtWidgets.QVBoxLayout(self)
        self.setLayout(self.verticalLayout)

        self.horizontalLayout1 = QtWidgets.QHBoxLayout()
        self.horizontalLayout1.setObjectName('horizontalLayout')

        self.startStopButton = QtWidgets.QPushButton(self)
        self.startStopButton.setText('Start')
        self.startStopButton.setObjectName('Start')
        self.startStopButton.clicked.connect(self.startStoPlotAction)
        self.startStopButton.setIcon(GUIToolKit.getIconByName('start'))
        self.horizontalLayout1.addWidget(self.startStopButton)

        self.pauseContinueButton = QtWidgets.QPushButton(self)
        self.pauseContinueButton.setObjectName('pauseButton')
        self.pauseContinueButton.setText('Pause')
        self.pauseContinueButton.setIcon(GUIToolKit.getIconByName('pause'))
        self.pauseContinueButton.clicked.connect(self.pauseContinuePlotAction)
        self.horizontalLayout1.addWidget(self.pauseContinueButton)

        self.zoomAllButton = QtWidgets.QPushButton(self)
        self.zoomAllButton.setObjectName('zoomAllButton')
        self.zoomAllButton.setText('View all')
        self.zoomAllButton.setIcon(GUIToolKit.getIconByName('zoomall'))
        self.zoomAllButton.clicked.connect(self.zoomAllPlot)
        self.horizontalLayout1.addWidget(self.zoomAllButton)

        self.signalCheckBox = []
        for i in range(len(self.controlledPlot.signals)):
            checkBox = QtWidgets.QCheckBox(self)
            checkBox.setObjectName('signalCheckBox' + str(i))
            checkBox.setToolTip(self.controlledPlot.signal_tooltip[i])
            checkBox.setText(self.controlledPlot.signals[i])
            checkBox.setIcon(
                GUIToolKit.getIconByName(self.controlledPlot.signalIcons[i]))
            checkBox.setChecked(True)
            self.signalCheckBox.append(checkBox)
            self.horizontalLayout1.addWidget(checkBox)

        spacerItem = QtWidgets.QSpacerItem(100, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Maximum)

        self.horizontalLayout1.addItem(spacerItem)
        self.horizontalLayout1.addItem(spacerItem)

        self.downsampleLabel = QtWidgets.QLabel(self)
        self.downsampleLabel.setText('Downsample')
        self.downampleValue = QtWidgets.QLineEdit(self.downsampleLabel)
        self.downampleValue.setText("100")
        self.downampleValue.editingFinished.connect(self.changeDownsampling)
        self.horizontalLayout1.addWidget(self.downsampleLabel)
        self.horizontalLayout1.addWidget(self.downampleValue)

        self.verticalLayout.addLayout(self.horizontalLayout1)
예제 #19
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.sFOCDevice = QtWidgets.QTreeWidgetItem(self)
        self.sFOCDevice.setText(0, 'sFOC Device')
        self.sFOCDevice.setIcon(0, GUIToolKit.getIconByName('motor'))

        self.setColumnCount(2)

        self.motionControl = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
        self.motionControl.setText(0, 'Motion config')
        self.motionControl.setIcon(0, GUIToolKit.getIconByName('pidconfig'))
        self.sFOCDevice.addChild(self.motionControl)

        self.controller = QtWidgets.QTreeWidgetItem(self.motionControl)
        self.controller.setText(0, 'Motion Control Type')
        self.controller.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.selectorControlLoop = QtWidgets.QComboBox(self)
        self.selectorControlLoop.addItems([
            'Torque', 'Velocity', 'Angle', 'Velocity openloop',
            'Angle openloop'
        ])
        self.selectorControlLoop.currentIndexChanged.connect(
            self.changeControlLoop)
        self.setItemWidget(self.controller, 1, self.selectorControlLoop)

        self.torque = QtWidgets.QTreeWidgetItem(self.motionControl)
        self.torque.setText(0, 'Torque Control Type')
        self.torque.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.selectorTorque = QtWidgets.QComboBox(self)
        self.selectorTorque.addItems(['Voltage', 'DC Curret', 'FOC Current'])
        self.selectorTorque.currentIndexChanged.connect(self.changeTorque)
        self.setItemWidget(self.torque, 1, self.selectorTorque)

        self.motionDownsample = QtWidgets.QTreeWidgetItem(self.motionControl)
        self.motionDownsample.setText(0, 'Motion Downsample')
        self.motionDownsample.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.motionDownsample.setText(1, '')
        self.motionDownsample.setFlags(self.motionDownsample.flags()
                                       | QtCore.Qt.ItemIsEditable)

        self.PIDVelocityConfig = self.addPIDSubtree(self.motionControl,
                                                    'Velocity PID')
        self.PIDAngleConfig = self.addPIDSubtree(self.motionControl,
                                                 'Angle PID')
        self.PIDCurrentQConfig = self.addPIDSubtree(self.motionControl,
                                                    'Current q PID')
        self.PIDCurrentDConfig = self.addPIDSubtree(self.motionControl,
                                                    'Current d PID')

        self.limitsConfig = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
        self.limitsConfig.setText(0, 'Limits')
        self.limitsConfig.setIcon(0, GUIToolKit.getIconByName('statistics'))
        self.sFOCDevice.addChild(self.limitsConfig)

        self.velocityLimit = QtWidgets.QTreeWidgetItem(self.limitsConfig)
        self.velocityLimit.setText(0, 'Velocity limit')
        self.velocityLimit.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.velocityLimit.setText(1, '')
        self.velocityLimit.setFlags(self.velocityLimit.flags()
                                    | QtCore.Qt.ItemIsEditable)

        self.voltageLimit = QtWidgets.QTreeWidgetItem(self.limitsConfig)
        self.voltageLimit.setText(0, 'Voltage limit')
        self.voltageLimit.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.voltageLimit.setText(1, '')
        self.voltageLimit.setFlags(self.voltageLimit.flags()
                                   | QtCore.Qt.ItemIsEditable)

        self.currentLimit = QtWidgets.QTreeWidgetItem(self.limitsConfig)
        self.currentLimit.setText(0, 'Current limit')
        self.currentLimit.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.currentLimit.setText(1, '')
        self.currentLimit.setFlags(self.currentLimit.flags()
                                   | QtCore.Qt.ItemIsEditable)

        self.statesConfig = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
        self.statesConfig.setText(0, 'States')
        self.statesConfig.setIcon(0, GUIToolKit.getIconByName('statistics'))
        self.sFOCDevice.addChild(self.statesConfig)

        self.satateTarget = QtWidgets.QTreeWidgetItem(self.statesConfig)
        self.satateTarget.setText(0, 'Target')
        self.satateTarget.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.satateTarget.setText(1, '')

        self.stateVq = QtWidgets.QTreeWidgetItem(self.statesConfig)
        self.stateVq.setText(0, 'Voltage q')
        self.stateVq.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.stateVd = QtWidgets.QTreeWidgetItem(self.statesConfig)
        self.stateVd.setText(0, 'Voltage d')
        self.stateVd.setIcon(0, GUIToolKit.getIconByName('gear'))

        self.stateCq = QtWidgets.QTreeWidgetItem(self.statesConfig)
        self.stateCq.setText(0, 'Current q')
        self.stateCq.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.stateCd = QtWidgets.QTreeWidgetItem(self.statesConfig)
        self.stateCd.setText(0, 'Current d')
        self.stateCd.setIcon(0, GUIToolKit.getIconByName('gear'))

        self.stateVel = QtWidgets.QTreeWidgetItem(self.statesConfig)
        self.stateVel.setText(0, 'Velocity')
        self.stateVel.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.stateVel.setText(1, '')

        self.stateAngle = QtWidgets.QTreeWidgetItem(self.statesConfig)
        self.stateAngle.setText(0, 'Angle')
        self.stateAngle.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.stateAngle.setText(1, '')

        self.sensorConfig = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
        self.sensorConfig.setText(0, 'Sensor config')
        self.sensorConfig.setIcon(0, GUIToolKit.getIconByName('sensor'))
        self.sFOCDevice.addChild(self.sensorConfig)

        self.sensorZeroOffset = QtWidgets.QTreeWidgetItem(self.sensorConfig)
        self.sensorZeroOffset.setText(0, 'Zero Angle Offset')
        self.sensorZeroOffset.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.sensorZeroOffset.setText(1, '')
        self.sensorZeroOffset.setFlags(self.sensorZeroOffset.flags()
                                       | QtCore.Qt.ItemIsEditable)

        self.sensorZeroElecOffset = QtWidgets.QTreeWidgetItem(
            self.sensorConfig)
        self.sensorZeroElecOffset.setText(0, 'Electrical Zero Offset')
        self.sensorZeroElecOffset.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.sensorZeroElecOffset.setText(1, '')
        self.sensorZeroElecOffset.setFlags(self.sensorZeroElecOffset.flags()
                                           | QtCore.Qt.ItemIsEditable)

        self.generalSettings = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
        self.generalSettings.setText(0, 'General settings')
        self.generalSettings.setIcon(
            0, GUIToolKit.getIconByName('generalsettings'))
        self.sFOCDevice.addChild(self.generalSettings)

        self.phaseRes = QtWidgets.QTreeWidgetItem(self.generalSettings)
        self.phaseRes.setText(0, 'Phase Resistance')
        self.phaseRes.setIcon(0, GUIToolKit.getIconByName('res'))
        self.phaseRes.setText(1, '')
        self.phaseRes.setFlags(self.phaseRes.flags()
                               | QtCore.Qt.ItemIsEditable)

        self.deviceStatus = QtWidgets.QTreeWidgetItem(self.generalSettings)
        self.deviceStatus.setText(0, 'Motor Status')
        self.deviceStatus.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.selectStatus = QtWidgets.QComboBox(self)
        self.selectStatus.addItems(['Disabled', 'Enabled'])
        self.selectStatus.currentIndexChanged.connect(self.changeStatus)
        self.setItemWidget(self.deviceStatus, 1, self.selectStatus)

        self.modulationType = QtWidgets.QTreeWidgetItem(self.generalSettings)
        self.modulationType.setText(0, 'PWM modulation')
        self.modulationType.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.selectModulation = QtWidgets.QComboBox(self)
        self.selectModulation.addItems([
            'Sine PWM', 'Space Vector PWM', 'Trapezoidal 120',
            'Trapezoidal 150'
        ])
        self.selectModulation.currentIndexChanged.connect(self.changeModType)
        self.setItemWidget(self.modulationType, 1, self.selectModulation)

        self.modulationCenter = QtWidgets.QTreeWidgetItem(self.generalSettings)
        self.modulationCenter.setText(0, 'Modulation center')
        self.modulationCenter.setIcon(0, GUIToolKit.getIconByName('gear'))
        self.selectModCenter = QtWidgets.QComboBox(self)
        self.selectModCenter.addItems(['Disabled', 'Enabled'])
        self.selectModCenter.currentIndexChanged.connect(self.changeModCenter)
        self.setItemWidget(self.modulationCenter, 1, self.selectModCenter)

        self.customComands = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
        self.customComands.setText(0, 'Custom commands')
        self.customComands.setIcon(0,
                                   GUIToolKit.getIconByName('customcommands'))
        self.sFOCDevice.addChild(self.customComands)

        for customCommand in self.device.customCommands.customCommandsList:
            self.initCustomCommand(customCommand)

        self.installEventFilter(self)
        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.customCommandsMenu)

        self.header().resizeSection(0, 230)

        self.setAlternatingRowColors(True)
        self.header().hide()
        self.expandItem(self.sFOCDevice)
        self.expandItem(self.motionControl)

        self.device.addConnectionStateListener(self)
        self.device.commProvider.commandDataReceived.connect(
            self.commandResponseReceived)
        self.device.commProvider.stateMonitorReceived.connect(
            self.stateResponseReceived)

        self.itemChanged.connect(self.treeItemEdited)

        self.setEnabled(self.device.isConnected)
예제 #20
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setupUi(SimpleFOCDevice.getInstance())
    def __init__(self, parent=None):

        super().__init__(parent)

        self.setMaximumWidth(300)

        onlyFloat = QtGui.QRegExpValidator(
            QtCore.QRegExp("[+-]?([0-9]*[.])?[0-9]+"))

        self.device = SimpleFOCDevice.getInstance()

        self.setTitle('General device settings')

        self.setObjectName('generalDeviceSettings')

        self.gcGridLayout = QtWidgets.QGridLayout(self)
        self.gcGridLayout.setObjectName('gcGridLayout')

        self.motionDownsample = QtWidgets.QLabel(self)
        self.motionDownsample.setObjectName('motionDownsample')
        self.motionDownsample.setText('Motion Downsample')
        self.gcGridLayout.addWidget(self.motionDownsample, 2, 0, 1, 1)

        self.motionDownsampleEdit = ConfigQLineEdit(self)
        self.motionDownsampleEdit.setObjectName('motionDownsampleEdit')
        self.motionDownsampleEdit.setValidator(onlyFloat)
        self.motionDownsampleEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.motionDownsampleEdit.updateValue.connect(
            self.sendMotionDownsampleAction)
        self.gcGridLayout.addWidget(self.motionDownsampleEdit, 2, 1, 1, 1)

        self.curLimitLabel = QtWidgets.QLabel(self)
        self.curLimitLabel.setObjectName('curLimitLabel')
        self.curLimitLabel.setText('Current Limit')
        self.gcGridLayout.addWidget(self.curLimitLabel, 3, 0, 1, 1)

        self.velLimitlabel = QtWidgets.QLabel(self)
        self.velLimitlabel.setObjectName('velLimitlabel')
        self.velLimitlabel.setText('Velocity limit')
        self.gcGridLayout.addWidget(self.velLimitlabel, 4, 0, 1, 1)

        self.volLimitLabel = QtWidgets.QLabel(self)
        self.volLimitLabel.setObjectName('volLimitLabel')
        self.volLimitLabel.setText('Voltage limit')
        self.gcGridLayout.addWidget(self.volLimitLabel, 6, 0, 1, 1)

        self.clLineEdit = ConfigQLineEdit(self)
        self.clLineEdit.setObjectName('clLineEdit')
        self.clLineEdit.setValidator(onlyFloat)
        self.clLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.clLineEdit.updateValue.connect(self.sendCurrentLimitAction)
        self.gcGridLayout.addWidget(self.clLineEdit, 3, 1, 1, 1)

        self.vlLineEdit = ConfigQLineEdit(self)
        self.vlLineEdit.setObjectName('vlLineEdit')
        self.vlLineEdit.setValidator(onlyFloat)
        self.vlLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.vlLineEdit.updateValue.connect(self.sendVelLimitAction)
        self.gcGridLayout.addWidget(self.vlLineEdit, 4, 1, 1, 1)

        self.volLLineEdit = ConfigQLineEdit(self)
        self.volLLineEdit.setObjectName('volLLineEdit')
        self.volLLineEdit.setValidator(onlyFloat)
        self.volLLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.volLLineEdit.updateValue.connect(self.sendVoltageLimitAction)
        self.gcGridLayout.addWidget(self.volLLineEdit, 6, 1, 1, 1)

        self.reloadValues()

        self.device.addConnectionStateListener(self)
        self.device.commProvider.commandDataReceived.connect(
            self.commandResponseReceived)

        self.connectionStateChanged(self.device.isConnected)
예제 #22
0
from src.simpleFOCConnector import SimpleFOCDevice
import time
if __name__ == '__main__':
    deviceConnector = SimpleFOCDevice.getInstance()
    deviceConnector.serialPortName = 'COM32'
    deviceConnector.serialRate = 115200
    deviceConnector.devCommandID = 'M'

    if deviceConnector.connect(SimpleFOCDevice.ONLY_CONNECT):
        while True:
            deviceConnector.sendControlType(SimpleFOCDevice.ANGLE_CONTROL)
            deviceConnector.sendTargetValue(0)
            time.sleep(2.0)
            deviceConnector.sendTargetValue(3)
            time.sleep(2)
            deviceConnector.sendTargetValue(6)
            time.sleep(2)
            deviceConnector.sendTargetValue(-6)
            time.sleep(2)
            deviceConnector.sendControlType(SimpleFOCDevice.VELOCITY_CONTROL)
            deviceConnector.sendTargetValue(30)
            time.sleep(2)
            deviceConnector.sendTargetValue(-30)
            time.sleep(2)
예제 #23
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.device = SimpleFOCDevice.getInstance()

        self.setTitle('Configure serial connection')
        self.setObjectName('configureConnection')

        self.configCoonLayout = QtWidgets.QHBoxLayout(self)
        self.configCoonLayout.setObjectName(
            'configureConnectionorizontalLayout')

        self.portNameLabel = QtWidgets.QLabel(self)
        self.portNameLabel.setObjectName('portNameLabel')
        self.configCoonLayout.addWidget(self.portNameLabel)

        self.portNameComboBox = SerialPortComboBox(self)
        self.portNameComboBox.setObjectName('portNameComboBox')
        self.portNameComboBox.setMinimumWidth(250)
        self.configCoonLayout.addWidget(self.portNameComboBox)

        self.bitRateLabel = QtWidgets.QLabel(self)
        self.bitRateLabel.setObjectName('bitRateLabel')
        self.configCoonLayout.addWidget(self.bitRateLabel)

        self.bitRatelineEdit = QtWidgets.QLineEdit(self)
        self.bitRatelineEdit.setObjectName('bitRatelineEdit')
        self.bitRatelineEdit.setValidator(
            QtGui.QRegExpValidator(QtCore.QRegExp("^[0-9]*$")))
        self.bitRatelineEdit.setText('115200')
        self.configCoonLayout.addWidget(self.bitRatelineEdit)

        self.parityLabel = QtWidgets.QLabel(self)
        self.parityLabel.setObjectName('parityLabel')
        self.configCoonLayout.addWidget(self.parityLabel)

        self.parityComboBox = QtWidgets.QComboBox(self)
        self.parityComboBox.setObjectName('parityComboBox')
        self.parityComboBox.addItems(serial.PARITY_NAMES.values())
        self.configCoonLayout.addWidget(self.parityComboBox)

        serial.PARITY_NAMES.values()

        self.byteSizeLabel = QtWidgets.QLabel(self)
        self.byteSizeLabel.setObjectName('byteSizeLabel')
        self.configCoonLayout.addWidget(self.byteSizeLabel)

        self.byteSizeComboBox = QtWidgets.QComboBox(self)
        self.byteSizeComboBox.setObjectName('byteSizeComboBox')
        byteSizeList = [
            str(serial.EIGHTBITS),
            str(serial.FIVEBITS),
            str(serial.SIXBITS),
            str(serial.SEVENBITS)
        ]
        self.byteSizeComboBox.addItems(byteSizeList)
        self.configCoonLayout.addWidget(self.byteSizeComboBox)

        self.stopBitsLabel = QtWidgets.QLabel(self)
        self.stopBitsLabel.setObjectName('stopBitsLabel')
        self.configCoonLayout.addWidget(self.stopBitsLabel)

        self.stopBitsComboBox = QtWidgets.QComboBox(self)
        byteStopBitsList = [
            str(serial.STOPBITS_ONE),
            str(serial.STOPBITS_ONE_POINT_FIVE),
            str(serial.STOPBITS_TWO)
        ]
        self.stopBitsComboBox.addItems(byteStopBitsList)
        self.stopBitsComboBox.setObjectName('stopBitsComboBox')
        self.configCoonLayout.addWidget(self.stopBitsComboBox)

        self.connectDisconnectButton = QtWidgets.QPushButton(self)
        self.connectDisconnectButton.setIcon(
            GUIToolKit.getIconByName('connect'))
        self.connectDisconnectButton.setObjectName('connectDeviceButton')
        self.connectDisconnectButton.setText('Connect')
        self.connectDisconnectButton.clicked.connect(
            self.connectDisconnectDeviceAction)

        self.configCoonLayout.addWidget(self.connectDisconnectButton)

        self.portNameLabel.setText('Port Name')
        self.bitRateLabel.setText('Bit rate')
        self.parityLabel.setText('Parity')
        self.byteSizeLabel.setText('Byte size')
        self.stopBitsLabel.setText('Stop bits')

        self.device.addConnectionStateListener(self)
        self.connectionStateChanged(self.device.isConnected)
예제 #24
0
    def __init__(self, parent=None):

        super().__init__(parent)
        self.setMaximumWidth(300)

        onlyFloatInputValidator = QtGui.QRegExpValidator(
            QtCore.QRegExp("[+-]?([0-9]*[.])?[0-9]+"))

        self.device = SimpleFOCDevice.getInstance()

        self.activePID = self.device.PIDVelocity
        self.activeLPF = self.device.LPFVelocity

        self.setObjectName('pidConfigurator')
        self.setTitle('PID Controller configuration')

        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName('gridLayout')

        self.sPidLabel = QtWidgets.QLabel(self)
        self.sPidLabel.setObjectName('pgLabel')
        self.sPidLabel.setText('Select PID')
        self.gridLayout.addWidget(self.sPidLabel, 0, 1, 1, 1)

        self.selectorPIDF = QtWidgets.QComboBox(self)
        self.selectorPIDF.setObjectName('selectPIDF')
        self.selectorPIDF.addItems(
            ['Velocity', 'Angle', 'Current Q', 'Current D'])
        self.selectorPIDF.currentIndexChanged.connect(self.changePIDF)
        self.gridLayout.addWidget(self.selectorPIDF, 0, 2, 1, 1)

        self.pgLabel = QtWidgets.QLabel(self)
        self.pgLabel.setObjectName('pgLabel')
        self.pgLabel.setText('Proportional gain')
        self.gridLayout.addWidget(self.pgLabel, 1, 1, 1, 1)

        self.iglabel = QtWidgets.QLabel(self)
        self.iglabel.setObjectName('iglabel')
        self.iglabel.setText('Integral gain')
        self.gridLayout.addWidget(self.iglabel, 2, 1, 1, 1)

        self.dgLabel = QtWidgets.QLabel(self)
        self.dgLabel.setObjectName('dgLabel')
        self.dgLabel.setText('Derivative gain')
        self.gridLayout.addWidget(self.dgLabel, 3, 1, 1, 1)

        self.vrLabel = QtWidgets.QLabel(self)
        self.vrLabel.setObjectName('vrLabel')
        self.vrLabel.setText('Output ramp')
        self.gridLayout.addWidget(self.vrLabel, 4, 1, 1, 1)

        self.vrLabel = QtWidgets.QLabel(self)
        self.vrLabel.setObjectName('lpfLabel')
        self.vrLabel.setText('Low pass filter')
        self.gridLayout.addWidget(self.vrLabel, 5, 1, 1, 1)

        self.pgLineEdit = ConfigQLineEdit(self)
        self.pgLineEdit.setObjectName('pgLineEdit')
        self.pgLineEdit.setValidator(onlyFloatInputValidator)
        self.pgLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.pgLineEdit.editingFinished.connect(
            self.sendProportionalGainAction)
        self.gridLayout.addWidget(self.pgLineEdit, 1, 2, 1, 1)

        self.igLineEdit = ConfigQLineEdit(self)
        self.igLineEdit.setObjectName('igLineEdit')
        self.igLineEdit.setValidator(onlyFloatInputValidator)
        self.igLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.igLineEdit.editingFinished.connect(self.sendIntegralGainAction)
        self.gridLayout.addWidget(self.igLineEdit, 2, 2, 1, 1)

        self.dgLineEdit = ConfigQLineEdit(self)
        self.dgLineEdit.setObjectName('dgLineEdit')
        self.dgLineEdit.setValidator(onlyFloatInputValidator)
        self.dgLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.dgLineEdit.editingFinished.connect(self.sendDerivativeGainAction)
        self.gridLayout.addWidget(self.dgLineEdit, 3, 2, 1, 1)

        self.vrLineEdit = ConfigQLineEdit(self)
        self.vrLineEdit.setObjectName('vrLineEdit')
        self.vrLineEdit.setValidator(onlyFloatInputValidator)
        self.vrLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.vrLineEdit.editingFinished.connect(self.sendRampAction)
        self.gridLayout.addWidget(self.vrLineEdit, 4, 2, 1, 1)

        self.lpfLineEdit = ConfigQLineEdit(self)
        self.lpfLineEdit.setObjectName('lpfLineEdit')
        self.lpfLineEdit.setValidator(onlyFloatInputValidator)
        self.lpfLineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.lpfLineEdit.editingFinished.connect(self.sendLPFAction)
        self.gridLayout.addWidget(self.lpfLineEdit, 5, 2, 1, 1)

        self.reloadPIDValues()

        # self.setDerivativeGainAction(self.device.derivativeGainPID)
        # self.setProportionalGainAction(self.device.proportionalGainPID)
        # self.setIntegralGainAction(self.device.integralGainPID)
        # self.setVoltageRampAction(self.device.voltageRampPID)

        self.connectionStateChanged(self.device.isConnected)
        self.device.addConnectionStateListener(self)
        self.device.commProvider.commandDataReceived.connect(
            self.commandResponseReceived)