Skip to content

Commit 10ba491

Browse files
committed
autotune: add vtol FW presets automatically if available
1 parent 98149b7 commit 10ba491

1 file changed

Lines changed: 63 additions & 26 deletions

File tree

autotune/data_selection_window.py

Lines changed: 63 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,19 @@ 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+
for candidate in self.preset_candidates:
133+
(index_u, index_y) = self.findInputOutputIndex(self.preset_candidates[candidate])
134+
if index_u > -1 and index_y > -1:
135+
self.presets[candidate] = self.preset_candidates[candidate]
136+
137+
self.combo_preset.clear()
138+
self.combo_preset.addItems(list(self.presets.keys()))
139+
96140
def printRangeError(self):
97141
msg = QMessageBox()
98142
msg.setIcon(QMessageBox.Critical)
@@ -101,36 +145,29 @@ def printRangeError(self):
101145
msg.exec_()
102146

103147
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")
148+
preset_key = list(self.presets.keys())[index]
149+
preset = self.presets[preset_key]
150+
(index_u, index_y) = self.findInputOutputIndex(preset)
128151

129152
if index_u > -1:
130153
self.combo_u.setCurrentIndex(index_u)
131154
if index_y > -1:
132155
self.combo_y.setCurrentIndex(index_y)
133156

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

0 commit comments

Comments
 (0)