Skip to content

Commit f485925

Browse files
authored
Merge pull request #4 from JorgeMaker/Updated16022021
Updated16022021
2 parents 4822340 + 351c246 commit f485925

22 files changed

+385
-71
lines changed

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"configToolMode": "TreeView"}

device.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
{"proportionalGainPID": "", "integralGainPID": "", "derivativeGainPID": "", "voltageRampPID": "", "lowPassFilter": "", "anglePGain": "", "velocityLimit": "", "voltageLimit": " 2.00", "controlType": 2, "initialTarget": 0, "connectionID": "", "serialPortName": "/dev/cu.usbserial-14130", "serialRate": "115200", "serialByteSize": 8, "serialParity": "N", "stopBits": 1}
1+
{
2+
"anglePGain": " 20.00",
3+
"connectionID": "",
4+
"controlType": 2,
5+
"derivativeGainPID": " 0.00",
6+
"initialTarget": 0,
7+
"integralGainPID": " 20.00",
8+
"lowPassFilter": " 0.20",
9+
"proportionalGainPID": " 0.30",
10+
"serialByteSize": 8,
11+
"serialParity": "N",
12+
"serialPortName": "/dev/cu.usbserial-14140",
13+
"serialRate": "115200",
14+
"stopBits": 1,
15+
"velocityLimit": " 20.00",
16+
"voltageLimit": "4",
17+
"voltageRampPID": " 1000.00"
18+
}

simpleFOCStudio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
if __name__ == '__main__':
1313
try:
1414
logging.basicConfig(filename='.SimpleFOCConfigTool.log', filemode='w',
15-
format='%(name)s - %(levelname)s - %(message)s')
15+
format='%(name)s - %(levelname)s - %(message)s')
1616
app = QtWidgets.QApplication(sys.argv)
1717
mainWindow = QtWidgets.QMainWindow()
1818
userInteractionMainWindow = UserInteractionMainWindow()
1919
userInteractionMainWindow.setupUi(mainWindow)
2020
mainWindow.show()
2121
sys.exit(app.exec_())
22-
except Exception as exception:
23-
logging.error(exception, exc_info=True)
22+
except Exception as exception:\
23+
logging.error(exception, exc_info=True)

src/gui/configtool/controlLoopConfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def __init__(self, parent=None):
3737

3838
self.disableUI()
3939
self.device.addConnectionStateListener(self)
40-
self.device.addCommandResponseListener(self)
40+
self.device.commProvider.commandDataReceived.connect(
41+
self.commandResponseReceived)
4142

4243
self.connectionStateChanged(self.device.isConnected)
4344

@@ -74,5 +75,4 @@ def sendControlLopModeVoltage(self):
7475

7576
def commandResponseReceived(self, cmdRespose):
7677
if 'Control: ' in cmdRespose:
77-
self.setControlLopMode((SimpleFOCDevice.getControlModeCode(cmdRespose.replace('Control: ', ''))))
78-
print("Received: " +cmdRespose.replace('Control: ', ''))
78+
self.setControlLopMode((SimpleFOCDevice.getControlModeCode(cmdRespose.replace('Control: ', ''))))

src/gui/configtool/deviceConfigurationTool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class DeviceConfigurationTool(WorkAreaTabWidget):
1616

17-
def __init__(self, parent=None,simpleFocConn=None):
17+
def __init__(self, parent=None):
1818
super().__init__(parent)
1919

2020
self.device = SimpleFOCDevice.getInstance()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from PyQt5.QtCore import Qt
4+
from PyQt5.QtWidgets import (QVBoxLayout, QFrame, QSplitter)
5+
6+
from src.gui.configtool.graphicWidget import SimpleFOCGraphicWidget
7+
from src.gui.sharedcomnponets.commandLineInterface import CommandLineWidget
8+
from src.simpleFOCConnector import SimpleFOCDevice
9+
10+
11+
class DeviceInteractionFrame(QFrame):
12+
def __init__(self, parent=None):
13+
super().__init__(parent)
14+
15+
self.layout = QVBoxLayout(self)
16+
self.setLayout(self.layout)
17+
self.device = SimpleFOCDevice.getInstance()
18+
19+
self.graphicWidget = SimpleFOCGraphicWidget(self)
20+
self.cmdLineTollWidget = CommandLineWidget(self)
21+
22+
self.cmdLineTollWidget.setMaximumHeight(150)
23+
24+
self.verticalSplitter = QSplitter(Qt.Vertical)
25+
self.verticalSplitter.addWidget(self.graphicWidget)
26+
self.verticalSplitter.addWidget(self.cmdLineTollWidget)
27+
self.device.commProvider.commandDataReceived.connect(
28+
self.cmdLineTollWidget.publishCommandResponseData)
29+
self.layout.addWidget(self.verticalSplitter)
30+
31+
self.setLayout(self.layout)
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from PyQt5 import QtWidgets, QtCore
4+
from PyQt5.Qt import QTreeWidget
5+
6+
from src.gui.sharedcomnponets.sharedcomponets import GUIToolKit
7+
from src.simpleFOCConnector import SimpleFOCDevice
8+
9+
10+
class DeviceTreeView(QTreeWidget):
11+
def __init__(self, parent=None):
12+
super().__init__(parent)
13+
14+
self.device = SimpleFOCDevice.getInstance()
15+
16+
self.sFOCDevice = QtWidgets.QTreeWidgetItem(self)
17+
self.sFOCDevice.setText(0, 'sFOC Device')
18+
self.sFOCDevice.setIcon(0, GUIToolKit.getIconByName('motor'))
19+
20+
self.pidConfiguration = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
21+
self.pidConfiguration.setText(0, 'Pid configuration')
22+
self.pidConfiguration.setIcon(0, GUIToolKit.getIconByName('pidconfig'))
23+
self.sFOCDevice.addChild(self.pidConfiguration)
24+
25+
self.proportionalGain = QtWidgets.QTreeWidgetItem(self.pidConfiguration)
26+
self.proportionalGain.setText(0, 'Proportional gain')
27+
self.proportionalGain.setIcon(0, GUIToolKit.getIconByName('gear'))
28+
self.pidConfiguration.addChild(self.proportionalGain)
29+
self.proportionalValue = QtWidgets.QTreeWidgetItem(self.proportionalGain)
30+
self.proportionalValue.setText(0, '')
31+
self.proportionalValue.setFlags(
32+
self.proportionalValue.flags() | QtCore.Qt.ItemIsEditable)
33+
self.proportionalGain.addChild(self.proportionalValue)
34+
35+
self.integralGain = QtWidgets.QTreeWidgetItem(self.pidConfiguration)
36+
self.integralGain.setText(0, 'Integral gain')
37+
self.integralGain.setIcon(0, GUIToolKit.getIconByName('gear'))
38+
self.pidConfiguration.addChild(self.integralGain)
39+
self.integralGainlValue = QtWidgets.QTreeWidgetItem(self.integralGain)
40+
self.integralGainlValue.setText(0, '')
41+
self.integralGainlValue.setFlags(
42+
self.integralGainlValue.flags() | QtCore.Qt.ItemIsEditable)
43+
self.integralGain.addChild(self.integralGainlValue)
44+
45+
self.derivativeGain = QtWidgets.QTreeWidgetItem(self.pidConfiguration)
46+
self.derivativeGain.setText(0, 'Derivative gain')
47+
self.derivativeGain.setIcon(0, GUIToolKit.getIconByName('gear'))
48+
self.pidConfiguration.addChild(self.derivativeGain)
49+
self.derivativeGainValue = QtWidgets.QTreeWidgetItem(self.derivativeGain)
50+
self.derivativeGainValue.setText(0, '')
51+
self.derivativeGainValue.setFlags(
52+
self.derivativeGainValue.flags() | QtCore.Qt.ItemIsEditable)
53+
self.derivativeGain.addChild(self.derivativeGainValue)
54+
55+
self.voltageRamp = QtWidgets.QTreeWidgetItem(self.pidConfiguration)
56+
self.voltageRamp.setText(0, 'Voltage Ramp')
57+
self.voltageRamp.setIcon(0, GUIToolKit.getIconByName('gear'))
58+
self.pidConfiguration.addChild(self.voltageRamp)
59+
self.voltageRampValue = QtWidgets.QTreeWidgetItem(self.voltageRamp)
60+
self.voltageRampValue.setText(0, '')
61+
self.voltageRampValue.setFlags(
62+
self.voltageRampValue.flags() | QtCore.Qt.ItemIsEditable)
63+
self.voltageRamp.addChild(self.derivativeGainValue)
64+
65+
self.generalStttings = QtWidgets.QTreeWidgetItem(self.sFOCDevice)
66+
self.generalStttings.setText(0, 'General settings')
67+
self.generalStttings.setIcon(0, GUIToolKit.getIconByName('generalsettings'))
68+
self.sFOCDevice.addChild(self.generalStttings)
69+
70+
self.lwpFilter = QtWidgets.QTreeWidgetItem(self.generalStttings)
71+
self.lwpFilter.setText(0, 'Low pass filterRamp')
72+
self.lwpFilter.setIcon(0, GUIToolKit.getIconByName('gear'))
73+
self.generalStttings.addChild(self.lwpFilter)
74+
self.lwpFilterValue = QtWidgets.QTreeWidgetItem(self.lwpFilter)
75+
self.lwpFilterValue.setText(0, '')
76+
self.lwpFilterValue.setFlags(
77+
self.lwpFilterValue.flags() | QtCore.Qt.ItemIsEditable)
78+
self.lwpFilter.addChild(self.lwpFilterValue)
79+
80+
self.pGain = QtWidgets.QTreeWidgetItem(self.generalStttings)
81+
self.pGain.setText(0, 'Prop gain')
82+
self.pGain.setIcon(0, GUIToolKit.getIconByName('gear'))
83+
self.generalStttings.addChild(self.pGain)
84+
self.pGainValue = QtWidgets.QTreeWidgetItem(self.pGain)
85+
self.pGainValue.setText(0, '')
86+
self.pGainValue.setFlags(self.pGainValue.flags() | QtCore.Qt.ItemIsEditable)
87+
self.pGain.addChild(self.pGainValue)
88+
89+
self.veliLimit = QtWidgets.QTreeWidgetItem(self.generalStttings)
90+
self.veliLimit.setText(0, 'Velocity limit')
91+
self.veliLimit.setIcon(0, GUIToolKit.getIconByName('gear'))
92+
self.generalStttings.addChild(self.veliLimit)
93+
self.veliLimitValue = QtWidgets.QTreeWidgetItem(self.veliLimit)
94+
self.veliLimitValue.setText(0, '')
95+
self.veliLimitValue.setFlags(
96+
self.veliLimitValue.flags() | QtCore.Qt.ItemIsEditable)
97+
self.veliLimit.addChild(self.veliLimitValue)
98+
99+
self.voliLimit = QtWidgets.QTreeWidgetItem(self.generalStttings)
100+
self.voliLimit.setText(0, 'Voltage limit')
101+
self.voliLimit.setIcon(0, GUIToolKit.getIconByName('gear'))
102+
self.generalStttings.addChild(self.voliLimit)
103+
self.voliLimitValue = QtWidgets.QTreeWidgetItem(self.voliLimit)
104+
self.voliLimitValue.setText(0, '')
105+
self.voliLimitValue.setFlags(
106+
self.voliLimitValue.flags() | QtCore.Qt.ItemIsEditable)
107+
self.voliLimit.addChild(self.voliLimitValue)
108+
109+
self.setAlternatingRowColors(True)
110+
self.header().hide()
111+
self.expandAll()
112+
113+
self.device.addConnectionStateListener(self)
114+
self.device.commProvider.commandDataReceived.connect(self.commandResponseReceived)
115+
116+
self.itemChanged.connect(self.sendCommand)
117+
118+
119+
self.proportionalValue.setText(0,str(self.device.proportionalGainPID))
120+
self.integralGainlValue.setText(0,str(self.device.integralGainPID))
121+
self.derivativeGainValue.setText(0,str(self.device.derivativeGainPID))
122+
self.voltageRampValue.setText(0,str(self.device.voltageRampPID))
123+
124+
self.lwpFilterValue.setText(0,str(self.device.lowPassFilter))
125+
self.pGainValue.setText(0,str(self.device.anglePGain))
126+
self.veliLimitValue.setText(0,str(self.device.velocityLimit))
127+
self.voliLimitValue.setText(0,str(self.device.voltageLimit))
128+
129+
self.setEnabled(False)
130+
131+
def sendCommand(self, item, column):
132+
value = item.text(0)
133+
fieldName = item.parent().text(0)
134+
if 'Proportional gain' in fieldName:
135+
self.device.sendProportionalGain(value)
136+
elif 'Integral gain' in fieldName:
137+
self.device.sendIntegralGain(value)
138+
elif 'Derivative gain' in fieldName:
139+
self.device.sendDerivativeGain(value)
140+
elif 'Voltage Ramp' in fieldName:
141+
self.device.sendVoltageRamp(value)
142+
elif 'Low pass filterRamp' in fieldName:
143+
self.device.sendLowPassFilter(value)
144+
elif 'Prop gain' in fieldName:
145+
self.device.sendPGain(value)
146+
elif 'Velocity limit' in fieldName:
147+
self.device.sendVelocityLimit(value)
148+
elif 'Voltage limit' in fieldName:
149+
self.device.sendVoltageLimit(value)
150+
151+
def commandResponseReceived(self, comandResponse):
152+
if 'PID velocity| P' in comandResponse:
153+
self.proportionalValue.setText(0,comandResponse.replace('PID velocity| P:', ''))
154+
elif 'PID velocity| I' in comandResponse:
155+
self.integralGainlValue.setText(0,comandResponse.replace('PID velocity| I:', ''))
156+
elif 'PID velocity| D' in comandResponse:
157+
self.derivativeGainValue.setText(0,comandResponse.replace('PID velocity| D:', ''))
158+
elif 'PID velocity| volt_ramp' in comandResponse:
159+
self.voltageRampValue.setText(0,comandResponse.replace('PID velocity| volt_ramp:', ''))
160+
elif 'LPF velocity| Tf:' in comandResponse:
161+
self.lwpFilterValue.setText(0,
162+
comandResponse.replace('LPF velocity| Tf:', ''))
163+
elif 'P angle| P:' in comandResponse:
164+
self.pGainValue.setText(0,
165+
comandResponse.replace('P angle| P:', ''))
166+
elif 'Limits| vel_limit:' in comandResponse:
167+
self.veliLimitValue.setText(0,
168+
comandResponse.replace('Limits| vel_limit:', ''))
169+
elif 'Limits| volt_limit:' in comandResponse:
170+
self.voliLimitValue.setText(0,
171+
comandResponse.replace('Limits| volt_limit:', ''))
172+
self.update()
173+
174+
def connectionStateChanged(self, connectionFlag):
175+
if connectionFlag is True:
176+
self.setEnabled(True)
177+
else:
178+
self.setEnabled(False)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from PyQt5.QtWidgets import (QVBoxLayout, QFrame)
4+
5+
from src.gui.configtool.connectionControl import ConnectionControlGroupBox
6+
from src.gui.configtool.controlLoopConfig import ControlLoopGroupBox
7+
from src.gui.configtool.deviceTreeview import DeviceTreeView
8+
from src.gui.configtool.droDisplayWidget import DROGroupBox
9+
from src.simpleFOCConnector import SimpleFOCDevice
10+
11+
12+
class DevicesInspectorTree(QFrame):
13+
def __init__(self, parent=None):
14+
super().__init__(parent)
15+
self.device = SimpleFOCDevice.getInstance()
16+
17+
self.layout = QVBoxLayout(self)
18+
self.setLayout(self.layout)
19+
20+
self.droWidget = DROGroupBox(self)
21+
self.layout.addWidget(self.droWidget)
22+
23+
self.controlLoopMode = ControlLoopGroupBox(self)
24+
self.layout.addWidget(self.controlLoopMode)
25+
26+
27+
self.treeView = DeviceTreeView(self)
28+
self.layout.addWidget(self.treeView)
29+
30+
self.connectionControl = ConnectionControlGroupBox(self)
31+
self.layout.addWidget(self.connectionControl)
32+
33+
self.setMaximumWidth(430)

src/gui/configtool/droDisplayWidget.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
import logging
4+
35
from PyQt5 import QtGui, QtWidgets
6+
47
from src.gui.sharedcomnponets.sharedcomponets import GUIToolKit
5-
import logging
68
from src.simpleFOCConnector import SimpleFOCDevice
79

10+
811
class DROGroupBox(QtWidgets.QGroupBox):
912

1013
def __init__(self, parent=None):
@@ -50,14 +53,14 @@ def __init__(self, parent=None):
5053

5154
self.device.commProvider.telemetryDataReceived.connect(self.updateDRO)
5255

53-
5456
self.controlTypeChonged(self.device.controlType)
5557

5658
self.initDiplay()
5759
self.disableUI()
5860

5961
self.device.addConnectionStateListener(self)
60-
self.device.addCommandResponseListener(self)
62+
self.device.commProvider.commandDataReceived.connect(
63+
self.commandResponseReceived)
6164

6265
self.connectionStateChanged(self.device.isConnected)
6366

@@ -87,21 +90,21 @@ def initDiplay(self):
8790

8891
def putStyleToLCDNumber(self, lcdNumber):
8992
lcdNumber.setStyleSheet('''QLCDNumber {background-color: white;}''')
90-
palette = self.setColor(lcdNumber.palette(),GUIToolKit.RED_COLOR)
93+
palette = self.setColor(lcdNumber.palette(), GUIToolKit.RED_COLOR)
9194
lcdNumber.setPalette(palette)
9295

9396
def setColor(self, palette, colorTouple):
9497
R = colorTouple[0]
9598
G = colorTouple[1]
9699
B = colorTouple[2]
97100
# foreground color
98-
palette.setColor(palette.WindowText, QtGui.QColor(R,G,B))
101+
palette.setColor(palette.WindowText, QtGui.QColor(R, G, B))
99102
# background color
100-
palette.setColor(palette.Background, QtGui.QColor(R,G,B))
103+
palette.setColor(palette.Background, QtGui.QColor(R, G, B))
101104
# 'light' border
102-
palette.setColor(palette.Light, QtGui.QColor(R,G,B))
105+
palette.setColor(palette.Light, QtGui.QColor(R, G, B))
103106
# 'dark' border
104-
palette.setColor(palette.Dark, QtGui.QColor(R,G,B))
107+
palette.setColor(palette.Dark, QtGui.QColor(R, G, B))
105108
return palette
106109

107110
def setValues(self, values):
@@ -111,7 +114,8 @@ def setValues(self, values):
111114

112115
def updateDRO(self, signal0, signal1, signal2):
113116
try:
114-
if type(signal0) is float and type(signal1) is float and type(signal2) is float:
117+
if type(signal0) is float and type(signal1) is float and type(
118+
signal2) is float:
115119
self.signal0LCDNumber.display(signal0)
116120
self.signal2LCDNumber.display(signal1)
117121
self.signal1LCDNumber.display(signal2)
@@ -124,4 +128,5 @@ def controlTypeChonged(self, controlMode):
124128

125129
def commandResponseReceived(self, cmdRespose):
126130
if 'Control: ' in cmdRespose:
127-
self.controlTypeChonged(SimpleFOCDevice.getControlModeCode(cmdRespose.replace('Control: ', '')))
131+
self.controlTypeChonged(SimpleFOCDevice.getControlModeCode(
132+
cmdRespose.replace('Control: ', '')))

src/gui/configtool/generalSettingsWidget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self, parent=None):
102102
self.setVoltageLimit(self.device.voltageLimit)
103103

104104
self.device.addConnectionStateListener(self)
105-
self.device.addCommandResponseListener(self)
105+
self.device.commProvider.commandDataReceived.connect(self.commandResponseReceived)
106106

107107
self.connectionStateChanged(self.device.isConnected)
108108

0 commit comments

Comments
 (0)