|
37 | 37 | """ |
38 | 38 |
|
39 | 39 | import sys |
40 | | -from PyQt5.QtWidgets import QDialog, QApplication, QLabel, QRadioButton, QSlider, QPushButton, QVBoxLayout, QHBoxLayout, QFormLayout, QFileDialog, QLineEdit, QSpinBox, QDoubleSpinBox, QMessageBox, QCheckBox, QTableWidget, QTableWidgetItem, QHeaderView |
| 40 | +from PyQt5.QtWidgets import QDialog, QApplication, QLabel, QRadioButton, QSlider, QPushButton, QVBoxLayout, QHBoxLayout, QFormLayout, QFileDialog, QLineEdit, QSpinBox, QDoubleSpinBox, QMessageBox, QCheckBox, QTableWidget, QTableWidgetItem, QHeaderView, QGroupBox, QComboBox |
41 | 41 | from PyQt5.QtCore import Qt |
42 | 42 |
|
43 | 43 | from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas |
@@ -116,17 +116,34 @@ def __init__(self, parent=None): |
116 | 116 | self.line_edit_delays.setRange(0, 1000) |
117 | 117 | self.line_edit_delays.valueChanged.connect(self.onDelaysChanged) |
118 | 118 | id_params_group.addRow(QLabel("Delays"), self.line_edit_delays) |
| 119 | + input_scale_group = QGroupBox('Input scaling') |
| 120 | + input_scale_group.setToolTip("Scale the input to identify a model at trim airspeed (requires true airspeed data)") |
| 121 | + |
| 122 | + input_scale_form = QFormLayout() |
| 123 | + self.input_scale_combo = QComboBox() |
| 124 | + self.input_scale_combo.setEditable(False) |
| 125 | + self.input_scale_choices = ["True airspeed^2", "True airspeed", "None"] |
| 126 | + self.input_scale_combo.addItems(self.input_scale_choices) |
| 127 | + self.input_scale_combo.setEnabled(False) |
| 128 | + self.input_scale_combo.currentIndexChanged.connect(self.selectInputScale) |
| 129 | + input_scale_form.addRow(self.input_scale_combo) |
| 130 | + |
119 | 131 | self.line_edit_trim = QDoubleSpinBox() |
120 | 132 | self.trim_airspeed = 20.0 |
121 | 133 | self.line_edit_trim.setValue(self.trim_airspeed) |
122 | 134 | self.line_edit_trim.setRange(0.0, 100.0) |
123 | 135 | self.line_edit_trim.textChanged.connect(self.onTrimChanged) |
124 | 136 | self.line_edit_trim.setEnabled(False) |
125 | | - id_params_group.addRow(QLabel("Trim airspeed"), self.line_edit_trim) |
| 137 | + input_scale_form.addRow(QLabel("Trim airspeed"), self.line_edit_trim) |
| 138 | + input_scale_group.setLayout(input_scale_form) |
| 139 | + id_params_group.addRow(input_scale_group) |
| 140 | + |
126 | 141 | self.btn_run_sys_id = QPushButton("Run identification") |
127 | 142 | self.btn_run_sys_id.clicked.connect(self.onSysIdClicked) |
128 | 143 | self.btn_run_sys_id.setEnabled(False) |
| 144 | + |
129 | 145 | id_params_group.addRow(self.btn_run_sys_id) |
| 146 | + |
130 | 147 | left_menu.addLayout(id_params_group) |
131 | 148 |
|
132 | 149 | layout_tf = self.createTfLayout() |
@@ -212,6 +229,10 @@ def updateCoeffTable(self): |
212 | 229 | self.t_coeffs.setFixedHeight(self.t_coeffs.verticalHeader().length() |
213 | 230 | + self.t_coeffs.horizontalHeader().height() + 2) |
214 | 231 |
|
| 232 | + def selectInputScale(self, index): |
| 233 | + self.btn_run_sys_id.setEnabled(True) |
| 234 | + self.plotInputOutput() |
| 235 | + |
215 | 236 | def onModelChanged(self): |
216 | 237 | self.btn_update_model.setEnabled(True) |
217 | 238 |
|
@@ -655,9 +676,21 @@ def plotBode(self, w, mag, w_cl, mag_cl): |
655 | 676 |
|
656 | 677 | def plotInputOutput(self, redraw=False): |
657 | 678 | if len(self.true_airspeed) == len(self.input): |
658 | | - scale = np.array(self.true_airspeed) / self.trim_airspeed |
659 | | - self.u = self.input * scale**2 |
| 679 | + scale = 1 |
| 680 | + |
| 681 | + scale_type = self.input_scale_choices[self.input_scale_combo.currentIndex()] |
| 682 | + if scale_type == "True airspeed": |
| 683 | + scale = np.array(self.true_airspeed) / self.trim_airspeed |
| 684 | + |
| 685 | + elif scale_type == "True airspeed^2": |
| 686 | + scale = (np.array(self.true_airspeed) / self.trim_airspeed)**2 |
| 687 | + |
| 688 | + self.u = self.input * scale |
| 689 | + self.input_scale_combo.setEnabled(True) |
660 | 690 | self.line_edit_trim.setEnabled(True) |
| 691 | + else: |
| 692 | + self.input_scale_combo.setEnabled(False) |
| 693 | + self.line_edit_trim.setEnabled(False) |
661 | 694 |
|
662 | 695 | if self.model_ref is None or redraw: |
663 | 696 | # First time we have no plot reference, so do a normal plot. |
|
0 commit comments