@@ -13,6 +13,41 @@ class DataSelectionWindow(QDialog):
13
13
def __init__ (self , filename ):
14
14
QDialog .__init__ (self )
15
15
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
+
16
51
self .t = []
17
52
self .u = []
18
53
self .y = []
@@ -35,8 +70,7 @@ def __init__(self, filename):
35
70
in_out_group = QFormLayout ()
36
71
self .combo_preset = QComboBox ()
37
72
self .combo_preset .setEditable (False )
38
- self .presets = ['Rollrate' , 'Pitchrate' , 'Yawrate' ]
39
- self .combo_preset .addItems (self .presets )
73
+
40
74
self .combo_preset .currentIndexChanged .connect (self .selectPreset )
41
75
in_out_group .addRow (QLabel ("Preset:" ), self .combo_preset )
42
76
@@ -90,9 +124,21 @@ def openFile(self):
90
124
self .combo_y .addItems (list_names )
91
125
92
126
# Trigger preset selection
127
+ self .fillPresets ()
93
128
self .combo_preset .setCurrentIndex (0 )
94
129
self .selectPreset (0 )
95
130
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
+
96
142
def printRangeError (self ):
97
143
msg = QMessageBox ()
98
144
msg .setIcon (QMessageBox .Critical )
@@ -101,36 +147,29 @@ def printRangeError(self):
101
147
msg .exec_ ()
102
148
103
149
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 )
128
153
129
154
if index_u > - 1 :
130
155
self .combo_u .setCurrentIndex (index_u )
131
156
if index_y > - 1 :
132
157
self .combo_y .setCurrentIndex (index_y )
133
158
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
+
134
173
def selectUData (self , index ):
135
174
self .index_u = index
136
175
(self .t , self .u ) = self .data_extractor .getPreview (self .topics [index ])
0 commit comments