Skip to content

Commit c9c48d4

Browse files
committed
autotune: add vtol FW presets automatically if available
1 parent 7fc2905 commit c9c48d4

File tree

1 file changed

+65
-26
lines changed

1 file changed

+65
-26
lines changed

autotune/data_selection_window.py

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@ class DataSelectionWindow(QDialog):
1313
def __init__(self, filename):
1414
QDialog.__init__(self)
1515

16+
self.preset_candidates = {
17+
'Rollrate': {
18+
'input': 'vehicle_torque_setpoint/xyz[0].0',
19+
'output': 'vehicle_angular_velocity/xyz[0].0',
20+
'input_legacy': 'actuator_controls_0/control[0].0'
21+
},
22+
'Pitchrate': {
23+
'input': 'vehicle_torque_setpoint/xyz[1].0',
24+
'output': 'vehicle_angular_velocity/xyz[1].0',
25+
'input_legacy': 'actuator_controls_0/control[1].0'
26+
},
27+
'Yawrate': {
28+
'input': 'vehicle_torque_setpoint/xyz[2].0',
29+
'output': 'vehicle_angular_velocity/xyz[2].0',
30+
'input_legacy': 'actuator_controls_0/control[2].0'
31+
},
32+
'Rollrate(FW)': {
33+
'input': 'vehicle_torque_setpoint/xyz[0].1',
34+
'output': 'vehicle_angular_velocity/xyz[0].0',
35+
'input_legacy': 'actuator_controls_1/control[0].0'
36+
},
37+
'Pitchrate(FW)': {
38+
'input': 'vehicle_torque_setpoint/xyz[1].1',
39+
'output': 'vehicle_angular_velocity/xyz[1].0',
40+
'input_legacy': 'actuator_controls_1/control[1].0'
41+
},
42+
'Yawrate(FW)': {
43+
'input': 'vehicle_torque_setpoint/xyz[2].1',
44+
'output': 'vehicle_angular_velocity/xyz[2].0',
45+
'input_legacy': 'actuator_controls_1/control[2].0'
46+
}
47+
}
48+
49+
self.presets = {}
50+
1651
self.t = []
1752
self.u = []
1853
self.y = []
@@ -35,8 +70,7 @@ def __init__(self, filename):
3570
in_out_group = QFormLayout()
3671
self.combo_preset = QComboBox()
3772
self.combo_preset.setEditable(False)
38-
self.presets = ['Rollrate', 'Pitchrate', 'Yawrate']
39-
self.combo_preset.addItems(self.presets)
73+
4074
self.combo_preset.currentIndexChanged.connect(self.selectPreset)
4175
in_out_group.addRow(QLabel("Preset:"), self.combo_preset)
4276

@@ -90,9 +124,21 @@ def openFile(self):
90124
self.combo_y.addItems(list_names)
91125

92126
# Trigger preset selection
127+
self.fillPresets()
93128
self.combo_preset.setCurrentIndex(0)
94129
self.selectPreset(0)
95130

131+
def fillPresets(self):
132+
self.combo_preset.clear()
133+
self.presets = {}
134+
135+
for candidate in self.preset_candidates:
136+
(index_u, index_y) = self.findInputOutputIndex(self.preset_candidates[candidate])
137+
if index_u > -1 and index_y > -1:
138+
self.presets[candidate] = self.preset_candidates[candidate]
139+
140+
self.combo_preset.addItems(list(self.presets.keys()))
141+
96142
def printRangeError(self):
97143
msg = QMessageBox()
98144
msg.setIcon(QMessageBox.Critical)
@@ -101,36 +147,29 @@ def printRangeError(self):
101147
msg.exec_()
102148

103149
def selectPreset(self, index):
104-
preset = self.presets[index]
105-
if preset == 'Rollrate':
106-
index_u = self.combo_u.findText("vehicle_torque_setpoint/xyz[0].0")
107-
index_y = self.combo_u.findText("vehicle_angular_velocity/xyz[0].0")
108-
109-
if index_u < 0:
110-
# Look for legacy topic
111-
index_u = self.combo_u.findText("actuator_controls_0/control[0].0")
112-
113-
elif preset == 'Pitchrate':
114-
index_u = self.combo_u.findText("vehicle_torque_setpoint/xyz[1].0")
115-
index_y = self.combo_u.findText("vehicle_angular_velocity/xyz[1].0")
116-
117-
if index_u < 0:
118-
# Look for legacy topic
119-
index_u = self.combo_u.findText("actuator_controls_0/control[1].0")
120-
121-
elif preset == 'Yawrate':
122-
index_u = self.combo_u.findText("vehicle_torque_setpoint/xyz[2].0")
123-
index_y = self.combo_u.findText("vehicle_angular_velocity/xyz[2].0")
124-
125-
if index_u < 0:
126-
# Look for legacy topic
127-
index_u = self.combo_u.findText("actuator_controls_0/control[2].0")
150+
preset_key = list(self.presets.keys())[index]
151+
preset = self.presets[preset_key]
152+
(index_u, index_y) = self.findInputOutputIndex(preset)
128153

129154
if index_u > -1:
130155
self.combo_u.setCurrentIndex(index_u)
131156
if index_y > -1:
132157
self.combo_y.setCurrentIndex(index_y)
133158

159+
def findInputOutputIndex(self, preset):
160+
index_u = self.combo_u.findText(preset['input'])
161+
index_y = self.combo_u.findText(preset['output'])
162+
163+
if index_u < 0 and 'input_legacy' in preset:
164+
# Look for legacy topic
165+
index_u = self.combo_u.findText(preset['input_legacy'])
166+
167+
if index_y < 0 and 'output_legacy' in preset:
168+
# Look for legacy topic
169+
index_y = self.combo_u.findText(preset['output_legacy'])
170+
171+
return (index_u, index_y)
172+
134173
def selectUData(self, index):
135174
self.index_u = index
136175
(self.t, self.u) = self.data_extractor.getPreview(self.topics[index])

0 commit comments

Comments
 (0)